Skip to content

Commit 628febf

Browse files
committed
notif test: Make init and prepare accept a list of accounts
Also, remove `addSelfAccount` param, which becomes redundant with the new list of accounts param.
1 parent 1fb5c09 commit 628febf

File tree

1 file changed

+13
-25
lines changed

1 file changed

+13
-25
lines changed

test/notifications/open_test.dart

Lines changed: 13 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -74,9 +74,9 @@ void main() {
7474
TestZulipBinding.ensureInitialized();
7575
final zulipLocalizations = GlobalLocalizations.zulipLocalizations;
7676

77-
Future<void> init({bool addSelfAccount = true}) async {
78-
if (addSelfAccount) {
79-
await testBinding.globalStore.add(eg.selfAccount, eg.initialSnapshot());
77+
Future<void> init({required List<Account> accounts}) async {
78+
for (final account in accounts) {
79+
await testBinding.globalStore.add(account, eg.initialSnapshot());
8080
}
8181
addTearDown(testBinding.reset);
8282
testBinding.firebaseMessagingInitialToken = '012abc';
@@ -103,8 +103,9 @@ void main() {
103103
}
104104

105105
Future<void> prepare(WidgetTester tester,
106-
{bool early = false, bool withAccount = true}) async {
107-
await init(addSelfAccount: false);
106+
{bool early = false, List<Account>? accounts}) async {
107+
accounts ??= [eg.selfAccount];
108+
await init(accounts: accounts);
108109
pushedRoutes = [];
109110
final testNavObserver = TestNavigatorObserver()
110111
..onPushed = (route, prevRoute) => pushedRoutes.add(route);
@@ -116,7 +117,7 @@ void main() {
116117
return;
117118
}
118119
await tester.pump();
119-
takeStartingRoutes(withAccount: withAccount);
120+
takeStartingRoutes(withAccount: accounts.isNotEmpty);
120121
check(pushedRoutes).isEmpty();
121122
}
122123

@@ -189,25 +190,20 @@ void main() {
189190

190191
testWidgets('stream message', (tester) async {
191192
addTearDown(testBinding.reset);
192-
await testBinding.globalStore.add(eg.selfAccount, eg.initialSnapshot());
193193
await prepare(tester);
194194
await checkOpenNotification(tester, eg.selfAccount, eg.streamMessage());
195195
}, variant: const TargetPlatformVariant({TargetPlatform.android, TargetPlatform.iOS}));
196196

197197
testWidgets('direct message', (tester) async {
198198
addTearDown(testBinding.reset);
199-
await testBinding.globalStore.add(eg.selfAccount, eg.initialSnapshot());
200199
await prepare(tester);
201200
await checkOpenNotification(tester, eg.selfAccount,
202201
eg.dmMessage(from: eg.otherUser, to: [eg.selfUser]));
203202
}, variant: const TargetPlatformVariant({TargetPlatform.android, TargetPlatform.iOS}));
204203

205204
testWidgets('account queried by realmUrl origin component', (tester) async {
206205
addTearDown(testBinding.reset);
207-
await testBinding.globalStore.add(
208-
eg.selfAccount.copyWith(realmUrl: Uri.parse('http://chat.example')),
209-
eg.initialSnapshot());
210-
await prepare(tester);
206+
await prepare(tester, accounts: [eg.selfAccount.copyWith(realmUrl: Uri.parse('http://chat.example'))]);
211207

212208
await checkOpenNotification(tester,
213209
eg.selfAccount.copyWith(realmUrl: Uri.parse('http://chat.example/')),
@@ -218,7 +214,7 @@ void main() {
218214
}, variant: const TargetPlatformVariant({TargetPlatform.android, TargetPlatform.iOS}));
219215

220216
testWidgets('no accounts', (tester) async {
221-
await prepare(tester, withAccount: false);
217+
await prepare(tester, accounts: []);
222218
await openNotification(tester, eg.selfAccount, eg.streamMessage());
223219
await tester.pump();
224220
check(pushedRoutes.single).isA<DialogRoute<void>>();
@@ -229,8 +225,7 @@ void main() {
229225

230226
testWidgets('mismatching account', (tester) async {
231227
addTearDown(testBinding.reset);
232-
await testBinding.globalStore.add(eg.selfAccount, eg.initialSnapshot());
233-
await prepare(tester);
228+
await prepare(tester, accounts: [eg.selfAccount]);
234229
await openNotification(tester, eg.otherAccount, eg.streamMessage());
235230
await tester.pump();
236231
check(pushedRoutes.single).isA<DialogRoute<void>>();
@@ -251,10 +246,7 @@ void main() {
251246
eg.account(id: 1003, realmUrl: realmUrlB, user: user1),
252247
eg.account(id: 1004, realmUrl: realmUrlB, user: user2),
253248
];
254-
for (final account in accounts) {
255-
await testBinding.globalStore.add(account, eg.initialSnapshot());
256-
}
257-
await prepare(tester);
249+
await prepare(tester, accounts: accounts);
258250

259251
await checkOpenNotification(tester, accounts[0], eg.streamMessage());
260252
await checkOpenNotification(tester, accounts[1], eg.streamMessage());
@@ -264,7 +256,6 @@ void main() {
264256

265257
testWidgets('wait for app to become ready', (tester) async {
266258
addTearDown(testBinding.reset);
267-
await testBinding.globalStore.add(eg.selfAccount, eg.initialSnapshot());
268259
await prepare(tester, early: true);
269260
final message = eg.streamMessage();
270261
await openNotification(tester, eg.selfAccount, message);
@@ -289,8 +280,7 @@ void main() {
289280
setupNotificationDataForLaunch(tester, account, message);
290281

291282
// Now start the app.
292-
await testBinding.globalStore.add(account, eg.initialSnapshot());
293-
await prepare(tester, early: true);
283+
await prepare(tester, early: true, accounts: [account]);
294284
check(pushedRoutes).isEmpty(); // GlobalStore hasn't loaded yet
295285

296286
// Once the app is ready, we navigate to the conversation.
@@ -305,11 +295,9 @@ void main() {
305295
final accountA = eg.selfAccount;
306296
final accountB = eg.otherAccount;
307297
final message = eg.streamMessage();
308-
await testBinding.globalStore.add(accountA, eg.initialSnapshot());
309-
await testBinding.globalStore.add(accountB, eg.initialSnapshot());
310298
setupNotificationDataForLaunch(tester, accountB, message);
311299

312-
await prepare(tester, early: true);
300+
await prepare(tester, early: true, accounts: [accountA, accountB]);
313301
check(pushedRoutes).isEmpty(); // GlobalStore hasn't loaded yet
314302

315303
await tester.pump();

0 commit comments

Comments
 (0)