Skip to content

Commit 0b7780f

Browse files
committed
compose test: Testing with multiple maxTopicLength variants
1 parent d78d008 commit 0b7780f

File tree

2 files changed

+21
-11
lines changed

2 files changed

+21
-11
lines changed

Diff for: test/example_data.dart

+2
Original file line numberDiff line numberDiff line change
@@ -897,6 +897,7 @@ InitialSnapshot initialSnapshot({
897897
String? zulipMergeBase,
898898
List<String>? alertWords,
899899
List<CustomProfileField>? customProfileFields,
900+
int? maxTopicLength,
900901
EmailAddressVisibility? emailAddressVisibility,
901902
int? serverTypingStartedExpiryPeriodMilliseconds,
902903
int? serverTypingStoppedWaitPeriodMilliseconds,
@@ -927,6 +928,7 @@ InitialSnapshot initialSnapshot({
927928
zulipMergeBase: zulipMergeBase ?? recentZulipVersion,
928929
alertWords: alertWords ?? ['klaxon'],
929930
customProfileFields: customProfileFields ?? [],
931+
maxTopicLength: maxTopicLength ?? 60,
930932
emailAddressVisibility: emailAddressVisibility ?? EmailAddressVisibility.everyone,
931933
serverTypingStartedExpiryPeriodMilliseconds:
932934
serverTypingStartedExpiryPeriodMilliseconds ?? 15000,

Diff for: test/widgets/compose_box_test.dart

+19-11
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ void main() {
4848
List<ZulipStream> streams = const [],
4949
bool? mandatoryTopics,
5050
int? zulipFeatureLevel,
51+
int? maxTopicLength,
5152
}) async {
5253
if (narrow case ChannelNarrow(:var streamId) || TopicNarrow(: var streamId)) {
5354
assert(streams.any((stream) => stream.streamId == streamId),
@@ -60,6 +61,7 @@ void main() {
6061
await testBinding.globalStore.add(selfAccount, eg.initialSnapshot(
6162
zulipFeatureLevel: zulipFeatureLevel,
6263
realmMandatoryTopics: mandatoryTopics,
64+
maxTopicLength: maxTopicLength,
6365
));
6466

6567
store = await testBinding.globalStore.perAccount(selfAccount.id);
@@ -286,41 +288,47 @@ void main() {
286288
});
287289

288290
group('topic', () {
289-
Future<void> prepareWithTopic(WidgetTester tester, String topic) async {
291+
Future<void> prepareWithTopic(WidgetTester tester, String topic, int maxTopicLength) async {
290292
TypingNotifier.debugEnable = false;
291293
addTearDown(TypingNotifier.debugReset);
292294

293295
final narrow = ChannelNarrow(channel.streamId);
294-
await prepareComposeBox(tester, narrow: narrow, streams: [channel]);
296+
await prepareComposeBox(tester, narrow: narrow, streams: [channel],
297+
maxTopicLength: maxTopicLength);
295298
await enterTopic(tester, narrow: narrow, topic: topic);
296299
await enterContent(tester, 'some content');
297300
}
298301

299-
Future<void> checkErrorResponse(WidgetTester tester) async {
302+
Future<void> checkErrorResponse(WidgetTester tester, {required int maxTopicLength}) async {
300303
await tester.tap(find.byWidget(checkErrorDialog(tester,
301304
expectedTitle: 'Message not sent',
302-
expectedMessage: 'Topic length shouldn\'t be greater than 60 characters.')));
305+
expectedMessage: 'Topic length shouldn\'t be greater than $maxTopicLength characters.')));
303306
}
304307

308+
final ValueVariant<int> maxTopicLengthVariants = ValueVariant<int>({50, 60, 70});
309+
305310
testWidgets('too-long topic is rejected', (tester) async {
311+
final maxTopicLength = maxTopicLengthVariants.currentValue!;
306312
await prepareWithTopic(tester,
307-
makeStringWithCodePoints(kMaxTopicLengthCodePoints + 1));
313+
makeStringWithCodePoints(maxTopicLength + 1), maxTopicLength);
308314
await tapSendButton(tester);
309-
await checkErrorResponse(tester);
310-
});
315+
await checkErrorResponse(tester, maxTopicLength: maxTopicLength);
316+
}, variant: maxTopicLengthVariants);
311317

312318
testWidgets('max-length topic not rejected', (tester) async {
319+
final maxTopicLength = maxTopicLengthVariants.currentValue!;
313320
await prepareWithTopic(tester,
314-
makeStringWithCodePoints(kMaxTopicLengthCodePoints));
321+
makeStringWithCodePoints(maxTopicLength), maxTopicLength);
315322
await tapSendButton(tester);
316323
checkNoErrorDialog(tester);
317-
});
324+
}, variant: maxTopicLengthVariants);
318325

319326
testWidgets('code points not counted unnecessarily', (tester) async {
320-
await prepareWithTopic(tester, 'a' * kMaxTopicLengthCodePoints);
327+
final maxTopicLength = maxTopicLengthVariants.currentValue!;
328+
await prepareWithTopic(tester, 'a' * maxTopicLength, maxTopicLength);
321329
check((controller as StreamComposeBoxController)
322330
.topic.debugLengthUnicodeCodePointsIfLong).isNull();
323-
});
331+
}, variant: maxTopicLengthVariants);
324332
});
325333
});
326334

0 commit comments

Comments
 (0)