Skip to content

Commit 454f27d

Browse files
committed
store test [nfc]: Push a bit more into setup for poll tests
1 parent dfefa8a commit 454f27d

File tree

1 file changed

+9
-21
lines changed

1 file changed

+9
-21
lines changed

test/model/store_test.dart

Lines changed: 9 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -580,12 +580,14 @@ void main() {
580580
connection = store.connection as FakeApiConnection;
581581
}
582582

583-
Future<void> prepareStore({int? lastEventId}) async {
583+
Future<void> preparePoll({int? lastEventId}) async {
584584
globalStore = TestGlobalStore(accounts: []);
585585
await globalStore.add(eg.selfAccount, eg.initialSnapshot(
586586
lastEventId: lastEventId));
587587
await globalStore.perAccount(eg.selfAccount.id);
588588
updateFromGlobalStore();
589+
updateMachine.debugPauseLoop();
590+
updateMachine.poll();
589591
}
590592

591593
void checkLastRequest({required int lastEventId}) {
@@ -599,12 +601,9 @@ void main() {
599601
}
600602

601603
test('loops on success', () => awaitFakeAsync((async) async {
602-
await prepareStore(lastEventId: 1);
604+
await preparePoll(lastEventId: 1);
603605
check(updateMachine.lastEventId).equals(1);
604606

605-
updateMachine.debugPauseLoop();
606-
updateMachine.poll();
607-
608607
// Loop makes first request, and processes result.
609608
connection.prepare(json: GetEventsResult(events: [
610609
HeartbeatEvent(id: 2),
@@ -627,9 +626,7 @@ void main() {
627626
}));
628627

629628
test('handles events', () => awaitFakeAsync((async) async {
630-
await prepareStore();
631-
updateMachine.debugPauseLoop();
632-
updateMachine.poll();
629+
await preparePoll();
633630

634631
// Pick some arbitrary event and check it gets processed on the store.
635632
check(store.userSettings!.twentyFourHourTime).isFalse();
@@ -644,9 +641,7 @@ void main() {
644641
}));
645642

646643
test('handles expired queue', () => awaitFakeAsync((async) async {
647-
await prepareStore();
648-
updateMachine.debugPauseLoop();
649-
updateMachine.poll();
644+
await preparePoll();
650645
check(globalStore.perAccountSync(store.accountId)).identicalTo(store);
651646

652647
// Let the server expire the event queue.
@@ -681,9 +676,7 @@ void main() {
681676

682677
test('expired queue disposes registered MessageListView instances', () => awaitFakeAsync((async) async {
683678
// Regression test for: https://github.com/zulip/zulip-flutter/issues/810
684-
await prepareStore();
685-
updateMachine.debugPauseLoop();
686-
updateMachine.poll();
679+
await preparePoll();
687680

688681
// Make sure there are [MessageListView]s in the message store.
689682
MessageListView.init(store: store, narrow: const MentionsNarrow());
@@ -707,9 +700,7 @@ void main() {
707700

708701
void checkRetry(void Function() prepareError) {
709702
awaitFakeAsync((async) async {
710-
await prepareStore(lastEventId: 1);
711-
updateMachine.debugPauseLoop();
712-
updateMachine.poll();
703+
await preparePoll(lastEventId: 1);
713704
check(async.pendingTimers).length.equals(0);
714705

715706
// Make the request, inducing an error in it.
@@ -774,10 +765,7 @@ void main() {
774765
Future<void> prepare() async {
775766
reportErrorToUserBriefly = logAndReportErrorToUserBriefly;
776767
addTearDown(() => reportErrorToUserBriefly = defaultReportErrorToUserBriefly);
777-
778-
await prepareStore(lastEventId: 1);
779-
updateMachine.debugPauseLoop();
780-
updateMachine.poll();
768+
await preparePoll(lastEventId: 1);
781769
}
782770

783771
void pollAndFail(FakeAsync async) {

0 commit comments

Comments
 (0)