π End-to-end encrypted cloud for everything.
Dart 2faandroidauthye2eeencryptionend-to-end-encryptionfluttergolanggoogle-photosgoogle-photos-alternativeiosopensourcephotosprivacyprivacy-toolstypescriptzero-knowledge
[mob][locker] Preserve emoji in generated Note titles (#13564)
aman-pilot4d7a571bc674
diff --git a/mobile/apps/locker/changes/note-title-emoji.md b/mobile/apps/locker/changes/note-title-emoji.mdnew file mode 100644index 0000000000..9db3626708--- /dev/null+++ b/mobile/apps/locker/changes/note-title-emoji.md@@ -0,0 +1 @@+- Fixed emoji being cut off in automatically generated Note titles.diff --git a/mobile/apps/locker/lib/ui/pages/personal_note_page.dart b/mobile/apps/locker/lib/ui/pages/personal_note_page.dartindex 7aad0b156e..b8d4b671ed 100644--- a/mobile/apps/locker/lib/ui/pages/personal_note_page.dart+++ b/mobile/apps/locker/lib/ui/pages/personal_note_page.dart@@ -105,11 +105,12 @@ class _PersonalNotePageStatefinal words = firstLine.split(RegExp(r'\s+'));final limitedWords = words.take(maxWords).join(' ');+ final characters = limitedWords.characters;- if (limitedWords.length <= maxLength) {+ if (characters.length <= maxLength) {return limitedWords;}- return '${limitedWords.substring(0, maxLength).trimRight()}...';+ return '${characters.take(maxLength).toString().trimRight()}...';}@overridediff --git a/mobile/apps/locker/test/ui/pages/required_info_fields_test.dart b/mobile/apps/locker/test/ui/pages/required_info_fields_test.dartindex ea3deabe3c..5ad2780d1a 100644--- a/mobile/apps/locker/test/ui/pages/required_info_fields_test.dart+++ b/mobile/apps/locker/test/ui/pages/required_info_fields_test.dart@@ -1,3 +1,4 @@+import 'dart:convert';import 'dart:io';import 'package:ente_components/ente_components.dart';@@ -5,6 +6,7 @@ import 'package:ente_strings/ente_strings.dart';import 'package:flutter/material.dart';import 'package:flutter_test/flutter_test.dart';import 'package:locker/models/file_type.dart';+import 'package:locker/models/info/info_item.dart';import 'package:locker/services/configuration.dart';import 'package:locker/services/files/sync/models/file.dart';import 'package:locker/services/files/sync/models/file_magic.dart';@@ -161,4 +163,75 @@ void main() {await tester.enterText(find.byType(TextField).first, 'Manual title');expect(state.validateForm(), isFalse);});++ testWidgets('generated Note titles preserve whole characters at the limit', (+ tester,+ ) async {+ await showPage(tester, const PersonalNotePage());+ final state = tester.state(find.byType(PersonalNotePage)) as dynamic;+ const prefix = 'RC285-edge-1234567890123456789012345678';++ for (final character in ['π', 'π©π½βπ»', 'e\u0301']) {+ final content = '$prefix${character}end';+ await tester.enterText(find.byType(TextField).at(1), content);+ final data = state.createInfoData();+ expect(data.title, '$prefix$character...');+ expect(data.content, content);+ }+ });++ testWidgets('generated Note titles count emoji as whole characters', (+ tester,+ ) async {+ await showPage(tester, const PersonalNotePage());+ final state = tester.state(find.byType(PersonalNotePage)) as dynamic;+ final content = List.filled(40, 'π').join();+ await tester.enterText(find.byType(TextField).at(1), content);+ expect(state.createInfoData().title, content);+ });++ testWidgets('generated Note titles keep first-line and word limits', (+ tester,+ ) async {+ await showPage(tester, const PersonalNotePage());+ final state = tester.state(find.byType(PersonalNotePage)) as dynamic;+ await tester.enterText(+ find.byType(TextField).at(1),+ ' one two three four five six\nsecond line',+ );+ expect(state.createInfoData().title, 'one two three four five');++ const manualTitle = 'My π©π½βπ» note title';+ await tester.enterText(find.byType(TextField).first, manualTitle);+ expect(state.createInfoData().title, manualTitle);+ });++ testWidgets('a generated emoji title reopens intact for editing', (+ tester,+ ) async {+ await showPage(tester, const PersonalNotePage());+ final state = tester.state(find.byType(PersonalNotePage)) as dynamic;+ const content = 'RC285-edge-1234567890123456789012345678πend';+ const expectedTitle = 'RC285-edge-1234567890123456789012345678π...';+ await tester.enterText(find.byType(TextField).at(1), content);+ final data = state.createInfoData() as PersonalNoteData;+ final file = EnteFile()+ ..fileType = FileType.info+ ..ownerID = 1+ ..title = data.title+ ..pubMagicMetadata = PubMagicMetadata(+ info: jsonDecode(jsonEncode({'type': 'note', 'data': data.toJson()})),+ noThumb: true,+ );+ await tester.pumpWidget(const SizedBox.shrink());+ await showPage(tester, PersonalNotePage(existingFile: file));++ await tester.tap(find.byType(TextField).first);+ await tester.pump();+ expect(tester.testTextInput.editingState!['text'], expectedTitle);+ expect(+ tester.widget<TextField>(find.byType(TextField).at(1)).controller!.text,+ content,+ );+ });}