1-
21import 'package:checks/checks.dart' ;
32import 'package:test/scaffolding.dart' ;
43import 'package:zulip/api/model/events.dart' ;
@@ -163,6 +162,10 @@ void main() {
163162 await store.setUserTopic (stream1, 'topic' , policy);
164163 check (store.topicVisibilityPolicy (stream1.streamId, eg.t ('topic' )))
165164 .equals (policy);
165+
166+ // Case-insensitive
167+ check (store.topicVisibilityPolicy (stream1.streamId, eg.t ('ToPiC' )))
168+ .equals (policy);
166169 }
167170 });
168171 });
@@ -198,6 +201,10 @@ void main() {
198201 await store.setUserTopic (stream1, 'topic' , UserTopicVisibilityPolicy .muted);
199202 check (store.isTopicVisibleInStream (stream1.streamId, eg.t ('topic' ))).isFalse ();
200203 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 ();
201208 });
202209
203210 test ('with policy unmuted' , () async {
@@ -207,6 +214,10 @@ void main() {
207214 await store.setUserTopic (stream1, 'topic' , UserTopicVisibilityPolicy .unmuted);
208215 check (store.isTopicVisibleInStream (stream1.streamId, eg.t ('topic' ))).isTrue ();
209216 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 ();
210221 });
211222
212223 test ('with policy followed' , () async {
@@ -216,19 +227,39 @@ void main() {
216227 await store.setUserTopic (stream1, 'topic' , UserTopicVisibilityPolicy .followed);
217228 check (store.isTopicVisibleInStream (stream1.streamId, eg.t ('topic' ))).isTrue ();
218229 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 ();
219234 });
220235 });
221236
222237 group ('willChangeIfTopicVisible/InStream' , () {
223238 UserTopicEvent mkEvent (UserTopicVisibilityPolicy policy) =>
224239 eg.userTopicEvent (stream1.streamId, 'topic' , policy);
225240
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+
226253 void checkChanges (PerAccountStore store,
227254 UserTopicVisibilityPolicy newPolicy,
228255 VisibilityEffect expectedInStream, VisibilityEffect expectedOverall) {
229256 final event = mkEvent (newPolicy);
230257 check (store.willChangeIfTopicVisibleInStream (event)).equals (expectedInStream);
231258 check (store.willChangeIfTopicVisible (event)).equals (expectedOverall);
259+
260+ final event2 = mkEventDifferentlyCased (newPolicy);
261+ check (store.willChangeIfTopicVisibleInStream (event2)).equals (expectedInStream);
262+ check (store.willChangeIfTopicVisible (event2)).equals (expectedOverall);
232263 }
233264
234265 test ('stream not muted, policy none -> followed, no change' , () async {
@@ -365,6 +396,12 @@ void main() {
365396 compareTopicVisibility (store, [
366397 eg.userTopicItem (stream1, 'topic' , UserTopicVisibilityPolicy .unmuted),
367398 ]);
399+
400+ // case-insensitivity
401+ await store.setUserTopic (stream1, 'ToPiC' , UserTopicVisibilityPolicy .followed);
402+ compareTopicVisibility (store, [
403+ eg.userTopicItem (stream1, 'topic' , UserTopicVisibilityPolicy .followed),
404+ ]);
368405 });
369406
370407 test ('remove, with others in stream' , () async {
@@ -380,15 +417,17 @@ void main() {
380417 test ('remove, as last in stream' , () async {
381418 final store = eg.store ();
382419 await store.setUserTopic (stream1, 'topic' , UserTopicVisibilityPolicy .muted);
383- await store.setUserTopic (stream1, 'topic' , UserTopicVisibilityPolicy .none);
420+ // case-insensitivity
421+ await store.setUserTopic (stream1, 'ToPiC' , UserTopicVisibilityPolicy .none);
384422 compareTopicVisibility (store, [
385423 ]);
386424 });
387425
388426 test ('treat unknown enum value as removing' , () async {
389427 final store = eg.store ();
390428 await store.setUserTopic (stream1, 'topic' , UserTopicVisibilityPolicy .muted);
391- await store.setUserTopic (stream1, 'topic' , UserTopicVisibilityPolicy .unknown);
429+ // case-insensitivity
430+ await store.setUserTopic (stream1, 'ToPiC' , UserTopicVisibilityPolicy .unknown);
392431 compareTopicVisibility (store, [
393432 ]);
394433 });
@@ -405,7 +444,8 @@ void main() {
405444 ]));
406445 check (store.topicVisibilityPolicy (stream.streamId, eg.t ('topic 1' )))
407446 .equals (UserTopicVisibilityPolicy .muted);
408- check (store.topicVisibilityPolicy (stream.streamId, eg.t ('topic 2' )))
447+ // case-insensitivity
448+ check (store.topicVisibilityPolicy (stream.streamId, eg.t ('ToPiC 2' )))
409449 .equals (UserTopicVisibilityPolicy .unmuted);
410450 check (store.topicVisibilityPolicy (stream.streamId, eg.t ('topic 3' )))
411451 .equals (UserTopicVisibilityPolicy .followed);
0 commit comments