Skip to content

Commit

Permalink
test: Use stream ID in default name and description in eg.stream
Browse files Browse the repository at this point in the history
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).
  • Loading branch information
gnprice committed Jul 24, 2024
1 parent f42af89 commit 24400bf
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 19 deletions.
11 changes: 7 additions & 4 deletions test/example_data.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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 ?? '<p>A description</p>', // TODO generate random
streamId: effectiveStreamId,
name: effectiveName,
description: effectiveDescription,
renderedDescription: renderedDescription ?? '<p>$effectiveDescription</p>',
dateCreated: dateCreated ?? 1686774898,
firstMessageId: firstMessageId,
inviteOnly: inviteOnly ?? false,
Expand Down
12 changes: 6 additions & 6 deletions test/model/channel_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -34,17 +34,17 @@ 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)],
)));
});

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);

Expand Down Expand Up @@ -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', () {
Expand Down
12 changes: 6 additions & 6 deletions test/model/message_list_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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<Message> messages) {
check(model.messages.map((e) => e.id)).deepEquals(messages.map((e) => e.id));
Expand Down Expand Up @@ -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));
Expand Down Expand Up @@ -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));
Expand Down Expand Up @@ -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));
Expand Down
6 changes: 3 additions & 3 deletions test/model/unreads_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down

0 comments on commit 24400bf

Please sign in to comment.