From c732f4e908fe6f694131256fff1b6b877b28ed2b Mon Sep 17 00:00:00 2001 From: "Lucas.Xu" Date: Mon, 15 Aug 2022 16:48:33 +0800 Subject: [PATCH] test: implement select all test for no-styled text --- .../test/infra/test_raw_key_event.dart | 3 ++ .../select_all_handler_test.dart | 38 +++++++++++++++++++ 2 files changed, 41 insertions(+) create mode 100644 frontend/app_flowy/packages/flowy_editor/test/service/internal_key_event_handlers/select_all_handler_test.dart diff --git a/frontend/app_flowy/packages/flowy_editor/test/infra/test_raw_key_event.dart b/frontend/app_flowy/packages/flowy_editor/test/infra/test_raw_key_event.dart index 8fa0e5e4e3..78ed06383e 100644 --- a/frontend/app_flowy/packages/flowy_editor/test/infra/test_raw_key_event.dart +++ b/frontend/app_flowy/packages/flowy_editor/test/infra/test_raw_key_event.dart @@ -94,6 +94,9 @@ extension on LogicalKeyboardKey { if (this == LogicalKeyboardKey.keyZ) { return PhysicalKeyboardKey.keyZ; } + if (this == LogicalKeyboardKey.keyA) { + return PhysicalKeyboardKey.keyA; + } throw UnimplementedError(); } } diff --git a/frontend/app_flowy/packages/flowy_editor/test/service/internal_key_event_handlers/select_all_handler_test.dart b/frontend/app_flowy/packages/flowy_editor/test/service/internal_key_event_handlers/select_all_handler_test.dart new file mode 100644 index 0000000000..53c13b7119 --- /dev/null +++ b/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 _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), + ), + ); +}