@@ -131,13 +131,16 @@ void main() {
131
131
final bool expected = testCase.$1;
132
132
final String description = testCase.$2;
133
133
final String urlString = testCase.$3;
134
+ final String urlWithChannelSyntax = urlString.replaceFirst ('#narrow/stream/' , '#narrow/channel/' );
134
135
final Uri realmUrl = testCase.$4;
135
- test ('${expected ? 'accepts' : 'rejects' } $description : $urlString ' , () {
136
- final store = setupStore (realmUrl: realmUrl, streams: streams);
137
- final url = store.tryResolveUrl (urlString)! ;
138
- final result = parseInternalLink (url, store);
139
- check (result != null ).equals (expected);
140
- });
136
+ for (var urlString in [urlString, urlWithChannelSyntax]) {
137
+ test ('${expected ? 'accepts' : 'rejects' } $description : $urlString ' , () {
138
+ final store = setupStore (realmUrl: realmUrl, streams: streams);
139
+ final url = store.tryResolveUrl (urlString)! ;
140
+ final result = parseInternalLink (url, store);
141
+ check (result != null ).equals (expected);
142
+ });
143
+ }
141
144
}
142
145
});
143
146
@@ -158,6 +161,15 @@ void main() {
158
161
testExpectedNarrows (testCases, streams: streams);
159
162
});
160
163
164
+ group ('"/#narrow/channel/<...>" returns expected StreamNarrow' , () {
165
+ const testCases = [
166
+ ('/#narrow/channel/check' , StreamNarrow (1 )),
167
+ ('/#narrow/channel/stream/' , StreamNarrow (5 )),
168
+ ('/#narrow/channel/topic/' , StreamNarrow (123 )),
169
+ ];
170
+ testExpectedNarrows (testCases, streams: streams);
171
+ });
172
+
161
173
group ('"/#narrow/stream/<...>/topic/<...>" returns expected TopicNarrow' , () {
162
174
const testCases = [
163
175
('/#narrow/stream/check/topic/test' , TopicNarrow (1 , 'test' )),
@@ -170,6 +182,18 @@ void main() {
170
182
testExpectedNarrows (testCases, streams: streams);
171
183
});
172
184
185
+ group ('"/#narrow/channel/<...>/topic/<...>" returns expected TopicNarrow' , () {
186
+ const testCases = [
187
+ ('/#narrow/channel/check/topic/test' , TopicNarrow (1 , 'test' )),
188
+ ('/#narrow/channel/mobile/subject/topic/near/378333' , TopicNarrow (3 , 'topic' )),
189
+ ('/#narrow/channel/mobile/topic/topic/' , TopicNarrow (3 , 'topic' )),
190
+ ('/#narrow/channel/stream/topic/topic/near/1' , TopicNarrow (5 , 'topic' )),
191
+ ('/#narrow/channel/stream/subject/topic/near/1' , TopicNarrow (5 , 'topic' )),
192
+ ('/#narrow/channel/stream/subject/topic' , TopicNarrow (5 , 'topic' )),
193
+ ];
194
+ testExpectedNarrows (testCases, streams: streams);
195
+ });
196
+
173
197
group ('"/#narrow/dm/<...>" returns expected DmNarrow' , () {
174
198
final expectedNarrow = DmNarrow .withUsers ([1 , 2 ],
175
199
selfUserId: eg.selfUser.userId);
@@ -196,6 +220,8 @@ void main() {
196
220
final testCases = [
197
221
('/#narrow/stream/name/topic/' , null ), // missing operand
198
222
('/#narrow/stream/name/unknown/operand/' , null ), // unknown operator
223
+ ('/#narrow/channel/name/topic/' , null ), // missing operand
224
+ ('/#narrow/channel/name/unknown/operand/' , null ), // unknown operator
199
225
];
200
226
testExpectedNarrows (testCases, streams: streams);
201
227
});
@@ -247,6 +273,23 @@ void main() {
247
273
];
248
274
testExpectedNarrows (testCases, streams: streams);
249
275
});
276
+
277
+ group ('parses correctly in channel and topic operands' , () {
278
+ final streams = [
279
+ eg.stream (streamId: 1 , name: 'some_stream' ),
280
+ eg.stream (streamId: 2 , name: 'some stream' ),
281
+ eg.stream (streamId: 3 , name: 'some.stream' ),
282
+ ];
283
+ const testCases = [
284
+ ('/#narrow/channel/some_stream' , StreamNarrow (1 )),
285
+ ('/#narrow/channel/some.20stream' , StreamNarrow (2 )),
286
+ ('/#narrow/channel/some.2Estream' , StreamNarrow (3 )),
287
+ ('/#narrow/channel/some_stream/topic/some_topic' , TopicNarrow (1 , 'some_topic' )),
288
+ ('/#narrow/channel/some_stream/topic/some.20topic' , TopicNarrow (1 , 'some topic' )),
289
+ ('/#narrow/channel/some_stream/topic/some.2Etopic' , TopicNarrow (1 , 'some.topic' )),
290
+ ];
291
+ testExpectedNarrows (testCases, streams: streams);
292
+ });
250
293
});
251
294
252
295
group ('parseInternalLink edge cases' , () {
@@ -259,21 +302,28 @@ void main() {
259
302
260
303
group ('basic' , () {
261
304
testExpectedStreamNarrow ('#narrow/stream/1-general' , 1 );
305
+ testExpectedStreamNarrow ('#narrow/channel/1-general' , 1 );
262
306
});
263
307
264
308
group ('if stream not found, use stream ID anyway' , () {
265
309
testExpectedStreamNarrow ('#narrow/stream/123-topic' , 123 );
310
+ testExpectedStreamNarrow ('#narrow/channel/123-topic' , 123 );
266
311
});
267
312
268
313
group ('on stream link with wrong name, ID wins' , () {
269
314
testExpectedStreamNarrow ('#narrow/stream/1-nonsense' , 1 );
270
315
testExpectedStreamNarrow ('#narrow/stream/1-' , 1 );
316
+ testExpectedStreamNarrow ('#narrow/channel/1-nonsense' , 1 );
317
+ testExpectedStreamNarrow ('#narrow/channel/1-' , 1 );
271
318
});
272
319
273
320
group ('on malformed stream link: reject' , () {
274
321
testExpectedStreamNarrow ('#narrow/stream/-1' , null );
275
322
testExpectedStreamNarrow ('#narrow/stream/1nonsense-general' , null );
276
323
testExpectedStreamNarrow ('#narrow/stream/-general' , null );
324
+ testExpectedStreamNarrow ('#narrow/channel/-1' , null );
325
+ testExpectedStreamNarrow ('#narrow/channel/1nonsense-general' , null );
326
+ testExpectedStreamNarrow ('#narrow/channel/-general' , null );
277
327
});
278
328
});
279
329
@@ -292,6 +342,11 @@ void main() {
292
342
('#narrow/stream/311-/' , StreamNarrow (3 )),
293
343
('#narrow/stream/311-help/' , StreamNarrow (4 )),
294
344
('#narrow/stream/--help/' , StreamNarrow (5 )),
345
+ ('#narrow/channel/test-team/' , StreamNarrow (1 )),
346
+ ('#narrow/channel/311/' , StreamNarrow (2 )),
347
+ ('#narrow/channel/311-/' , StreamNarrow (3 )),
348
+ ('#narrow/channel/311-help/' , StreamNarrow (4 )),
349
+ ('#narrow/channel/--help/' , StreamNarrow (5 )),
295
350
];
296
351
testExpectedNarrows (testCases, streams: streams);
297
352
});
@@ -307,6 +362,9 @@ void main() {
307
362
('#narrow/stream/311/' , StreamNarrow (311 )),
308
363
('#narrow/stream/311-/' , StreamNarrow (311 )),
309
364
('#narrow/stream/311-help/' , StreamNarrow (311 )),
365
+ ('#narrow/channel/311/' , StreamNarrow (311 )),
366
+ ('#narrow/channel/311-/' , StreamNarrow (311 )),
367
+ ('#narrow/channel/311-help/' , StreamNarrow (311 )),
310
368
];
311
369
testExpectedNarrows (testCases, streams: streams);
312
370
});
@@ -327,6 +385,14 @@ void main() {
327
385
('#narrow/stream/topic/' , StreamNarrow (5 )),
328
386
329
387
('#narrow/stream/check.API/' , null ),
388
+
389
+ ('#narrow/channel/check/' , StreamNarrow (1 )),
390
+ ('#narrow/channel/bot.20testing/' , StreamNarrow (2 )),
391
+ ('#narrow/channel/check.2EAPI/' , StreamNarrow (3 )),
392
+ ('#narrow/channel/stream/' , StreamNarrow (4 )),
393
+ ('#narrow/channel/topic/' , StreamNarrow (5 )),
394
+
395
+ ('#narrow/channel/check.API/' , null ),
330
396
];
331
397
testExpectedNarrows (testCases, streams: streams);
332
398
});
@@ -337,27 +403,36 @@ void main() {
337
403
final stream = eg.stream (name: "general" );
338
404
339
405
group ('basic' , () {
340
- String mkUrlString (operand) {
341
- return '#narrow/stream /${stream .streamId }-${stream .name }/topic/$operand ' ;
406
+ String mkUrlString (operand, String streamSyntax ) {
407
+ return '#narrow/$ streamSyntax /${stream .streamId }-${stream .name }/topic/$operand ' ;
342
408
}
343
409
final testCases = [
344
- (mkUrlString ('(no.20topic)' ), TopicNarrow (stream.streamId, '(no topic)' )),
345
- (mkUrlString ('lunch' ), TopicNarrow (stream.streamId, 'lunch' )),
410
+ (mkUrlString ('(no.20topic)' , 'stream' ), TopicNarrow (stream.streamId, '(no topic)' )),
411
+ (mkUrlString ('lunch' , 'stream' ), TopicNarrow (stream.streamId, 'lunch' )),
412
+ (mkUrlString ('(no.20topic)' , 'channel' ), TopicNarrow (stream.streamId, '(no topic)' )),
413
+ (mkUrlString ('lunch' , 'channel' ), TopicNarrow (stream.streamId, 'lunch' )),
346
414
];
347
415
testExpectedNarrows (testCases, streams: [stream]);
348
416
});
349
417
350
418
group ('on old topic link, with dot-encoding' , () {
351
- String mkUrlString (operand) {
419
+ String mkUrlString (operand, String streamSyntax ) {
352
420
return '#narrow/stream/${stream .name }/topic/$operand ' ;
353
421
}
354
422
final testCases = [
355
- (mkUrlString ('(no.20topic)' ), TopicNarrow (stream.streamId, '(no topic)' )),
356
- (mkUrlString ('google.2Ecom' ), TopicNarrow (stream.streamId, 'google.com' )),
357
- (mkUrlString ('google.com' ), null ),
358
- (mkUrlString ('topic.20name' ), TopicNarrow (stream.streamId, 'topic name' )),
359
- (mkUrlString ('stream' ), TopicNarrow (stream.streamId, 'stream' )),
360
- (mkUrlString ('topic' ), TopicNarrow (stream.streamId, 'topic' )),
423
+ (mkUrlString ('(no.20topic)' , 'stream' ), TopicNarrow (stream.streamId, '(no topic)' )),
424
+ (mkUrlString ('google.2Ecom' , 'stream' ), TopicNarrow (stream.streamId, 'google.com' )),
425
+ (mkUrlString ('google.com' , 'stream' ), null ),
426
+ (mkUrlString ('topic.20name' , 'stream' ), TopicNarrow (stream.streamId, 'topic name' )),
427
+ (mkUrlString ('stream' , 'stream' ), TopicNarrow (stream.streamId, 'stream' )),
428
+ (mkUrlString ('topic' , 'stream' ), TopicNarrow (stream.streamId, 'topic' )),
429
+
430
+ (mkUrlString ('(no.20topic)' , 'channel' ), TopicNarrow (stream.streamId, '(no topic)' )),
431
+ (mkUrlString ('google.2Ecom' , 'channel' ), TopicNarrow (stream.streamId, 'google.com' )),
432
+ (mkUrlString ('google.com' , 'channel' ), null ),
433
+ (mkUrlString ('topic.20name' , 'channel' ), TopicNarrow (stream.streamId, 'topic name' )),
434
+ (mkUrlString ('stream' , 'channel' ), TopicNarrow (stream.streamId, 'stream' )),
435
+ (mkUrlString ('topic' , 'channel' ), TopicNarrow (stream.streamId, 'topic' )),
361
436
];
362
437
testExpectedNarrows (testCases, streams: [stream]);
363
438
});
0 commit comments