Skip to content

Commit 827fccc

Browse files
gnpricechrisbobbe
authored andcommitted
test [nfc]: Explicitly convert various other topics to TopicName
1 parent e3f3c58 commit 827fccc

File tree

6 files changed

+23
-19
lines changed

6 files changed

+23
-19
lines changed

test/api/model/events_test.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -116,8 +116,8 @@ void main() {
116116
'orig_subject': 'foo',
117117
'subject': 'bar',
118118
}) as UpdateMessageEvent)
119-
..origTopic.equals('foo')
120-
..newTopic.equals('bar');
119+
..origTopic.equals(const TopicName('foo'))
120+
..newTopic.equals(const TopicName('bar'));
121121
});
122122
});
123123

test/api/model/initial_snapshot_test.dart

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import 'package:checks/checks.dart';
22
import 'package:test/scaffolding.dart';
33
import 'package:zulip/api/model/initial_snapshot.dart';
4+
import 'package:zulip/api/model/model.dart';
45

56
import '../../stdlib_checks.dart';
67

@@ -20,7 +21,7 @@ void main() {
2021

2122
check(snapshot.channels).single.jsonEquals(
2223
UnreadChannelSnapshot(
23-
topic: 'topic name', streamId: 1,
24+
topic: const TopicName('topic name'), streamId: 1,
2425
unreadMessageIds: [1, 2]));
2526
});
2627

