@@ -8,31 +8,7 @@ import 'package:zulip/widgets/store.dart';
88import '../api/fake_api.dart' ;
99import '../example_data.dart' as eg;
1010
11- /// A [GlobalStore] containing data provided by callers,
12- /// and that causes no database queries or network requests.
13- ///
14- /// Tests can provide data to the store by calling [add] .
15- ///
16- /// The per-account stores will use [FakeApiConnection] .
17- ///
18- /// Unlike with [LiveGlobalStore] and the associated [UpdateMachine.load] ,
19- /// there is no automatic event-polling loop or other automated requests.
20- /// For each account loaded, there is a corresponding [UpdateMachine]
21- /// in [updateMachines] , which tests can use for invoking that logic
22- /// explicitly when desired.
23- ///
24- /// See also [TestZulipBinding.globalStore] , which provides one of these.
25- class TestGlobalStore extends GlobalStore {
26- TestGlobalStore ({
27- GlobalSettingsData ? globalSettings,
28- required super .accounts,
29- }) : super (globalSettings: globalSettings ?? eg.globalSettings ());
30-
31- @override
32- Future <void > doUpdateGlobalSettings (GlobalSettingsCompanion data) async {
33- // Nothing to do.
34- }
35-
11+ mixin _ApiConnectionsMixin on GlobalStore {
3612 final Map <
3713 ({Uri realmUrl, int ? zulipFeatureLevel, String ? email, String ? apiKey}),
3814 FakeApiConnection
@@ -81,25 +57,12 @@ class TestGlobalStore extends GlobalStore {
8157 realmUrl: realmUrl, zulipFeatureLevel: zulipFeatureLevel,
8258 email: email, apiKey: apiKey));
8359 }
60+ }
8461
85- /// A corresponding [UpdateMachine] for each loaded account.
86- final Map <int , UpdateMachine > updateMachines = {};
87-
88- final Map <int , InitialSnapshot > _initialSnapshots = {};
89-
90- /// Add an account and corresponding server data to the test data.
91- ///
92- /// The given account will be added to the store.
93- /// The given initial snapshot will be used to initialize a corresponding
94- /// [PerAccountStore] when [perAccount] is subsequently called for this
95- /// account, in particular when a [PerAccountStoreWidget] is mounted.
96- Future <void > add (Account account, InitialSnapshot initialSnapshot) async {
97- assert (initialSnapshot.zulipVersion == account.zulipVersion);
98- assert (initialSnapshot.zulipMergeBase == account.zulipMergeBase);
99- assert (initialSnapshot.zulipFeatureLevel == account.zulipFeatureLevel);
100- await insertAccount (account.toCompanion (false ));
101- assert (! _initialSnapshots.containsKey (account.id));
102- _initialSnapshots[account.id] = initialSnapshot;
62+ mixin _DatabaseMixin on GlobalStore {
63+ @override
64+ Future <void > doUpdateGlobalSettings (GlobalSettingsCompanion data) async {
65+ // Nothing to do.
10366 }
10467
10568 int _nextAccountId = 1 ;
@@ -136,10 +99,6 @@ class TestGlobalStore extends GlobalStore {
13699 // Nothing to do.
137100 }
138101
139- static const Duration removeAccountDuration = Duration (milliseconds: 1 );
140- Duration ? loadPerAccountDuration;
141- Object ? loadPerAccountException;
142-
143102 /// Consume the log of calls made to [doRemoveAccount] .
144103 List <int > takeDoRemoveAccountCalls () {
145104 final result = _doRemoveAccountCalls;
@@ -151,9 +110,55 @@ class TestGlobalStore extends GlobalStore {
151110 @override
152111 Future <void > doRemoveAccount (int accountId) async {
153112 (_doRemoveAccountCalls ?? = []).add (accountId);
154- await Future <void >.delayed (removeAccountDuration);
113+ await Future <void >.delayed (TestGlobalStore . removeAccountDuration);
155114 // Nothing else to do.
156115 }
116+ }
117+
118+ /// A [GlobalStore] containing data provided by callers,
119+ /// and that causes no database queries or network requests.
120+ ///
121+ /// Tests can provide data to the store by calling [add] .
122+ ///
123+ /// The per-account stores will use [FakeApiConnection] .
124+ ///
125+ /// Unlike with [LiveGlobalStore] and the associated [UpdateMachine.load] ,
126+ /// there is no automatic event-polling loop or other automated requests.
127+ /// For each account loaded, there is a corresponding [UpdateMachine]
128+ /// in [updateMachines] , which tests can use for invoking that logic
129+ /// explicitly when desired.
130+ ///
131+ /// See also [TestZulipBinding.globalStore] , which provides one of these.
132+ class TestGlobalStore extends GlobalStore with _ApiConnectionsMixin , _DatabaseMixin {
133+ TestGlobalStore ({
134+ GlobalSettingsData ? globalSettings,
135+ required super .accounts,
136+ }) : super (globalSettings: globalSettings ?? eg.globalSettings ());
137+
138+ /// A corresponding [UpdateMachine] for each loaded account.
139+ final Map <int , UpdateMachine > updateMachines = {};
140+
141+ final Map <int , InitialSnapshot > _initialSnapshots = {};
142+
143+ static const Duration removeAccountDuration = Duration (milliseconds: 1 );
144+
145+ /// Add an account and corresponding server data to the test data.
146+ ///
147+ /// The given account will be added to the store.
148+ /// The given initial snapshot will be used to initialize a corresponding
149+ /// [PerAccountStore] when [perAccount] is subsequently called for this
150+ /// account, in particular when a [PerAccountStoreWidget] is mounted.
151+ Future <void > add (Account account, InitialSnapshot initialSnapshot) async {
152+ assert (initialSnapshot.zulipVersion == account.zulipVersion);
153+ assert (initialSnapshot.zulipMergeBase == account.zulipMergeBase);
154+ assert (initialSnapshot.zulipFeatureLevel == account.zulipFeatureLevel);
155+ await insertAccount (account.toCompanion (false ));
156+ assert (! _initialSnapshots.containsKey (account.id));
157+ _initialSnapshots[account.id] = initialSnapshot;
158+ }
159+
160+ Duration ? loadPerAccountDuration;
161+ Object ? loadPerAccountException;
157162
158163 @override
159164 Future <PerAccountStore > doLoadPerAccount (int accountId) async {
0 commit comments