@@ -189,6 +189,97 @@ void main() {
189
189
});
190
190
});
191
191
192
+ group ('willChangeIfTopicVisible/InStream' , () {
193
+ UserTopicEvent mkEvent (UserTopicVisibilityPolicy policy) =>
194
+ eg.userTopicEvent (stream1.streamId, 'topic' , policy);
195
+
196
+ void checkChanges (PerAccountStore store,
197
+ UserTopicVisibilityPolicy newPolicy,
198
+ VisibilityEffect expectedInStream, VisibilityEffect expectedOverall) {
199
+ final event = mkEvent (newPolicy);
200
+ check (store.willChangeIfTopicVisibleInStream (event)).equals (expectedInStream);
201
+ check (store.willChangeIfTopicVisible (event)).equals (expectedOverall);
202
+ }
203
+
204
+ test ('stream not muted, policy none -> followed, no change' , () async {
205
+ final store = eg.store ();
206
+ await store.addStream (stream1);
207
+ await store.addSubscription (eg.subscription (stream1));
208
+ checkChanges (store, UserTopicVisibilityPolicy .followed,
209
+ VisibilityEffect .none, VisibilityEffect .none);
210
+ });
211
+
212
+ test ('stream not muted, policy none -> muted, means muted' , () async {
213
+ final store = eg.store ();
214
+ await store.addStream (stream1);
215
+ await store.addSubscription (eg.subscription (stream1));
216
+ checkChanges (store, UserTopicVisibilityPolicy .muted,
217
+ VisibilityEffect .muted, VisibilityEffect .muted);
218
+ });
219
+
220
+ test ('stream muted, policy none -> followed, means none/unmuted' , () async {
221
+ final store = eg.store ();
222
+ await store.addStream (stream1);
223
+ await store.addSubscription (eg.subscription (stream1, isMuted: true ));
224
+ checkChanges (store, UserTopicVisibilityPolicy .followed,
225
+ VisibilityEffect .none, VisibilityEffect .unmuted);
226
+ });
227
+
228
+ test ('stream muted, policy none -> muted, means muted/none' , () async {
229
+ final store = eg.store ();
230
+ await store.addStream (stream1);
231
+ await store.addSubscription (eg.subscription (stream1, isMuted: true ));
232
+ checkChanges (store, UserTopicVisibilityPolicy .muted,
233
+ VisibilityEffect .muted, VisibilityEffect .none);
234
+ });
235
+
236
+ final policies = [
237
+ UserTopicVisibilityPolicy .muted,
238
+ UserTopicVisibilityPolicy .none,
239
+ UserTopicVisibilityPolicy .unmuted,
240
+ ];
241
+ for (final streamMuted in [null , false , true ]) {
242
+ for (final oldPolicy in policies) {
243
+ for (final newPolicy in policies) {
244
+ final streamDesc = switch (streamMuted) {
245
+ false => "stream not muted" ,
246
+ true => "stream muted" ,
247
+ null => "stream unsubscribed" ,
248
+ };
249
+ test ('$streamDesc , topic ${oldPolicy .name } -> ${newPolicy .name }' , () async {
250
+ final store = eg.store ();
251
+ await store.addStream (stream1);
252
+ if (streamMuted != null ) {
253
+ await store.addSubscription (
254
+ eg.subscription (stream1, isMuted: streamMuted));
255
+ }
256
+ store.handleEvent (mkEvent (oldPolicy));
257
+ final oldVisibleInStream = store.isTopicVisibleInStream (stream1.streamId, 'topic' );
258
+ final oldVisible = store.isTopicVisible (stream1.streamId, 'topic' );
259
+
260
+ final event = mkEvent (newPolicy);
261
+ final willChangeInStream = store.willChangeIfTopicVisibleInStream (event);
262
+ final willChange = store.willChangeIfTopicVisible (event);
263
+
264
+ store.handleEvent (event);
265
+ final newVisibleInStream = store.isTopicVisibleInStream (stream1.streamId, 'topic' );
266
+ final newVisible = store.isTopicVisible (stream1.streamId, 'topic' );
267
+
268
+ VisibilityEffect fromOldNew (bool oldVisible, bool newVisible) {
269
+ if (newVisible == oldVisible) return VisibilityEffect .none;
270
+ if (newVisible) return VisibilityEffect .unmuted;
271
+ return VisibilityEffect .muted;
272
+ }
273
+ check (willChangeInStream)
274
+ .equals (fromOldNew (oldVisibleInStream, newVisibleInStream));
275
+ check (willChange)
276
+ .equals (fromOldNew (oldVisible, newVisible));
277
+ });
278
+ }
279
+ }
280
+ }
281
+ });
282
+
192
283
void compareTopicVisibility (PerAccountStore store, List <UserTopicItem > expected) {
193
284
final expectedStore = eg.store (initialSnapshot: eg.initialSnapshot (
194
285
userTopics: expected,
0 commit comments