test/api/route/channels_test.dart

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ void main() {
1212
return FakeApiConnection.with_((connection) async {
1313
connection.prepare(json: {});
1414
await updateUserTopic(connection,
15-
streamId: 1, topic: 'topic',
15+
streamId: 1, topic: const TopicName('topic'),
1616
visibilityPolicy: UserTopicVisibilityPolicy.followed);
1717
check(connection.takeRequests()).single.isA<http.Request>()
1818
..method.equals('POST')
@@ -28,7 +28,7 @@ void main() {
2828
test('updateUserTopic only accepts valid visibility policy', () {
2929
return FakeApiConnection.with_((connection) async {
3030
check(() => updateUserTopic(connection,
31-
streamId: 1, topic: 'topic',
31+
streamId: 1, topic: const TopicName('topic'),
3232
visibilityPolicy: UserTopicVisibilityPolicy.unknown),
3333
).throws<AssertionError>();
3434
});
@@ -38,7 +38,7 @@ void main() {
3838
return FakeApiConnection.with_((connection) async {
3939
connection.prepare(json: {});
4040
await updateUserTopicCompat(connection,
41-
streamId: 1, topic: 'topic',
41+
streamId: 1, topic: const TopicName('topic'),
4242
visibilityPolicy: UserTopicVisibilityPolicy.followed);
4343
check(connection.takeRequests()).single.isA<http.Request>()
4444
..method.equals('POST')
@@ -55,7 +55,7 @@ void main() {
5555
test('updateUserTopic throws AssertionError when FL < 170', () {
5656
return FakeApiConnection.with_(zulipFeatureLevel: 169, (connection) async {
5757
check(() => updateUserTopic(connection,
58-
streamId: 1, topic: 'topic',
58+
streamId: 1, topic: const TopicName('topic'),
5959
visibilityPolicy: UserTopicVisibilityPolicy.muted),
6060
).throws<AssertionError>();
6161
});
@@ -64,7 +64,7 @@ void main() {
6464
test('updateUserTopicCompat throws UnsupportedError on unsupported policy', () {
6565
return FakeApiConnection.with_(zulipFeatureLevel: 169, (connection) async {
6666
check(() => updateUserTopicCompat(connection,
67-
streamId: 1, topic: 'topic',
67+
streamId: 1, topic: const TopicName('topic'),
6868
visibilityPolicy: UserTopicVisibilityPolicy.followed),
6969
).throws<UnsupportedError>();
7070
});
@@ -74,7 +74,7 @@ void main() {
7474
return FakeApiConnection.with_(zulipFeatureLevel: 169, (connection) async {
7575
connection.prepare(json: {});
7676
await updateUserTopicCompat(connection,
77-
streamId: 1, topic: 'topic',
77+
streamId: 1, topic: const TopicName('topic'),
7878
visibilityPolicy: UserTopicVisibilityPolicy.none);
7979
check(connection.takeRequests()).single.isA<http.Request>()
8080
..method.equals('PATCH')
@@ -91,7 +91,7 @@ void main() {
9191
return FakeApiConnection.with_(zulipFeatureLevel: 169, (connection) async {
9292
connection.prepare(json: {});
9393
await updateUserTopicCompat(connection,
94-
streamId: 1, topic: 'topic',
94+
streamId: 1, topic: const TopicName('topic'),
9595
visibilityPolicy: UserTopicVisibilityPolicy.muted);
9696
check(connection.takeRequests()).single.isA<http.Request>()
9797
..method.equals('PATCH')

test/api/route/typing_test.dart

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import 'package:http/http.dart' as http;
44
import 'package:checks/checks.dart';
55
import 'package:flutter_test/flutter_test.dart';
66
import 'package:zulip/api/model/events.dart';
7+
import 'package:zulip/api/model/model.dart';
78
import 'package:zulip/api/route/messages.dart';
89
import 'package:zulip/api/route/typing.dart';
910

@@ -31,7 +32,7 @@ void main() {
3132
Future<void> checkSetTypingStatusForTopic(TypingOp op, String expectedOp) {
3233
return FakeApiConnection.with_((connection) {
3334
return checkSetTypingStatus(connection, op,
34-
destination: const StreamDestination(streamId, topic),
35+
destination: const StreamDestination(streamId, TopicName(topic)),
3536
expectedBodyFields: {
3637
'op': expectedOp,
3738
'type': 'channel',
@@ -64,7 +65,7 @@ void main() {
6465
test('legacy: use "stream" instead of "channel"', () {
6566
return FakeApiConnection.with_(zulipFeatureLevel: 247, (connection) {
6667
return checkSetTypingStatus(connection, TypingOp.start,
67-
destination: const StreamDestination(streamId, topic),
68+
destination: const StreamDestination(streamId, TopicName(topic)),
6869
expectedBodyFields: {
6970
'op': 'start',
7071
'type': 'stream',
@@ -77,7 +78,7 @@ void main() {
7778
test('legacy: use to=[streamId] instead of stream_id=streamId', () {
7879
return FakeApiConnection.with_(zulipFeatureLevel: 214, (connection) {
7980
return checkSetTypingStatus(connection, TypingOp.start,
80-
destination: const StreamDestination(streamId, topic),
81+
destination: const StreamDestination(streamId, TopicName(topic)),
8182
expectedBodyFields: {
8283
'op': 'start',
8384
'type': 'stream',

test/example_data.dart

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -241,7 +241,8 @@ const _stream = stream;
241241

242242
GetStreamTopicsEntry getStreamTopicsEntry({int? maxId, String? name}) {
243243
maxId ??= 123;
244-
return GetStreamTopicsEntry(maxId: maxId, name: name ?? 'Test Topic #$maxId');
244+
return GetStreamTopicsEntry(maxId: maxId,
245+
name: TopicName(name ?? 'Test Topic #$maxId'));
245246
}
246247

247248
/// Construct an example subscription from a stream.
@@ -296,7 +297,7 @@ UserTopicItem userTopicItem(
296297
ZulipStream stream, String topic, UserTopicVisibilityPolicy policy) {
297298
return UserTopicItem(
298299
streamId: stream.streamId,
299-
topicName: topic,
300+
topicName: TopicName(topic),
300301
lastUpdated: 1234567890,
301302
visibilityPolicy: policy,
302303
);
@@ -534,7 +535,7 @@ UnreadChannelSnapshot unreadChannelMsgs({
534535
required List<int> unreadMessageIds,
535536
}) {
536537
return UnreadChannelSnapshot(
537-
topic: topic,
538+
topic: TopicName(topic),
538539
streamId: streamId,
539540
unreadMessageIds: unreadMessageIds,
540541
);
@@ -568,7 +569,7 @@ UserTopicEvent userTopicEvent(
568569
return UserTopicEvent(
569570
id: 1,
570571
streamId: streamId,
571-
topicName: topic,
572+
topicName: TopicName(topic),
572573
lastUpdated: 1234567890,
573574
visibilityPolicy: visibilityPolicy,
574575
);

test/model/autocomplete_test.dart

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -481,10 +481,11 @@ void main() {
481481
}
482482

483483
int compareAB({required String? topic}) {
484+
final realTopic = topic == null ? null : TopicName(topic);
484485
final resultAB = MentionAutocompleteView.compareByRecency(userA, userB,
485-
streamId: stream.streamId, topic: topic, store: store);
486+
streamId: stream.streamId, topic: realTopic, store: store);
486487
final resultBA = MentionAutocompleteView.compareByRecency(userB, userA,
487-
streamId: stream.streamId, topic: topic, store: store);
488+
streamId: stream.streamId, topic: realTopic, store: store);
488489
switch (resultAB) {
489490
case <0: check(resultBA).isGreaterThan(0);
490491
case >0: check(resultBA).isLessThan(0);

0 commit comments

Comments
 (0)