@@ -8,31 +8,7 @@ import 'package:zulip/widgets/store.dart';
8
8
import '../api/fake_api.dart' ;
9
9
import '../example_data.dart' as eg;
10
10
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 {
36
12
final Map <
37
13
({Uri realmUrl, int ? zulipFeatureLevel, String ? email, String ? apiKey}),
38
14
FakeApiConnection
@@ -81,25 +57,12 @@ class TestGlobalStore extends GlobalStore {
81
57
realmUrl: realmUrl, zulipFeatureLevel: zulipFeatureLevel,
82
58
email: email, apiKey: apiKey));
83
59
}
60
+ }
84
61
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.
103
66
}
104
67
105
68
int _nextAccountId = 1 ;
@@ -136,10 +99,6 @@ class TestGlobalStore extends GlobalStore {
136
99
// Nothing to do.
137
100
}
138
101
139
- static const Duration removeAccountDuration = Duration (milliseconds: 1 );
140
- Duration ? loadPerAccountDuration;
141
- Object ? loadPerAccountException;
142
-
143
102
/// Consume the log of calls made to [doRemoveAccount] .
144
103
List <int > takeDoRemoveAccountCalls () {
145
104
final result = _doRemoveAccountCalls;
@@ -151,9 +110,55 @@ class TestGlobalStore extends GlobalStore {
151
110
@override
152
111
Future <void > doRemoveAccount (int accountId) async {
153
112
(_doRemoveAccountCalls ?? = []).add (accountId);
154
- await Future <void >.delayed (removeAccountDuration);
113
+ await Future <void >.delayed (TestGlobalStore . removeAccountDuration);
155
114
// Nothing else to do.
156
115
}
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;
157
162
158
163
@override
159
164
Future <PerAccountStore > doLoadPerAccount (int accountId) async {
0 commit comments