Skip to content

Commit b3e73a9

Browse files
authored
Merge pull request #440 from Workiva/fix-over_react_redux-tests-redux-7.1.3
CPLAT-8834 fix tests for redux 7.1.3
2 parents 3cb8efd + 2cc4379 commit b3e73a9

File tree

2 files changed

+85
-83
lines changed

2 files changed

+85
-83
lines changed

test/over_react_redux/connect_test.dart

+61-62
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ main() {
2929
group('connect', () {
3030
UiFactory<CounterProps> ConnectedCounter;
3131
TestJacket<CounterComponent> jacket;
32-
dynamic counterRef;
32+
final counterRef = createRef<CounterComponent>();
3333

3434
JsConnectOptions connectOptions;
3535
var originalConnect = mockableJsConnect;
@@ -83,10 +83,10 @@ main() {
8383

8484
render(
8585
(ReduxProvider()..store = store1)(
86-
(ConnectedCounter()..ref=(ref){counterRef = ref;})('test'),
86+
(ConnectedCounter()..ref = counterRef)('test'),
8787
),
8888
);
89-
expect(getDartComponent(counterRef), isA<CounterComponent>());
89+
expect(counterRef.current, isA<CounterComponent>());
9090
});
9191
});
9292

@@ -98,12 +98,12 @@ main() {
9898

9999
jacket = mount(
100100
(ReduxProvider()..store = store1)(
101-
(ConnectedCounter()..ref = (ref){ counterRef = ref; })('test'),
101+
(ConnectedCounter()..ref = counterRef)('test'),
102102
),
103103
);
104104

105-
expect(getDartComponent<CounterComponent>(counterRef).props.currentCount, 0);
106-
expect(jacket.getNode().innerHtml, contains('Count: 0'));
105+
expect(counterRef.current.props.currentCount, 0);
106+
expect(jacket.mountNode.innerHtml, contains('Count: 0'));
107107
});
108108

109109
test('after dispatch', () async {
@@ -113,21 +113,21 @@ main() {
113113

114114
jacket = mount(
115115
(ReduxProvider()..store = store1)(
116-
(ConnectedCounter()..ref = (ref){ counterRef = ref; })('test'),
116+
(ConnectedCounter()..ref = counterRef)('test'),
117117
),
118118
);
119119

120-
expect(getDartComponent<CounterComponent>(counterRef).props.currentCount, 0);
121-
expect(jacket.getNode().innerHtml, contains('Count: 0'));
120+
expect(counterRef.current.props.currentCount, 0);
121+
expect(jacket.mountNode.innerHtml, contains('Count: 0'));
122122

123-
var dispatchButton = getByTestId(jacket.getInstance(), 'button-increment');
123+
var dispatchButton = queryByTestId(jacket.mountNode, 'button-increment');
124124
click(dispatchButton);
125125

126126
// wait for the next tick for the async dispatch to propagate
127127
await Future(() {});
128128

129-
expect(getDartComponent<CounterComponent>(counterRef).props.currentCount, 1);
130-
expect(jacket.getNode().innerHtml, contains('Count: 1'));
129+
expect(counterRef.current.props.currentCount, 1);
130+
expect(jacket.mountNode.innerHtml, contains('Count: 1'));
131131
});
132132
});
133133

@@ -139,12 +139,12 @@ main() {
139139

140140
jacket = mount(
141141
(ReduxProvider()..store = store1)(
142-
(ConnectedCounter()..ref = (ref){ counterRef = ref; })('test'),
142+
(ConnectedCounter()..ref = counterRef)('test'),
143143
),
144144
);
145145

146-
expect(getDartComponent<CounterComponent>(counterRef).props.currentCount, 0);
147-
expect(jacket.getNode().innerHtml, contains('Count: 0'));
146+
expect(counterRef.current.props.currentCount, 0);
147+
expect(jacket.mountNode.innerHtml, contains('Count: 0'));
148148
});
149149

