@@ -7,23 +7,7 @@ import 'package:zulip/widgets/store.dart';
7
7
import '../api/fake_api.dart' ;
8
8
import '../example_data.dart' as eg;
9
9
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 {
27
11
final Map <
28
12
({Uri realmUrl, int ? zulipFeatureLevel, String ? email, String ? apiKey}),
29
13
FakeApiConnection
@@ -72,27 +56,9 @@ class TestGlobalStore extends GlobalStore {
72
56
realmUrl: realmUrl, zulipFeatureLevel: zulipFeatureLevel,
73
57
email: email, apiKey: apiKey));
74
58
}
59
+ }
75
60
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 {
96
62
int _nextAccountId = 1 ;
97
63
98
64
@override
@@ -127,10 +93,6 @@ class TestGlobalStore extends GlobalStore {
127
93
// Nothing to do.
128
94
}
129
95
130
- static const Duration removeAccountDuration = Duration (milliseconds: 1 );
131
- Duration ? loadPerAccountDuration;
132
- Object ? loadPerAccountException;
133
-
134
96
/// Consume the log of calls made to [doRemoveAccount] .
135
97
List <int > takeDoRemoveAccountCalls () {
136
98
final result = _doRemoveAccountCalls;
@@ -142,9 +104,52 @@ class TestGlobalStore extends GlobalStore {
142
104
@override
143
105
Future <void > doRemoveAccount (int accountId) async {
144
106
(_doRemoveAccountCalls ?? = []).add (accountId);
145
- await Future <void >.delayed (removeAccountDuration);
107
+ await Future <void >.delayed (TestGlobalStore . removeAccountDuration);
146
108
// Nothing else to do.
147
109
}
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;
148
153
149
154
@override
150
155
Future <PerAccountStore > doLoadPerAccount (int accountId) async {
0 commit comments