@@ -85,22 +85,21 @@ void main() {
8585 group ('NotificationOpenService' , () {
8686 late List <Route <void >> pushedRoutes;
8787
88- void takeStartingRoutes ({ Account ? account, bool withAccount = true } ) {
89- account ?? = eg.selfAccount;
90- final expected = < Condition < Object ?> > [
91- if (withAccount )
92- (it) => it. isA <MaterialAccountWidgetRoute >()
93- ..accountId. equals (account ! .id)
94- ..page. isA < HomePage >()
95- else
96- (it) => it. isA < WidgetRoute >().page. isA < ChooseAccountPage >(),
97- ];
98- check (pushedRoutes. take (expected.length)). deepEquals (expected );
99- pushedRoutes.removeRange ( 0 , expected.length );
88+ void takeHomePageRouteForAccount ( int accountId ) {
89+ check (pushedRoutes).first. which (
90+ (it) => it. isA < MaterialAccountWidgetRoute >()
91+ ..accountId. equals (accountId )
92+ ..page. isA <HomePage >());
93+ pushedRoutes. removeAt ( 0 );
94+ }
95+
96+ void takeChooseAccountPageRoute () {
97+ check (pushedRoutes).first. which (
98+ (it) => it. isA < WidgetRoute >().page. isA < ChooseAccountPage >() );
99+ pushedRoutes.removeAt ( 0 );
100100 }
101101
102- Future <void > prepare (WidgetTester tester,
103- {bool early = false , bool withAccount = true }) async {
102+ Future <void > prepare (WidgetTester tester, {bool early = false }) async {
104103 await init ();
105104 pushedRoutes = [];
106105 final testNavObserver = TestNavigatorObserver ()
@@ -113,7 +112,13 @@ void main() {
113112 return ;
114113 }
115114 await tester.pump ();
116- takeStartingRoutes (withAccount: withAccount);
115+ final accountIds = testBinding.globalStore.accountIds;
116+ final initialAccountId = accountIds.firstOrNull;
117+ if (initialAccountId == null ) {
118+ takeChooseAccountPageRoute ();
119+ } else {
120+ takeHomePageRouteForAccount (initialAccountId);
121+ }
117122 check (pushedRoutes).isEmpty ();
118123 }
119124
@@ -215,7 +220,9 @@ void main() {
215220 }, variant: const TargetPlatformVariant ({TargetPlatform .android, TargetPlatform .iOS}));
216221
217222 testWidgets ('no accounts' , (tester) async {
218- await prepare (tester, withAccount: false );
223+ await prepare (tester);
224+ // (just to make sure the test is working)
225+ check (testBinding.globalStore.accountIds).isEmpty ();
219226 await openNotification (tester, eg.selfAccount, eg.streamMessage ());
220227 await tester.pump ();
221228 check (pushedRoutes.single).isA <DialogRoute <void >>();
@@ -279,7 +286,7 @@ void main() {
279286 // Now let the GlobalStore get loaded and the app's main UI get mounted.
280287 await tester.pump ();
281288 // The navigator first pushes the starting routes…
282- takeStartingRoutes ();
289+ takeHomePageRouteForAccount (eg.selfAccount.id); // because first in list
283290 // … and then the one the notification leads to.
284291 matchesNavigation (check (pushedRoutes).single, eg.selfAccount, message);
285292 }, variant: const TargetPlatformVariant ({TargetPlatform .android, TargetPlatform .iOS}));
@@ -297,7 +304,7 @@ void main() {
297304
298305 // Once the app is ready, we navigate to the conversation.
299306 await tester.pump ();
300- takeStartingRoutes ();
307+ takeHomePageRouteForAccount (account.id); // because associated account
301308 matchesNavigation (check (pushedRoutes).single, account, message);
302309 }, variant: const TargetPlatformVariant ({TargetPlatform .android, TargetPlatform .iOS}));
303310
@@ -316,7 +323,7 @@ void main() {
316323 check (pushedRoutes).isEmpty (); // GlobalStore hasn't loaded yet
317324
318325 await tester.pump ();
319- takeStartingRoutes (account : accountB);
326+ takeHomePageRouteForAccount ( accountB.id); // because associated account
320327 matchesNavigation (check (pushedRoutes).single, accountB, message);
321328 }, variant: const TargetPlatformVariant ({TargetPlatform .android, TargetPlatform .iOS}));
322329 });
0 commit comments