From f49e2571facf01059d8e510793e72e4775ce4fe7 Mon Sep 17 00:00:00 2001 From: squidrye Date: Tue, 21 Mar 2023 19:40:48 +0530 Subject: [PATCH] test: added tests for key events in selection menu widget --- .../selection_menu_widget_test.dart | 81 +++++++++++++++++++ 1 file changed, 81 insertions(+) diff --git a/frontend/appflowy_flutter/packages/appflowy_editor/test/render/selection_menu/selection_menu_widget_test.dart b/frontend/appflowy_flutter/packages/appflowy_editor/test/render/selection_menu/selection_menu_widget_test.dart index 6b392cdebb..45bbea120a 100644 --- a/frontend/appflowy_flutter/packages/appflowy_editor/test/render/selection_menu/selection_menu_widget_test.dart +++ b/frontend/appflowy_flutter/packages/appflowy_editor/test/render/selection_menu/selection_menu_widget_test.dart @@ -118,6 +118,79 @@ void main() async { findsNothing, ); }); + + group('tab and arrow keys move selection in desired direction', () { + + testWidgets('left and right keys move selection in desired direction', + (tester) async { + final editor = await _prepare(tester); + + var initialSelection = getSelectedMenuItem(tester); + expect(defaultSelectionMenuItems.indexOf(initialSelection.item), 0); + + await editor.pressLogicKey(LogicalKeyboardKey.arrowRight); + + var newSelection = getSelectedMenuItem(tester); + expect(defaultSelectionMenuItems.indexOf(newSelection.item), 5); + + await editor.pressLogicKey(LogicalKeyboardKey.arrowLeft); + + var finalSelection = getSelectedMenuItem(tester); + expect(defaultSelectionMenuItems.indexOf(initialSelection.item), 0); + }); + + testWidgets('up and down keys move selection in desired direction', + (tester) async { + final editor = await _prepare(tester); + + var initialSelection = getSelectedMenuItem(tester); + expect(defaultSelectionMenuItems.indexOf(initialSelection.item), 0); + + await editor.pressLogicKey(LogicalKeyboardKey.arrowDown); + + var newSelection = getSelectedMenuItem(tester); + expect(defaultSelectionMenuItems.indexOf(newSelection.item), 1); + + await editor.pressLogicKey(LogicalKeyboardKey.arrowUp); + + var finalSelection = getSelectedMenuItem(tester); + expect(defaultSelectionMenuItems.indexOf(finalSelection.item), 0); + }); + + testWidgets('arrow keys and tab move same selection', + (tester) async { + final editor = await _prepare(tester); + + var initialSelection = getSelectedMenuItem(tester); + expect(defaultSelectionMenuItems.indexOf(initialSelection.item), 0); + + await editor.pressLogicKey(LogicalKeyboardKey.arrowDown); + + var newSelection = getSelectedMenuItem(tester); + expect(defaultSelectionMenuItems.indexOf(newSelection.item), 1); + + await editor.pressLogicKey(LogicalKeyboardKey.tab); + + var finalSelection = getSelectedMenuItem(tester); + expect(defaultSelectionMenuItems.indexOf(finalSelection.item), 6); + }); + + testWidgets('tab moves selection to next row Item on reaching end of current row', + (tester) async { + final editor = await _prepare(tester); + + final initialSelection = getSelectedMenuItem(tester); + + expect(defaultSelectionMenuItems.indexOf(initialSelection.item), 0); + + await editor.pressLogicKey(LogicalKeyboardKey.tab); + await editor.pressLogicKey(LogicalKeyboardKey.tab); + + final finalSelection = getSelectedMenuItem(tester); + + expect(defaultSelectionMenuItems.indexOf(finalSelection.item), 1); + }); + }); }); } @@ -178,3 +251,11 @@ Future _testDefaultSelectionMenuItems( expect(node?.attributes.check, false); } } + +SelectionMenuItemWidget getSelectedMenuItem(WidgetTester tester) { + return tester + .state(find.byWidgetPredicate( + (widget) => widget is SelectionMenuItemWidget && widget.isSelected, + )) + .widget as SelectionMenuItemWidget; +} \ No newline at end of file