Skip to content

Commit 98bbfde

Browse files
committed
compose test: Testing with multiple maxTopicLength variants
1 parent 28d6324 commit 98bbfde

File tree

2 files changed

+21
-12
lines changed

2 files changed

+21
-12
lines changed

test/example_data.dart

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -902,6 +902,7 @@ InitialSnapshot initialSnapshot({
902902
String? zulipMergeBase,
903903
List<String>? alertWords,
904904
List<CustomProfileField>? customProfileFields,
905+
int? maxTopicLength,
905906
EmailAddressVisibility? emailAddressVisibility,
906907
int? serverTypingStartedExpiryPeriodMilliseconds,
907908
int? serverTypingStoppedWaitPeriodMilliseconds,
@@ -932,6 +933,7 @@ InitialSnapshot initialSnapshot({
932933
zulipMergeBase: zulipMergeBase ?? recentZulipVersion,
933934
alertWords: alertWords ?? ['klaxon'],
934935
customProfileFields: customProfileFields ?? [],
936+
maxTopicLength: maxTopicLength ?? 60,
935937
emailAddressVisibility: emailAddressVisibility ?? EmailAddressVisibility.everyone,
936938
serverTypingStartedExpiryPeriodMilliseconds:
937939
serverTypingStartedExpiryPeriodMilliseconds ?? 15000,

test/widgets/compose_box_test.dart

Lines changed: 19 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ void main() {
4747
List<User> otherUsers = const [],
4848
List<ZulipStream> streams = const [],
4949
bool? mandatoryTopics,
50+
int? maxTopicLength,
5051
}) async {
5152
if (narrow case ChannelNarrow(:var streamId) || TopicNarrow(: var streamId)) {
5253
assert(streams.any((stream) => stream.streamId == streamId),
@@ -56,7 +57,7 @@ void main() {
5657
selfUser ??= eg.selfUser;
5758
final selfAccount = eg.account(user: selfUser);
5859
await testBinding.globalStore.add(selfAccount, eg.initialSnapshot(
59-
realmMandatoryTopics: mandatoryTopics,
60+
realmMandatoryTopics: mandatoryTopics, maxTopicLength: maxTopicLength
6061
));
6162

6263
store = await testBinding.globalStore.perAccount(selfAccount.id);
@@ -283,41 +284,47 @@ void main() {
283284
});
284285

285286
group('topic', () {
286-
Future<void> prepareWithTopic(WidgetTester tester, String topic) async {
287+
Future<void> prepareWithTopic(WidgetTester tester, String topic, int maxTopicLength) async {
287288
TypingNotifier.debugEnable = false;
288289
addTearDown(TypingNotifier.debugReset);
289290

290291
final narrow = ChannelNarrow(channel.streamId);
291-
await prepareComposeBox(tester, narrow: narrow, streams: [channel]);
292+
await prepareComposeBox(tester, narrow: narrow, streams: [channel],
293+
maxTopicLength: maxTopicLength);
292294
await enterTopic(tester, narrow: narrow, topic: topic);
293295
await enterContent(tester, 'some content');
294296
}
295297

296-
Future<void> checkErrorResponse(WidgetTester tester) async {
298+
Future<void> checkErrorResponse(WidgetTester tester, {required int maxTopicLength}) async {
297299
await tester.tap(find.byWidget(checkErrorDialog(tester,
298300
expectedTitle: 'Message not sent',
299-
expectedMessage: 'Topic length shouldn\'t be greater than 60 characters.')));
301+
expectedMessage: 'Topic length shouldn\'t be greater than $maxTopicLength characters.')));
300302
}
301303

304+
final ValueVariant<int> maxTopicLengthVariants = ValueVariant<int>({50, 60, 70});
305+
302306
testWidgets('too-long topic is rejected', (tester) async {
307+
final maxTopicLength = maxTopicLengthVariants.currentValue!;
303308
await prepareWithTopic(tester,
304-
makeStringWithCodePoints(kMaxTopicLengthCodePoints + 1));
309+
makeStringWithCodePoints(maxTopicLength + 1), maxTopicLength);
305310
await tapSendButton(tester);
306-
await checkErrorResponse(tester);
307-
});
311+
await checkErrorResponse(tester, maxTopicLength: maxTopicLength);
312+
}, variant: maxTopicLengthVariants);
308313

309314
testWidgets('max-length topic not rejected', (tester) async {
315+
final maxTopicLength = maxTopicLengthVariants.currentValue!;
310316
await prepareWithTopic(tester,
311-
makeStringWithCodePoints(kMaxTopicLengthCodePoints));
317+
makeStringWithCodePoints(maxTopicLength), maxTopicLength);
312318
await tapSendButton(tester);
313319
checkNoErrorDialog(tester);
314-
});
320+
}, variant: maxTopicLengthVariants);
315321

316322
testWidgets('code points not counted unnecessarily', (tester) async {
317-
await prepareWithTopic(tester, 'a' * kMaxTopicLengthCodePoints);
323+
final maxTopicLength = maxTopicLengthVariants.currentValue!;
324+
await prepareWithTopic(tester, 'a' * maxTopicLength, maxTopicLength);
318325
check((controller as StreamComposeBoxController)
319326
.topic.debugLengthUnicodeCodePointsIfLong).isNull();
320-
});
327+
}, variant: maxTopicLengthVariants);
321328
});
322329
});
323330

0 commit comments

Comments
 (0)