Skip to content

Commit e2d55be

Browse files
committed
test [nfc]: Parameterize some narrow-related tests.
These tests are mostly similar to each other. This refactor makes it easier to add tests for new narrows. Signed-off-by: Zixuan James Li <[email protected]>
1 parent a783ced commit e2d55be

File tree

2 files changed

+56
-69
lines changed

2 files changed

+56
-69
lines changed

test/widgets/action_sheet_test.dart

+13-10
Original file line numberDiff line numberDiff line change
@@ -372,16 +372,19 @@ void main() {
372372
));
373373
});
374374

375-
testWidgets('not offered in CombinedFeedNarrow (composing to reply is not yet supported)', (WidgetTester tester) async {
376-
final message = eg.streamMessage();
377-
await setupToMessageActionSheet(tester, message: message, narrow: const CombinedFeedNarrow());
378-
check(findQuoteAndReplyButton(tester)).isNull();
379-
});
380-
381-
testWidgets('not offered in MentionsNarrow (composing to reply is not yet supported)', (WidgetTester tester) async {
382-
final message = eg.streamMessage();
383-
await setupToMessageActionSheet(tester, message: message, narrow: const MentionsNarrow());
384-
check(findQuoteAndReplyButton(tester)).isNull();
375+
group('composing to reply is not yet supported', () {
376+
final testCases = [
377+
('CombinedFeedNarrow', const CombinedFeedNarrow(), eg.streamMessage()),
378+
('MentionsNarrow', const MentionsNarrow(), eg.streamMessage(flags: [MessageFlag.mentioned])),
379+
];
380+
381+
for (final (narrowName, narrow, message) in testCases) {
382+
assert(narrow.containsMessage(message));
383+
testWidgets('not offered in $narrowName (composing to reply is not yet supported)', (WidgetTester tester) async {
384+
await setupToMessageActionSheet(tester, message: message, narrow: narrow);
385+
check(findQuoteAndReplyButton(tester)).isNull();
386+
});
387+
}
385388
});
386389
});
387390

test/widgets/message_list_test.dart

