Skip to content

Commit

Permalink
test [nfc]: Centralize a helper eg.unreadChannelMsgs
Browse files Browse the repository at this point in the history
  • Loading branch information
gnprice committed Jan 8, 2025
1 parent f4783f1 commit 15cc6ba
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 17 deletions.
12 changes: 12 additions & 0 deletions test/example_data.dart
Original file line number Diff line number Diff line change
Expand Up @@ -519,6 +519,18 @@ Submessage submessage({
// Aggregate data structures.
//

UnreadChannelSnapshot unreadChannelMsgs({
required String topic,
required int streamId,
required List<int> unreadMessageIds,
}) {
return UnreadChannelSnapshot(
topic: topic,
streamId: streamId,
unreadMessageIds: unreadMessageIds,
);
}

UnreadMessagesSnapshot unreadMsgs({
int? count,
List<UnreadDmSnapshot>? dms,
Expand Down
8 changes: 4 additions & 4 deletions test/model/unreads_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -114,10 +114,10 @@ void main() {
prepare(initial: UnreadMessagesSnapshot(
count: 0,
channels: [
UnreadChannelSnapshot(streamId: stream1.streamId, topic: 'a', unreadMessageIds: [1, 2]),
UnreadChannelSnapshot(streamId: stream1.streamId, topic: 'b', unreadMessageIds: [3, 4]),
UnreadChannelSnapshot(streamId: stream2.streamId, topic: 'b', unreadMessageIds: [5, 6]),
UnreadChannelSnapshot(streamId: stream2.streamId, topic: 'c', unreadMessageIds: [7, 8]),
eg.unreadChannelMsgs(streamId: stream1.streamId, topic: 'a', unreadMessageIds: [1, 2]),
eg.unreadChannelMsgs(streamId: stream1.streamId, topic: 'b', unreadMessageIds: [3, 4]),
eg.unreadChannelMsgs(streamId: stream2.streamId, topic: 'b', unreadMessageIds: [5, 6]),
eg.unreadChannelMsgs(streamId: stream2.streamId, topic: 'c', unreadMessageIds: [7, 8]),
],
dms: [
UnreadDmSnapshot(otherUserId: 1, unreadMessageIds: [9, 10]),
Expand Down
26 changes: 13 additions & 13 deletions test/widgets/subscription_list_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ void main() {
testWidgets('unread badge shows with unreads', (tester) async {
final stream = eg.stream();
final unreadMsgs = eg.unreadMsgs(channels: [
UnreadChannelSnapshot(streamId: stream.streamId, topic: 'a', unreadMessageIds: [1, 2]),
eg.unreadChannelMsgs(streamId: stream.streamId, topic: 'a', unreadMessageIds: [1, 2]),
]);
await setupStreamListPage(tester, subscriptions: [
eg.subscription(stream),
Expand All @@ -167,8 +167,8 @@ void main() {
testWidgets('unread badge counts unmuted only', (tester) async {
final stream = eg.stream();
final unreadMsgs = eg.unreadMsgs(channels: [
UnreadChannelSnapshot(streamId: stream.streamId, topic: 'a', unreadMessageIds: [1, 2]),
UnreadChannelSnapshot(streamId: stream.streamId, topic: 'b', unreadMessageIds: [3]),
eg.unreadChannelMsgs(streamId: stream.streamId, topic: 'a', unreadMessageIds: [1, 2]),
eg.unreadChannelMsgs(streamId: stream.streamId, topic: 'b', unreadMessageIds: [3]),
]);
await setupStreamListPage(tester,
subscriptions: [eg.subscription(stream, isMuted: true)],
Expand Down Expand Up @@ -198,7 +198,7 @@ void main() {
testWidgets('muted unread badge shows when unreads are visible in channel but not inbox', (tester) async {
final stream = eg.stream();
final unreadMsgs = eg.unreadMsgs(channels: [
UnreadChannelSnapshot(streamId: stream.streamId, topic: 'b', unreadMessageIds: [3]),
eg.unreadChannelMsgs(streamId: stream.streamId, topic: 'b', unreadMessageIds: [3]),
]);
await setupStreamListPage(tester,
subscriptions: [eg.subscription(stream, isMuted: true)],
Expand All @@ -211,7 +211,7 @@ void main() {
testWidgets('muted unread badge does not show when unreads are visible in both channel & inbox', (tester) async {
final stream = eg.stream();
final unreadMsgs = eg.unreadMsgs(channels: [
UnreadChannelSnapshot(streamId: stream.streamId, topic: 'b', unreadMessageIds: [3]),
eg.unreadChannelMsgs(streamId: stream.streamId, topic: 'b', unreadMessageIds: [3]),
]);
await setupStreamListPage(tester,
subscriptions: [eg.subscription(stream, isMuted: false)],
Expand All @@ -224,7 +224,7 @@ void main() {
testWidgets('muted unread badge does not show when unreads are not visible in channel nor inbox', (tester) async {
final stream = eg.stream();
final unreadMsgs = eg.unreadMsgs(channels: [
UnreadChannelSnapshot(streamId: stream.streamId, topic: 'b', unreadMessageIds: [3]),
eg.unreadChannelMsgs(streamId: stream.streamId, topic: 'b', unreadMessageIds: [3]),
]);
await setupStreamListPage(tester,
subscriptions: [eg.subscription(stream, isMuted: true)],
Expand All @@ -237,7 +237,7 @@ void main() {
testWidgets('color propagates to icon and badge', (tester) async {
final stream = eg.stream();
final unreadMsgs = eg.unreadMsgs(channels: [
UnreadChannelSnapshot(streamId: stream.streamId, topic: 'a', unreadMessageIds: [1, 2]),
eg.unreadChannelMsgs(streamId: stream.streamId, topic: 'a', unreadMessageIds: [1, 2]),
]);
final subscription = eg.subscription(stream, color: Colors.red.argbInt);
final swatch = ChannelColorSwatch.light(subscription.color);
Expand Down Expand Up @@ -275,8 +275,8 @@ void main() {
eg.userTopicItem(stream2, 'b', UserTopicVisibilityPolicy.unmuted),
],
unreadMsgs: eg.unreadMsgs(channels: [
UnreadChannelSnapshot(streamId: stream1.streamId, topic: 'a', unreadMessageIds: [1, 2]),
UnreadChannelSnapshot(streamId: stream2.streamId, topic: 'b', unreadMessageIds: [3]),
eg.unreadChannelMsgs(streamId: stream1.streamId, topic: 'a', unreadMessageIds: [1, 2]),
eg.unreadChannelMsgs(streamId: stream2.streamId, topic: 'b', unreadMessageIds: [3]),
]),
);

Expand Down Expand Up @@ -310,10 +310,10 @@ void main() {
eg.userTopicItem(mutedStreamWithNoUnmutedUnreads, 'd', UserTopicVisibilityPolicy.muted),
],
unreadMsgs: eg.unreadMsgs(channels: [
UnreadChannelSnapshot(streamId: unmutedStreamWithUnmutedUnreads.streamId, topic: 'a', unreadMessageIds: [1]),
UnreadChannelSnapshot(streamId: unmutedStreamWithNoUnmutedUnreads.streamId, topic: 'b', unreadMessageIds: [2]),
UnreadChannelSnapshot(streamId: mutedStreamWithUnmutedUnreads.streamId, topic: 'c', unreadMessageIds: [3]),
UnreadChannelSnapshot(streamId: mutedStreamWithNoUnmutedUnreads.streamId, topic: 'd', unreadMessageIds: [4]),
eg.unreadChannelMsgs(streamId: unmutedStreamWithUnmutedUnreads.streamId, topic: 'a', unreadMessageIds: [1]),
eg.unreadChannelMsgs(streamId: unmutedStreamWithNoUnmutedUnreads.streamId, topic: 'b', unreadMessageIds: [2]),
eg.unreadChannelMsgs(streamId: mutedStreamWithUnmutedUnreads.streamId, topic: 'c', unreadMessageIds: [3]),
eg.unreadChannelMsgs(streamId: mutedStreamWithNoUnmutedUnreads.streamId, topic: 'd', unreadMessageIds: [4]),
]),
);

Expand Down

0 comments on commit 15cc6ba

Please sign in to comment.