@@ -9,6 +9,13 @@ import 'package:zulip/model/store.dart';
9
9
import '../example_data.dart' as eg;
10
10
import 'test_store.dart' ;
11
11
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
+
12
19
Future <PerAccountStore > setupStore ({
13
20
required Uri realmUrl,
14
21
List <ZulipStream >? streams,
@@ -36,12 +43,14 @@ void main() {
36
43
assert (streams != null || users != null );
37
44
for (final testCase in testCases) {
38
45
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
+ }
45
54
}
46
55
}
47
56
@@ -131,12 +140,14 @@ void main() {
131
140
final String description = testCase.$2;
132
141
final String urlString = testCase.$3;
133
142
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
+ }
140
151
}
141
152
});
142
153
@@ -169,6 +180,18 @@ void main() {
169
180
testExpectedNarrows (testCases, streams: streams);
170
181
});
171
182
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
+
172
195
group ('"/#narrow/dm/<...>" returns expected DmNarrow' , () {
173
196
final expectedNarrow = DmNarrow .withUsers ([1 , 2 ],
174
197
selfUserId: eg.selfUser.userId);
0 commit comments