Skip to content

Commit 372b882

Browse files
committed
store test [nfc]: Pull out checkReload, to use for more cases of reloading
1 parent c99bb9c commit 372b882

File tree

1 file changed

+35
-30
lines changed

1 file changed

+35
-30
lines changed

test/model/store_test.dart

Lines changed: 35 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -640,39 +640,36 @@ void main() {
640640
check(store.userSettings!.twentyFourHourTime).isTrue();
641641
}));
642642

643-
test('handles expired queue', () => awaitFakeAsync((async) async {
644-
await preparePoll();
645-
check(globalStore.perAccountSync(store.accountId)).identicalTo(store);
643+
void checkReload(void Function() prepareError) {
644+
awaitFakeAsync((async) async {
645+
await preparePoll();
646+
check(globalStore.perAccountSync(store.accountId)).identicalTo(store);
646647

647-
// Let the server expire the event queue.
648-
connection.prepare(httpStatus: 400, json: {
649-
'result': 'error', 'code': 'BAD_EVENT_QUEUE_ID',
650-
'queue_id': updateMachine.queueId,
651-
'msg': 'Bad event queue ID: ${updateMachine.queueId}',
652-
});
653-
updateMachine.debugAdvanceLoop();
654-
async.flushMicrotasks();
655-
await Future<void>.delayed(Duration.zero);
656-
check(store).isLoading.isTrue();
648+
prepareError();
649+
updateMachine.debugAdvanceLoop();
650+
async.flushMicrotasks();
651+
await Future<void>.delayed(Duration.zero);
652+
check(store).isLoading.isTrue();
657653

658-
// The global store has a new store.
659-
check(globalStore.perAccountSync(store.accountId)).not((it) => it.identicalTo(store));
660-
updateFromGlobalStore();
661-
check(store).isLoading.isFalse();
654+
// The global store has a new store.
655+
check(globalStore.perAccountSync(store.accountId)).not((it) => it.identicalTo(store));
656+
updateFromGlobalStore();
657+
check(store).isLoading.isFalse();
662658

663-
// The new UpdateMachine updates the new store.
664-
updateMachine.debugPauseLoop();
665-
updateMachine.poll();
666-
check(store.userSettings!.twentyFourHourTime).isFalse();
667-
connection.prepare(json: GetEventsResult(events: [
668-
UserSettingsUpdateEvent(id: 2,
669-
property: UserSettingName.twentyFourHourTime, value: true),
670-
], queueId: null).toJson());
671-
updateMachine.debugAdvanceLoop();
672-
async.flushMicrotasks();
673-
await Future<void>.delayed(Duration.zero);
674-
check(store.userSettings!.twentyFourHourTime).isTrue();
675-
}));
659+
// The new UpdateMachine updates the new store.
660+
updateMachine.debugPauseLoop();
661+
updateMachine.poll();
662+
check(store.userSettings!.twentyFourHourTime).isFalse();
663+
connection.prepare(json: GetEventsResult(events: [
664+
UserSettingsUpdateEvent(id: 2,
665+
property: UserSettingName.twentyFourHourTime, value: true),
666+
], queueId: null).toJson());
667+
updateMachine.debugAdvanceLoop();
668+
async.flushMicrotasks();
669+
await Future<void>.delayed(Duration.zero);
670+
check(store.userSettings!.twentyFourHourTime).isTrue();
671+
});
672+
}
676673

677674
test('expired queue disposes registered MessageListView instances', () => awaitFakeAsync((async) async {
678675
// Regression test for: https://github.com/zulip/zulip-flutter/issues/810
@@ -747,6 +744,14 @@ void main() {
747744
'result': 'error', 'code': 'BAD_REQUEST', 'msg': 'Bad request'}));
748745
});
749746

747+
test('reloads on expired queue', () {
748+
checkReload(() => connection.prepare(httpStatus: 400, json: {
749+
'result': 'error', 'code': 'BAD_EVENT_QUEUE_ID',
750+
'queue_id': updateMachine.queueId,
751+
'msg': 'Bad event queue ID: ${updateMachine.queueId}',
752+
}));
753+
});
754+
750755
group('report error', () {
751756
String? lastReportedError;
752757
String? takeLastReportedError() {

0 commit comments

Comments
 (0)