Skip to content

Commit b9f2790

Browse files
committed
select5 test
1 parent e85cf94 commit b9f2790

File tree

1 file changed

+179
-0
lines changed

1 file changed

+179
-0
lines changed

test/store_test.dart

Lines changed: 179 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -718,6 +718,91 @@ void main() {
718718
await future;
719719
});
720720

721+
test('select5', () async {
722+
final initial = Tuple6(
723+
0,
724+
1.0,
725+
'',
726+
true,
727+
<String>[].build(),
728+
<String, int>{}.build(),
729+
);
730+
731+
final store = RxReduxStore<
732+
int,
733+
Tuple6<int, double, String, bool, BuiltList<String>,
734+
BuiltMap<String, int>>>(
735+
initialState: initial,
736+
sideEffects: [],
737+
reducer: (s, a) {
738+
switch (a) {
739+
case 0:
740+
return s;
741+
case 1:
742+
return s.withItem1(s.item1 + a); // [item 1]
743+
case 2:
744+
return s.withItem2(s.item2 + a); // [item 2]
745+
case 3:
746+
return s.withItem6(
747+
s.item6.rebuild((b) => b['@'] = a)); // ------------
748+
case 4:
749+
return s.withItem3(s.item3 + a.toString()); // [item 3]
750+
case 5:
751+
return s.withItem4(!s.item4); // [item 4]
752+
case 6:
753+
return s.withItem6(
754+
s.item6.rebuild((b) => b.remove('@'))); // ------------
755+
case 7:
756+
return s.withItem5(
757+
s.item5.rebuild((b) => b.add(a.toString()))); // [item 5]
758+
case 8:
759+
return s;
760+
default:
761+
throw a;
762+
}
763+
},
764+
);
765+
766+
final tuple$ = store.select5(
767+
expectAsync1((state) => state.item1, count: 7 + 1),
768+
// 7 action causes state changed
769+
expectAsync1((state) => state.item2, count: 7 + 1),
770+
// 7 action causes state changed
771+
expectAsync1((state) => state.item3, count: 7 + 1),
772+
// 7 action causes state changed
773+
expectAsync1((state) => state.item4, count: 7 + 1),
774+
// 7 action causes state changed
775+
expectAsync1((state) => state.item5, count: 7 + 1),
776+
// 7 action causes state changed
777+
expectAsync5(
778+
(int subState1, double subState2, String subState3, bool subState4,
779+
BuiltList<String> subState5) =>
780+
Tuple5(subState1, subState2, subState3, subState4, subState5),
781+
count: 5 + 1, // inc. calling to produce seed value
782+
),
783+
);
784+
785+
expect(tuple$.value, Tuple5(0, 1.0, '', true, <String>[].build()));
786+
final future = expectLater(
787+
tuple$,
788+
emitsInOrder(<Object>[
789+
Tuple5(1, 1.0, '', true, <String>[].build()),
790+
Tuple5(1, 3.0, '', true, <String>[].build()),
791+
Tuple5(1, 3.0, '4', true, <String>[].build()),
792+
Tuple5(1, 3.0, '4', false, <String>[].build()),
793+
Tuple5(1, 3.0, '4', false, <String>['7'].build()),
794+
emitsDone,
795+
]),
796+
);
797+
798+
for (var i = 0; i <= 8; i++) {
799+
i.dispatchTo(store);
800+
}
801+
await pumpEventQueue(times: 100);
802+
await store.dispose();
803+
await future;
804+
});
805+
721806
group('selectMany', () {
722807
test('~= select2', () async {
723808
final store = RxReduxStore<int, _State>(
@@ -1000,6 +1085,100 @@ void main() {
10001085
await store.dispose();
10011086
await future;
10021087
});
1088+
1089+
test('~= select5', () async {
1090+
final initial = Tuple6(
1091+
0,
1092+
1.0,
1093+
'',
1094+
true,
1095+
<String>[].build(),
1096+
<String, int>{}.build(),
1097+
);
1098+
1099+
final store = RxReduxStore<
1100+
int,
1101+
Tuple6<int, double, String, bool, BuiltList<String>,
1102+
BuiltMap<String, int>>>(
1103+
initialState: initial,
1104+
sideEffects: [],
1105+
reducer: (s, a) {
1106+
switch (a) {
1107+
case 0:
1108+
return s;
1109+
case 1:
1110+
return s.withItem1(s.item1 + a); // [item 1]
1111+
case 2:
1112+
return s.withItem2(s.item2 + a); // [item 2]
1113+
case 3:
1114+
return s.withItem6(
1115+
s.item6.rebuild((b) => b['@'] = a)); // ------------
1116+
case 4:
1117+
return s.withItem3(s.item3 + a.toString()); // [item 3]
1118+
case 5:
1119+
return s.withItem4(!s.item4); // [item 4]
1120+
case 6:
1121+
return s.withItem6(
1122+
s.item6.rebuild((b) => b.remove('@'))); // ------------
1123+
case 7:
1124+
return s.withItem5(
1125+
s.item5.rebuild((b) => b.add(a.toString()))); // [item 5]
1126+
case 8:
1127+
return s;
1128+
default:
1129+
throw a;
1130+
}
1131+
},
1132+
);
1133+
1134+
final tuple$ = store.selectMany(
1135+
[
1136+
expectAsync1((state) => state.item1, count: 7 + 1),
1137+
// 7 action causes state changed
1138+
expectAsync1((state) => state.item2, count: 7 + 1),
1139+
// 7 action causes state changed
1140+
expectAsync1((state) => state.item3, count: 7 + 1),
1141+
// 7 action causes state changed
1142+
expectAsync1((state) => state.item4, count: 7 + 1),
1143+
// 7 action causes state changed
1144+
expectAsync1((state) => state.item5, count: 7 + 1),
1145+
// 7 action causes state changed
1146+
],
1147+
[null, null, null, null, null],
1148+
expectAsync1(
1149+
(subStates) {
1150+
return Tuple5(
1151+
subStates[0] as int,
1152+
subStates[1] as double,
1153+
subStates[2] as String,
1154+
subStates[3] as bool,
1155+
subStates[4] as BuiltList<String>,
1156+
);
1157+
},
1158+
count: 5 + 1, // inc. calling to produce seed value
1159+
),
1160+
);
1161+
1162+
expect(tuple$.value, Tuple5(0, 1.0, '', true, <String>[].build()));
1163+
final future = expectLater(
1164+
tuple$,
1165+
emitsInOrder(<Object>[
1166+
Tuple5(1, 1.0, '', true, <String>[].build()),
1167+
Tuple5(1, 3.0, '', true, <String>[].build()),
1168+
Tuple5(1, 3.0, '4', true, <String>[].build()),
1169+
Tuple5(1, 3.0, '4', false, <String>[].build()),
1170+
Tuple5(1, 3.0, '4', false, <String>['7'].build()),
1171+
emitsDone,
1172+
]),
1173+
);
1174+
1175+
for (var i = 0; i <= 8; i++) {
1176+
i.dispatchTo(store);
1177+
}
1178+
await pumpEventQueue(times: 100);
1179+
await store.dispose();
1180+
await future;
1181+
});
10031182
});
10041183
});
10051184
});

0 commit comments

Comments
 (0)