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,20 +227,40 @@ 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 UserTopicVisibilityEffect expectedInStream,
229256 UserTopicVisibilityEffect expectedOverall) {
230257 final event = mkEvent (newPolicy);
231258 check (store.willChangeIfTopicVisibleInStream (event)).equals (expectedInStream);
232259 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);
233264 }
234265
235266 test ('stream not muted, policy none -> followed, no change' , () async {
@@ -366,6 +397,12 @@ void main() {
366397 compareTopicVisibility (store, [
367398 eg.userTopicItem (stream1, 'topic' , UserTopicVisibilityPolicy .unmuted),
368399 ]);
400+
401+ // case-insensitivity
402+ await store.setUserTopic (stream1, 'ToPiC' , UserTopicVisibilityPolicy .followed);
403+ compareTopicVisibility (store, [
404+ eg.userTopicItem (stream1, 'topic' , UserTopicVisibilityPolicy .followed),
405+ ]);
369406 });
370407
371408 test ('remove, with others in stream' , () async {
@@ -381,15 +418,17 @@ void main() {
381418 test ('remove, as last in stream' , () async {
382419 final store = eg.store ();
383420 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);
385423 compareTopicVisibility (store, [
386424 ]);
387425 });
388426
389427 test ('treat unknown enum value as removing' , () async {
390428 final store = eg.store ();
391429 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);
393432 compareTopicVisibility (store, [
394433 ]);
395434 });
@@ -406,7 +445,8 @@ void main() {
406445 ]));
407446 check (store.topicVisibilityPolicy (stream.streamId, eg.t ('topic 1' )))
408447 .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' )))
410450 .equals (UserTopicVisibilityPolicy .unmuted);
411451 check (store.topicVisibilityPolicy (stream.streamId, eg.t ('topic 3' )))
412452 .equals (UserTopicVisibilityPolicy .followed);
0 commit comments