Explorar o código

test: implement select all test for no-styled text

Lucas.Xu %!s(int64=2) %!d(string=hai) anos
pai
achega
c732f4e908

+ 3 - 0
frontend/app_flowy/packages/flowy_editor/test/infra/test_raw_key_event.dart

@@ -94,6 +94,9 @@ extension on LogicalKeyboardKey {
     if (this == LogicalKeyboardKey.keyZ) {
     if (this == LogicalKeyboardKey.keyZ) {
       return PhysicalKeyboardKey.keyZ;
       return PhysicalKeyboardKey.keyZ;
     }
     }
+    if (this == LogicalKeyboardKey.keyA) {
+      return PhysicalKeyboardKey.keyA;
+    }
     throw UnimplementedError();
     throw UnimplementedError();
   }
   }
 }
 }

+ 38 - 0
frontend/app_flowy/packages/flowy_editor/test/service/internal_key_event_handlers/select_all_handler_test.dart

@@ -0,0 +1,38 @@
+import 'package:flowy_editor/flowy_editor.dart';
+import 'package:flutter/services.dart';
+import 'package:flutter_test/flutter_test.dart';
+import '../../infra/test_editor.dart';
+
+void main() async {
+  setUpAll(() {
+    TestWidgetsFlutterBinding.ensureInitialized();
+  });
+
+  group('select_all_handler_test.dart', () {
+    testWidgets('Presses Command + A in small document', (tester) async {
+      await _testSelectAllHandler(tester, 10);
+    });
+
+    testWidgets('Presses Command + A in small document', (tester) async {
+      await _testSelectAllHandler(tester, 1000);
+    });
+  });
+}
+
+Future<void> _testSelectAllHandler(WidgetTester tester, int lines) async {
+  const text = 'Welcome to Appflowy 😁';
+  final editor = tester.editor;
+  for (var i = 0; i < lines; i++) {
+    editor.insertTextNode(text);
+  }
+  await editor.startTesting();
+  await editor.pressLogicKey(LogicalKeyboardKey.keyA, isMetaPressed: true);
+
+  expect(
+    editor.documentSelection,
+    Selection(
+      start: Position(path: [0], offset: 0),
+      end: Position(path: [lines - 1], offset: text.length),
+    ),
+  );
+}