Skip to content

Commit

Permalink
wip more test
Browse files Browse the repository at this point in the history
  • Loading branch information
gnprice committed Nov 2, 2023
1 parent 04a9ed0 commit 0c6a4a3
Showing 1 changed file with 29 additions and 4 deletions.
33 changes: 29 additions & 4 deletions test/notifications_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -186,13 +186,14 @@ void main() {
late List<Route<dynamic>> pushedRoutes;

Future<void> prepare(WidgetTester tester) async {
await init();
pushedRoutes = [];
final testNavObserver = TestNavigatorObserver()
..onPushed = (route, prevRoute) => pushedRoutes.add(route);
await tester.pumpWidget(ZulipApp(navigatorObservers: [testNavObserver]));
await tester.pump();
check(pushedRoutes).length.equals(1);
pushedRoutes.removeLast();
pushedRoutes.clear();
}

void openNotification(Account account, Message message) {
Expand All @@ -208,6 +209,7 @@ void main() {
..accountId.equals(expectedAccountId)
..child.isA<MessageListPage>()
.narrow.equals(expectedNarrow);
pushedRoutes.clear();
}

void checkOpenNotification(Account account, Message message) {
Expand All @@ -227,26 +229,49 @@ void main() {
});

testWidgets('no accounts', (tester) async {
await init();
await prepare(tester);
openNotification(eg.selfAccount, eg.streamMessage());
check(pushedRoutes).isEmpty();
});

testWidgets('stream message', (tester) async {
await init();
testBinding.globalStore.add(eg.selfAccount, eg.initialSnapshot());
await prepare(tester);
checkOpenNotification(eg.selfAccount, eg.streamMessage());
});

testWidgets('direct message', (tester) async {
await init();
testBinding.globalStore.add(eg.selfAccount, eg.initialSnapshot());
await prepare(tester);
checkOpenNotification(eg.selfAccount,
eg.dmMessage(from: eg.otherUser, to: [eg.selfUser]));
});

testWidgets('account but no server data yet', (tester) async {
testBinding.globalStore.insertAccount(eg.selfAccount.toCompanion(false));
await prepare(tester);
checkOpenNotification(eg.selfAccount, eg.streamMessage());
});

testWidgets('find account among several', (tester) async {
final realmUrlA = Uri.parse('https://a-chat.example/');
final realmUrlB = Uri.parse('https://chat-b.example/');
final accounts = [
eg.account(id: 1001, realmUrl: realmUrlA, user: eg.user(userId: 123)),
eg.account(id: 1002, realmUrl: realmUrlA, user: eg.user(userId: 234)),
eg.account(id: 1003, realmUrl: realmUrlB, user: eg.user(userId: 123)),
eg.account(id: 1004, realmUrl: realmUrlB, user: eg.user(userId: 234)),
];
for (final account in accounts) {
testBinding.globalStore.insertAccount(account.toCompanion(false));
}
await prepare(tester);

checkOpenNotification(accounts[0], eg.streamMessage());
checkOpenNotification(accounts[1], eg.streamMessage());
checkOpenNotification(accounts[2], eg.streamMessage());
checkOpenNotification(accounts[3], eg.streamMessage());
});
});
}

Expand Down

0 comments on commit 0c6a4a3

Please sign in to comment.