From 24400bf49580e5daa727b7c09fea92b40f206d06 Mon Sep 17 00:00:00 2001 From: Greg Price Date: Wed, 17 Jul 2024 13:41:11 -0700 Subject: [PATCH] test: Use stream ID in default name and description in eg.stream In particular this means that repeated calls `eg.stream()` with no arguments will get distinct names, as well as IDs, so that they can all be added to the same store without collision. Then also simplify away the various places where a test was passing a stream name when the only thing about the name that mattered to the test was being distinct from other names (or when nothing about the name mattered to the test at all). --- test/example_data.dart | 11 +++++++---- test/model/channel_test.dart | 12 ++++++------ test/model/message_list_test.dart | 12 ++++++------ test/model/unreads_test.dart | 6 +++--- 4 files changed, 22 insertions(+), 19 deletions(-) diff --git a/test/example_data.dart b/test/example_data.dart index f6d21e35b17..6f3f5551360 100644 --- a/test/example_data.dart +++ b/test/example_data.dart @@ -175,11 +175,14 @@ ZulipStream stream({ int? canRemoveSubscribersGroup, int? streamWeeklyTraffic, }) { + var effectiveStreamId = streamId ?? _nextStreamId(); + var effectiveName = name ?? 'stream $effectiveStreamId'; + var effectiveDescription = description ?? 'Description of $effectiveName'; return ZulipStream( - streamId: streamId ?? _nextStreamId(), - name: name ?? 'A stream', // TODO generate example names - description: description ?? 'A description', // TODO generate example descriptions - renderedDescription: renderedDescription ?? '

A description

', // TODO generate random + streamId: effectiveStreamId, + name: effectiveName, + description: effectiveDescription, + renderedDescription: renderedDescription ?? '

$effectiveDescription

', dateCreated: dateCreated ?? 1686774898, firstMessageId: firstMessageId, inviteOnly: inviteOnly ?? false, diff --git a/test/model/channel_test.dart b/test/model/channel_test.dart index d8dc3c07f49..7e86d75b163 100644 --- a/test/model/channel_test.dart +++ b/test/model/channel_test.dart @@ -34,8 +34,8 @@ void main() { } test('initial', () { - final stream1 = eg.stream(streamId: 1, name: 'stream 1'); - final stream2 = eg.stream(streamId: 2, name: 'stream 2'); + final stream1 = eg.stream(); + final stream2 = eg.stream(); checkUnified(eg.store(initialSnapshot: eg.initialSnapshot( streams: [stream1, stream2], subscriptions: [eg.subscription(stream1)], @@ -43,8 +43,8 @@ void main() { }); test('added by events', () async { - final stream1 = eg.stream(streamId: 1, name: 'stream 1'); - final stream2 = eg.stream(streamId: 2, name: 'stream 2'); + final stream1 = eg.stream(); + final stream2 = eg.stream(); final store = eg.store(); checkUnified(store); @@ -106,8 +106,8 @@ void main() { }); group('topic visibility', () { - final stream1 = eg.stream(streamId: 1, name: 'stream 1'); - final stream2 = eg.stream(streamId: 2, name: 'stream 2'); + final stream1 = eg.stream(); + final stream2 = eg.stream(); group('getter topicVisibilityPolicy', () { test('with nothing for stream', () { diff --git a/test/model/message_list_test.dart b/test/model/message_list_test.dart index 5f4060571ff..2c5145de1f5 100644 --- a/test/model/message_list_test.dart +++ b/test/model/message_list_test.dart @@ -467,8 +467,8 @@ void main() { }); group('messagesMoved', () { - final stream = eg.stream(streamId: 1, name: 'test stream'); - final otherStream = eg.stream(streamId: 2, name: 'other stream'); + final stream = eg.stream(); + final otherStream = eg.stream(); void checkHasMessages(Iterable messages) { check(model.messages.map((e) => e.id)).deepEquals(messages.map((e) => e.id)); @@ -945,8 +945,8 @@ void main() { group('stream/topic muting', () { test('in CombinedFeedNarrow', () async { - final stream1 = eg.stream(streamId: 1, name: 'stream 1'); - final stream2 = eg.stream(streamId: 2, name: 'stream 2'); + final stream1 = eg.stream(); + final stream2 = eg.stream(); await prepare(narrow: const CombinedFeedNarrow()); await store.addStreams([stream1, stream2]); await store.addSubscription(eg.subscription(stream1)); @@ -1008,7 +1008,7 @@ void main() { }); test('in StreamNarrow', () async { - final stream = eg.stream(streamId: 1, name: 'stream 1'); + final stream = eg.stream(); await prepare(narrow: StreamNarrow(stream.streamId)); await store.addStream(stream); await store.addSubscription(eg.subscription(stream, isMuted: true)); @@ -1055,7 +1055,7 @@ void main() { }); test('in TopicNarrow', () async { - final stream = eg.stream(streamId: 1, name: 'stream 1'); + final stream = eg.stream(); await prepare(narrow: TopicNarrow(stream.streamId, 'A')); await store.addStream(stream); await store.addSubscription(eg.subscription(stream, isMuted: true)); diff --git a/test/model/unreads_test.dart b/test/model/unreads_test.dart index 4c2bfa5aa5b..923fb43c716 100644 --- a/test/model/unreads_test.dart +++ b/test/model/unreads_test.dart @@ -153,9 +153,9 @@ void main() { group('count helpers', () { test('countInCombinedFeedNarrow', () async { - final stream1 = eg.stream(streamId: 1, name: 'stream 1'); - final stream2 = eg.stream(streamId: 2, name: 'stream 2'); - final stream3 = eg.stream(streamId: 3, name: 'stream 3'); + final stream1 = eg.stream(); + final stream2 = eg.stream(); + final stream3 = eg.stream(); prepare(); await channelStore.addStreams([stream1, stream2, stream3]); await channelStore.addSubscription(eg.subscription(stream1));