Skip to content

Commit 5ae1e13

Browse files
gnpricechrisbobbe
authored andcommitted
test [nfc]: Add a helper eg.topicNarrow; use it
1 parent 767682f commit 5ae1e13

10 files changed

+64
-60
lines changed

test/api/route/messages_test.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,7 @@ void main() {
184184
checkNarrow(const ChannelNarrow(12).apiEncode(), jsonEncode([
185185
{'operator': 'stream', 'operand': 12},
186186
]));
187-
checkNarrow(const TopicNarrow(12, 'stuff').apiEncode(), jsonEncode([
187+
checkNarrow(eg.topicNarrow(12, 'stuff').apiEncode(), jsonEncode([
188188
{'operator': 'stream', 'operand': 12},
189189
{'operator': 'topic', 'operand': 'stuff'},
190190
]));

test/example_data.dart

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -288,6 +288,10 @@ Subscription subscription(
288288
/// Useful in test code that mentions a lot of topics in a compact format.
289289
TopicName t(String apiName) => TopicName(apiName);
290290

291+
TopicNarrow topicNarrow(int channelId, String topicName) {
292+
return TopicNarrow(channelId, TopicName(topicName));
293+
}
294+
291295
UserTopicItem userTopicItem(
292296
ZulipStream stream, String topic, UserTopicVisibilityPolicy policy) {
293297
return UserTopicItem(

test/model/autocomplete_test.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -659,7 +659,7 @@ void main() {
659659
eg.user(fullName: 'b', isBot: true),
660660
];
661661
final stream = eg.stream();
662-
final narrow = TopicNarrow(stream.streamId, 'this');
662+
final narrow = eg.topicNarrow(stream.streamId, 'this');
663663
await prepare(users: users, messages: [
664664
eg.streamMessage(sender: users[1], stream: stream, topic: 'this'),
665665
eg.streamMessage(sender: users[0], stream: stream, topic: 'this'),
@@ -790,7 +790,7 @@ void main() {
790790

791791
final stream = eg.stream();
792792
const topic = 'topic';
793-
final topicNarrow = TopicNarrow(stream.streamId, topic);
793+
final topicNarrow = eg.topicNarrow(stream.streamId, topic);
794794

795795
final users = [
796796
eg.user(userId: 1, fullName: 'User One'),

test/model/internal_link_test.dart

Lines changed: 32 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ void main() {
7272
await store.addStream(eg.stream(streamId: streamId, name: name));
7373
final narrow = topic == null
7474
? ChannelNarrow(streamId)
75-
: TopicNarrow(streamId, topic);
75+
: eg.topicNarrow(streamId, topic);
7676
check(narrowLink(store, narrow, nearMessageId: nearMessageId))
7777
.equals(store.realmUrl.resolve(expectedFragment));
7878
}
@@ -281,28 +281,28 @@ void main() {
281281
});
282282

283283
group('"/#narrow/stream/<...>/topic/<...>" returns expected TopicNarrow', () {
284-
const testCases = [
285-
('/#narrow/stream/check/topic/test', TopicNarrow(1, 'test')),
286-
('/#narrow/stream/mobile/subject/topic/near/378333', TopicNarrow(3, 'topic')),
287-
('/#narrow/stream/mobile/subject/topic/with/1', TopicNarrow(3, 'topic')),
288-
('/#narrow/stream/mobile/topic/topic/', TopicNarrow(3, 'topic')),
289-
('/#narrow/stream/stream/topic/topic/near/1', TopicNarrow(5, 'topic')),
290-
('/#narrow/stream/stream/topic/topic/with/22', TopicNarrow(5, 'topic')),
291-
('/#narrow/stream/stream/subject/topic/near/1', TopicNarrow(5, 'topic')),
292-
('/#narrow/stream/stream/subject/topic/with/333', TopicNarrow(5, 'topic')),
293-
('/#narrow/stream/stream/subject/topic', TopicNarrow(5, 'topic')),
284+
final testCases = [
285+
('/#narrow/stream/check/topic/test', eg.topicNarrow(1, 'test')),
286+
('/#narrow/stream/mobile/subject/topic/near/378333', eg.topicNarrow(3, 'topic')),
287+
('/#narrow/stream/mobile/subject/topic/with/1', eg.topicNarrow(3, 'topic')),
288+
('/#narrow/stream/mobile/topic/topic/', eg.topicNarrow(3, 'topic')),
289+
('/#narrow/stream/stream/topic/topic/near/1', eg.topicNarrow(5, 'topic')),
290+
('/#narrow/stream/stream/topic/topic/with/22', eg.topicNarrow(5, 'topic')),
291+
('/#narrow/stream/stream/subject/topic/near/1', eg.topicNarrow(5, 'topic')),
292+
('/#narrow/stream/stream/subject/topic/with/333', eg.topicNarrow(5, 'topic')),
293+
('/#narrow/stream/stream/subject/topic', eg.topicNarrow(5, 'topic')),
294294
];
295295
testExpectedNarrows(testCases, streams: streams);
296296
});
297297

298298
group('Both `stream` and `channel` can be used interchangeably', () {
299-
const testCases = [
300-
('/#narrow/stream/check', ChannelNarrow(1)),
301-
('/#narrow/channel/check', ChannelNarrow(1)),
302-
('/#narrow/stream/check/topic/test', TopicNarrow(1, 'test')),
303-
('/#narrow/channel/check/topic/test', TopicNarrow(1, 'test')),
304-
('/#narrow/stream/check/topic/test/near/378333', TopicNarrow(1, 'test')),
305-
('/#narrow/channel/check/topic/test/near/378333', TopicNarrow(1, 'test')),
299+
final testCases = [
300+
('/#narrow/stream/check', const ChannelNarrow(1)),
301+
('/#narrow/channel/check', const ChannelNarrow(1)),
302+
('/#narrow/stream/check/topic/test', eg.topicNarrow(1, 'test')),
303+
('/#narrow/channel/check/topic/test', eg.topicNarrow(1, 'test')),
304+
('/#narrow/stream/check/topic/test/near/378333', eg.topicNarrow(1, 'test')),
305+
('/#narrow/channel/check/topic/test/near/378333', eg.topicNarrow(1, 'test')),
306306
];
307307
testExpectedNarrows(testCases, streams: streams);
308308
});
@@ -414,13 +414,13 @@ void main() {
414414
eg.stream(streamId: 2, name: 'some stream'),
415415
eg.stream(streamId: 3, name: 'some.stream'),
416416
];
417-
const testCases = [
418-
('/#narrow/stream/some_stream', ChannelNarrow(1)),
419-
('/#narrow/stream/some.20stream', ChannelNarrow(2)),
420-
('/#narrow/stream/some.2Estream', ChannelNarrow(3)),
421-
('/#narrow/stream/some_stream/topic/some_topic', TopicNarrow(1, 'some_topic')),
422-
('/#narrow/stream/some_stream/topic/some.20topic', TopicNarrow(1, 'some topic')),
423-
('/#narrow/stream/some_stream/topic/some.2Etopic', TopicNarrow(1, 'some.topic')),
417+
final testCases = [
418+
('/#narrow/stream/some_stream', const ChannelNarrow(1)),
419+
('/#narrow/stream/some.20stream', const ChannelNarrow(2)),
420+
('/#narrow/stream/some.2Estream', const ChannelNarrow(3)),
421+
('/#narrow/stream/some_stream/topic/some_topic', eg.topicNarrow(1, 'some_topic')),
422+
('/#narrow/stream/some_stream/topic/some.20topic', eg.topicNarrow(1, 'some topic')),
423+
('/#narrow/stream/some_stream/topic/some.2Etopic', eg.topicNarrow(1, 'some.topic')),
424424
];
425425
testExpectedNarrows(testCases, streams: streams);
426426
});
@@ -518,8 +518,8 @@ void main() {
518518
return '#narrow/stream/${stream.streamId}-${stream.name}/topic/$operand';
519519
}
520520
final testCases = [
521-
(mkUrlString('(no.20topic)'), TopicNarrow(stream.streamId, '(no topic)')),
522-
(mkUrlString('lunch'), TopicNarrow(stream.streamId, 'lunch')),
521+
(mkUrlString('(no.20topic)'), eg.topicNarrow(stream.streamId, '(no topic)')),
522+
(mkUrlString('lunch'), eg.topicNarrow(stream.streamId, 'lunch')),
523523
];
524524
testExpectedNarrows(testCases, streams: [stream]);
525525
});
@@ -529,12 +529,12 @@ void main() {
529529
return '#narrow/stream/${stream.name}/topic/$operand';
530530
}
531531
final testCases = [
532-
(mkUrlString('(no.20topic)'), TopicNarrow(stream.streamId, '(no topic)')),
533-
(mkUrlString('google.2Ecom'), TopicNarrow(stream.streamId, 'google.com')),
532+
(mkUrlString('(no.20topic)'), eg.topicNarrow(stream.streamId, '(no topic)')),
533+
(mkUrlString('google.2Ecom'), eg.topicNarrow(stream.streamId, 'google.com')),
534534
(mkUrlString('google.com'), null),
535-
(mkUrlString('topic.20name'), TopicNarrow(stream.streamId, 'topic name')),
536-
(mkUrlString('stream'), TopicNarrow(stream.streamId, 'stream')),
537-
(mkUrlString('topic'), TopicNarrow(stream.streamId, 'topic')),
535+
(mkUrlString('topic.20name'), eg.topicNarrow(stream.streamId, 'topic name')),
536+
(mkUrlString('stream'), eg.topicNarrow(stream.streamId, 'stream')),
537+
(mkUrlString('topic'), eg.topicNarrow(stream.streamId, 'topic')),
538538
];
539539
testExpectedNarrows(testCases, streams: [stream]);
540540
});

test/model/message_list_test.dart

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -440,7 +440,7 @@ void main() {
440440
});
441441

442442
test('in TopicNarrow, stay visible', () async {
443-
await prepare(narrow: TopicNarrow(stream.streamId, topic));
443+
await prepare(narrow: eg.topicNarrow(stream.streamId, topic));
444444
await prepareMutes();
445445
await prepareMessages(foundOldest: true, messages: [
446446
eg.streamMessage(id: 1, stream: stream, topic: topic),
@@ -832,7 +832,7 @@ void main() {
832832
});
833833

834834
group('in topic narrow', () {
835-
final narrow = TopicNarrow(stream.streamId, 'topic');
835+
final narrow = eg.topicNarrow(stream.streamId, 'topic');
836836
final initialMessages = List.generate(5, (i) => eg.streamMessage(stream: stream, topic: 'topic'));
837837
final movedMessages = List.generate(5, (i) => eg.streamMessage(stream: stream, topic: 'topic'));
838838
final otherTopicMovedMessages = List.generate(5, (i) => eg.streamMessage(stream: stream, topic: 'other topic'));
@@ -937,21 +937,21 @@ void main() {
937937
handleMoveEvent(PropagateMode.changeOne);
938938
checkNotNotified();
939939
checkHasMessages(initialMessages);
940-
check(model).narrow.equals(TopicNarrow(stream.streamId, 'topic'));
940+
check(model).narrow.equals(eg.topicNarrow(stream.streamId, 'topic'));
941941
});
942942

943943
test('follow to the new narrow when propagateMode = changeLater', () {
944944
handleMoveEvent(PropagateMode.changeLater);
945945
checkNotifiedOnce();
946946
checkHasMessages(movedMessages);
947-
check(model).narrow.equals(TopicNarrow(otherStream.streamId, 'new'));
947+
check(model).narrow.equals(eg.topicNarrow(otherStream.streamId, 'new'));
948948
});
949949

950950
test('follow to the new narrow when propagateMode = changeAll', () {
951951
handleMoveEvent(PropagateMode.changeAll);
952952
checkNotifiedOnce();
953953
checkHasMessages(movedMessages);
954-
check(model).narrow.equals(TopicNarrow(otherStream.streamId, 'new'));
954+
check(model).narrow.equals(eg.topicNarrow(otherStream.streamId, 'new'));
955955
});
956956

957957
test('handle move event before initial fetch', () => awaitFakeAsync((async) async {
@@ -973,7 +973,7 @@ void main() {
973973
newMessages: [followedMessage],
974974
propagateMode: PropagateMode.changeAll,
975975
));
976-
check(model).narrow.equals(TopicNarrow(stream.streamId, 'new'));
976+
check(model).narrow.equals(eg.topicNarrow(stream.streamId, 'new'));
977977

978978
async.elapse(const Duration(seconds: 2));
979979
checkHasMessages([followedMessage]);
@@ -1255,7 +1255,7 @@ void main() {
12551255

12561256
int notifiedCount2 = 0;
12571257
final model2 = MessageListView.init(store: store,
1258-
narrow: TopicNarrow(stream.streamId, 'hello'))
1258+
narrow: eg.topicNarrow(stream.streamId, 'hello'))
12591259
..addListener(() => notifiedCount2++);
12601260

12611261
for (final m in [model1, model2]) {
@@ -1481,7 +1481,7 @@ void main() {
14811481

14821482
test('in TopicNarrow', () async {
14831483
final stream = eg.stream();
1484-
await prepare(narrow: TopicNarrow(stream.streamId, 'A'));
1484+
await prepare(narrow: eg.topicNarrow(stream.streamId, 'A'));
14851485
await store.addStream(stream);
14861486
await store.addSubscription(eg.subscription(stream, isMuted: true));
14871487
await store.addUserTopic(stream, 'A', UserTopicVisibilityPolicy.muted);

test/model/typing_status_test.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ void main() {
9494
}
9595

9696
final stream = eg.stream();
97-
final topicNarrow = TopicNarrow(stream.streamId, 'foo');
97+
final topicNarrow = eg.topicNarrow(stream.streamId, 'foo');
9898

9999
final dmNarrow = DmNarrow.withUser(eg.otherUser.userId, selfUserId: eg.selfUser.userId);
100100
final groupNarrow = DmNarrow.withOtherUsers(
@@ -272,7 +272,7 @@ void main() {
272272
final channel = eg.stream();
273273
await store.addStream(channel);
274274
await store.addSubscription(eg.subscription(channel));
275-
narrow = TopicNarrow(channel.streamId, 'topic');
275+
narrow = eg.topicNarrow(channel.streamId, 'topic');
276276
}
277277

278278
/// Prepares store and triggers a "typing started" notice.

test/notifications/display_test.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1116,7 +1116,7 @@ void main() {
11161116
payload = NotificationOpenPayload(
11171117
realmUrl: Uri.parse('http://chat.example'),
11181118
userId: 1001,
1119-
narrow: const TopicNarrow(1, 'topic A'),
1119+
narrow: eg.topicNarrow(1, 'topic A'),
11201120
);
11211121
url = payload.buildUrl();
11221122
check(NotificationOpenPayload.parseUrl(url))
@@ -1146,7 +1146,7 @@ void main() {
11461146
final url = NotificationOpenPayload(
11471147
realmUrl: Uri.parse('http://chat.example'),
11481148
userId: 1001,
1149-
narrow: const TopicNarrow(1, 'topic A'),
1149+
narrow: eg.topicNarrow(1, 'topic A'),
11501150
).buildUrl();
11511151
check(url)
11521152
..scheme.equals('zulip')

test/widgets/action_sheet_test.dart

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ void main() {
145145
foundOldest: true, messages: [message]).toJson());
146146
await tester.pumpWidget(TestZulipApp(accountId: eg.selfAccount.id,
147147
child: MessageListPage(
148-
initNarrow: TopicNarrow(channel.streamId, topic))));
148+
initNarrow: eg.topicNarrow(channel.streamId, topic))));
149149
// global store, per-account store, and message list get loaded
150150
await tester.pumpAndSettle();
151151

@@ -214,7 +214,7 @@ void main() {
214214
eg.streamMessage(stream: channel, topic: topic)]).toJson());
215215
await tester.pumpWidget(TestZulipApp(accountId: account.id,
216216
child: MessageListPage(
217-
initNarrow: TopicNarrow(channel.streamId, topic))));
217+
initNarrow: eg.topicNarrow(channel.streamId, topic))));
218218
await tester.pumpAndSettle();
219219

220220
await tester.longPress(find.descendant(
@@ -823,7 +823,7 @@ void main() {
823823
..method.equals('POST')
824824
..url.path.equals('/api/v1/messages/flags/narrow')
825825
..bodyFields['narrow'].equals(
826-
jsonEncode(TopicNarrow(newStream.streamId, newTopic).apiEncode()));
826+
jsonEncode(eg.topicNarrow(newStream.streamId, newTopic).apiEncode()));
827827
});
828828

829829
testWidgets('shows error when fails', (tester) async {

test/widgets/compose_box_test.dart

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -230,14 +230,14 @@ void main() {
230230
testWidgets('_FixedDestinationComposeBox', (tester) async {
231231
final channel = eg.stream();
232232
await prepareComposeBox(tester,
233-
narrow: TopicNarrow(channel.streamId, 'topic'), streams: [channel]);
233+
narrow: eg.topicNarrow(channel.streamId, 'topic'), streams: [channel]);
234234
checkComposeBoxTextFields(tester, expectTopicTextField: false);
235235
});
236236
});
237237

238238
group('ComposeBox typing notices', () {
239239
final channel = eg.stream();
240-
final narrow = TopicNarrow(channel.streamId, 'some topic');
240+
final narrow = eg.topicNarrow(channel.streamId, 'some topic');
241241

242242
void checkTypingRequest(TypingOp op, SendableNarrow narrow) =>
243243
checkSetTypingStatusRequests(connection.takeRequests(), [(op, narrow)]);
@@ -272,7 +272,7 @@ void main() {
272272

273273
testWidgets('smoke ChannelNarrow', (tester) async {
274274
final narrow = ChannelNarrow(channel.streamId);
275-
final destinationNarrow = TopicNarrow(narrow.streamId, 'test topic');
275+
final destinationNarrow = eg.topicNarrow(narrow.streamId, 'test topic');
276276
await prepareComposeBox(tester, narrow: narrow, streams: [channel]);
277277
await enterTopic(tester, narrow: narrow, topic: destinationNarrow.topic);
278278

@@ -339,7 +339,7 @@ void main() {
339339

340340
testWidgets('for content input, unfocusing sends a "typing stopped" notice', (tester) async {
341341
final narrow = ChannelNarrow(channel.streamId);
342-
final destinationNarrow = TopicNarrow(narrow.streamId, 'test topic');
342+
final destinationNarrow = eg.topicNarrow(narrow.streamId, 'test topic');
343343
await prepareComposeBox(tester, narrow: narrow, streams: [channel]);
344344
await enterTopic(tester, narrow: narrow, topic: destinationNarrow.topic);
345345

@@ -402,7 +402,7 @@ void main() {
402402
addTearDown(TypingNotifier.debugReset);
403403

404404
final zulipLocalizations = GlobalLocalizations.zulipLocalizations;
405-
await prepareComposeBox(tester, narrow: const TopicNarrow(123, 'some topic'),
405+
await prepareComposeBox(tester, narrow: eg.topicNarrow(123, 'some topic'),
406406
streams: [eg.stream(streamId: 123)]);
407407

408408
await tester.enterText(contentInputFinder, 'hello world');
@@ -708,7 +708,7 @@ void main() {
708708

709709
final narrowTestCases = [
710710
('channel', const ChannelNarrow(1)),
711-
('topic', const TopicNarrow(1, 'topic')),
711+
('topic', eg.topicNarrow(1, 'topic')),
712712
];
713713

714714
for (final (String narrowType, Narrow narrow) in narrowTestCases) {
@@ -802,7 +802,7 @@ void main() {
802802
group('ComposeBox content input scaling', () {
803803
const verticalPadding = 8;
804804
final stream = eg.stream();
805-
final narrow = TopicNarrow(stream.streamId, 'foo');
805+
final narrow = eg.topicNarrow(stream.streamId, 'foo');
806806

807807
Future<void> checkContentInputMaxHeight(WidgetTester tester, {
808808
required double maxHeight,

test/widgets/message_list_test.dart

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ void main() {
138138
final navObserver = TestNavigatorObserver()
139139
..onPushed = (route, prevRoute) => pushedRoutes.add(route);
140140
final channel = eg.stream();
141-
await setupMessageListPage(tester, narrow: TopicNarrow(channel.streamId, 'hi'),
141+
await setupMessageListPage(tester, narrow: eg.topicNarrow(channel.streamId, 'hi'),
142142
navObservers: [navObserver],
143143
streams: [channel], messageCount: 1);
144144

@@ -157,7 +157,7 @@ void main() {
157157
final channel = eg.stream();
158158
const topic = 'topic';
159159
await setupMessageListPage(tester,
160-
narrow: TopicNarrow(channel.streamId, topic),
160+
narrow: eg.topicNarrow(channel.streamId, topic),
161161
streams: [channel], subscriptions: [eg.subscription(channel)],
162162
messageCount: 1);
163163
await store.handleEvent(eg.userTopicEvent(
@@ -661,7 +661,7 @@ void main() {
661661
const topic = 'foo';
662662
final channel = eg.stream();
663663
final otherChannel = eg.stream();
664-
final narrow = TopicNarrow(channel.streamId, topic);
664+
final narrow = eg.topicNarrow(channel.streamId, topic);
665665

666666
void prepareGetMessageResponse(List<Message> messages) {
667667
connection.prepare(json: eg.newestGetMessagesResult(

0 commit comments

Comments
 (0)