Skip to content

Commit 18dae84

Browse files
committed
squash into main commit? saved_snippet: Check for title/content length
1 parent 299c53e commit 18dae84

11 files changed

+108
-4
lines changed

assets/l10n/app_en.arb

+8
Original file line numberDiff line numberDiff line change
@@ -373,10 +373,18 @@
373373
"@savedSnippetTitleValidationErrorEmpty": {
374374
"description": "Validation error message when the title of the saved snippet is empty."
375375
},
376+
"savedSnippetTitleValidationErrorTooLong": "Title length shouldn't be greater than 60 characters.",
377+
"@savedSnippetTitleValidationErrorTooLong": {
378+
"description": "Validation error message when the title of the saved snippet is too long."
379+
},
376380
"savedSnippetContentValidationErrorEmpty": "Content cannot be empty.",
377381
"@savedSnippetContentValidationErrorEmpty": {
378382
"description": "Validation error message when the content of the saved snippet is empty."
379383
},
384+
"savedSnippetContentValidationErrorTooLong": "Content length shouldn't be greater than 10000 characters.",
385+
"@savedSnippetContentValidationErrorTooLong": {
386+
"description": "Validation error message when the content of the saved snippet is too long."
387+
},
380388
"composeBoxGenericContentHint": "Type a message",
381389
"@composeBoxGenericContentHint": {
382390
"description": "Hint text for content input when sending a message."

lib/generated/l10n/zulip_localizations.dart

+12
Original file line numberDiff line numberDiff line change
@@ -609,12 +609,24 @@ abstract class ZulipLocalizations {
609609
/// **'Title cannot be empty.'**
610610
String get savedSnippetTitleValidationErrorEmpty;
611611

612+
/// Validation error message when the title of the saved snippet is too long.
613+
///
614+
/// In en, this message translates to:
615+
/// **'Title length shouldn\'t be greater than 60 characters.'**
616+
String get savedSnippetTitleValidationErrorTooLong;
617+
612618
/// Validation error message when the content of the saved snippet is empty.
613619
///
614620
/// In en, this message translates to:
615621
/// **'Content cannot be empty.'**
616622
String get savedSnippetContentValidationErrorEmpty;
617623

624+
/// Validation error message when the content of the saved snippet is too long.
625+
///
626+
/// In en, this message translates to:
627+
/// **'Content length shouldn\'t be greater than 10000 characters.'**
628+
String get savedSnippetContentValidationErrorTooLong;
629+
618630
/// Hint text for content input when sending a message.
619631
///
620632
/// In en, this message translates to:

lib/generated/l10n/zulip_localizations_ar.dart

+6
Original file line numberDiff line numberDiff line change
@@ -294,9 +294,15 @@ class ZulipLocalizationsAr extends ZulipLocalizations {
294294
@override
295295
String get savedSnippetTitleValidationErrorEmpty => 'Title cannot be empty.';
296296

297+
@override
298+
String get savedSnippetTitleValidationErrorTooLong => 'Title length shouldn\'t be greater than 60 characters.';
299+
297300
@override
298301
String get savedSnippetContentValidationErrorEmpty => 'Content cannot be empty.';
299302

303+
@override
304+
String get savedSnippetContentValidationErrorTooLong => 'Content length shouldn\'t be greater than 10000 characters.';
305+
300306
@override
301307
String get composeBoxGenericContentHint => 'Type a message';
302308

lib/generated/l10n/zulip_localizations_en.dart

+6
Original file line numberDiff line numberDiff line change
@@ -294,9 +294,15 @@ class ZulipLocalizationsEn extends ZulipLocalizations {
294294
@override
295295
String get savedSnippetTitleValidationErrorEmpty => 'Title cannot be empty.';
296296

297+
@override
298+
String get savedSnippetTitleValidationErrorTooLong => 'Title length shouldn\'t be greater than 60 characters.';
299+
297300
@override
298301
String get savedSnippetContentValidationErrorEmpty => 'Content cannot be empty.';
299302

303+
@override
304+
String get savedSnippetContentValidationErrorTooLong => 'Content length shouldn\'t be greater than 10000 characters.';
305+
300306
@override
301307
String get composeBoxGenericContentHint => 'Type a message';
302308

lib/generated/l10n/zulip_localizations_ja.dart

+6
Original file line numberDiff line numberDiff line change
@@ -294,9 +294,15 @@ class ZulipLocalizationsJa extends ZulipLocalizations {
294294
@override
295295
String get savedSnippetTitleValidationErrorEmpty => 'Title cannot be empty.';
296296

297+
@override
298+
String get savedSnippetTitleValidationErrorTooLong => 'Title length shouldn\'t be greater than 60 characters.';
299+
297300
@override
298301
String get savedSnippetContentValidationErrorEmpty => 'Content cannot be empty.';
299302

303+
@override
304+
String get savedSnippetContentValidationErrorTooLong => 'Content length shouldn\'t be greater than 10000 characters.';
305+
300306
@override
301307
String get composeBoxGenericContentHint => 'Type a message';
302308

lib/generated/l10n/zulip_localizations_nb.dart

+6
Original file line numberDiff line numberDiff line change
@@ -294,9 +294,15 @@ class ZulipLocalizationsNb extends ZulipLocalizations {
294294
@override
295295
String get savedSnippetTitleValidationErrorEmpty => 'Title cannot be empty.';
296296

297+
@override
298+
String get savedSnippetTitleValidationErrorTooLong => 'Title length shouldn\'t be greater than 60 characters.';
299+
297300
@override
298301
String get savedSnippetContentValidationErrorEmpty => 'Content cannot be empty.';
299302

303+
@override
304+
String get savedSnippetContentValidationErrorTooLong => 'Content length shouldn\'t be greater than 10000 characters.';
305+
300306
@override
301307
String get composeBoxGenericContentHint => 'Type a message';
302308

lib/generated/l10n/zulip_localizations_pl.dart

+6
Original file line numberDiff line numberDiff line change
@@ -294,9 +294,15 @@ class ZulipLocalizationsPl extends ZulipLocalizations {
294294
@override
295295
String get savedSnippetTitleValidationErrorEmpty => 'Title cannot be empty.';
296296

297+
@override
298+
String get savedSnippetTitleValidationErrorTooLong => 'Title length shouldn\'t be greater than 60 characters.';
299+
297300
@override
298301
String get savedSnippetContentValidationErrorEmpty => 'Content cannot be empty.';
299302

303+
@override
304+
String get savedSnippetContentValidationErrorTooLong => 'Content length shouldn\'t be greater than 10000 characters.';
305+
300306
@override
301307
String get composeBoxGenericContentHint => 'Wpisz wiadomość';
302308

lib/generated/l10n/zulip_localizations_ru.dart

+6
Original file line numberDiff line numberDiff line change
@@ -294,9 +294,15 @@ class ZulipLocalizationsRu extends ZulipLocalizations {
294294
@override
295295
String get savedSnippetTitleValidationErrorEmpty => 'Title cannot be empty.';
296296

297+
@override
298+
String get savedSnippetTitleValidationErrorTooLong => 'Title length shouldn\'t be greater than 60 characters.';
299+
297300
@override
298301
String get savedSnippetContentValidationErrorEmpty => 'Content cannot be empty.';
299302

303+
@override
304+
String get savedSnippetContentValidationErrorTooLong => 'Content length shouldn\'t be greater than 10000 characters.';
305+
300306
@override
301307
String get composeBoxGenericContentHint => 'Ввести сообщение';
302308

lib/generated/l10n/zulip_localizations_sk.dart

+6
Original file line numberDiff line numberDiff line change
@@ -294,9 +294,15 @@ class ZulipLocalizationsSk extends ZulipLocalizations {
294294
@override
295295
String get savedSnippetTitleValidationErrorEmpty => 'Title cannot be empty.';
296296

297+
@override
298+
String get savedSnippetTitleValidationErrorTooLong => 'Title length shouldn\'t be greater than 60 characters.';
299+
297300
@override
298301
String get savedSnippetContentValidationErrorEmpty => 'Content cannot be empty.';
299302

303+
@override
304+
String get savedSnippetContentValidationErrorTooLong => 'Content length shouldn\'t be greater than 10000 characters.';
305+
300306
@override
301307
String get composeBoxGenericContentHint => 'Type a message';
302308

lib/widgets/compose_box.dart

+20-4
Original file line numberDiff line numberDiff line change
@@ -379,11 +379,13 @@ class ComposeContentController extends ComposeController<ContentValidationError>
379379
}
380380

381381
enum SavedSnippetTitleValidationError {
382-
empty;
382+
empty,
383+
tooLong;
383384

384385
String message(ZulipLocalizations zulipLocalizations) {
385386
return switch (this) {
386387
SavedSnippetTitleValidationError.empty => zulipLocalizations.savedSnippetTitleValidationErrorEmpty,
388+
SavedSnippetTitleValidationError.tooLong => zulipLocalizations.savedSnippetTitleValidationErrorTooLong,
387389
};
388390
}
389391
}
@@ -393,7 +395,7 @@ class SavedSnippetTitleComposeController extends ComposeController<SavedSnippetT
393395
_update();
394396
}
395397

396-
@override final maxLengthUnicodeCodePoints = null;
398+
@override int get maxLengthUnicodeCodePoints => kMaxTopicLengthCodePoints;
397399

398400
@override
399401
String _computeTextNormalized() {
@@ -405,16 +407,24 @@ class SavedSnippetTitleComposeController extends ComposeController<SavedSnippetT
405407
return [
406408
if (textNormalized.isEmpty)
407409
SavedSnippetTitleValidationError.empty,
410+
411+
if (
412+
_lengthUnicodeCodePointsIfLong != null
413+
&& _lengthUnicodeCodePointsIfLong! > maxLengthUnicodeCodePoints
414+
)
415+
SavedSnippetTitleValidationError.tooLong,
408416
];
409417
}
410418
}
411419

412420
enum SavedSnippetContentValidationError {
413-
empty;
421+
empty,
422+
tooLong;
414423

415424
String message(ZulipLocalizations zulipLocalizations) {
416425
return switch (this) {
417426
SavedSnippetContentValidationError.empty => zulipLocalizations.savedSnippetContentValidationErrorEmpty,
427+
SavedSnippetContentValidationError.tooLong => zulipLocalizations.savedSnippetContentValidationErrorTooLong,
418428
};
419429
}
420430
}
@@ -424,7 +434,7 @@ class SavedSnippetContentComposeController extends ComposeController<SavedSnippe
424434
_update();
425435
}
426436

427-
@override final maxLengthUnicodeCodePoints = null;
437+
@override int get maxLengthUnicodeCodePoints => kMaxMessageLengthCodePoints;
428438

429439
@override
430440
String _computeTextNormalized() {
@@ -436,6 +446,12 @@ class SavedSnippetContentComposeController extends ComposeController<SavedSnippe
436446
return [
437447
if (textNormalized.isEmpty)
438448
SavedSnippetContentValidationError.empty,
449+
450+
if (
451+
_lengthUnicodeCodePointsIfLong != null
452+
&& _lengthUnicodeCodePointsIfLong! > maxLengthUnicodeCodePoints
453+
)
454+
SavedSnippetContentValidationError.tooLong,
439455
];
440456
}
441457
}

test/widgets/compose_box_test.dart

+26
Original file line numberDiff line numberDiff line change
@@ -932,6 +932,32 @@ void main() {
932932
expectedMessage: 'Content cannot be empty.');
933933
});
934934

935+
testWidgets('title is too long', (tester) async {
936+
await prepareSavedSnippetComposeBox(tester,
937+
title: 'a' * 61, content: 'content bar');
938+
939+
await tester.tap(find.byIcon(ZulipIcons.check));
940+
await tester.pump(Duration.zero);
941+
check(poppedRoutes).isEmpty();
942+
check(connection.takeRequests()).isEmpty();
943+
checkErrorDialog(tester,
944+
expectedTitle: 'Failed to create saved snippet',
945+
expectedMessage: "Title length shouldn't be greater than 60 characters.");
946+
});
947+
948+
testWidgets('content is too long', (tester) async {
949+
await prepareSavedSnippetComposeBox(tester,
950+
title: 'title foo', content: 'a' * 10001);
951+
952+
await tester.tap(find.byIcon(ZulipIcons.check));
953+
await tester.pump(Duration.zero);
954+
check(poppedRoutes).isEmpty();
955+
check(connection.takeRequests()).isEmpty();
956+
checkErrorDialog(tester,
957+
expectedTitle: 'Failed to create saved snippet',
958+
expectedMessage: "Content length shouldn't be greater than 10000 characters.");
959+
});
960+
935961
testWidgets('disable send button if there are validation errors', (tester) async {
936962
await prepareSavedSnippetComposeBox(tester,
937963
title: '', content: 'content bar');

0 commit comments

Comments
 (0)