Skip to content

Commit 01e63be

Browse files
committed
internal_link test [nfc]: Merge tests with the same name
These tests are originally from the legacy app: https://github.com/zulip/zulip-mobile/blob/0d92d2e10d52713a1beba7339200ec3dc305f348/src/utils/__tests__/internalLinks-test.js#L340-L408 They were added in the early days of the internal links, and we should integrate them with the new tests. Signed-off-by: Zixuan James Li <[email protected]>
1 parent 627784f commit 01e63be

File tree

1 file changed

+38
-54
lines changed

1 file changed

+38
-54
lines changed

test/model/internal_link_test.dart

Lines changed: 38 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -184,6 +184,36 @@ void main() {
184184
testExpectedNarrows(testCases, streams: streams);
185185
});
186186

187+
group('topic link parsing', () {
188+
final stream = eg.stream(name: "general");
189+
190+
group('basic', () {
191+
String mkUrlString(String operand) {
192+
return '#narrow/stream/${stream.streamId}-${stream.name}/topic/$operand';
193+
}
194+
final testCases = [
195+
(mkUrlString('(no.20topic)'), TopicNarrow(stream.streamId, '(no topic)')),
196+
(mkUrlString('lunch'), TopicNarrow(stream.streamId, 'lunch')),
197+
];
198+
testExpectedNarrows(testCases, streams: [stream]);
199+
});
200+
201+
group('on old topic link, with dot-encoding', () {
202+
String mkUrlString(String operand) {
203+
return '#narrow/stream/${stream.name}/topic/$operand';
204+
}
205+
final testCases = [
206+
(mkUrlString('(no.20topic)'), TopicNarrow(stream.streamId, '(no topic)')),
207+
(mkUrlString('google.2Ecom'), TopicNarrow(stream.streamId, 'google.com')),
208+
(mkUrlString('google.com'), null),
209+
(mkUrlString('topic.20name'), TopicNarrow(stream.streamId, 'topic name')),
210+
(mkUrlString('stream'), TopicNarrow(stream.streamId, 'stream')),
211+
(mkUrlString('topic'), TopicNarrow(stream.streamId, 'topic')),
212+
];
213+
testExpectedNarrows(testCases, streams: [stream]);
214+
});
215+
});
216+
187217
group('Both `stream` and `channel` can be used interchangeably', () {
188218
const testCases = [
189219
('/#narrow/stream/check', ChannelNarrow(1)),
@@ -203,6 +233,10 @@ void main() {
203233
('/#narrow/dm/1,2-group', expectedNarrow),
204234
('/#narrow/dm/1,2-group/near/1', expectedNarrow),
205235
('/#narrow/dm/1,2-group/with/2', expectedNarrow),
236+
237+
// The webapp doesn't generate this, but best to handle it anyway.
238+
('#narrow/dm/1,2,${eg.selfUser.userId}-group', expectedNarrow),
239+
206240
('/#narrow/dm/a.40b.2Ecom.2Ec.2Ed.2Ecom/near/3', null),
207241
('/#narrow/dm/a.40b.2Ecom.2Ec.2Ed.2Ecom/with/4', null),
208242
];
@@ -216,6 +250,10 @@ void main() {
216250
('/#narrow/pm-with/1,2-group', expectedNarrow),
217251
('/#narrow/pm-with/1,2-group/near/1', expectedNarrow),
218252
('/#narrow/pm-with/1,2-group/with/2', expectedNarrow),
253+
254+
// The webapp doesn't generate this, but best to handle it anyway.
255+
('#narrow/pm-with/1,2,${eg.selfUser.userId}-group', expectedNarrow),
256+
219257
('/#narrow/pm-with/a.40b.2Ecom.2Ec.2Ed.2Ecom/near/3', null),
220258
('/#narrow/pm-with/a.40b.2Ecom.2Ec.2Ed.2Ecom/with/3', null),
221259
];
@@ -397,58 +435,4 @@ void main() {
397435
testExpectedNarrows(testCases, streams: streams);
398436
});
399437
});
400-
401-
group('parseInternalLink', () {
402-
group('topic link parsing', () {
403-
final stream = eg.stream(name: "general");
404-
405-
group('basic', () {
406-
String mkUrlString(String operand) {
407-
return '#narrow/stream/${stream.streamId}-${stream.name}/topic/$operand';
408-
}
409-
final testCases = [
410-
(mkUrlString('(no.20topic)'), TopicNarrow(stream.streamId, '(no topic)')),
411-
(mkUrlString('lunch'), TopicNarrow(stream.streamId, 'lunch')),
412-
];
413-
testExpectedNarrows(testCases, streams: [stream]);
414-
});
415-
416-
group('on old topic link, with dot-encoding', () {
417-
String mkUrlString(String operand) {
418-
return '#narrow/stream/${stream.name}/topic/$operand';
419-
}
420-
final testCases = [
421-
(mkUrlString('(no.20topic)'), TopicNarrow(stream.streamId, '(no topic)')),
422-
(mkUrlString('google.2Ecom'), TopicNarrow(stream.streamId, 'google.com')),
423-
(mkUrlString('google.com'), null),
424-
(mkUrlString('topic.20name'), TopicNarrow(stream.streamId, 'topic name')),
425-
(mkUrlString('stream'), TopicNarrow(stream.streamId, 'stream')),
426-
(mkUrlString('topic'), TopicNarrow(stream.streamId, 'topic')),
427-
];
428-
testExpectedNarrows(testCases, streams: [stream]);
429-
});
430-
});
431-
432-
group('DM link parsing', () {
433-
void testExpectedDmNarrow(String testCase) {
434-
final expectedNarrow = DmNarrow.withUsers([1, 2],
435-
selfUserId: eg.selfUser.userId);
436-
testExpectedNarrows([(testCase, expectedNarrow)], users: [
437-
eg.user(userId: 1),
438-
eg.user(userId: 2),
439-
]);
440-
}
441-
442-
group('on group PM link', () {
443-
testExpectedDmNarrow('#narrow/dm/1,2-group');
444-
testExpectedDmNarrow('#narrow/pm-with/1,2-group');
445-
});
446-
447-
group('on group PM link including self', () {
448-
// The webapp doesn't generate these, but best to handle them anyway.
449-
testExpectedDmNarrow('#narrow/dm/1,2,${eg.selfUser.userId}-group');
450-
testExpectedDmNarrow('#narrow/pm-with/1,2,${eg.selfUser.userId}-group');
451-
});
452-
});
453-
});
454438
}

0 commit comments

Comments
 (0)