150150
test('after dispatch', () async {
@@ -154,21 +154,21 @@ main() {
154154

155155
jacket = mount(
156156
(ReduxProvider()..store = store1)(
157-
(ConnectedCounter()..ref = (ref){ counterRef = ref; })('test'),
157+
(ConnectedCounter()..ref = counterRef)('test'),
158158
),
159159
);
160160

161-
expect(getDartComponent<CounterComponent>(counterRef).props.currentCount, 0);
162-
expect(jacket.getNode().innerHtml, contains('Count: 0'));
161+
expect(counterRef.current.props.currentCount, 0);
162+
expect(jacket.mountNode.innerHtml, contains('Count: 0'));
163163

164-
var dispatchButton = getByTestId(jacket.getInstance(), 'button-increment');
164+
var dispatchButton = queryByTestId(jacket.mountNode, 'button-increment');
165165
click(dispatchButton);
166166

167167
// wait for the next tick for the async dispatch to propagate
168168
await Future(() {});
169169

170-
expect(getDartComponent<CounterComponent>(counterRef).props.currentCount, 1);
171-
expect(jacket.getNode().innerHtml, contains('Count: 1'));
170+
expect(counterRef.current.props.currentCount, 1);
171+
expect(jacket.mountNode.innerHtml, contains('Count: 1'));
172172
});
173173
});
174174

@@ -187,24 +187,24 @@ main() {
187187

188188
jacket = mount(
189189
(ReduxProvider()..store = store1)(
190-
(ConnectedCounter()..ref = (ref){ counterRef = ref; })('test'),
190+
(ConnectedCounter()..ref = counterRef)('test'),
191191
),
192192
);
193193

194-
expect(getDartComponent<CounterComponent>(counterRef).props.decrement, isA<Function>());
194+
expect(counterRef.current.props.decrement, isA<Function>());
195195

196-
expect(getDartComponent<CounterComponent>(counterRef).props.currentCount, 0);
197-
expect(jacket.getNode().innerHtml, contains('Count: 0'));
196+
expect(counterRef.current.props.currentCount, 0);
197+
expect(jacket.mountNode.innerHtml, contains('Count: 0'));
198198

199199
// Click button mapped to trigger `propFromDispatch` prop.
200-
var dispatchButton = getByTestId(jacket.getInstance(), 'button-decrement');
200+
var dispatchButton = queryByTestId(jacket.mountNode, 'button-decrement');
201201
click(dispatchButton);
202202

203203
// wait for the next tick for the async dispatch to propagate
204204
await Future(() {});
205205

206-
expect(getDartComponent<CounterComponent>(counterRef).props.currentCount, -1);
207-
expect(jacket.getNode().innerHtml, contains('Count: -1'));
206+
expect(counterRef.current.props.currentCount, -1);
207+
expect(jacket.mountNode.innerHtml, contains('Count: -1'));
208208
});
209209
});
210210

@@ -223,24 +223,24 @@ main() {
223223

224224
jacket = mount(
225225
(ReduxProvider()..store = store1)(
226-
(ConnectedCounter()..ref = (ref){ counterRef = ref; })('test'),
226+
(ConnectedCounter()..ref = counterRef)('test'),
227227
),
228228
);
229229

230-
expect(getDartComponent<CounterComponent>(counterRef).props.decrement, isA<Function>());
230+
expect(counterRef.current.props.decrement, isA<Function>());
231231

232-
expect(getDartComponent<CounterComponent>(counterRef).props.currentCount, 0);
233-
expect(jacket.getNode().innerHtml, contains('Count: 0'));
232+
expect(counterRef.current.props.currentCount, 0);
233+
expect(jacket.mountNode.innerHtml, contains('Count: 0'));
234234

235235
// Click button mapped to trigger `propFromDispatch` prop.
236-
var dispatchButton = getByTestId(jacket.getInstance(), 'button-decrement');
236+
var dispatchButton = queryByTestId(jacket.mountNode, 'button-decrement');
237237
click(dispatchButton);
238238

239239
// wait for the next tick for the async dispatch to propagate
240240
await Future(() {});
241241

242-
expect(getDartComponent<CounterComponent>(counterRef).props.currentCount, -1);
243-
expect(jacket.getNode().innerHtml, contains('Count: -1'));
242+
expect(counterRef.current.props.currentCount, -1);
243+
expect(jacket.mountNode.innerHtml, contains('Count: -1'));
244244
});
245245
});
246246

