Skip to content

Commit 767682f

Browse files
gnpricechrisbobbe
authored andcommitted
test [nfc]: Add an "eg.t" helper to make a TopicName; use it
1 parent 7bf8458 commit 767682f

File tree

9 files changed

+45
-40
lines changed

9 files changed

+45
-40
lines changed

test/api/route/messages_test.dart

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -328,7 +328,7 @@ void main() {
328328
test('smoke', () {
329329
return FakeApiConnection.with_((connection) async {
330330
await checkSendMessage(connection,
331-
destination: const StreamDestination(streamId, topic), content: content,
331+
destination: StreamDestination(streamId, eg.t(topic)), content: content,
332332
queueId: 'abc:123',
333333
localId: '456',
334334
readBySender: true,
@@ -347,7 +347,7 @@ void main() {
347347
test('to stream', () {
348348
return FakeApiConnection.with_((connection) async {
349349
await checkSendMessage(connection,
350-
destination: const StreamDestination(streamId, topic), content: content,
350+
destination: StreamDestination(streamId, eg.t(topic)), content: content,
351351
readBySender: true,
352352
expectedBodyFields: {
353353
'type': 'stream',
@@ -391,7 +391,7 @@ void main() {
391391
test('when readBySender is null, sends a User-Agent we know the server will recognize', () {
392392
return FakeApiConnection.with_((connection) async {
393393
await checkSendMessage(connection,
394-
destination: const StreamDestination(streamId, topic), content: content,
394+
destination: StreamDestination(streamId, eg.t(topic)), content: content,
395395
readBySender: null,
396396
expectedBodyFields: {
397397
'type': 'stream',
@@ -406,7 +406,7 @@ void main() {
406406
test('legacy: when server does not support readBySender, sends a User-Agent the server will recognize', () {
407407
return FakeApiConnection.with_(zulipFeatureLevel: 235, (connection) async {
408408
await checkSendMessage(connection,
409-
destination: const StreamDestination(streamId, topic), content: content,
409+
destination: StreamDestination(streamId, eg.t(topic)), content: content,
410410
readBySender: true,
411411
expectedBodyFields: {
412412
'type': 'stream',
@@ -743,7 +743,7 @@ void main() {
743743
}) async {
744744
connection.prepare(json: {});
745745
await markTopicAsRead(connection,
746-
streamId: streamId, topicName: topicName);
746+
streamId: streamId, topicName: eg.t(topicName));
747747
check(connection.lastRequest).isA<http.Request>()
748748
..method.equals('POST')
749749
..url.path.equals('/api/v1/mark_topic_as_read')

test/example_data.dart

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -283,6 +283,11 @@ Subscription subscription(
283283
);
284284
}
285285

286+
/// The [TopicName] constructor, but shorter.
287+
///
288+
/// Useful in test code that mentions a lot of topics in a compact format.
289+
TopicName t(String apiName) => TopicName(apiName);
290+
286291
UserTopicItem userTopicItem(
287292
ZulipStream stream, String topic, UserTopicVisibilityPolicy policy) {
288293
return UserTopicItem(

test/model/autocomplete_test.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -900,7 +900,7 @@ void main() {
900900

901901
group('TopicAutocompleteQuery.testTopic', () {
902902
void doCheck(String rawQuery, String topic, bool expected) {
903-
final result = TopicAutocompleteQuery(rawQuery).testTopic(topic);
903+
final result = TopicAutocompleteQuery(rawQuery).testTopic(eg.t(topic));
904904
expected ? check(result).isTrue() : check(result).isFalse();
905905
}
906906

test/model/channel_test.dart

Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -123,14 +123,14 @@ void main() {
123123
group('getter topicVisibilityPolicy', () {
124124
test('with nothing for stream', () {
125125
final store = eg.store();
126-
check(store.topicVisibilityPolicy(stream1.streamId, 'topic'))
126+
check(store.topicVisibilityPolicy(stream1.streamId, eg.t('topic')))
127127
.equals(UserTopicVisibilityPolicy.none);
128128
});
129129

130130
test('with nothing for topic', () async {
131131
final store = eg.store();
132132
await store.addUserTopic(stream1, 'other topic', UserTopicVisibilityPolicy.muted);
133-
check(store.topicVisibilityPolicy(stream1.streamId, 'topic'))
133+
check(store.topicVisibilityPolicy(stream1.streamId, eg.t('topic')))
134134
.equals(UserTopicVisibilityPolicy.none);
135135
});
136136

@@ -142,7 +142,7 @@ void main() {
142142
UserTopicVisibilityPolicy.followed,
143143
]) {
144144
await store.addUserTopic(stream1, 'topic', policy);
145-
check(store.topicVisibilityPolicy(stream1.streamId, 'topic'))
145+
check(store.topicVisibilityPolicy(stream1.streamId, eg.t('topic')))
146146
.equals(policy);
147147
}
148148
});
@@ -153,50 +153,50 @@ void main() {
153153
final store = eg.store();
154154
await store.addStream(stream1);
155155
await store.addSubscription(eg.subscription(stream1));
156-
check(store.isTopicVisibleInStream(stream1.streamId, 'topic')).isTrue();
157-
check(store.isTopicVisible (stream1.streamId, 'topic')).isTrue();
156+
check(store.isTopicVisibleInStream(stream1.streamId, eg.t('topic'))).isTrue();
157+
check(store.isTopicVisible (stream1.streamId, eg.t('topic'))).isTrue();
158158
});
159159

160160
test('with policy none, stream muted', () async {
161161
final store = eg.store();
162162
await store.addStream(stream1);
163163
await store.addSubscription(eg.subscription(stream1, isMuted: true));
164-
check(store.isTopicVisibleInStream(stream1.streamId, 'topic')).isTrue();
165-
check(store.isTopicVisible (stream1.streamId, 'topic')).isFalse();
164+
check(store.isTopicVisibleInStream(stream1.streamId, eg.t('topic'))).isTrue();
165+
check(store.isTopicVisible (stream1.streamId, eg.t('topic'))).isFalse();
166166
});
167167

168168
test('with policy none, stream unsubscribed', () async {
169169
final store = eg.store();
170170
await store.addStream(stream1);
171-
check(store.isTopicVisibleInStream(stream1.streamId, 'topic')).isTrue();
172-
check(store.isTopicVisible (stream1.streamId, 'topic')).isFalse();
171+
check(store.isTopicVisibleInStream(stream1.streamId, eg.t('topic'))).isTrue();
172+
check(store.isTopicVisible (stream1.streamId, eg.t('topic'))).isFalse();
173173
});
174174

175175
test('with policy muted', () async {
176176
final store = eg.store();
177177
await store.addStream(stream1);
178178
await store.addSubscription(eg.subscription(stream1));
179179
await store.addUserTopic(stream1, 'topic', UserTopicVisibilityPolicy.muted);
180-
check(store.isTopicVisibleInStream(stream1.streamId, 'topic')).isFalse();
181-
check(store.isTopicVisible (stream1.streamId, 'topic')).isFalse();
180+
check(store.isTopicVisibleInStream(stream1.streamId, eg.t('topic'))).isFalse();
181+
check(store.isTopicVisible (stream1.streamId, eg.t('topic'))).isFalse();
182182
});
183183

184184
test('with policy unmuted', () async {
185185
final store = eg.store();
186186
await store.addStream(stream1);
187187
await store.addSubscription(eg.subscription(stream1, isMuted: true));
188188
await store.addUserTopic(stream1, 'topic', UserTopicVisibilityPolicy.unmuted);
189-
check(store.isTopicVisibleInStream(stream1.streamId, 'topic')).isTrue();
190-
check(store.isTopicVisible (stream1.streamId, 'topic')).isTrue();
189+
check(store.isTopicVisibleInStream(stream1.streamId, eg.t('topic'))).isTrue();
190+
check(store.isTopicVisible (stream1.streamId, eg.t('topic'))).isTrue();
191191
});
192192

193193
test('with policy followed', () async {
194194
final store = eg.store();
195195
await store.addStream(stream1);
196196
await store.addSubscription(eg.subscription(stream1, isMuted: true));
197197
await store.addUserTopic(stream1, 'topic', UserTopicVisibilityPolicy.followed);
198-
check(store.isTopicVisibleInStream(stream1.streamId, 'topic')).isTrue();
199-
check(store.isTopicVisible (stream1.streamId, 'topic')).isTrue();
198+
check(store.isTopicVisibleInStream(stream1.streamId, eg.t('topic'))).isTrue();
199+
check(store.isTopicVisible (stream1.streamId, eg.t('topic'))).isTrue();
200200
});
201201
});
202202

@@ -265,16 +265,16 @@ void main() {
265265
eg.subscription(stream1, isMuted: streamMuted));
266266
}
267267
await store.handleEvent(mkEvent(oldPolicy));
268-
final oldVisibleInStream = store.isTopicVisibleInStream(stream1.streamId, 'topic');
269-
final oldVisible = store.isTopicVisible(stream1.streamId, 'topic');
268+
final oldVisibleInStream = store.isTopicVisibleInStream(stream1.streamId, eg.t('topic'));
269+
final oldVisible = store.isTopicVisible(stream1.streamId, eg.t('topic'));
270270

271271
final event = mkEvent(newPolicy);
272272
final willChangeInStream = store.willChangeIfTopicVisibleInStream(event);
273273
final willChange = store.willChangeIfTopicVisible(event);
274274

275275
await store.handleEvent(event);
276-
final newVisibleInStream = store.isTopicVisibleInStream(stream1.streamId, 'topic');
277-
final newVisible = store.isTopicVisible(stream1.streamId, 'topic');
276+
final newVisibleInStream = store.isTopicVisibleInStream(stream1.streamId, eg.t('topic'));
277+
final newVisible = store.isTopicVisible(stream1.streamId, eg.t('topic'));
278278

279279
VisibilityEffect fromOldNew(bool oldVisible, bool newVisible) {
280280
if (newVisible == oldVisible) return VisibilityEffect.none;
@@ -384,13 +384,13 @@ void main() {
384384
eg.userTopicItem(stream, 'topic 2', UserTopicVisibilityPolicy.unmuted),
385385
eg.userTopicItem(stream, 'topic 3', UserTopicVisibilityPolicy.followed),
386386
]));
387-
check(store.topicVisibilityPolicy(stream.streamId, 'topic 1'))
387+
check(store.topicVisibilityPolicy(stream.streamId, eg.t('topic 1')))
388388
.equals(UserTopicVisibilityPolicy.muted);
389-
check(store.topicVisibilityPolicy(stream.streamId, 'topic 2'))
389+
check(store.topicVisibilityPolicy(stream.streamId, eg.t('topic 2')))
390390
.equals(UserTopicVisibilityPolicy.unmuted);
391-
check(store.topicVisibilityPolicy(stream.streamId, 'topic 3'))
391+
check(store.topicVisibilityPolicy(stream.streamId, eg.t('topic 3')))
392392
.equals(UserTopicVisibilityPolicy.followed);
393-
check(store.topicVisibilityPolicy(stream.streamId, 'topic 4'))
393+
check(store.topicVisibilityPolicy(stream.streamId, eg.t('topic 4')))
394394
.equals(UserTopicVisibilityPolicy.none);
395395
});
396396
});

test/model/recent_senders_test.dart

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -199,15 +199,15 @@ void main() {
199199
model.handleMessages(messages);
200200

201201
check(model.latestMessageIdOfSenderInTopic(streamId: 1,
202-
topic: 'a', senderId: 10)).equals(300);
202+
topic: eg.t('a'), senderId: 10)).equals(300);
203203
// No message of user 20 in topic "a".
204204
check(model.latestMessageIdOfSenderInTopic(streamId: 1,
205-
topic: 'a', senderId: 20)).equals(null);
205+
topic: eg.t('a'), senderId: 20)).equals(null);
206206
// No message in topic "b" at all.
207207
check(model.latestMessageIdOfSenderInTopic(streamId: 1,
208-
topic: 'b', senderId: 10)).equals(null);
208+
topic: eg.t('b'), senderId: 10)).equals(null);
209209
// No message in stream 2 at all.
210210
check(model.latestMessageIdOfSenderInTopic(streamId: 2,
211-
topic: 'a', senderId: 10)).equals(null);
211+
topic: eg.t('a'), senderId: 10)).equals(null);
212212
});
213213
}

test/model/store_test.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -386,7 +386,7 @@ void main() {
386386
final stream = eg.stream();
387387
connection.prepare(json: SendMessageResult(id: 12345).toJson());
388388
await store.sendMessage(
389-
destination: StreamDestination(stream.streamId, 'world'),
389+
destination: StreamDestination(stream.streamId, eg.t('world')),
390390
content: 'hello');
391391
check(connection.takeRequests()).single.isA<http.Request>()
392392
..method.equals('POST')

test/model/unreads_test.dart

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,7 @@ void main() {
204204
prepare();
205205
fillWithMessages(List.generate(7, (i) => eg.streamMessage(
206206
stream: stream, topic: 'a', flags: [])));
207-
check(model.countInTopicNarrow(stream.streamId, 'a')).equals(7);
207+
check(model.countInTopicNarrow(stream.streamId, eg.t('a'))).equals(7);
208208
});
209209

210210
test('countInDmNarrow', () {
@@ -538,7 +538,7 @@ void main() {
538538
messageIds: [11, 12],
539539
messageType: MessageType.stream,
540540
streamId: stream1.streamId,
541-
topic: 'a',
541+
topic: eg.t('a'),
542542
));
543543
checkNotifiedOnce();
544544
checkMatchesMessages(expectedRemainingMessages..removeAll([message11, message12]));
@@ -547,7 +547,7 @@ void main() {
547547
messageIds: [13, 14],
548548
messageType: MessageType.stream,
549549
streamId: stream2.streamId,
550-
topic: 'b',
550+
topic: eg.t('b'),
551551
));
552552
checkNotifiedOnce();
553553
checkMatchesMessages(expectedRemainingMessages..removeAll([message13, message14]));
@@ -1029,7 +1029,7 @@ void main() {
10291029
type: MessageType.stream,
10301030
mentioned: false,
10311031
streamId: stream.streamId,
1032-
topic: topic,
1032+
topic: eg.t(topic),
10331033
userIds: null,
10341034
),
10351035
// message 2 and 3 have their details missing

test/notifications/display_test.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1194,7 +1194,7 @@ void main() {
11941194
..userId.equals(1001)
11951195
..narrow.which((it) => it.isA<TopicNarrow>()
11961196
..streamId.equals(1)
1197-
..topic.equals('topic A'));
1197+
..topic.equals(eg.t('topic A')));
11981198
});
11991199

12001200
test('parse: fails when missing any expected query parameters', () {

test/widgets/subscription_list_test.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,7 @@ void main() {
174174
subscriptions: [eg.subscription(stream, isMuted: true)],
175175
userTopics: [UserTopicItem(
176176
streamId: stream.streamId,
177-
topicName: 'b',
177+
topicName: eg.t('b'),
178178
lastUpdated: 1234567890,
179179
visibilityPolicy: UserTopicVisibilityPolicy.unmuted,
180180
)],

0 commit comments

Comments
 (0)