Skip to content

Commit bbe2d4c

Browse files
gnpricechrisbobbe
authored andcommitted
test [nfc]: Centralize a helper eg.unreadChannelMsgs
1 parent 4821024 commit bbe2d4c

File tree

3 files changed

+29
-17
lines changed

3 files changed

+29
-17
lines changed

test/example_data.dart

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -519,6 +519,18 @@ Submessage submessage({
519519
// Aggregate data structures.
520520
//
521521

522+
UnreadChannelSnapshot unreadChannelMsgs({
523+
required String topic,
524+
required int streamId,
525+
required List<int> unreadMessageIds,
526+
}) {
527+
return UnreadChannelSnapshot(
528+
topic: topic,
529+
streamId: streamId,
530+
unreadMessageIds: unreadMessageIds,
531+
);
532+
}
533+
522534
UnreadMessagesSnapshot unreadMsgs({
523535
int? count,
524536
List<UnreadDmSnapshot>? dms,

test/model/unreads_test.dart

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -114,10 +114,10 @@ void main() {
114114
prepare(initial: UnreadMessagesSnapshot(
115115
count: 0,
116116
channels: [
117-
UnreadChannelSnapshot(streamId: stream1.streamId, topic: 'a', unreadMessageIds: [1, 2]),
118-
UnreadChannelSnapshot(streamId: stream1.streamId, topic: 'b', unreadMessageIds: [3, 4]),
119-
UnreadChannelSnapshot(streamId: stream2.streamId, topic: 'b', unreadMessageIds: [5, 6]),
120-
UnreadChannelSnapshot(streamId: stream2.streamId, topic: 'c', unreadMessageIds: [7, 8]),
117+
eg.unreadChannelMsgs(streamId: stream1.streamId, topic: 'a', unreadMessageIds: [1, 2]),
118+
eg.unreadChannelMsgs(streamId: stream1.streamId, topic: 'b', unreadMessageIds: [3, 4]),
119+
eg.unreadChannelMsgs(streamId: stream2.streamId, topic: 'b', unreadMessageIds: [5, 6]),
120+
eg.unreadChannelMsgs(streamId: stream2.streamId, topic: 'c', unreadMessageIds: [7, 8]),
121121
],
122122
dms: [
123123
UnreadDmSnapshot(otherUserId: 1, unreadMessageIds: [9, 10]),

test/widgets/subscription_list_test.dart

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ void main() {
155155
testWidgets('unread badge shows with unreads', (tester) async {
156156
final stream = eg.stream();
157157
final unreadMsgs = eg.unreadMsgs(channels: [
158-
UnreadChannelSnapshot(streamId: stream.streamId, topic: 'a', unreadMessageIds: [1, 2]),
158+
eg.unreadChannelMsgs(streamId: stream.streamId, topic: 'a', unreadMessageIds: [1, 2]),
159159
]);
160160
await setupStreamListPage(tester, subscriptions: [
161161
eg.subscription(stream),
@@ -167,8 +167,8 @@ void main() {
167167
testWidgets('unread badge counts unmuted only', (tester) async {
168168
final stream = eg.stream();
169169
final unreadMsgs = eg.unreadMsgs(channels: [
170-
UnreadChannelSnapshot(streamId: stream.streamId, topic: 'a', unreadMessageIds: [1, 2]),
171-
UnreadChannelSnapshot(streamId: stream.streamId, topic: 'b', unreadMessageIds: [3]),
170+
eg.unreadChannelMsgs(streamId: stream.streamId, topic: 'a', unreadMessageIds: [1, 2]),
171+
eg.unreadChannelMsgs(streamId: stream.streamId, topic: 'b', unreadMessageIds: [3]),
172172
]);
173173
await setupStreamListPage(tester,
174174
subscriptions: [eg.subscription(stream, isMuted: true)],
@@ -198,7 +198,7 @@ void main() {
198198
testWidgets('muted unread badge shows when unreads are visible in channel but not inbox', (tester) async {
199199
final stream = eg.stream();
200200
final unreadMsgs = eg.unreadMsgs(channels: [
201-
UnreadChannelSnapshot(streamId: stream.streamId, topic: 'b', unreadMessageIds: [3]),
201+
eg.unreadChannelMsgs(streamId: stream.streamId, topic: 'b', unreadMessageIds: [3]),
202202
]);
203203
await setupStreamListPage(tester,
204204
subscriptions: [eg.subscription(stream, isMuted: true)],
@@ -211,7 +211,7 @@ void main() {
211211
testWidgets('muted unread badge does not show when unreads are visible in both channel & inbox', (tester) async {
212212
final stream = eg.stream();
213213
final unreadMsgs = eg.unreadMsgs(channels: [
214-
UnreadChannelSnapshot(streamId: stream.streamId, topic: 'b', unreadMessageIds: [3]),
214+
eg.unreadChannelMsgs(streamId: stream.streamId, topic: 'b', unreadMessageIds: [3]),
215215
]);
216216
await setupStreamListPage(tester,
217217
subscriptions: [eg.subscription(stream, isMuted: false)],
@@ -224,7 +224,7 @@ void main() {
224224
testWidgets('muted unread badge does not show when unreads are not visible in channel nor inbox', (tester) async {
225225
final stream = eg.stream();
226226
final unreadMsgs = eg.unreadMsgs(channels: [
227-
UnreadChannelSnapshot(streamId: stream.streamId, topic: 'b', unreadMessageIds: [3]),
227+
eg.unreadChannelMsgs(streamId: stream.streamId, topic: 'b', unreadMessageIds: [3]),
228228
]);
229229
await setupStreamListPage(tester,
230230
subscriptions: [eg.subscription(stream, isMuted: true)],
@@ -237,7 +237,7 @@ void main() {
237237
testWidgets('color propagates to icon and badge', (tester) async {
238238
final stream = eg.stream();
239239
final unreadMsgs = eg.unreadMsgs(channels: [
240-
UnreadChannelSnapshot(streamId: stream.streamId, topic: 'a', unreadMessageIds: [1, 2]),
240+
eg.unreadChannelMsgs(streamId: stream.streamId, topic: 'a', unreadMessageIds: [1, 2]),
241241
]);
242242
final subscription = eg.subscription(stream, color: Colors.red.argbInt);
243243
final swatch = ChannelColorSwatch.light(subscription.color);
@@ -275,8 +275,8 @@ void main() {
275275
eg.userTopicItem(stream2, 'b', UserTopicVisibilityPolicy.unmuted),
276276
],
277277
unreadMsgs: eg.unreadMsgs(channels: [
278-
UnreadChannelSnapshot(streamId: stream1.streamId, topic: 'a', unreadMessageIds: [1, 2]),
279-
UnreadChannelSnapshot(streamId: stream2.streamId, topic: 'b', unreadMessageIds: [3]),
278+
eg.unreadChannelMsgs(streamId: stream1.streamId, topic: 'a', unreadMessageIds: [1, 2]),
279+
eg.unreadChannelMsgs(streamId: stream2.streamId, topic: 'b', unreadMessageIds: [3]),
280280
]),
281281
);
282282

@@ -310,10 +310,10 @@ void main() {
310310
eg.userTopicItem(mutedStreamWithNoUnmutedUnreads, 'd', UserTopicVisibilityPolicy.muted),
311311
],
312312
unreadMsgs: eg.unreadMsgs(channels: [
313-
UnreadChannelSnapshot(streamId: unmutedStreamWithUnmutedUnreads.streamId, topic: 'a', unreadMessageIds: [1]),
314-
UnreadChannelSnapshot(streamId: unmutedStreamWithNoUnmutedUnreads.streamId, topic: 'b', unreadMessageIds: [2]),
315-
UnreadChannelSnapshot(streamId: mutedStreamWithUnmutedUnreads.streamId, topic: 'c', unreadMessageIds: [3]),
316-
UnreadChannelSnapshot(streamId: mutedStreamWithNoUnmutedUnreads.streamId, topic: 'd', unreadMessageIds: [4]),
313+
eg.unreadChannelMsgs(streamId: unmutedStreamWithUnmutedUnreads.streamId, topic: 'a', unreadMessageIds: [1]),
314+
eg.unreadChannelMsgs(streamId: unmutedStreamWithNoUnmutedUnreads.streamId, topic: 'b', unreadMessageIds: [2]),
315+
eg.unreadChannelMsgs(streamId: mutedStreamWithUnmutedUnreads.streamId, topic: 'c', unreadMessageIds: [3]),
316+
eg.unreadChannelMsgs(streamId: mutedStreamWithNoUnmutedUnreads.streamId, topic: 'd', unreadMessageIds: [4]),
317317
]),
318318
);
319319

0 commit comments

Comments
 (0)