@@ -268,30 +268,30 @@ main() {
268268
jacket = mount(
269269
(ReduxProvider()..store = store1)(
270270
(ConnectedCounter()
271-
..ref = (ref){ counterRef = ref; }
271+
..ref = counterRef
272272
// make `decrement` increment
273273
..decrement = () {store1.dispatch(IncrementAction());}
274274
..currentCount = 900
275275
)('test'),
276276
),
277277
);
278278
// `button-decrement` will be incrementing now
279-
var dispatchButton = getByTestId(jacket.getInstance(), 'button-decrement');
279+
var dispatchButton = queryByTestId(jacket.mountNode, 'button-decrement');
280280

281-
expect(getDartComponent<CounterComponent>(counterRef).props.decrement, isA<Function>());
281+
expect(counterRef.current.props.decrement, isA<Function>());
282282

283283
// state.count is at 0
284-
expect(getDartComponent<CounterComponent>(counterRef).props.currentCount, 900);
285-
expect(jacket.getNode().innerHtml, contains('Count: 900'));
284+
expect(counterRef.current.props.currentCount, 900);
285+
expect(jacket.mountNode.innerHtml, contains('Count: 900'));
286286

287287
// Click button mapped to trigger `propFromDispatch` prop.
288288
click(dispatchButton); // state.count is now equal to 1
289289

290290
// wait for the next tick for the async dispatch to propagate
291291
await Future(() {});
292292

293-
expect(getDartComponent<CounterComponent>(counterRef).props.currentCount, 1);
294-
expect(jacket.getNode().innerHtml, contains('Count: 1'));
293+
expect(counterRef.current.props.currentCount, 1);
294+
expect(jacket.mountNode.innerHtml, contains('Count: 1'));
295295
});
296296
});
297297

@@ -328,7 +328,6 @@ main() {
328328
areStatePropsEqual: (next, prev) {
329329
expect(next, isA<CounterProps>());
330330
expect(prev, isA<CounterProps>());
331-
expect(next.currentCount, 1);
332331
methodsCalled.add('areStatePropsEqual');
333332
// Force it to always be true, meaing it shouldnt re-render if they change.
334333
return true;
@@ -338,13 +337,13 @@ main() {
338337

339338
jacket = mount(
340339
(ReduxProvider()..store = store1)(
341-
(ConnectedCounter()..ref = (ref){ counterRef = ref; }..currentCount = 0)('test'),
340+
(ConnectedCounter()..ref = counterRef..currentCount = 0)('test'),
342341
),
343342
);
344343
expect(methodsCalled, ['mapStateToProps']);
345344
methodsCalled.clear();
346345

347-
var dispatchButton = getByTestId(jacket.getInstance(), 'button-increment');
346+
var dispatchButton = queryByTestId(jacket.mountNode, 'button-increment');
348347
click(dispatchButton);
349348

350349
// wait for the next tick for the async dispatch to propagate
@@ -353,7 +352,7 @@ main() {
353352
// store.state.count should be 1 but does not re-render due to override in `areStatePropsEqual`
354353

355354
expect(methodsCalled, ['mapStateToProps', 'areStatePropsEqual']);
356-
expect(jacket.getNode().innerHtml, contains('Count: 0'));
355+
expect(jacket.mountNode.innerHtml, contains('Count: 0'));
357356
});
358357
});
359358

@@ -398,24 +397,24 @@ main() {
398397

399398
jacket = mount(
400399
(ReduxProvider()..store = store1)(
401-
(ConnectedCounter()..ref = (ref){ counterRef = ref; }..currentCount = 0)('test'),
400+
(ConnectedCounter()..ref = counterRef..currentCount = 0)('test'),
402401
),
403402
);
404403

405-
// `mapStateToProps` is called once,
406-
// then `areStatesEqual` shows up 2 times due to `initialState`.
407-
expect(methodsCalled, ['mapStateToProps', 'areStatesEqual', 'areStatesEqual']);
404+
expect(methodsCalled, contains('mapStateToProps'));
405+
expect(methodsCalled, contains('areStatesEqual'));
408406
methodsCalled.clear();
409407

410-
var dispatchButton = getByTestId(jacket.getInstance(), 'button-increment');
408+
var dispatchButton = queryByTestId(jacket.mountNode, 'button-increment');
411409
click(dispatchButton);
412410

413411
// wait for the next tick for the async dispatch to propagate
414412
await Future(() {});
415413

416-
// only checks `areStatesEqual` and does not call `mapStateToProps` since it returned `true`.
417-
expect(methodsCalled, ['areStatesEqual']);
418-
expect(jacket.getNode().innerHtml, contains('Count: 0'));
414+
// only calls `areStatesEqual` and does not call `mapStateToProps` since it returned `true`.
415+
expect(methodsCalled, isNot(contains('mapStateToProps')));
416+
expect(methodsCalled, contains('areStatesEqual'));
417+
expect(jacket.mountNode.innerHtml, contains('Count: 0'));
419418
});
420419
});
421420
});
@@ -449,13 +448,13 @@ main() {
449448
),
450449
));
451450

