Skip to content

Commit a9b4399

Browse files
committed
compose_box test [nfc]: Factor some tests out of a loop structure
1 parent fb8bde9 commit a9b4399

File tree

1 file changed

+42
-19
lines changed

1 file changed

+42
-19
lines changed

test/widgets/compose_box_test.dart

Lines changed: 42 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1411,31 +1411,54 @@ void main() {
14111411
void checkComposeBox({required bool isShown}) => checkComposeBoxIsShown(isShown,
14121412
bannerLabel: zulipLocalizations.errorBannerCannotPostInChannelLabel);
14131413

1414-
final narrowTestCases = [
1415-
('channel', const ChannelNarrow(1)),
1416-
('topic', eg.topicNarrow(1, 'topic')),
1417-
];
1418-
1419-
for (final (String narrowType, Narrow narrow) in narrowTestCases) {
1420-
testWidgets('compose box is shown in $narrowType narrow', (tester) async {
1414+
const channelNarrow = ChannelNarrow(1);
1415+
final topicNarrow = eg.topicNarrow(1, 'topic');
1416+
1417+
void doTestComposeBoxShown({
1418+
required Narrow narrow,
1419+
required ChannelPostPolicy channelPostPolicy,
1420+
required UserRole selfUserRole,
1421+
required bool expected,
1422+
}) {
1423+
final description = [
1424+
narrow.toString(),
1425+
'channelPostPolicy: ${channelPostPolicy.name}',
1426+
'self-user role: ${selfUserRole.name}',
1427+
].join(', ');
1428+
testWidgets(description, (tester) async {
14211429
await prepareComposeBox(tester,
14221430
narrow: narrow,
1423-
selfUser: eg.user(role: UserRole.administrator),
1431+
selfUser: eg.user(role: selfUserRole),
14241432
subscriptions: [eg.subscription(eg.stream(streamId: 1,
1425-
channelPostPolicy: ChannelPostPolicy.moderators))]);
1426-
checkComposeBox(isShown: true);
1427-
});
1428-
1429-
testWidgets('error banner is shown in $narrowType narrow', (tester) async {
1430-
await prepareComposeBox(tester,
1431-
narrow: narrow,
1432-
selfUser: eg.user(role: UserRole.moderator),
1433-
subscriptions: [eg.subscription(eg.stream(streamId: 1,
1434-
channelPostPolicy: ChannelPostPolicy.administrators))]);
1435-
checkComposeBox(isShown: false);
1433+
channelPostPolicy: channelPostPolicy))]);
1434+
checkComposeBox(isShown: expected);
14361435
});
14371436
}
14381437

1438+
doTestComposeBoxShown(
1439+
narrow: channelNarrow,
1440+
channelPostPolicy: ChannelPostPolicy.moderators,
1441+
selfUserRole: UserRole.administrator,
1442+
expected: true);
1443+
1444+
doTestComposeBoxShown(
1445+
narrow: topicNarrow,
1446+
channelPostPolicy: ChannelPostPolicy.moderators,
1447+
selfUserRole: UserRole.administrator,
1448+
expected: true);
1449+
1450+
doTestComposeBoxShown(
1451+
narrow: channelNarrow,
1452+
channelPostPolicy: ChannelPostPolicy.administrators,
1453+
selfUserRole: UserRole.moderator,
1454+
expected: false);
1455+
1456+
doTestComposeBoxShown(
1457+
narrow: topicNarrow,
1458+
channelPostPolicy: ChannelPostPolicy.administrators,
1459+
selfUserRole: UserRole.moderator,
1460+
expected: false);
1461+
14391462
testWidgets('user loses privilege -> compose box is replaced with the banner', (tester) async {
14401463
final selfUser = eg.user(role: UserRole.administrator);
14411464
await prepareComposeBox(tester,

0 commit comments

Comments
 (0)