Skip to content

Commit cd7b181

Browse files
committed
test: 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 1bea14d commit cd7b181

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
@@ -381,16 +381,19 @@ void main() {
381381
));
382382
});
383383

384-
testWidgets('not offered in CombinedFeedNarrow (composing to reply is not yet supported)', (tester) async {
385-
final message = eg.streamMessage();
386-
await setupToMessageActionSheet(tester, message: message, narrow: const CombinedFeedNarrow());
387-
check(findQuoteAndReplyButton(tester)).isNull();
388-
});
389-
390-
testWidgets('not offered in MentionsNarrow (composing to reply is not yet supported)', (tester) async {
391-
final message = eg.streamMessage();
392-
await setupToMessageActionSheet(tester, message: message, narrow: const MentionsNarrow());
393-
check(findQuoteAndReplyButton(tester)).isNull();
384+
group('composing to reply is not yet supported', () {
385+
final testCases = [
386+
('CombinedFeedNarrow', const CombinedFeedNarrow(), eg.streamMessage()),
387+
('MentionsNarrow', const MentionsNarrow(), eg.streamMessage(flags: [MessageFlag.mentioned])),
388+
];
389+
390+
for (final (narrowName, narrow, message) in testCases) {
391+
assert(narrow.containsMessage(message));
392+
testWidgets('not offered in $narrowName', (tester) async {
393+
await setupToMessageActionSheet(tester, message: message, narrow: narrow);
394+
check(findQuoteAndReplyButton(tester)).isNull();
395+
});
396+
}
394397
});
395398
});
396399

test/widgets/message_list_test.dart

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

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

153146
testWidgets('smoke test for light/dark/lerped', (tester) async {
@@ -717,40 +710,31 @@ void main() {
717710
matching: find.text(text)).evaluate();
718711
}
719712

720-
testWidgets('show stream name in CombinedFeedNarrow', (tester) async {
721-
await setupMessageListPage(tester,
722-
narrow: const CombinedFeedNarrow(),
723-
messages: [message], subscriptions: [eg.subscription(stream)]);
724-
await tester.pump();
725-
check(findInMessageList('stream name')).length.equals(1);
726-
check(findInMessageList('topic name')).length.equals(1);
727-
});
728-
729-
testWidgets('show channel name in MentionsNarrow', (tester) async {
730-
await setupMessageListPage(tester,
731-
narrow: const MentionsNarrow(),
732-
messages: [message], subscriptions: [eg.subscription(stream)]);
733-
await tester.pump();
734-
check(findInMessageList('stream name')).length.equals(1);
735-
check(findInMessageList('topic name')).length.equals(1);
736-
});
737-
738-
testWidgets('do not show channel name in ChannelNarrow', (tester) async {
739-
await setupMessageListPage(tester,
740-
narrow: ChannelNarrow(stream.streamId),
741-
messages: [message], streams: [stream]);
742-
await tester.pump();
743-
check(findInMessageList('stream name')).length.equals(0);
744-
check(findInMessageList('topic name')).length.equals(1);
745-
});
746-
747-
testWidgets('do not show stream name in TopicNarrow', (tester) async {
748-
await setupMessageListPage(tester,
749-
narrow: TopicNarrow.ofMessage(message),
750-
messages: [message], streams: [stream]);
751-
await tester.pump();
752-
check(findInMessageList('stream name')).length.equals(0);
753-
check(findInMessageList('topic name')).length.equals(1);
713+
group('show channel name conditionally', () {
714+
final mentionedMessage =
715+
eg.streamMessage(stream: stream, topic: 'topic name', flags: [MessageFlag.mentioned]);
716+
final testCases = [
717+
(true, 'CombinedFeedNarrow', const CombinedFeedNarrow(), message),
718+
(true, 'MentionsNarrow', const MentionsNarrow(), mentionedMessage),
719+
(false, 'ChannelNarrow', ChannelNarrow(stream.streamId), message),
720+
(false, 'TopicNarrow', TopicNarrow.ofMessage(message), message)
721+
];
722+
723+
for (final (showChannelName, narrowName, narrow, message) in testCases) {
724+
testWidgets('in $narrowName, show channel name: $showChannelName', (tester) async {
725+
assert(narrow.containsMessage(message));
726+
await setupMessageListPage(tester,
727+
narrow: narrow,
728+
messages: [message], subscriptions: [eg.subscription(stream)]);
729+
await tester.pump();
730+
if (showChannelName) {
731+
check(findInMessageList('stream name')).single;
732+
} else {
733+
check(findInMessageList('stream name')).isEmpty();
734+
}
735+
check(findInMessageList('topic name')).length.equals(1);
736+
});
737+
}
754738
});
755739

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

0 commit comments

Comments
 (0)