@@ -42,7 +42,7 @@ void main() {
4242
4343 testWidgets ('should update the children if the store changes' ,
4444 (WidgetTester tester) async {
45- Widget widget ([ String state] ) {
45+ Widget widget (String state) {
4646 return StoreProvider <String >(
4747 store: Store <String >(
4848 identityReducer,
@@ -487,14 +487,139 @@ void main() {
487487
488488 expect (numBuilds, 1 );
489489
490- // Dispatch another action of a different type. This should trigger another
491- // rebuild
490+ // Dispatch another action of a different type. This should trigger
491+ // another rebuild
492492 store.dispatch ('A' );
493493
494494 await tester.pumpWidget (widget);
495495
496496 expect (numBuilds, 2 );
497497 });
498+
499+ group ('Updates' , () {
500+ testWidgets (
501+ 'converter update results in proper rebuild' ,
502+ (WidgetTester tester) async {
503+ String currentState;
504+ final store = Store <String >(
505+ identityReducer,
506+ initialState: 'I' ,
507+ );
508+ Widget widget ([StoreConverter <String , String > converter = selector]) {
509+ return StoreProvider <String >(
510+ store: store,
511+ child: StoreConnector <String , String >(
512+ converter: converter,
513+ onInit: (store) => store.dispatch ('A' ),
514+ builder: (context, vm) {
515+ currentState = vm;
516+ return Container ();
517+ },
518+ ),
519+ );
520+ }
521+
522+ // Build the widget with the initial state
523+ await tester.pumpWidget (widget ());
524+
525+ // Expect the Widget to be rebuilt and the onInit method to be called
526+ expect (currentState, 'A' );
527+
528+ // Rebuild the widget with a new converter
529+ await tester.pumpWidget (widget ((Store <String > s) => 'B' ));
530+
531+ // Expect the Widget to be rebuilt and the converter should be rerun
532+ expect (currentState, 'B' );
533+ },
534+ );
535+
536+ testWidgets (
537+ 'onDidChange works as expected' ,
538+ (WidgetTester tester) async {
539+ String currentState;
540+ final store = Store <String >(
541+ identityReducer,
542+ initialState: 'I' ,
543+ );
544+ Widget widget ([void Function (String viewModel) onDidChange]) {
545+ return StoreProvider <String >(
546+ store: store,
547+ child: StoreConnector <String , String >(
548+ converter: selector,
549+ onDidChange: onDidChange,
550+ onInit: (store) => store.dispatch ('A' ),
551+ builder: (context, vm) {
552+ return Container ();
553+ },
554+ ),
555+ );
556+ }
557+
558+ // Build the widget with the initial state
559+ await tester.pumpWidget (widget ());
560+
561+ // No onDidChange function to run, so currentState should be null
562+ expect (currentState, isNull);
563+
564+ // Build the widget with a new onDidChange
565+ final newWidget = widget ((_) => currentState = 'S' );
566+ await tester.pumpWidget (newWidget);
567+
568+ // Dispatch a new value, which should cause onDidChange to run
569+ store.dispatch ('B' );
570+
571+ // Run pumpWidget, which should flush the after build (didChange)
572+ // callbacks
573+ await tester.pumpWidget (newWidget);
574+
575+ // Expect our new onDidChange to run
576+ expect (currentState, 'S' );
577+ },
578+ );
579+ testWidgets (
580+ 'onWillChange works as expected' ,
581+ (WidgetTester tester) async {
582+ String currentState;
583+ final store = Store <String >(
584+ identityReducer,
585+ initialState: 'I' ,
586+ );
587+ Widget widget ([void Function (String viewModel) onWillChange]) {
588+ return StoreProvider <String >(
589+ store: store,
590+ child: StoreConnector <String , String >(
591+ converter: selector,
592+ onWillChange: onWillChange,
593+ onInit: (store) => store.dispatch ('A' ),
594+ builder: (context, vm) {
595+ return Container ();
596+ },
597+ ),
598+ );
599+ }
600+
601+ // Build the widget with the initial state
602+ await tester.pumpWidget (widget ());
603+
604+ // No onWillChange function to run, so currentState should be null
605+ expect (currentState, isNull);
606+
607+ // Build the widget with a new onWillChange
608+ final newWidget = widget ((_) => currentState = 'S' );
609+ await tester.pumpWidget (newWidget);
610+
611+ // Dispatch a new value, which should cause onWillChange to run
612+ store.dispatch ('B' );
613+
614+ // Run pumpWidget, which should flush the after build (didChange)
615+ // callbacks
616+ await tester.pumpWidget (newWidget);
617+
618+ // Expect our new onWillChange to run
619+ expect (currentState, 'S' );
620+ },
621+ );
622+ });
498623 });
499624
500625 group ('StoreBuilder' , () {
0 commit comments