@@ -9,6 +9,13 @@ import 'package:zulip/model/store.dart';
99import '../example_data.dart' as eg;
1010import 'test_store.dart' ;
1111
12+ // Using Set instead of List in to avoid any duplicated test urls.
13+ Set <String > getUrlSyntaxVariants (String urlString) {
14+ final urlWithChannelSyntax = urlString.replaceFirst ('#narrow/stream' , '#narrow/channel' );
15+ final urlWithStreamSyntax = urlString.replaceFirst ('#narrow/channel' , '#narrow/stream' );
16+ return {urlWithStreamSyntax, urlWithChannelSyntax};
17+ }
18+
1219Future <PerAccountStore > setupStore ({
1320 required Uri realmUrl,
1421 List <ZulipStream >? streams,
@@ -36,12 +43,14 @@ void main() {
3643 assert (streams != null || users != null );
3744 for (final testCase in testCases) {
3845 final String urlString = testCase.$1;
39- final Narrow ? expected = testCase.$2;
40- test (urlString, () async {
41- final store = await setupStore (realmUrl: realmUrl, streams: streams, users: users);
42- final url = store.tryResolveUrl (urlString)! ;
43- check (parseInternalLink (url, store)).equals (expected);
44- });
46+ for (final urlString in getUrlSyntaxVariants (urlString)) {
47+ final Narrow ? expected = testCase.$2;
48+ test (urlString, () async {
49+ final store = await setupStore (realmUrl: realmUrl, streams: streams, users: users);
50+ final url = store.tryResolveUrl (urlString)! ;
51+ check (parseInternalLink (url, store)).equals (expected);
52+ });
53+ }
4554 }
4655 }
4756
@@ -131,12 +140,14 @@ void main() {
131140 final String description = testCase.$2;
132141 final String urlString = testCase.$3;
133142 final Uri realmUrl = testCase.$4;
134- test ('${expected ? 'accepts' : 'rejects' } $description : $urlString ' , () async {
135- final store = await setupStore (realmUrl: realmUrl, streams: streams);
136- final url = store.tryResolveUrl (urlString)! ;
137- final result = parseInternalLink (url, store);
138- check (result != null ).equals (expected);
139- });
143+ for (final urlString in getUrlSyntaxVariants (urlString)) {
144+ test ('${expected ? 'accepts' : 'rejects' } $description : $urlString ' , () async {
145+ final store = await setupStore (realmUrl: realmUrl, streams: streams);
146+ final url = store.tryResolveUrl (urlString)! ;
147+ final result = parseInternalLink (url, store);
148+ check (result != null ).equals (expected);
149+ });
150+ }
140151 }
141152 });
142153
@@ -169,6 +180,18 @@ void main() {
169180 testExpectedNarrows (testCases, streams: streams);
170181 });
171182
183+ group ('Both `stream` and `channel` can be used interchangeably' , () {
184+ const testCases = [
185+ ('/#narrow/stream/check' , StreamNarrow (1 )),
186+ ('/#narrow/channel/check' , StreamNarrow (1 )),
187+ ('/#narrow/stream/check/topic/test' , TopicNarrow (1 , 'test' )),
188+ ('/#narrow/channel/check/topic/test' , TopicNarrow (1 , 'test' )),
189+ ('/#narrow/stream/check/topic/test/near/378333' , TopicNarrow (1 , 'test' )),
190+ ('/#narrow/channel/check/topic/test/near/378333' , TopicNarrow (1 , 'test' )),
191+ ];
192+ testExpectedNarrows (testCases, streams: streams);
193+ });
194+
172195 group ('"/#narrow/dm/<...>" returns expected DmNarrow' , () {
173196 final expectedNarrow = DmNarrow .withUsers ([1 , 2 ],
174197 selfUserId: eg.selfUser.userId);
0 commit comments