@@ -75,9 +75,9 @@ void main() {
75
75
check (pushedRoutes).isEmpty ();
76
76
}
77
77
78
- Future < void > openNotification ( WidgetTester tester, Account account, Message message) async {
78
+ Uri androidNotificationUrlForMessage ( Account account, Message message) {
79
79
final data = messageFcmMessage (message, account: account);
80
- final intentDataUrl = NotificationOpenPayload (
80
+ return NotificationOpenPayload (
81
81
realmUrl: data.realmUrl,
82
82
userId: data.userId,
83
83
narrow: switch (data.recipient) {
@@ -86,11 +86,23 @@ void main() {
86
86
FcmMessageDmRecipient (: var allRecipientIds) =>
87
87
DmNarrow (allRecipientIds: allRecipientIds, selfUserId: data.userId),
88
88
}).buildAndroidNotificationUrl ();
89
+ }
90
+
91
+ Future <void > openNotification (WidgetTester tester, Account account, Message message) async {
92
+ final intentDataUrl = androidNotificationUrlForMessage (account, message);
89
93
unawaited (
90
94
WidgetsBinding .instance.handlePushRoute (intentDataUrl.toString ()));
91
95
await tester.idle (); // let navigateForNotification find navigator
92
96
}
93
97
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
+
94
106
void matchesNavigation (Subject <Route <void >> route, Account account, Message message) {
95
107
route.isA <MaterialAccountWidgetRoute >()
96
108
..accountId.equals (account.id)
@@ -202,22 +214,9 @@ void main() {
202
214
203
215
testWidgets ('at app launch' , (tester) async {
204
216
addTearDown (testBinding.reset);
205
- // Set up a value for `PlatformDispatcher.defaultRouteName` to return,
206
- // for determining the intial route.
207
217
final account = eg.selfAccount;
208
218
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);
221
220
222
221
// Now start the app.
223
222
await testBinding.globalStore.add (account, eg.initialSnapshot ());
@@ -236,21 +235,9 @@ void main() {
236
235
final accountA = eg.selfAccount;
237
236
final accountB = eg.otherAccount;
238
237
final message = eg.streamMessage ();
239
- final data = messageFcmMessage (message, account: accountB);
240
238
await testBinding.globalStore.add (accountA, eg.initialSnapshot ());
241
239
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);
254
241
255
242
await prepare (tester, early: true );
256
243
check (pushedRoutes).isEmpty (); // GlobalStore hasn't loaded yet
0 commit comments