@@ -7,23 +7,7 @@ import 'package:zulip/widgets/store.dart';
77import '../api/fake_api.dart' ;
88import '../example_data.dart' as eg;
99
10- /// A [GlobalStore] containing data provided by callers,
11- /// and that causes no database queries or network requests.
12- ///
13- /// Tests can provide data to the store by calling [add] .
14- ///
15- /// The per-account stores will use [FakeApiConnection] .
16- ///
17- /// Unlike with [LiveGlobalStore] and the associated [UpdateMachine.load] ,
18- /// there is no automatic event-polling loop or other automated requests.
19- /// For each account loaded, there is a corresponding [UpdateMachine]
20- /// in [updateMachines] , which tests can use for invoking that logic
21- /// explicitly when desired.
22- ///
23- /// See also [TestZulipBinding.globalStore] , which provides one of these.
24- class TestGlobalStore extends GlobalStore {
25- TestGlobalStore ({required super .accounts});
26-
10+ mixin _ApiConnectionsMixin on GlobalStore {
2711 final Map <
2812 ({Uri realmUrl, int ? zulipFeatureLevel, String ? email, String ? apiKey}),
2913 FakeApiConnection
@@ -72,27 +56,9 @@ class TestGlobalStore extends GlobalStore {
7256 realmUrl: realmUrl, zulipFeatureLevel: zulipFeatureLevel,
7357 email: email, apiKey: apiKey));
7458 }
59+ }
7560
76- /// A corresponding [UpdateMachine] for each loaded account.
77- final Map <int , UpdateMachine > updateMachines = {};
78-
79- final Map <int , InitialSnapshot > _initialSnapshots = {};
80-
81- /// Add an account and corresponding server data to the test data.
82- ///
83- /// The given account will be added to the store.
84- /// The given initial snapshot will be used to initialize a corresponding
85- /// [PerAccountStore] when [perAccount] is subsequently called for this
86- /// account, in particular when a [PerAccountStoreWidget] is mounted.
87- Future <void > add (Account account, InitialSnapshot initialSnapshot) async {
88- assert (initialSnapshot.zulipVersion == account.zulipVersion);
89- assert (initialSnapshot.zulipMergeBase == account.zulipMergeBase);
90- assert (initialSnapshot.zulipFeatureLevel == account.zulipFeatureLevel);
91- await insertAccount (account.toCompanion (false ));
92- assert (! _initialSnapshots.containsKey (account.id));
93- _initialSnapshots[account.id] = initialSnapshot;
94- }
95-
61+ mixin _DatabaseMixin on GlobalStore {
9662 int _nextAccountId = 1 ;
9763
9864 @override
@@ -127,10 +93,6 @@ class TestGlobalStore extends GlobalStore {
12793 // Nothing to do.
12894 }
12995
130- static const Duration removeAccountDuration = Duration (milliseconds: 1 );
131- Duration ? loadPerAccountDuration;
132- Object ? loadPerAccountException;
133-
13496 /// Consume the log of calls made to [doRemoveAccount] .
13597 List <int > takeDoRemoveAccountCalls () {
13698 final result = _doRemoveAccountCalls;
@@ -142,9 +104,52 @@ class TestGlobalStore extends GlobalStore {
142104 @override
143105 Future <void > doRemoveAccount (int accountId) async {
144106 (_doRemoveAccountCalls ?? = []).add (accountId);
145- await Future <void >.delayed (removeAccountDuration);
107+ await Future <void >.delayed (TestGlobalStore . removeAccountDuration);
146108 // Nothing else to do.
147109 }
110+ }
111+
112+ /// A [GlobalStore] containing data provided by callers,
113+ /// and that causes no database queries or network requests.
114+ ///
115+ /// Tests can provide data to the store by calling [add] .
116+ ///
117+ /// The per-account stores will use [FakeApiConnection] .
118+ ///
119+ /// Unlike with [LiveGlobalStore] and the associated [UpdateMachine.load] ,
120+ /// there is no automatic event-polling loop or other automated requests.
121+ /// For each account loaded, there is a corresponding [UpdateMachine]
122+ /// in [updateMachines] , which tests can use for invoking that logic
123+ /// explicitly when desired.
124+ ///
125+ /// See also [TestZulipBinding.globalStore] , which provides one of these.
126+ class TestGlobalStore extends GlobalStore with _ApiConnectionsMixin , _DatabaseMixin {
127+ TestGlobalStore ({required super .accounts});
128+
129+ /// A corresponding [UpdateMachine] for each loaded account.
130+ final Map <int , UpdateMachine > updateMachines = {};
131+
132+ final Map <int , InitialSnapshot > _initialSnapshots = {};
133+
134+ static const Duration removeAccountDuration = Duration (milliseconds: 1 );
135+
136+ /// Add an account and corresponding server data to the test data.
137+ ///
138+ /// The given account will be added to the store.
139+ /// The given initial snapshot will be used to initialize a corresponding
140+ /// [PerAccountStore] when [perAccount] is subsequently called for this
141+ /// account, in particular when a [PerAccountStoreWidget] is mounted.
142+ Future <void > add (Account account, InitialSnapshot initialSnapshot) async {
143+ assert (initialSnapshot.zulipVersion == account.zulipVersion);
144+ assert (initialSnapshot.zulipMergeBase == account.zulipMergeBase);
145+ assert (initialSnapshot.zulipFeatureLevel == account.zulipFeatureLevel);
146+ await insertAccount (account.toCompanion (false ));
147+ assert (! _initialSnapshots.containsKey (account.id));
148+ _initialSnapshots[account.id] = initialSnapshot;
149+ }
150+
151+ Duration ? loadPerAccountDuration;
152+ Object ? loadPerAccountException;
148153
149154 @override
150155 Future <PerAccountStore > doLoadPerAccount (int accountId) async {
0 commit comments