1
-
2
1
import 'package:checks/checks.dart' ;
3
2
import 'package:test/scaffolding.dart' ;
4
3
import 'package:zulip/api/model/events.dart' ;
@@ -163,6 +162,10 @@ void main() {
163
162
await store.setUserTopic (stream1, 'topic' , policy);
164
163
check (store.topicVisibilityPolicy (stream1.streamId, eg.t ('topic' )))
165
164
.equals (policy);
165
+
166
+ // Case-insensitive
167
+ check (store.topicVisibilityPolicy (stream1.streamId, eg.t ('ToPiC' )))
168
+ .equals (policy);
166
169
}
167
170
});
168
171
});
@@ -198,6 +201,10 @@ void main() {
198
201
await store.setUserTopic (stream1, 'topic' , UserTopicVisibilityPolicy .muted);
199
202
check (store.isTopicVisibleInStream (stream1.streamId, eg.t ('topic' ))).isFalse ();
200
203
check (store.isTopicVisible (stream1.streamId, eg.t ('topic' ))).isFalse ();
204
+
205
+ // Case-insensitive
206
+ check (store.isTopicVisibleInStream (stream1.streamId, eg.t ('ToPiC' ))).isFalse ();
207
+ check (store.isTopicVisible (stream1.streamId, eg.t ('ToPiC' ))).isFalse ();
201
208
});
202
209
203
210
test ('with policy unmuted' , () async {
@@ -207,6 +214,10 @@ void main() {
207
214
await store.setUserTopic (stream1, 'topic' , UserTopicVisibilityPolicy .unmuted);
208
215
check (store.isTopicVisibleInStream (stream1.streamId, eg.t ('topic' ))).isTrue ();
209
216
check (store.isTopicVisible (stream1.streamId, eg.t ('topic' ))).isTrue ();
217
+
218
+ // Case-insensitive
219
+ check (store.isTopicVisibleInStream (stream1.streamId, eg.t ('tOpIc' ))).isTrue ();
220
+ check (store.isTopicVisible (stream1.streamId, eg.t ('tOpIc' ))).isTrue ();
210
221
});
211
222
212
223
test ('with policy followed' , () async {
@@ -216,20 +227,40 @@ void main() {
216
227
await store.setUserTopic (stream1, 'topic' , UserTopicVisibilityPolicy .followed);
217
228
check (store.isTopicVisibleInStream (stream1.streamId, eg.t ('topic' ))).isTrue ();
218
229
check (store.isTopicVisible (stream1.streamId, eg.t ('topic' ))).isTrue ();
230
+
231
+ // Case-insensitive
232
+ check (store.isTopicVisibleInStream (stream1.streamId, eg.t ('TOPIC' ))).isTrue ();
233
+ check (store.isTopicVisible (stream1.streamId, eg.t ('TOPIC' ))).isTrue ();
219
234
});
220
235
});
221
236
222
237
group ('willChangeIfTopicVisible/InStream' , () {
223
238
UserTopicEvent mkEvent (UserTopicVisibilityPolicy policy) =>
224
239
eg.userTopicEvent (stream1.streamId, 'topic' , policy);
225
240
241
+ // For testing case-insensitivity
242
+ UserTopicEvent mkEventDifferentlyCased (UserTopicVisibilityPolicy policy) =>
243
+ eg.userTopicEvent (stream1.streamId, 'ToPiC' , policy);
244
+
245
+ assert (() {
246
+ // (sanity check on mkEvent and mkEventDifferentlyCased)
247
+ final event1 = mkEvent (UserTopicVisibilityPolicy .followed);
248
+ final event2 = mkEventDifferentlyCased (UserTopicVisibilityPolicy .followed);
249
+ return event1.topicName.isSameAs (event2.topicName)
250
+ && event1.topicName.apiName != event2.topicName.apiName;
251
+ }());
252
+
226
253
void checkChanges (PerAccountStore store,
227
254
UserTopicVisibilityPolicy newPolicy,
228
255
UserTopicVisibilityEffect expectedInStream,
229
256
UserTopicVisibilityEffect expectedOverall) {
230
257
final event = mkEvent (newPolicy);
231
258
check (store.willChangeIfTopicVisibleInStream (event)).equals (expectedInStream);
232
259
check (store.willChangeIfTopicVisible (event)).equals (expectedOverall);
260
+
261
+ final event2 = mkEventDifferentlyCased (newPolicy);
262
+ check (store.willChangeIfTopicVisibleInStream (event2)).equals (expectedInStream);
263
+ check (store.willChangeIfTopicVisible (event2)).equals (expectedOverall);
233
264
}
234
265
235
266
test ('stream not muted, policy none -> followed, no change' , () async {
@@ -366,6 +397,12 @@ void main() {
366
397
compareTopicVisibility (store, [
367
398
eg.userTopicItem (stream1, 'topic' , UserTopicVisibilityPolicy .unmuted),
368
399
]);
400
+
401
+ // case-insensitivity
402
+ await store.setUserTopic (stream1, 'ToPiC' , UserTopicVisibilityPolicy .followed);
403
+ compareTopicVisibility (store, [
404
+ eg.userTopicItem (stream1, 'topic' , UserTopicVisibilityPolicy .followed),
405
+ ]);
369
406
});
370
407
371
408
test ('remove, with others in stream' , () async {
@@ -381,15 +418,17 @@ void main() {
381
418
test ('remove, as last in stream' , () async {
382
419
final store = eg.store ();
383
420
await store.setUserTopic (stream1, 'topic' , UserTopicVisibilityPolicy .muted);
384
- await store.setUserTopic (stream1, 'topic' , UserTopicVisibilityPolicy .none);
421
+ // case-insensitivity
422
+ await store.setUserTopic (stream1, 'ToPiC' , UserTopicVisibilityPolicy .none);
385
423
compareTopicVisibility (store, [
386
424
]);
387
425
});
388
426
389
427
test ('treat unknown enum value as removing' , () async {
390
428
final store = eg.store ();
391
429
await store.setUserTopic (stream1, 'topic' , UserTopicVisibilityPolicy .muted);
392
- await store.setUserTopic (stream1, 'topic' , UserTopicVisibilityPolicy .unknown);
430
+ // case-insensitivity
431
+ await store.setUserTopic (stream1, 'ToPiC' , UserTopicVisibilityPolicy .unknown);
393
432
compareTopicVisibility (store, [
394
433
]);
395
434
});
@@ -406,7 +445,8 @@ void main() {
406
445
]));
407
446
check (store.topicVisibilityPolicy (stream.streamId, eg.t ('topic 1' )))
408
447
.equals (UserTopicVisibilityPolicy .muted);
409
- check (store.topicVisibilityPolicy (stream.streamId, eg.t ('topic 2' )))
448
+ // case-insensitivity
449
+ check (store.topicVisibilityPolicy (stream.streamId, eg.t ('ToPiC 2' )))
410
450
.equals (UserTopicVisibilityPolicy .unmuted);
411
451
check (store.topicVisibilityPolicy (stream.streamId, eg.t ('topic 3' )))
412
452
.equals (UserTopicVisibilityPolicy .followed);
0 commit comments