452-
var bigCounter = getDartComponent(getByTestId(jacket.getInstance(), 'big-counter'));
453-
var dispatchButton = queryByTestId(findDomNode(bigCounter), 'button-increment');
451+
var bigCounter = queryByTestId(jacket.mountNode, 'big-counter');
452+
var dispatchButton = queryByTestId(bigCounter, 'button-increment');
454453
click(dispatchButton);
455454

456455
await Future((){});
457456

458-
expect(findDomNode(bigCounter).innerHtml, contains('Count: 100'));
457+
expect(bigCounter.innerHtml, contains('Count: 100'));
459458
});
460459

461460
test('correctly renderes when contexts are nested', () async {
@@ -492,11 +491,11 @@ main() {
492491
)
493492
);
494493

495-
var bigCounter = getDartComponent(getByTestId(jacket.getInstance(), 'big-counter'));
496-
var smallCounter = getDartComponent(getByTestId(jacket.getInstance(), 'small-counter'));
494+
var bigCounter = queryByTestId(jacket.mountNode, 'big-counter');
495+
var smallCounter = queryByTestId(jacket.mountNode, 'small-counter');
497496

498-
var smallDispatchButton = queryByTestId(findDomNode(smallCounter), 'button-increment');
499-
var dispatchButton = queryByTestId(findDomNode(bigCounter), 'button-increment');
497+
var smallDispatchButton = queryByTestId(smallCounter, 'button-increment');
498+
var dispatchButton = queryByTestId(bigCounter, 'button-increment');
500499

501500
click(dispatchButton);
502501
click(smallDispatchButton);
@@ -507,7 +506,7 @@ main() {
507506
expect(findDomNode(bigCounter).innerHtml, contains('Count: 100'), reason: 'Should have a count of 100');
508507

509508
// Normal counter incremented only 1 at both instances
510-
expect(findDomNode(getByTestId(jacket.getInstance(), 'outside')).innerHtml, contains('Count: 1</div>'));
509+
expect(findDomNode(queryByTestId(jacket.mountNode, 'outside')).innerHtml, contains('Count: 1</div>'));
511510
expect(findDomNode(bigCounter).innerHtml, contains('Count: 1</div>'));
512511
});
513512
});

test/over_react_redux/fixtures/counter.dart

+24-21
Original file line numberDiff line numberDiff line change
@@ -22,29 +22,32 @@ class _$CounterProps extends UiProps with ConnectPropsMixin {
2222
class CounterComponent extends UiComponent2<CounterProps> {
2323
@override
2424
render() {
25-
return (Dom.div()..style = props.wrapperStyles)(
26-
Dom.div()('Count: ${props.currentCount}'),
27-
(Dom.button()
28-
..addTestId('button-increment')
29-
..onClick = (_) {
30-
if (props.increment != null) {
31-
props.increment();
32-
} else if (props.dispatch != null) {
33-
props.dispatch(IncrementAction());
34-
}
25+
return (Dom.div()
26+
..modifyProps(addUnconsumedProps)
27+
..style = props.wrapperStyles
28+
)(
29+
Dom.div()('Count: ${props.currentCount}'),
30+
(Dom.button()
31+
..addTestId('button-increment')
32+
..onClick = (_) {
33+
if (props.increment != null) {
34+
props.increment();
35+
} else if (props.dispatch != null) {
36+
props.dispatch(IncrementAction());
3537
}
36-
)('+'),
37-
(Dom.button()
38-
..addTestId('button-decrement')
39-
..onClick = (_) {
40-
if (props.decrement != null) {
41-
props.decrement();
42-
} else if (props.dispatch != null) {
43-
props.dispatch(DecrementAction());
44-
}
38+
}
39+
)('+'),
40+
(Dom.button()
41+
..addTestId('button-decrement')
42+
..onClick = (_) {
43+
if (props.decrement != null) {
44+
props.decrement();
45+
} else if (props.dispatch != null) {
46+
props.dispatch(DecrementAction());
4547
}
46-
)('-'),
47-
props.children
48+
}
49+
)('-'),
50+
props.children
4851
);
4952
}
5053
}

0 commit comments

Comments
 (0)