Bring projects, wikis, and teams together with AI. AppFlowy is the AI collaborative workspace where you achieve more without losing control of your data. The leading open source Notion alternative.
Dart blogconfluence-alternativecontent-managementcontent-servicesdocumentationflutternote-takingnotion-alternativeproject-managementtask-managementteam-collaborationwiki
test: added tests for key events in selection menu widget
squidryef49e2571facf
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.dartindex 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<void> _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