From 34e033d036d049c83e292cea1ba55aaac4861619 Mon Sep 17 00:00:00 2001 From: Keal Jones Date: Wed, 11 Dec 2019 10:55:31 -0700 Subject: [PATCH 1/2] fix tests for redux 7.1.3 --- test/over_react_redux/connect_test.dart | 132 ++++++++++---------- test/over_react_redux/fixtures/counter.dart | 45 +++---- 2 files changed, 89 insertions(+), 88 deletions(-) diff --git a/test/over_react_redux/connect_test.dart b/test/over_react_redux/connect_test.dart index 9fd01e94e..e28e2c7a8 100644 --- a/test/over_react_redux/connect_test.dart +++ b/test/over_react_redux/connect_test.dart @@ -29,7 +29,7 @@ main() { group('connect', () { UiFactory ConnectedCounter; TestJacket jacket; - dynamic counterRef; + Ref counterRef = createRef(); JsConnectOptions connectOptions; var originalConnect = mockableJsConnect; @@ -83,10 +83,10 @@ main() { render( (ReduxProvider()..store = store1)( - (ConnectedCounter()..ref=(ref){counterRef = ref;})('test'), + (ConnectedCounter()..ref = counterRef)('test'), ), ); - expect(getDartComponent(counterRef), isA()); + expect(counterRef.current, isA()); }); }); @@ -98,12 +98,12 @@ main() { jacket = mount( (ReduxProvider()..store = store1)( - (ConnectedCounter()..ref = (ref){ counterRef = ref; })('test'), + (ConnectedCounter()..ref = counterRef)('test'), ), ); - expect(getDartComponent(counterRef).props.currentCount, 0); - expect(jacket.getNode().innerHtml, contains('Count: 0')); + expect(counterRef.current.props.currentCount, 0); + expect(jacket.mountNode.innerHtml, contains('Count: 0')); }); test('after dispatch', () async { @@ -113,21 +113,21 @@ main() { jacket = mount( (ReduxProvider()..store = store1)( - (ConnectedCounter()..ref = (ref){ counterRef = ref; })('test'), + (ConnectedCounter()..ref = counterRef)('test'), ), ); - expect(getDartComponent(counterRef).props.currentCount, 0); - expect(jacket.getNode().innerHtml, contains('Count: 0')); + expect(counterRef.current.props.currentCount, 0); + expect(jacket.mountNode.innerHtml, contains('Count: 0')); - var dispatchButton = getByTestId(jacket.getInstance(), 'button-increment'); + var dispatchButton = queryByTestId(jacket.mountNode, 'button-increment'); click(dispatchButton); // wait for the next tick for the async dispatch to propagate await Future(() {}); - expect(getDartComponent(counterRef).props.currentCount, 1); - expect(jacket.getNode().innerHtml, contains('Count: 1')); + expect(counterRef.current.props.currentCount, 1); + expect(jacket.mountNode.innerHtml, contains('Count: 1')); }); }); @@ -139,12 +139,12 @@ main() { jacket = mount( (ReduxProvider()..store = store1)( - (ConnectedCounter()..ref = (ref){ counterRef = ref; })('test'), + (ConnectedCounter()..ref = counterRef)('test'), ), ); - expect(getDartComponent(counterRef).props.currentCount, 0); - expect(jacket.getNode().innerHtml, contains('Count: 0')); + expect(counterRef.current.props.currentCount, 0); + expect(jacket.mountNode.innerHtml, contains('Count: 0')); }); test('after dispatch', () async { @@ -154,21 +154,21 @@ main() { jacket = mount( (ReduxProvider()..store = store1)( - (ConnectedCounter()..ref = (ref){ counterRef = ref; })('test'), + (ConnectedCounter()..ref = counterRef)('test'), ), ); - expect(getDartComponent(counterRef).props.currentCount, 0); - expect(jacket.getNode().innerHtml, contains('Count: 0')); + expect(counterRef.current.props.currentCount, 0); + expect(jacket.mountNode.innerHtml, contains('Count: 0')); - var dispatchButton = getByTestId(jacket.getInstance(), 'button-increment'); + var dispatchButton = queryByTestId(jacket.mountNode, 'button-increment'); click(dispatchButton); // wait for the next tick for the async dispatch to propagate await Future(() {}); - expect(getDartComponent(counterRef).props.currentCount, 1); - expect(jacket.getNode().innerHtml, contains('Count: 1')); + expect(counterRef.current.props.currentCount, 1); + expect(jacket.mountNode.innerHtml, contains('Count: 1')); }); }); @@ -187,24 +187,24 @@ main() { jacket = mount( (ReduxProvider()..store = store1)( - (ConnectedCounter()..ref = (ref){ counterRef = ref; })('test'), + (ConnectedCounter()..ref = counterRef)('test'), ), ); - expect(getDartComponent(counterRef).props.decrement, isA()); + expect(counterRef.current.props.decrement, isA()); - expect(getDartComponent(counterRef).props.currentCount, 0); - expect(jacket.getNode().innerHtml, contains('Count: 0')); + expect(counterRef.current.props.currentCount, 0); + expect(jacket.mountNode.innerHtml, contains('Count: 0')); // Click button mapped to trigger `propFromDispatch` prop. - var dispatchButton = getByTestId(jacket.getInstance(), 'button-decrement'); + var dispatchButton = queryByTestId(jacket.mountNode, 'button-decrement'); click(dispatchButton); // wait for the next tick for the async dispatch to propagate await Future(() {}); - expect(getDartComponent(counterRef).props.currentCount, -1); - expect(jacket.getNode().innerHtml, contains('Count: -1')); + expect(counterRef.current.props.currentCount, -1); + expect(jacket.mountNode.innerHtml, contains('Count: -1')); }); }); @@ -223,24 +223,24 @@ main() { jacket = mount( (ReduxProvider()..store = store1)( - (ConnectedCounter()..ref = (ref){ counterRef = ref; })('test'), + (ConnectedCounter()..ref = counterRef)('test'), ), ); - expect(getDartComponent(counterRef).props.decrement, isA()); + expect(counterRef.current.props.decrement, isA()); - expect(getDartComponent(counterRef).props.currentCount, 0); - expect(jacket.getNode().innerHtml, contains('Count: 0')); + expect(counterRef.current.props.currentCount, 0); + expect(jacket.mountNode.innerHtml, contains('Count: 0')); // Click button mapped to trigger `propFromDispatch` prop. - var dispatchButton = getByTestId(jacket.getInstance(), 'button-decrement'); + var dispatchButton = queryByTestId(jacket.mountNode, 'button-decrement'); click(dispatchButton); // wait for the next tick for the async dispatch to propagate await Future(() {}); - expect(getDartComponent(counterRef).props.currentCount, -1); - expect(jacket.getNode().innerHtml, contains('Count: -1')); + expect(counterRef.current.props.currentCount, -1); + expect(jacket.mountNode.innerHtml, contains('Count: -1')); }); }); @@ -268,7 +268,7 @@ main() { jacket = mount( (ReduxProvider()..store = store1)( (ConnectedCounter() - ..ref = (ref){ counterRef = ref; } + ..ref = counterRef // make `decrement` increment ..decrement = () {store1.dispatch(IncrementAction());} ..currentCount = 900 @@ -276,13 +276,13 @@ main() { ), ); // `button-decrement` will be incrementing now - var dispatchButton = getByTestId(jacket.getInstance(), 'button-decrement'); + var dispatchButton = queryByTestId(jacket.mountNode, 'button-decrement'); - expect(getDartComponent(counterRef).props.decrement, isA()); + expect(counterRef.current.props.decrement, isA()); // state.count is at 0 - expect(getDartComponent(counterRef).props.currentCount, 900); - expect(jacket.getNode().innerHtml, contains('Count: 900')); + expect(counterRef.current.props.currentCount, 900); + expect(jacket.mountNode.innerHtml, contains('Count: 900')); // Click button mapped to trigger `propFromDispatch` prop. click(dispatchButton); // state.count is now equal to 1 @@ -290,8 +290,8 @@ main() { // wait for the next tick for the async dispatch to propagate await Future(() {}); - expect(getDartComponent(counterRef).props.currentCount, 1); - expect(jacket.getNode().innerHtml, contains('Count: 1')); + expect(counterRef.current.props.currentCount, 1); + expect(jacket.mountNode.innerHtml, contains('Count: 1')); }); }); @@ -299,13 +299,13 @@ main() { group('areOwnPropsEqual', () { test('', () { ConnectedCounter = connect( - areOwnPropsEqual: expectAsync2((next, prev) { + areOwnPropsEqual: (next, prev) { expect(next, isA()); expect(prev, isA()); expect(next.id, 'test'); expect(prev.id, 'test2'); return true; - }), + }, )(Counter); var whatever = connectOptions.areOwnPropsEqual( @@ -328,9 +328,8 @@ main() { areStatePropsEqual: (next, prev) { expect(next, isA()); expect(prev, isA()); - expect(next.currentCount, 1); methodsCalled.add('areStatePropsEqual'); - // Force it to always be true, meaing it shouldnt re-render if they change. + // Force it to always betrue, meaing it shouldnt re-render if they change. return true; }, forwardRef: true, @@ -338,13 +337,13 @@ main() { jacket = mount( (ReduxProvider()..store = store1)( - (ConnectedCounter()..ref = (ref){ counterRef = ref; }..currentCount = 0)('test'), + (ConnectedCounter()..ref = counterRef..currentCount = 0)('test'), ), ); expect(methodsCalled, ['mapStateToProps']); methodsCalled.clear(); - var dispatchButton = getByTestId(jacket.getInstance(), 'button-increment'); + var dispatchButton = queryByTestId(jacket.mountNode, 'button-increment'); click(dispatchButton); // wait for the next tick for the async dispatch to propagate @@ -353,20 +352,20 @@ main() { // store.state.count should be 1 but does not re-render due to override in `areStatePropsEqual` expect(methodsCalled, ['mapStateToProps', 'areStatePropsEqual']); - expect(jacket.getNode().innerHtml, contains('Count: 0')); + expect(jacket.mountNode.innerHtml, contains('Count: 0')); }); }); group('areMergedPropsEqual', () { test('', () { ConnectedCounter = connect( - areMergedPropsEqual: expectAsync2((next, prev) { + areMergedPropsEqual: (next, prev) { expect(next, isA()); expect(prev, isA()); expect(next.id, 'test'); expect(prev.id, 'test2'); return true; - }), + }, pure: false, )(Counter); @@ -398,24 +397,23 @@ main() { jacket = mount( (ReduxProvider()..store = store1)( - (ConnectedCounter()..ref = (ref){ counterRef = ref; }..currentCount = 0)('test'), + (ConnectedCounter()..ref = counterRef..currentCount = 0)('test'), ), ); - // `mapStateToProps` is called once, - // then `areStatesEqual` shows up 2 times due to `initialState`. - expect(methodsCalled, ['mapStateToProps', 'areStatesEqual', 'areStatesEqual']); + expect(methodsCalled, ['mapStateToProps', 'areStatesEqual']); methodsCalled.clear(); - var dispatchButton = getByTestId(jacket.getInstance(), 'button-increment'); + var dispatchButton = queryByTestId(jacket.mountNode, 'button-increment'); click(dispatchButton); // wait for the next tick for the async dispatch to propagate await Future(() {}); - // only checks `areStatesEqual` and does not call `mapStateToProps` since it returned `true`. - expect(methodsCalled, ['areStatesEqual']); - expect(jacket.getNode().innerHtml, contains('Count: 0')); + // only calls `areStatesEqual` and does not call `mapStateToProps` since it returned `true`. + expect(methodsCalled, isNot(contains('mapStateToProps'))); + expect(methodsCalled, contains('areStatesEqual')); + expect(jacket.mountNode.innerHtml, contains('Count: 0')); }); }); }); @@ -449,13 +447,13 @@ main() { ), )); - var bigCounter = getDartComponent(getByTestId(jacket.getInstance(), 'big-counter')); - var dispatchButton = queryByTestId(findDomNode(bigCounter), 'button-increment'); + var bigCounter = queryByTestId(jacket.mountNode, 'big-counter'); + var dispatchButton = queryByTestId(bigCounter, 'button-increment'); click(dispatchButton); await Future((){}); - expect(findDomNode(bigCounter).innerHtml, contains('Count: 100')); + expect(bigCounter.innerHtml, contains('Count: 100')); }); test('correctly renderes when contexts are nested', () async { @@ -492,11 +490,11 @@ main() { ) ); - var bigCounter = getDartComponent(getByTestId(jacket.getInstance(), 'big-counter')); - var smallCounter = getDartComponent(getByTestId(jacket.getInstance(), 'small-counter')); + var bigCounter = queryByTestId(jacket.mountNode, 'big-counter'); + var smallCounter = queryByTestId(jacket.mountNode, 'small-counter'); - var smallDispatchButton = queryByTestId(findDomNode(smallCounter), 'button-increment'); - var dispatchButton = queryByTestId(findDomNode(bigCounter), 'button-increment'); + var smallDispatchButton = queryByTestId(smallCounter, 'button-increment'); + var dispatchButton = queryByTestId(bigCounter, 'button-increment'); click(dispatchButton); click(smallDispatchButton); @@ -507,7 +505,7 @@ main() { expect(findDomNode(bigCounter).innerHtml, contains('Count: 100'), reason: 'Should have a count of 100'); // Normal counter incremented only 1 at both instances - expect(findDomNode(getByTestId(jacket.getInstance(), 'outside')).innerHtml, contains('Count: 1')); + expect(findDomNode(queryByTestId(jacket.mountNode, 'outside')).innerHtml, contains('Count: 1')); expect(findDomNode(bigCounter).innerHtml, contains('Count: 1')); }); }); diff --git a/test/over_react_redux/fixtures/counter.dart b/test/over_react_redux/fixtures/counter.dart index 06ccc880d..5a07b81e1 100644 --- a/test/over_react_redux/fixtures/counter.dart +++ b/test/over_react_redux/fixtures/counter.dart @@ -22,29 +22,32 @@ class _$CounterProps extends UiProps with ConnectPropsMixin { class CounterComponent extends UiComponent2 { @override render() { - return (Dom.div()..style = props.wrapperStyles)( - Dom.div()('Count: ${props.currentCount}'), - (Dom.button() - ..addTestId('button-increment') - ..onClick = (_) { - if (props.increment != null) { - props.increment(); - } else if (props.dispatch != null) { - props.dispatch(IncrementAction()); - } + return (Dom.div() + ..modifyProps(addUnconsumedProps) + ..style = props.wrapperStyles + )( + Dom.div()('Count: ${props.currentCount}'), + (Dom.button() + ..addTestId('button-increment') + ..onClick = (_) { + if (props.increment != null) { + props.increment(); + } else if (props.dispatch != null) { + props.dispatch(IncrementAction()); } - )('+'), - (Dom.button() - ..addTestId('button-decrement') - ..onClick = (_) { - if (props.decrement != null) { - props.decrement(); - } else if (props.dispatch != null) { - props.dispatch(DecrementAction()); - } + } + )('+'), + (Dom.button() + ..addTestId('button-decrement') + ..onClick = (_) { + if (props.decrement != null) { + props.decrement(); + } else if (props.dispatch != null) { + props.dispatch(DecrementAction()); } - )('-'), - props.children + } + )('-'), + props.children ); } } From 2cc43793487194f355419e45b0eb1124212ece40 Mon Sep 17 00:00:00 2001 From: Keal Jones Date: Wed, 11 Dec 2019 12:55:16 -0700 Subject: [PATCH 2/2] address cr feedback --- test/over_react_redux/connect_test.dart | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/test/over_react_redux/connect_test.dart b/test/over_react_redux/connect_test.dart index e28e2c7a8..c4ac9c28e 100644 --- a/test/over_react_redux/connect_test.dart +++ b/test/over_react_redux/connect_test.dart @@ -29,7 +29,7 @@ main() { group('connect', () { UiFactory ConnectedCounter; TestJacket jacket; - Ref counterRef = createRef(); + final counterRef = createRef(); JsConnectOptions connectOptions; var originalConnect = mockableJsConnect; @@ -299,13 +299,13 @@ main() { group('areOwnPropsEqual', () { test('', () { ConnectedCounter = connect( - areOwnPropsEqual: (next, prev) { + areOwnPropsEqual: expectAsync2((next, prev) { expect(next, isA()); expect(prev, isA()); expect(next.id, 'test'); expect(prev.id, 'test2'); return true; - }, + }), )(Counter); var whatever = connectOptions.areOwnPropsEqual( @@ -329,7 +329,7 @@ main() { expect(next, isA()); expect(prev, isA()); methodsCalled.add('areStatePropsEqual'); - // Force it to always betrue, meaing it shouldnt re-render if they change. + // Force it to always be true, meaing it shouldnt re-render if they change. return true; }, forwardRef: true, @@ -359,13 +359,13 @@ main() { group('areMergedPropsEqual', () { test('', () { ConnectedCounter = connect( - areMergedPropsEqual: (next, prev) { + areMergedPropsEqual: expectAsync2((next, prev) { expect(next, isA()); expect(prev, isA()); expect(next.id, 'test'); expect(prev.id, 'test2'); return true; - }, + }), pure: false, )(Counter); @@ -401,7 +401,8 @@ main() { ), ); - expect(methodsCalled, ['mapStateToProps', 'areStatesEqual']); + expect(methodsCalled, contains('mapStateToProps')); + expect(methodsCalled, contains('areStatesEqual')); methodsCalled.clear(); var dispatchButton = queryByTestId(jacket.mountNode, 'button-increment');