@@ -75,9 +75,9 @@ void main() {
7575 check (pushedRoutes).isEmpty ();
7676 }
7777
78- Future < void > openNotification ( WidgetTester tester, Account account, Message message) async {
78+ Uri androidNotificationUrlForMessage ( Account account, Message message) {
7979 final data = messageFcmMessage (message, account: account);
80- final intentDataUrl = NotificationOpenPayload (
80+ return NotificationOpenPayload (
8181 realmUrl: data.realmUrl,
8282 userId: data.userId,
8383 narrow: switch (data.recipient) {
@@ -86,11 +86,23 @@ void main() {
8686 FcmMessageDmRecipient (: var allRecipientIds) =>
8787 DmNarrow (allRecipientIds: allRecipientIds, selfUserId: data.userId),
8888 }).buildAndroidNotificationUrl ();
89+ }
90+
91+ Future <void > openNotification (WidgetTester tester, Account account, Message message) async {
92+ final intentDataUrl = androidNotificationUrlForMessage (account, message);
8993 unawaited (
9094 WidgetsBinding .instance.handlePushRoute (intentDataUrl.toString ()));
9195 await tester.idle (); // let navigateForNotification find navigator
9296 }
9397
98+ void setupNotificationDataForLaunch (WidgetTester tester, Account account, Message message) {
99+ // Set up a value for `PlatformDispatcher.defaultRouteName` to return,
100+ // for determining the initial route.
101+ final intentDataUrl = androidNotificationUrlForMessage (account, message);
102+ addTearDown (tester.binding.platformDispatcher.clearDefaultRouteNameTestValue);
103+ tester.binding.platformDispatcher.defaultRouteNameTestValue = intentDataUrl.toString ();
104+ }
105+
94106 void matchesNavigation (Subject <Route <void >> route, Account account, Message message) {
95107 route.isA <MaterialAccountWidgetRoute >()
96108 ..accountId.equals (account.id)
@@ -202,22 +214,9 @@ void main() {
202214
203215 testWidgets ('at app launch' , (tester) async {
204216 addTearDown (testBinding.reset);
205- // Set up a value for `PlatformDispatcher.defaultRouteName` to return,
206- // for determining the intial route.
207217 final account = eg.selfAccount;
208218 final message = eg.streamMessage ();
209- final data = messageFcmMessage (message, account: account);
210- final intentDataUrl = NotificationOpenPayload (
211- realmUrl: data.realmUrl,
212- userId: data.userId,
213- narrow: switch (data.recipient) {
214- FcmMessageChannelRecipient (: var streamId, : var topic) =>
215- TopicNarrow (streamId, topic),
216- FcmMessageDmRecipient (: var allRecipientIds) =>
217- DmNarrow (allRecipientIds: allRecipientIds, selfUserId: data.userId),
218- }).buildAndroidNotificationUrl ();
219- addTearDown (tester.binding.platformDispatcher.clearDefaultRouteNameTestValue);
220- tester.binding.platformDispatcher.defaultRouteNameTestValue = intentDataUrl.toString ();
219+ setupNotificationDataForLaunch (tester, account, message);
221220
222221 // Now start the app.
223222 await testBinding.globalStore.add (account, eg.initialSnapshot ());
@@ -236,21 +235,9 @@ void main() {
236235 final accountA = eg.selfAccount;
237236 final accountB = eg.otherAccount;
238237 final message = eg.streamMessage ();
239- final data = messageFcmMessage (message, account: accountB);
240238 await testBinding.globalStore.add (accountA, eg.initialSnapshot ());
241239 await testBinding.globalStore.add (accountB, eg.initialSnapshot ());
242-
243- final intentDataUrl = NotificationOpenPayload (
244- realmUrl: data.realmUrl,
245- userId: data.userId,
246- narrow: switch (data.recipient) {
247- FcmMessageChannelRecipient (: var streamId, : var topic) =>
248- TopicNarrow (streamId, topic),
249- FcmMessageDmRecipient (: var allRecipientIds) =>
250- DmNarrow (allRecipientIds: allRecipientIds, selfUserId: data.userId),
251- }).buildAndroidNotificationUrl ();
252- addTearDown (tester.binding.platformDispatcher.clearDefaultRouteNameTestValue);
253- tester.binding.platformDispatcher.defaultRouteNameTestValue = intentDataUrl.toString ();
240+ setupNotificationDataForLaunch (tester, accountB, message);
254241
255242 await prepare (tester, early: true );
256243 check (pushedRoutes).isEmpty (); // GlobalStore hasn't loaded yet
0 commit comments