@@ -959,6 +959,8 @@ void main() {
959
959
960
960
group ('NotificationDisplayManager open' , () {
961
961
late List <Route <void >> pushedRoutes;
962
+ late List <Route <void >> poppedRoutes;
963
+ late TestNavigatorObserver testNavObserver;
962
964
963
965
void takeStartingRoutes ({Account ? account, bool withAccount = true }) {
964
966
account ?? = eg.selfAccount;
@@ -978,8 +980,14 @@ void main() {
978
980
{bool early = false , bool withAccount = true }) async {
979
981
await init ();
980
982
pushedRoutes = [];
981
- final testNavObserver = TestNavigatorObserver ()
982
- ..onPushed = (route, prevRoute) => pushedRoutes.add (route);
983
+ poppedRoutes = [];
984
+ testNavObserver = TestNavigatorObserver ();
985
+ testNavObserver.onPushed = (route, prevRoute) => pushedRoutes.add (route);
986
+ testNavObserver.onPopped = (route, prevRoute) => poppedRoutes.add (route);
987
+ testNavObserver.onReplaced = (route, prevRoute) {
988
+ poppedRoutes.add (prevRoute! );
989
+ pushedRoutes.add (route! );
990
+ };
983
991
// This uses [ZulipApp] instead of [TestZulipApp] because notification
984
992
// logic uses `await ZulipApp.navigator`.
985
993
await tester.pumpWidget (ZulipApp (navigatorObservers: [testNavObserver]));
@@ -1018,7 +1026,7 @@ void main() {
1018
1026
1019
1027
Future <void > checkOpenNotification (WidgetTester tester, Account account, Message message) async {
1020
1028
await openNotification (tester, account, message);
1021
- matchesNavigation ( check (pushedRoutes).single , account, message);
1029
+ check (pushedRoutes).any ((it) => matchesNavigation (it , account, message) );
1022
1030
pushedRoutes.clear ();
1023
1031
}
1024
1032
@@ -1176,6 +1184,80 @@ void main() {
1176
1184
takeStartingRoutes (account: accountB);
1177
1185
matchesNavigation (check (pushedRoutes).single, accountB, message);
1178
1186
});
1187
+
1188
+ testWidgets ('notification switches account only when from different account' , (tester) async {
1189
+ addTearDown (testBinding.reset);
1190
+
1191
+ final accountA = eg.selfAccount;
1192
+ final accountB = eg.otherAccount;
1193
+ final message = eg.streamMessage ();
1194
+
1195
+ await testBinding.globalStore.add (accountA, eg.initialSnapshot ());
1196
+ await testBinding.globalStore.add (accountB, eg.initialSnapshot ());
1197
+
1198
+ await prepare (tester, early: true );
1199
+ await tester.pump ();
1200
+ takeStartingRoutes (account: accountA);
1201
+
1202
+ await openNotification (tester, accountB, message);
1203
+ check (poppedRoutes).any ((it) => it.isA <MaterialAccountWidgetRoute >()
1204
+ .accountId.equals (accountA.id));
1205
+ check (pushedRoutes.last).isA <MaterialAccountWidgetRoute >()
1206
+ ..accountId.equals (accountB.id)
1207
+ ..page.isA <MessageListPage >();
1208
+ });
1209
+
1210
+ testWidgets ('notification preserves navigation stack when in same account' , (tester) async {
1211
+ addTearDown (testBinding.reset);
1212
+
1213
+ final account = eg.selfAccount;
1214
+ final message = eg.streamMessage ();
1215
+
1216
+ await testBinding.globalStore.add (account, eg.initialSnapshot ());
1217
+
1218
+ await prepare (tester, early: true );
1219
+ await tester.pump ();
1220
+ takeStartingRoutes (account: account);
1221
+
1222
+ await openNotification (tester, account, message);
1223
+ check (pushedRoutes.last).isA <MaterialAccountWidgetRoute >()
1224
+ ..accountId.equals (account.id)
1225
+ ..page.isA <MessageListPage >();
1226
+
1227
+ check (poppedRoutes).isEmpty ();
1228
+ });
1229
+
1230
+ testWidgets ('notification keeps AccountRoute in stack when opened from non-AccountRoute' , (tester) async {
1231
+ addTearDown (testBinding.reset);
1232
+
1233
+ final accountA = eg.selfAccount;
1234
+ final accountB = eg.otherAccount;
1235
+ final message = eg.streamMessage ();
1236
+
1237
+ await testBinding.globalStore.add (accountA, eg.initialSnapshot ());
1238
+ await testBinding.globalStore.add (accountB, eg.initialSnapshot ());
1239
+
1240
+ await prepare (tester, early: true );
1241
+ await tester.pump ();
1242
+ takeStartingRoutes (account: accountA);
1243
+
1244
+ final navigator = await ZulipApp .navigator;
1245
+ unawaited (navigator.push (MaterialWidgetRoute (page: const ChooseAccountPage ())));
1246
+ await tester.pumpAndSettle ();
1247
+
1248
+ await openNotification (tester, accountA, message);
1249
+ check (poppedRoutes).isEmpty ();
1250
+ check (pushedRoutes.last).isA <MaterialAccountWidgetRoute >()
1251
+ ..accountId.equals (accountA.id)
1252
+ ..page.isA <MessageListPage >();
1253
+
1254
+ await openNotification (tester, accountB, message);
1255
+ check (poppedRoutes).any ((it) => it.isA <MaterialAccountWidgetRoute >()
1256
+ .accountId.equals (accountA.id));
1257
+ check (pushedRoutes.last).isA <MaterialAccountWidgetRoute >()
1258
+ ..accountId.equals (accountB.id)
1259
+ ..page.isA <MessageListPage >();
1260
+ });
1179
1261
});
1180
1262
1181
1263
group ('NotificationOpenPayload' , () {
0 commit comments