+43-59
Original file line numberDiff line numberDiff line change
@@ -124,31 +124,24 @@ void main() {
124124

125125
group('presents message content appropriately', () {
126126
// regression test for https://github.com/zulip/zulip-flutter/issues/736
127-
testWidgets('content in "Combined feed" not asked to consume insets (including bottom)', (tester) async {
128-
const fakePadding = FakeViewPadding(left: 10, top: 10, right: 10, bottom: 10);
129-
tester.view.viewInsets = fakePadding;
130-
tester.view.padding = fakePadding;
131-
132-
await setupMessageListPage(tester, narrow: const CombinedFeedNarrow(),
133-
messages: [eg.streamMessage(content: ContentExample.codeBlockPlain.html)]);
134-
135-
final element = tester.element(find.byType(CodeBlock));
136-
final padding = MediaQuery.of(element).padding;
137-
check(padding).equals(EdgeInsets.zero);
138-
});
139-
140-
testWidgets('content in MentionsNarrow not asked to consume insets (including bottom)', (tester) async {
141-
const fakePadding = FakeViewPadding(left: 10, top: 10, right: 10, bottom: 10);
142-
tester.view.viewInsets = fakePadding;
143-
tester.view.padding = fakePadding;
144-
145-
await setupMessageListPage(tester, narrow: const MentionsNarrow(),
146-
messages: [eg.streamMessage(content: ContentExample.codeBlockPlain.html, flags: [MessageFlag.mentioned])]);
147-
148-
final element = tester.element(find.byType(CodeBlock));
149-
final padding = MediaQuery.of(element).padding;
150-
check(padding).equals(EdgeInsets.zero);
151-
});
127+
final testCases = [
128+
("Combined feed", const CombinedFeedNarrow(), <MessageFlag>[]),
129+
("MentionsNarrow", const MentionsNarrow(), [MessageFlag.mentioned]),
130+
];
131+
for (final (narrowName, narrow, flags) in testCases) {
132+
testWidgets('content in $narrowName not asked to consume insets (including bottom)', (tester) async {
133+
const fakePadding = FakeViewPadding(left: 10, top: 10, right: 10, bottom: 10);
134+
tester.view.viewInsets = fakePadding;
135+
tester.view.padding = fakePadding;
136+
137+
await setupMessageListPage(tester, narrow: narrow,
138+
messages: [eg.streamMessage(content: ContentExample.codeBlockPlain.html, flags: flags)]);
139+
140+
final element = tester.element(find.byType(CodeBlock));
141+
final padding = MediaQuery.of(element).padding;
142+
check(padding).equals(EdgeInsets.zero);
143+
});
144+
}
152145
});
153146

154147
testWidgets('smoke test for light/dark/lerped', (tester) async {
@@ -633,40 +626,31 @@ void main() {
633626
matching: find.text(text)).evaluate();
634627
}
635628

636-
testWidgets('show stream name in CombinedFeedNarrow', (tester) async {
637-
await setupMessageListPage(tester,
638-
narrow: const CombinedFeedNarrow(),
639-
messages: [message], subscriptions: [eg.subscription(stream)]);
640-
await tester.pump();
641-
check(findInMessageList('stream name')).length.equals(1);
642-
check(findInMessageList('topic name')).length.equals(1);
643-
});
644-
645-
testWidgets('show channel name in MentionsNarrow', (tester) async {
646-
await setupMessageListPage(tester,
647-
narrow: const MentionsNarrow(),
648-
messages: [message], subscriptions: [eg.subscription(stream)]);
649-
await tester.pump();
650-
check(findInMessageList('stream name')).length.equals(1);
651-
check(findInMessageList('topic name')).length.equals(1);
652-
});
653-
654-
testWidgets('do not show channel name in ChannelNarrow', (tester) async {
655-
await setupMessageListPage(tester,
656-
narrow: ChannelNarrow(stream.streamId),
657-
messages: [message], streams: [stream]);
658-
await tester.pump();
659-
check(findInMessageList('stream name')).length.equals(0);
660-
check(findInMessageList('topic name')).length.equals(1);
661-
});
662-
663-
testWidgets('do not show stream name in TopicNarrow', (tester) async {
664-
await setupMessageListPage(tester,
665-
narrow: TopicNarrow.ofMessage(message),
666-
messages: [message], streams: [stream]);
667-
await tester.pump();
668-
check(findInMessageList('stream name')).length.equals(0);
669-
check(findInMessageList('topic name')).length.equals(1);
629+
group('show channel name conditionally', () {
630+
final mentionedMessage =
631+
eg.streamMessage(stream: stream, topic: 'topic name', flags: [MessageFlag.mentioned]);
632+
final testCases = [
633+
(true, 'CombinedFeedNarrow', const CombinedFeedNarrow(), message),
634+
(true, 'MentionsNarrow', const MentionsNarrow(), mentionedMessage),
635+
(false, 'ChannelNarrow', ChannelNarrow(stream.streamId), message),
636+
(false, 'TopicNarrow', TopicNarrow.ofMessage(message), message)
637+
];
638+
639+
for (final (showChannelName, narrowName, narrow, message) in testCases) {
640+
testWidgets('in $narrowName, show channel name: $showChannelName', (tester) async {
641+
assert(narrow.containsMessage(message));
642+
await setupMessageListPage(tester,
643+
narrow: narrow,
644+
messages: [message], subscriptions: [eg.subscription(stream)]);
645+
await tester.pump();
646+
if (showChannelName) {
647+
check(findInMessageList('stream name')).single;
648+
} else {
649+
check(findInMessageList('stream name')).isEmpty();
650+
}
651+
check(findInMessageList('topic name')).length.equals(1);
652+
});
653+
}
670654
});
671655

672656
testWidgets('color of recipient header background', (tester) async {

0 commit comments

Comments
 (0)