Skip to content

Commit 042e10b

Browse files
gnpricechrisbobbe
authored andcommitted
test: Include self-user in users lists
This completes the sweep through the tests to ensure the self-user is always found in the list of users in the initial snapshot, like it would be in a real-life initial snapshot from a Zulip server. Upcoming commits will start checking that expectation in the model code.
1 parent c4f5256 commit 042e10b

File tree

8 files changed

+34
-22
lines changed

8 files changed

+34
-22
lines changed

test/model/store_test.dart

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ void main() {
4747
final store1 = PerAccountStore.fromInitialSnapshot(
4848
globalStore: globalStore,
4949
accountId: 1,
50-
initialSnapshot: eg.initialSnapshot(),
50+
initialSnapshot: eg.initialSnapshot(realmUsers: [eg.selfUser]),
5151
);
5252
completers(1).single.complete(store1);
5353
check(await future1).identicalTo(store1);
@@ -58,7 +58,7 @@ void main() {
5858
final store2 = PerAccountStore.fromInitialSnapshot(
5959
globalStore: globalStore,
6060
accountId: 2,
61-
initialSnapshot: eg.initialSnapshot(),
61+
initialSnapshot: eg.initialSnapshot(realmUsers: [eg.otherUser]),
6262
);
6363
completers(2).single.complete(store2);
6464
check(await future2).identicalTo(store2);
@@ -85,12 +85,12 @@ void main() {
8585
final store1 = PerAccountStore.fromInitialSnapshot(
8686
globalStore: globalStore,
8787
accountId: 1,
88-
initialSnapshot: eg.initialSnapshot(),
88+
initialSnapshot: eg.initialSnapshot(realmUsers: [eg.selfUser]),
8989
);
9090
final store2 = PerAccountStore.fromInitialSnapshot(
9191
globalStore: globalStore,
9292
accountId: 2,
93-
initialSnapshot: eg.initialSnapshot(),
93+
initialSnapshot: eg.initialSnapshot(realmUsers: [eg.otherUser]),
9494
);
9595
completers(1).single.complete(store1);
9696
completers(2).single.complete(store2);

test/model/user_test.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -201,7 +201,7 @@ void main() {
201201
final user3 = eg.user(userId: 3);
202202

203203
store = eg.store(initialSnapshot: eg.initialSnapshot(
204-
realmUsers: [user1, user2, user3],
204+
realmUsers: [user1, user2, user3, eg.selfUser],
205205
mutedUsers: [MutedUserItem(id: 2), MutedUserItem(id: 1)]));
206206
check(store.isUserMuted(1)).isTrue();
207207
check(store.isUserMuted(2)).isTrue();

test/notifications/open_test.dart

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -251,9 +251,14 @@ void main() {
251251
eg.account(id: 1003, realmUrl: realmUrlB, user: user1),
252252
eg.account(id: 1004, realmUrl: realmUrlB, user: user2),
253253
];
254-
for (final account in accounts) {
255-
await testBinding.globalStore.add(account, eg.initialSnapshot());
256-
}
254+
await testBinding.globalStore.add(
255+
accounts[0], eg.initialSnapshot(realmUsers: [user1]));
256+
await testBinding.globalStore.add(
257+
accounts[1], eg.initialSnapshot(realmUsers: [user2]));
258+
await testBinding.globalStore.add(
259+
accounts[2], eg.initialSnapshot(realmUsers: [user1]));
260+
await testBinding.globalStore.add(
261+
accounts[3], eg.initialSnapshot(realmUsers: [user2]));
257262
await prepare(tester);
258263

259264
await checkOpenNotification(tester, accounts[0], eg.streamMessage());
@@ -306,7 +311,8 @@ void main() {
306311
final accountB = eg.otherAccount;
307312
final message = eg.streamMessage();
308313
await testBinding.globalStore.add(accountA, eg.initialSnapshot());
309-
await testBinding.globalStore.add(accountB, eg.initialSnapshot());
314+
await testBinding.globalStore.add(accountB, eg.initialSnapshot(
315+
realmUsers: [eg.otherUser]));
310316
setupNotificationDataForLaunch(tester, accountB, message);
311317

312318
await prepare(tester, early: true);

test/widgets/action_sheet_test.dart

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@ Future<void> setupToMessageActionSheet(WidgetTester tester, {
7777
await testBinding.globalStore.add(
7878
selfAccount,
7979
eg.initialSnapshot(
80+
realmUsers: [selfUser],
8081
realmAllowMessageEditing: realmAllowMessageEditing,
8182
realmMessageContentEditLimitSeconds: realmMessageContentEditLimitSeconds,
8283
realmEnableReadReceipts: realmEnableReadReceipts,

test/widgets/app_test.dart

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -281,7 +281,8 @@ void main() {
281281
testWidgets('choosing an account clears the navigator stack', (tester) async {
282282
addTearDown(testBinding.reset);
283283
await testBinding.globalStore.add(eg.selfAccount, eg.initialSnapshot());
284-
await testBinding.globalStore.add(eg.otherAccount, eg.initialSnapshot());
284+
await testBinding.globalStore.add(eg.otherAccount, eg.initialSnapshot(
285+
realmUsers: [eg.otherUser]));
285286

286287
final pushedRoutes = <Route<void>>[];
287288
final poppedRoutes = <Route<void>>[];

test/widgets/home_test.dart

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -333,7 +333,8 @@ void main () {
333333
pushedRoutes = [];
334334
lastPoppedRoute = null;
335335
await testBinding.globalStore.add(eg.selfAccount, eg.initialSnapshot());
336-
await testBinding.globalStore.add(eg.otherAccount, eg.initialSnapshot());
336+
await testBinding.globalStore.add(eg.otherAccount, eg.initialSnapshot(
337+
realmUsers: [eg.otherUser]));
337338
await tester.pumpWidget(ZulipApp(navigatorObservers: [testNavObserver]));
338339
await tester.pump(Duration.zero); // wait for the loading page
339340
checkOnLoadingPage();
@@ -445,7 +446,8 @@ void main () {
445446
testWidgets('while loading, go to nested levels of ChooseAccountPage', (tester) async {
446447
testBinding.globalStore.loadPerAccountDuration = loadPerAccountDuration;
447448
final thirdAccount = eg.account(user: eg.thirdUser);
448-
await testBinding.globalStore.add(thirdAccount, eg.initialSnapshot());
449+
await testBinding.globalStore.add(thirdAccount, eg.initialSnapshot(
450+
realmUsers: [eg.thirdUser]));
449451
await prepare(tester);
450452

451453
await tester.pump(kTryAnotherAccountWaitPeriod);

test/widgets/recent_dm_conversations_test.dart

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -38,13 +38,10 @@ Future<void> setupPage(WidgetTester tester, {
3838

3939
selfUser ??= eg.selfUser;
4040
final selfAccount = eg.account(user: selfUser);
41-
await testBinding.globalStore.add(selfAccount, eg.initialSnapshot());
41+
await testBinding.globalStore.add(selfAccount, eg.initialSnapshot(
42+
realmUsers: [selfUser, ...users]));
4243
store = await testBinding.globalStore.perAccount(selfAccount.id);
4344

44-
await store.addUser(selfUser);
45-
for (final user in users) {
46-
await store.addUser(user);
47-
}
4845
if (mutedUserIds != null) {
4946
await store.setMutedUsers(mutedUserIds);
5047
}

test/widgets/store_test.dart

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -281,10 +281,14 @@ void main() {
281281

282282
addTearDown(testBinding.reset);
283283

284-
final account1 = eg.account(id: 1, user: eg.user());
285-
final account2 = eg.account(id: 2, user: eg.user());
286-
await testBinding.globalStore.add(account1, eg.initialSnapshot());
287-
await testBinding.globalStore.add(account2, eg.initialSnapshot());
284+
final user1 = eg.user();
285+
final user2 = eg.user();
286+
final account1 = eg.account(id: 1, user: user1);
287+
final account2 = eg.account(id: 2, user: user2);
288+
await testBinding.globalStore.add(account1, eg.initialSnapshot(
289+
realmUsers: [user1]));
290+
await testBinding.globalStore.add(account2, eg.initialSnapshot(
291+
realmUsers: [user2]));
288292

289293
final testNavObserver = TestNavigatorObserver();
290294
await tester.pumpWidget(ZulipApp(navigatorObservers: [testNavObserver]));
@@ -374,7 +378,8 @@ void main() {
374378
// production code, where we could reasonably add an assert against it.
375379
// If forced, we could let this test code proceed despite such an assert…)
376380
// hack; the snapshot probably corresponds to selfAccount, not otherAccount.
377-
await testBinding.globalStore.add(eg.otherAccount, eg.initialSnapshot());
381+
await testBinding.globalStore.add(eg.otherAccount, eg.initialSnapshot(
382+
realmUsers: [eg.otherUser]));
378383
await pumpWithParams(light: false, accountId: eg.otherAccount.id);
379384
// Nudge PerAccountStoreWidget to send its updated store to MyWidgetWithMixin.
380385
//

0 commit comments

Comments
 (0)