diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index acbcbac4c..f0c64ca88 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -33,7 +33,7 @@ jobs: - uses: subosito/flutter-action@v2 with: channel: "stable" - flutter-version: "3.19.0" + flutter-version: "3.22.0" cache: true - name: Run tests diff --git a/lib/src/editor/block_component/image_block_component/image_upload_widget.dart b/lib/src/editor/block_component/image_block_component/image_upload_widget.dart index 695f797b2..9bc82e517 100644 --- a/lib/src/editor/block_component/image_block_component/image_upload_widget.dart +++ b/lib/src/editor/block_component/image_block_component/image_upload_widget.dart @@ -217,8 +217,8 @@ class _UploadImageMenuState extends State { height: 36, child: TextButton( style: ButtonStyle( - backgroundColor: MaterialStateProperty.all(const Color(0xFF00BCF0)), - shape: MaterialStateProperty.all( + backgroundColor: WidgetStateProperty.all(const Color(0xFF00BCF0)), + shape: WidgetStateProperty.all( RoundedRectangleBorder( borderRadius: BorderRadius.circular(12.0), ), diff --git a/lib/src/editor/selection_menu/selection_menu_item_widget.dart b/lib/src/editor/selection_menu/selection_menu_item_widget.dart index 71d60b354..4fb4a6ffc 100644 --- a/lib/src/editor/selection_menu/selection_menu_item_widget.dart +++ b/lib/src/editor/selection_menu/selection_menu_item_widget.dart @@ -44,14 +44,14 @@ class _SelectionMenuItemWidgetState extends State { ), style: ButtonStyle( alignment: Alignment.centerLeft, - overlayColor: MaterialStateProperty.all( + overlayColor: WidgetStateProperty.all( style.selectionMenuItemSelectedColor, ), backgroundColor: widget.isSelected - ? MaterialStateProperty.all( + ? WidgetStateProperty.all( style.selectionMenuItemSelectedColor, ) - : MaterialStateProperty.all(Colors.transparent), + : WidgetStateProperty.all(Colors.transparent), ), label: Text( widget.item.name, diff --git a/lib/src/editor/toolbar/desktop/items/color/color_picker.dart b/lib/src/editor/toolbar/desktop/items/color/color_picker.dart index 9c2ef4bc3..49b5df35e 100644 --- a/lib/src/editor/toolbar/desktop/items/color/color_picker.dart +++ b/lib/src/editor/toolbar/desktop/items/color/color_picker.dart @@ -169,9 +169,9 @@ class ResetColorButton extends StatelessWidget { textAlign: TextAlign.left, ), style: ButtonStyle( - backgroundColor: MaterialStateProperty.resolveWith( - (Set states) { - if (states.contains(MaterialState.hovered)) { + backgroundColor: WidgetStateProperty.resolveWith( + (Set states) { + if (states.contains(WidgetState.hovered)) { return Theme.of(context).hoverColor; } return Colors.transparent; diff --git a/lib/src/editor/toolbar/desktop/items/utils/overlay_util.dart b/lib/src/editor/toolbar/desktop/items/utils/overlay_util.dart index d3ff99d73..5e8822167 100644 --- a/lib/src/editor/toolbar/desktop/items/utils/overlay_util.dart +++ b/lib/src/editor/toolbar/desktop/items/utils/overlay_util.dart @@ -3,9 +3,9 @@ import 'package:flutter/material.dart'; ButtonStyle buildOverlayButtonStyle(BuildContext context) { return ButtonStyle( - backgroundColor: MaterialStateProperty.resolveWith( - (Set states) { - if (states.contains(MaterialState.hovered)) { + backgroundColor: WidgetStateProperty.resolveWith( + (Set states) { + if (states.contains(WidgetState.hovered)) { return Theme.of(context).hoverColor; } return Colors.transparent; diff --git a/lib/src/editor/toolbar/mobile/toolbar_items/link_mobile_toolbar_item.dart b/lib/src/editor/toolbar/mobile/toolbar_items/link_mobile_toolbar_item.dart index 8145a5e23..8ef148fb5 100644 --- a/lib/src/editor/toolbar/mobile/toolbar_items/link_mobile_toolbar_item.dart +++ b/lib/src/editor/toolbar/mobile/toolbar_items/link_mobile_toolbar_item.dart @@ -123,20 +123,20 @@ class _MobileLinkMenuState extends State { widget.onCancel.call(); }, style: ButtonStyle( - backgroundColor: MaterialStateProperty.all( + backgroundColor: WidgetStateProperty.all( style.backgroundColor, ), - foregroundColor: MaterialStateProperty.all( + foregroundColor: WidgetStateProperty.all( style.primaryColor, ), - elevation: MaterialStateProperty.all(0), - shape: MaterialStateProperty.all( + elevation: WidgetStateProperty.all(0), + shape: WidgetStateProperty.all( RoundedRectangleBorder( borderRadius: BorderRadius.circular(style.borderRadius), ), ), - side: MaterialStateBorderSide.resolveWith( + side: WidgetStateBorderSide.resolveWith( (states) => BorderSide(color: style.outlineColor), ), ), @@ -154,14 +154,14 @@ class _MobileLinkMenuState extends State { ?.closeKeyboard(); }, style: ButtonStyle( - backgroundColor: MaterialStateProperty.all( + backgroundColor: WidgetStateProperty.all( style.primaryColor, ), - foregroundColor: MaterialStateProperty.all( + foregroundColor: WidgetStateProperty.all( style.onPrimaryColor, ), - elevation: MaterialStateProperty.all(0), - shape: MaterialStateProperty.all( + elevation: WidgetStateProperty.all(0), + shape: WidgetStateProperty.all( RoundedRectangleBorder( borderRadius: BorderRadius.circular(style.borderRadius), diff --git a/lib/src/editor/toolbar/mobile/utils/mobile_toolbar_item_menu_btn.dart b/lib/src/editor/toolbar/mobile/utils/mobile_toolbar_item_menu_btn.dart index 78cb50e91..d99842a54 100644 --- a/lib/src/editor/toolbar/mobile/utils/mobile_toolbar_item_menu_btn.dart +++ b/lib/src/editor/toolbar/mobile/utils/mobile_toolbar_item_menu_btn.dart @@ -22,9 +22,9 @@ class MobileToolbarItemMenuBtn extends StatelessWidget { onPressed: onPressed, style: ButtonStyle( alignment: label == null ? Alignment.center : Alignment.centerLeft, - foregroundColor: MaterialStateProperty.all(style.foregroundColor), + foregroundColor: WidgetStateProperty.all(style.foregroundColor), splashFactory: NoSplash.splashFactory, - side: MaterialStateProperty.resolveWith( + side: WidgetStateProperty.resolveWith( (states) { if (isSelected == true) { return BorderSide( @@ -35,12 +35,12 @@ class MobileToolbarItemMenuBtn extends StatelessWidget { return BorderSide(color: style.itemOutlineColor); }, ), - shape: MaterialStateProperty.all( + shape: WidgetStateProperty.all( RoundedRectangleBorder( borderRadius: BorderRadius.circular(style.borderRadius), ), ), - padding: MaterialStateProperty.all( + padding: WidgetStateProperty.all( EdgeInsets.zero, ), ), diff --git a/pubspec.yaml b/pubspec.yaml index cdd416849..fe5b07114 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -19,7 +19,7 @@ platforms: environment: sdk: ">=3.1.5 <4.0.0" - flutter: ">=3.13.0" + flutter: ">=3.19.0" dependencies: flutter: @@ -33,7 +33,7 @@ dependencies: sdk: flutter flutter_svg: ^2.0.6 html: ^0.15.0 - intl: ^0.18.0 + intl: ^0.19.0 intl_utils: ^2.8.2 keyboard_height_plugin: ^0.0.4 logging: ^1.2.0 @@ -52,7 +52,7 @@ dependencies: dev_dependencies: flutter_test: sdk: flutter - flutter_lints: ^3.0.1 + flutter_lints: ^4.0.0 network_image_mock: ^2.1.1 mockito: ^5.4.1 leak_tracker: ^10.0.0 diff --git a/test/new/block_component/table_block_component/table_commands_test.dart b/test/new/block_component/table_block_component/table_commands_test.dart index 26735d4e4..96da43bd7 100644 --- a/test/new/block_component/table_block_component/table_commands_test.dart +++ b/test/new/block_component/table_block_component/table_commands_test.dart @@ -30,7 +30,7 @@ void main() async { startOffset: 0, ), ); - await simulateKeyDownEvent(LogicalKeyboardKey.enter); + await editor.pressKey(key: LogicalKeyboardKey.enter); var selection = editor.selection!; var cell01 = getCellNode(tableNode.node, 0, 1)!; @@ -59,7 +59,7 @@ void main() async { startOffset: 0, ), ); - await simulateKeyDownEvent(LogicalKeyboardKey.enter); + await editor.pressKey(key: LogicalKeyboardKey.enter); var selection = editor.selection!; @@ -88,7 +88,8 @@ void main() async { startOffset: 0, ), ); - await simulateKeyDownEvent(LogicalKeyboardKey.backspace); + await editor.pressKey(key: LogicalKeyboardKey.backspace); + await tester.pumpAndSettle(); var selection = editor.selection!; @@ -123,7 +124,7 @@ void main() async { // ), // ), // ); - // await simulateKeyDownEvent(LogicalKeyboardKey.backspace); + // await editor.pressKey(key: LogicalKeyboardKey.backspace); // var selection = editor.selection!; @@ -165,7 +166,7 @@ void main() async { ), ), ); - await simulateKeyDownEvent(LogicalKeyboardKey.backspace); + await editor.pressKey(key: LogicalKeyboardKey.backspace); var selection = editor.selection!; @@ -204,7 +205,7 @@ void main() async { ), ), ); - await simulateKeyDownEvent(LogicalKeyboardKey.backspace); + await editor.pressKey(key: LogicalKeyboardKey.backspace); var selection = editor.selection!; @@ -237,7 +238,7 @@ void main() async { startOffset: 1, ), ); - await simulateKeyDownEvent(LogicalKeyboardKey.arrowUp); + await editor.pressKey(key: LogicalKeyboardKey.arrowUp); var selection = editor.selection!; @@ -251,7 +252,7 @@ void main() async { startOffset: 3, ), ); - await simulateKeyDownEvent(LogicalKeyboardKey.arrowUp); + await editor.pressKey(key: LogicalKeyboardKey.arrowUp); selection = editor.selection!; @@ -281,7 +282,7 @@ void main() async { startOffset: 1, ), ); - await simulateKeyDownEvent(LogicalKeyboardKey.arrowDown); + await editor.pressKey(key: LogicalKeyboardKey.arrowDown); var selection = editor.selection!; @@ -295,7 +296,7 @@ void main() async { startOffset: 3, ), ); - await simulateKeyDownEvent(LogicalKeyboardKey.arrowDown); + await editor.pressKey(key: LogicalKeyboardKey.arrowDown); selection = editor.selection!; @@ -325,7 +326,7 @@ void main() async { ), ); - await simulateKeyDownEvent(LogicalKeyboardKey.arrowLeft); + await editor.pressKey(key: LogicalKeyboardKey.arrowLeft); var selection = editor.selection!; @@ -340,7 +341,7 @@ void main() async { ), ); - await simulateKeyDownEvent(LogicalKeyboardKey.arrowLeft); + await editor.pressKey(key: LogicalKeyboardKey.arrowLeft); selection = editor.selection!; @@ -370,7 +371,7 @@ void main() async { ), ); - await simulateKeyDownEvent(LogicalKeyboardKey.arrowLeft); + await editor.pressKey(key: LogicalKeyboardKey.arrowLeft); var selection = editor.selection!; @@ -400,7 +401,7 @@ void main() async { ), ); - await simulateKeyDownEvent(LogicalKeyboardKey.arrowRight); + await editor.pressKey(key: LogicalKeyboardKey.arrowRight); var selection = editor.selection!; @@ -432,7 +433,7 @@ void main() async { ), ); - await simulateKeyDownEvent(LogicalKeyboardKey.arrowRight); + await editor.pressKey(key: LogicalKeyboardKey.arrowRight); var selection = editor.selection!; @@ -448,7 +449,7 @@ void main() async { ), ); - await simulateKeyDownEvent(LogicalKeyboardKey.arrowRight); + await editor.pressKey(key: LogicalKeyboardKey.arrowRight); selection = editor.selection!; @@ -480,7 +481,7 @@ void main() async { ), ); - await simulateKeyDownEvent(LogicalKeyboardKey.tab); + await editor.pressKey(key: LogicalKeyboardKey.tab); var selection = editor.selection!; @@ -495,7 +496,7 @@ void main() async { ), ); - await simulateKeyDownEvent(LogicalKeyboardKey.tab); + await editor.pressKey(key: LogicalKeyboardKey.tab); selection = editor.selection!; @@ -511,7 +512,7 @@ void main() async { ), ); - await simulateKeyDownEvent(LogicalKeyboardKey.tab); + await editor.pressKey(key: LogicalKeyboardKey.tab); selection = editor.selection!; @@ -543,8 +544,7 @@ void main() async { ), ); - await simulateKeyDownEvent(LogicalKeyboardKey.shiftLeft); - await simulateKeyDownEvent(LogicalKeyboardKey.tab); + await editor.pressKey(key: LogicalKeyboardKey.tab, isShiftPressed: true); var selection = editor.selection!; @@ -559,8 +559,7 @@ void main() async { ), ); - await simulateKeyDownEvent(LogicalKeyboardKey.shiftLeft); - await simulateKeyDownEvent(LogicalKeyboardKey.tab); + await editor.pressKey(key: LogicalKeyboardKey.tab, isShiftPressed: true); selection = editor.selection!; @@ -576,8 +575,7 @@ void main() async { ), ); - await simulateKeyDownEvent(LogicalKeyboardKey.shiftLeft); - await simulateKeyDownEvent(LogicalKeyboardKey.tab); + await editor.pressKey(key: LogicalKeyboardKey.tab, isShiftPressed: true); selection = editor.selection!; diff --git a/test/new/block_component/text_direction_mixin_test.dart b/test/new/block_component/text_direction_mixin_test.dart index c6755a0f0..f58c6901d 100644 --- a/test/new/block_component/text_direction_mixin_test.dart +++ b/test/new/block_component/text_direction_mixin_test.dart @@ -466,7 +466,7 @@ void main() { .indentPadding(node, TextDirection.ltr), ); - await simulateKeyDownEvent(LogicalKeyboardKey.backspace); + await editor.pressKey(key: LogicalKeyboardKey.backspace); await tester.pumpAndSettle(); nestedBlock = diff --git a/test/new/infra/testable_editor.dart b/test/new/infra/testable_editor.dart index d20211d4a..c40991c8b 100644 --- a/test/new/infra/testable_editor.dart +++ b/test/new/infra/testable_editor.dart @@ -234,6 +234,7 @@ class TestableEditor { LogicalKeyboardKey.asterisk: '*', LogicalKeyboardKey.underscore: '_', }; + Future pressKey({ String? character, LogicalKeyboardKey? key, diff --git a/test/new/service/shortcuts/command_shortcut_events/arrow_left_command_test.dart b/test/new/service/shortcuts/command_shortcut_events/arrow_left_command_test.dart index b58505cab..48aea0c5b 100644 --- a/test/new/service/shortcuts/command_shortcut_events/arrow_left_command_test.dart +++ b/test/new/service/shortcuts/command_shortcut_events/arrow_left_command_test.dart @@ -71,13 +71,13 @@ void main() async { // move the cursor to the beginning of node 1 for (var i = 1; i < text.length; i++) { - await simulateKeyDownEvent(LogicalKeyboardKey.arrowLeft); + await editor.pressKey(key: LogicalKeyboardKey.arrowLeft); await tester.pumpAndSettle(); } expect(editor.selection, Selection.collapsed(Position(path: [1]))); // move the cursor to the ending of node 0 - await simulateKeyDownEvent(LogicalKeyboardKey.arrowLeft); + await editor.pressKey(key: LogicalKeyboardKey.arrowLeft); expect( editor.selection, Selection.collapsed(Position(path: [0], offset: text.length)), @@ -85,7 +85,7 @@ void main() async { // move the cursor to the beginning of node 0 for (var i = 1; i < text.length; i++) { - await simulateKeyDownEvent(LogicalKeyboardKey.arrowLeft); + await editor.pressKey(key: LogicalKeyboardKey.arrowLeft); await tester.pumpAndSettle(); } expect(editor.selection, Selection.collapsed(Position(path: [0]))); @@ -192,7 +192,7 @@ void main() async { // |Welcome to AppFlowy Editor 🔥! // After on Windows & Linux // Welcome to AppFlowy |Editor 🔥! - testWidgets('''press the ctrl+arrow left key, + testWidgets('''press the ctrl+arrow left key, on windows & linux it should move to the start of a word, on mac it should move the cursor to the start of the line ''', (tester) async { @@ -228,7 +228,7 @@ void main() async { await editor.dispose(); }); - testWidgets('''press the ctrl+shift+arrow left key, + testWidgets('''press the ctrl+shift+arrow left key, on windows & linux it should move to the start of a word and select it, on mac it should move the cursor to the start of the line and select it ''', (tester) async { diff --git a/test/new/service/shortcuts/command_shortcut_events/arrow_right_command_test.dart b/test/new/service/shortcuts/command_shortcut_events/arrow_right_command_test.dart index 8b3ef657b..3aff9998e 100644 --- a/test/new/service/shortcuts/command_shortcut_events/arrow_right_command_test.dart +++ b/test/new/service/shortcuts/command_shortcut_events/arrow_right_command_test.dart @@ -73,7 +73,7 @@ void main() async { // move the cursor to the ending of node 0 for (var i = 1; i < text.length; i++) { - await simulateKeyDownEvent(LogicalKeyboardKey.arrowRight); + await editor.pressKey(key: LogicalKeyboardKey.arrowRight); await tester.pumpAndSettle(); } expect( @@ -82,12 +82,12 @@ void main() async { ); // move the cursor to the beginning of node 1 - await simulateKeyDownEvent(LogicalKeyboardKey.arrowRight); + await editor.pressKey(key: LogicalKeyboardKey.arrowRight); expect(editor.selection, Selection.collapsed(Position(path: [1]))); // move the cursor to the ending of node 1 for (var i = 1; i < text.length; i++) { - await simulateKeyDownEvent(LogicalKeyboardKey.arrowRight); + await editor.pressKey(key: LogicalKeyboardKey.arrowRight); await tester.pumpAndSettle(); } expect( @@ -171,7 +171,7 @@ void main() async { // Welcome to AppFlowy Editor 🔥!| // After on Windows & Linux // Welcome| to AppFlowy Editor 🔥! - testWidgets('''press the ctrl+arrow right key, + testWidgets('''press the ctrl+arrow right key, on windows & linux it should move to the end of a word, on mac it should move the cursor to the end of the line ''', (tester) async { @@ -211,7 +211,7 @@ void main() async { // |Welcome to AppFlowy Editor 🔥!| // After on Windows & Linux // |Welcome| to AppFlowy Editor 🔥! - testWidgets('''press the ctrl+shift+arrow right key, + testWidgets('''press the ctrl+shift+arrow right key, on windows & linux it should move to the end of a word and select it, on mac it should move the cursor to the end of the line and select it ''', (tester) async { diff --git a/test/new/service/shortcuts/command_shortcut_events/backspace_command_test.dart b/test/new/service/shortcuts/command_shortcut_events/backspace_command_test.dart index 256dff7be..6f5bd297b 100644 --- a/test/new/service/shortcuts/command_shortcut_events/backspace_command_test.dart +++ b/test/new/service/shortcuts/command_shortcut_events/backspace_command_test.dart @@ -319,7 +319,7 @@ void main() async { ); await editor.updateSelection(selection); - await simulateKeyDownEvent(LogicalKeyboardKey.backspace); + await editor.pressKey(key: LogicalKeyboardKey.backspace); await tester.pumpAndSettle(); // the first node should be deleted. @@ -366,7 +366,7 @@ void main() async { ); await editor.updateSelection(selection); - await simulateKeyDownEvent(LogicalKeyboardKey.backspace); + await editor.pressKey(key: LogicalKeyboardKey.backspace); await tester.pumpAndSettle(); expect( @@ -416,7 +416,7 @@ void main() async { ); await editor.updateSelection(selection); - await simulateKeyDownEvent(LogicalKeyboardKey.backspace); + await editor.pressKey(key: LogicalKeyboardKey.backspace); await tester.pumpAndSettle(); expect( @@ -453,7 +453,7 @@ void main() async { ); await editor.updateSelection(selection); - await simulateKeyDownEvent(LogicalKeyboardKey.backspace); + await editor.pressKey(key: LogicalKeyboardKey.backspace); await tester.pumpAndSettle(); expect( @@ -495,7 +495,7 @@ void main() async { ); await editor.updateSelection(selection); - await simulateKeyDownEvent(LogicalKeyboardKey.backspace); + await editor.pressKey(key: LogicalKeyboardKey.backspace); await tester.pumpAndSettle(); node = editor.nodeAtPath([1])!; diff --git a/test/new/service/shortcuts/command_shortcut_events/delete_command_test.dart b/test/new/service/shortcuts/command_shortcut_events/delete_command_test.dart index 2620a6d51..1b6436080 100644 --- a/test/new/service/shortcuts/command_shortcut_events/delete_command_test.dart +++ b/test/new/service/shortcuts/command_shortcut_events/delete_command_test.dart @@ -289,7 +289,7 @@ void main() async { ); await editor.updateSelection(selection); - await simulateKeyDownEvent(LogicalKeyboardKey.delete); + await editor.pressKey(key: LogicalKeyboardKey.delete); await tester.pumpAndSettle(); // the first node should be deleted. @@ -336,7 +336,7 @@ void main() async { ); await editor.updateSelection(selection); - await simulateKeyDownEvent(LogicalKeyboardKey.delete); + await editor.pressKey(key: LogicalKeyboardKey.delete); await tester.pumpAndSettle(); expect( @@ -386,7 +386,7 @@ void main() async { ); await editor.updateSelection(selection); - await simulateKeyDownEvent(LogicalKeyboardKey.delete); + await editor.pressKey(key: LogicalKeyboardKey.delete); await tester.pumpAndSettle(); expect( @@ -424,7 +424,7 @@ void main() async { ); await editor.updateSelection(selection); - await simulateKeyDownEvent(LogicalKeyboardKey.delete); + await editor.pressKey(key: LogicalKeyboardKey.delete); await tester.pumpAndSettle(); expect( diff --git a/test/new/service/shortcuts/command_shortcut_events/delete_left_character_command_test.dart b/test/new/service/shortcuts/command_shortcut_events/delete_left_character_command_test.dart index 2c24400c9..2f96888c2 100644 --- a/test/new/service/shortcuts/command_shortcut_events/delete_left_character_command_test.dart +++ b/test/new/service/shortcuts/command_shortcut_events/delete_left_character_command_test.dart @@ -35,7 +35,7 @@ void main() async { await editor.updateSelection(selection); for (final LogicalKeyboardKey key in keys) { - await simulateKeyDownEvent(key); + await editor.pressKey(key: key); await tester.pumpAndSettle(); } @@ -84,7 +84,7 @@ void main() async { await editor.updateSelection(selection); for (final LogicalKeyboardKey key in keys) { - await simulateKeyDownEvent(key); + await editor.pressKey(key: key); await tester.pumpAndSettle(); } @@ -136,7 +136,7 @@ void main() async { await editor.updateSelection(selection); for (final LogicalKeyboardKey key in keys) { - await simulateKeyDownEvent(key); + await editor.pressKey(key: key); await tester.pumpAndSettle(); } @@ -175,7 +175,7 @@ void main() async { await editor.updateSelection(selection); for (final LogicalKeyboardKey key in keys) { - await simulateKeyDownEvent(key); + await editor.pressKey(key: key); await tester.pumpAndSettle(); } @@ -219,7 +219,7 @@ void main() async { await editor.updateSelection(selection); for (final LogicalKeyboardKey key in keys) { - await simulateKeyDownEvent(key); + await editor.pressKey(key: key); await tester.pumpAndSettle(); } diff --git a/test/new/service/shortcuts/command_shortcut_events/end_command_test.dart b/test/new/service/shortcuts/command_shortcut_events/end_command_test.dart index fc827d709..d5f2a9035 100644 --- a/test/new/service/shortcuts/command_shortcut_events/end_command_test.dart +++ b/test/new/service/shortcuts/command_shortcut_events/end_command_test.dart @@ -1,4 +1,5 @@ import 'dart:io' show Platform; + import 'package:appflowy_editor/appflowy_editor.dart'; import 'package:flutter/services.dart'; import 'package:flutter_test/flutter_test.dart'; @@ -25,7 +26,7 @@ void main() async { final selection = Selection.collapsed(Position(path: [0])); await editor.updateSelection(selection); - await simulateKeyDownEvent(LogicalKeyboardKey.end); + await editor.pressKey(key: LogicalKeyboardKey.end); if (Platform.isWindows || Platform.isLinux) { expect( @@ -50,7 +51,7 @@ void main() async { final selection = Selection.collapsed(Position(path: [5])); await editor.updateSelection(selection); - await simulateKeyDownEvent(LogicalKeyboardKey.end); + await editor.pressKey(key: LogicalKeyboardKey.end); if (Platform.isWindows || Platform.isLinux) { expect( diff --git a/test/new/service/shortcuts/command_shortcut_events/home_command_test.dart b/test/new/service/shortcuts/command_shortcut_events/home_command_test.dart index 0f09a63a9..40386182f 100644 --- a/test/new/service/shortcuts/command_shortcut_events/home_command_test.dart +++ b/test/new/service/shortcuts/command_shortcut_events/home_command_test.dart @@ -1,4 +1,5 @@ import 'dart:io' show Platform; + import 'package:appflowy_editor/appflowy_editor.dart'; import 'package:flutter/services.dart'; import 'package:flutter_test/flutter_test.dart'; @@ -27,7 +28,7 @@ void main() async { Selection.collapsed(Position(path: [0], offset: text.length)); await editor.updateSelection(selection); - await simulateKeyDownEvent(LogicalKeyboardKey.home); + await editor.pressKey(key: LogicalKeyboardKey.home); if (Platform.isWindows || Platform.isLinux) { expect( @@ -53,7 +54,7 @@ void main() async { Selection.collapsed(Position(path: [5], offset: text.length)); await editor.updateSelection(selection); - await simulateKeyDownEvent(LogicalKeyboardKey.home); + await editor.pressKey(key: LogicalKeyboardKey.home); if (Platform.isWindows || Platform.isLinux) { expect( diff --git a/test/new/service/shortcuts/command_shortcut_events/indent_command_test.dart b/test/new/service/shortcuts/command_shortcut_events/indent_command_test.dart index b99db6682..13d25dc64 100644 --- a/test/new/service/shortcuts/command_shortcut_events/indent_command_test.dart +++ b/test/new/service/shortcuts/command_shortcut_events/indent_command_test.dart @@ -1,9 +1,7 @@ +import 'package:appflowy_editor/appflowy_editor.dart'; import 'package:flutter/services.dart'; - import 'package:flutter_test/flutter_test.dart'; -import 'package:appflowy_editor/appflowy_editor.dart'; - import '../../../infra/testable_editor.dart'; const _padding = 24.0; @@ -51,7 +49,7 @@ void main() async { ('خط دوم', blockComponentTextDirectionRTL), ); - await simulateKeyDownEvent(LogicalKeyboardKey.tab); + await editor.pressKey(key: LogicalKeyboardKey.tab); await tester.pumpAndSettle(); final node = editor.nodeAtPath([0])!; @@ -71,7 +69,7 @@ void main() async { ('خط دوم', blockComponentTextDirectionRTL), ); - await simulateKeyDownEvent(LogicalKeyboardKey.tab); + await editor.pressKey(key: LogicalKeyboardKey.tab); await tester.pumpAndSettle(); final node = editor.nodeAtPath([0])!; @@ -91,7 +89,7 @@ void main() async { ('خط دوم', blockComponentTextDirectionAuto), ); - await simulateKeyDownEvent(LogicalKeyboardKey.tab); + await editor.pressKey(key: LogicalKeyboardKey.tab); await tester.pumpAndSettle(); final node = editor.nodeAtPath([0])!; @@ -116,7 +114,7 @@ void main() async { ('س', blockComponentTextDirectionAuto), ); - await simulateKeyDownEvent(LogicalKeyboardKey.tab); + await editor.pressKey(key: LogicalKeyboardKey.tab); await tester.pumpAndSettle(); Node node = editor.nodeAtPath([0])!; @@ -163,7 +161,7 @@ Future indentTestHelper( ); await editor.updateSelection(selection); - await simulateKeyDownEvent(LogicalKeyboardKey.tab); + await editor.pressKey(key: LogicalKeyboardKey.tab); await tester.pumpAndSettle(); final node = editor.nodeAtPath([0])!; diff --git a/test/new/service/shortcuts/command_shortcut_events/select_all_command_test.dart b/test/new/service/shortcuts/command_shortcut_events/select_all_command_test.dart index aa7a44ada..fa49ed03f 100644 --- a/test/new/service/shortcuts/command_shortcut_events/select_all_command_test.dart +++ b/test/new/service/shortcuts/command_shortcut_events/select_all_command_test.dart @@ -1,7 +1,8 @@ +import 'dart:io'; + import 'package:appflowy_editor/appflowy_editor.dart'; import 'package:flutter/services.dart'; import 'package:flutter_test/flutter_test.dart'; -import 'dart:io'; import '../../../infra/testable_editor.dart'; @@ -98,13 +99,13 @@ void main() async { // move the cursor to the beginning of node 1 for (var i = 1; i < text.length; i++) { - await simulateKeyDownEvent(LogicalKeyboardKey.arrowLeft); + await editor.pressKey(key: LogicalKeyboardKey.arrowLeft); await tester.pumpAndSettle(); } expect(editor.selection, Selection.collapsed(Position(path: [1]))); // move the cursor to the ending of node 0 - await simulateKeyDownEvent(LogicalKeyboardKey.arrowLeft); + await editor.pressKey(key: LogicalKeyboardKey.arrowLeft); expect( editor.selection, Selection.collapsed(Position(path: [0], offset: text.length)), @@ -112,7 +113,7 @@ void main() async { // move the cursor to the beginning of node 0 for (var i = 1; i < text.length; i++) { - await simulateKeyDownEvent(LogicalKeyboardKey.arrowLeft); + await editor.pressKey(key: LogicalKeyboardKey.arrowLeft); await tester.pumpAndSettle(); } expect(editor.selection, Selection.collapsed(Position(path: [0]))); diff --git a/test/new/service/shortcuts/command_shortcut_events/undo_redo_command_test.dart b/test/new/service/shortcuts/command_shortcut_events/undo_redo_command_test.dart index 171d86b8c..30fc06181 100644 --- a/test/new/service/shortcuts/command_shortcut_events/undo_redo_command_test.dart +++ b/test/new/service/shortcuts/command_shortcut_events/undo_redo_command_test.dart @@ -48,7 +48,7 @@ void main() async { ); await editor.updateSelection(selection); - await simulateKeyDownEvent(LogicalKeyboardKey.backspace); + await editor.pressKey(key: LogicalKeyboardKey.backspace); await tester.pumpAndSettle(); // the first node should be deleted. @@ -220,5 +220,5 @@ Future _selectNodeAtPathAndDelete(TestableEditor editor) async { ); await editor.updateSelection(selection); - await simulateKeyDownEvent(LogicalKeyboardKey.backspace); + await editor.pressKey(key: LogicalKeyboardKey.backspace); } diff --git a/test/new/util/arrow_util.dart b/test/new/util/arrow_util.dart index 7d6b32eca..1c26db916 100644 --- a/test/new/util/arrow_util.dart +++ b/test/new/util/arrow_util.dart @@ -1,6 +1,6 @@ +import 'package:appflowy_editor/appflowy_editor.dart'; import 'package:flutter/services.dart'; import 'package:flutter_test/flutter_test.dart'; -import 'package:appflowy_editor/appflowy_editor.dart'; import '../infra/testable_editor.dart'; import './typedef_util.dart'; @@ -47,7 +47,7 @@ Future runArrowTest( await editor.updateSelection(alt.initialSel); - await simulateKeyDownEvent(arrowKey); + await editor.pressKey(key: arrowKey); expect(editor.selection, alt.expSel, reason: reason); await editor.dispose(); diff --git a/test/new/util/keyboard_util.dart b/test/new/util/keyboard_util.dart new file mode 100644 index 000000000..91479fc80 --- /dev/null +++ b/test/new/util/keyboard_util.dart @@ -0,0 +1,21 @@ +// import 'package:flutter/services.dart'; +// import 'package:flutter_test/flutter_test.dart'; + +// Future simulateKeyEvent( +// LogicalKeyboardKey key, { +// String? platform, +// PhysicalKeyboardKey? physicalKey, +// String? character, +// }) async { +// await editor.pressKey( +// key, +// platform: platform, +// physicalKey: physicalKey, +// character: character, +// ); +// await simulateKeyUpEvent( +// key, +// platform: platform, +// physicalKey: physicalKey, +// ); +// } diff --git a/test/new/util/util.dart b/test/new/util/util.dart index b9a92365a..9c4dd92d2 100644 --- a/test/new/util/util.dart +++ b/test/new/util/util.dart @@ -1,5 +1,6 @@ +export 'arrow_util.dart'; export 'document_util.dart'; +export 'keyboard_util.dart'; +export 'log_util.dart'; export 'node_util.dart'; export 'typedef_util.dart'; -export 'log_util.dart'; -export 'arrow_util.dart';