empty_document_test.dart 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. import 'package:appflowy/plugins/document/presentation/plugins/base/built_in_page_widget.dart';
  2. import 'package:appflowy_editor/appflowy_editor.dart';
  3. import 'package:flutter/services.dart';
  4. import 'package:flutter_test/flutter_test.dart';
  5. import 'package:integration_test/integration_test.dart';
  6. import 'util/keyboard.dart';
  7. import 'util/util.dart';
  8. /// Integration tests for an empty document. The [TestWorkspaceService] will load a workspace from an empty document `assets/test/workspaces/empty_document.zip` for all tests.
  9. ///
  10. /// To create another integration test with a preconfigured workspace. Use the following steps:
  11. /// 1. Create a new workspace from the AppFlowy launch screen.
  12. /// 2. Modify the workspace until it is suitable as the starting point for the integration test you need to land.
  13. /// 3. Use a zip utility program to zip the workspace folder that you created.
  14. /// 4. Add the zip file under `assets/test/workspaces/`
  15. /// 5. Add a new enumeration to [TestWorkspace] in `integration_test/utils/data.dart`. For example, if you added a workspace called `empty_calendar.zip`, then [TestWorkspace] should have the following value:
  16. /// ```dart
  17. /// enum TestWorkspace {
  18. /// board('board'),
  19. /// empty_calendar('empty_calendar');
  20. ///
  21. /// /* code */
  22. /// }
  23. /// ```
  24. /// 6. Double check that the .zip file that you added is included as an asset in the pubspec.yaml file under appflowy_flutter.
  25. void main() {
  26. IntegrationTestWidgetsFlutterBinding.ensureInitialized();
  27. const service = TestWorkspaceService(TestWorkspace.emptyDocument);
  28. group('Tests on a workspace with only an empty document', () {
  29. setUpAll(() async => await service.setUpAll());
  30. setUp(() async => await service.setUp());
  31. testWidgets('/board shortcut creates a new board and view of the board', (tester) async {
  32. await tester.initializeAppFlowy();
  33. // Needs tab to obtain focus for the app flowy editor.
  34. // by default the tap appears at the center of the widget.
  35. final Finder editor = find.byType(AppFlowyEditor);
  36. await tester.tap(editor);
  37. await tester.pumpAndSettle();
  38. // tester.sendText() cannot be used since the editor
  39. // does not contain any EditableText widgets.
  40. // to interact with the app during an integration test,
  41. // simulate physical keyboard events.
  42. await FlowyTestKeyboard.simulateKeyDownEvent([
  43. LogicalKeyboardKey.slash,
  44. LogicalKeyboardKey.keyB,
  45. LogicalKeyboardKey.keyO,
  46. LogicalKeyboardKey.keyA,
  47. LogicalKeyboardKey.keyR,
  48. LogicalKeyboardKey.keyD,
  49. LogicalKeyboardKey.arrowDown,
  50. ], tester: tester);
  51. // Checks whether the options in the selection menu
  52. // for /board exist.
  53. expect(find.byType(SelectionMenuItemWidget), findsAtLeastNWidgets(2));
  54. // Finalizes the slash command that creates the board.
  55. await FlowyTestKeyboard.simulateKeyDownEvent([
  56. LogicalKeyboardKey.enter,
  57. ], tester: tester);
  58. // Checks whether new board is referenced and properly on the page.
  59. expect(find.byType(BuiltInPageWidget), findsOneWidget);
  60. // Checks whether the new database was created
  61. const newBoardLabel = "Untitled";
  62. expect(find.text(newBoardLabel), findsOneWidget);
  63. // Checks whether a view of the database was created
  64. const viewOfBoardLabel = "View of Untitled";
  65. expect(find.text(viewOfBoardLabel), findsNWidgets(2));
  66. });
  67. testWidgets('/grid shortcut creates a new grid and view of the grid', (tester) async {
  68. await tester.initializeAppFlowy();
  69. // Needs tab to obtain focus for the app flowy editor.
  70. // by default the tap appears at the center of the widget.
  71. final Finder editor = find.byType(AppFlowyEditor);
  72. await tester.tap(editor);
  73. await tester.pumpAndSettle();
  74. // tester.sendText() cannot be used since the editor
  75. // does not contain any EditableText widgets.
  76. // to interact with the app during an integration test,
  77. // simulate physical keyboard events.
  78. await FlowyTestKeyboard.simulateKeyDownEvent([
  79. LogicalKeyboardKey.slash,
  80. LogicalKeyboardKey.keyG,
  81. LogicalKeyboardKey.keyR,
  82. LogicalKeyboardKey.keyI,
  83. LogicalKeyboardKey.keyD,
  84. LogicalKeyboardKey.arrowDown,
  85. ], tester: tester);
  86. // Checks whether the options in the selection menu
  87. // for /grid exist.
  88. expect(find.byType(SelectionMenuItemWidget), findsAtLeastNWidgets(2));
  89. // Finalizes the slash command that creates the board.
  90. await simulateKeyDownEvent(LogicalKeyboardKey.enter);
  91. await tester.pumpAndSettle();
  92. // Checks whether new board is referenced and properly on the page.
  93. expect(find.byType(BuiltInPageWidget), findsOneWidget);
  94. // Checks whether the new database was created
  95. const newTableLabel = "Untitled";
  96. expect(find.text(newTableLabel), findsOneWidget);
  97. // Checks whether a view of the database was created
  98. const viewOfTableLabel = "View of Untitled";
  99. expect(find.text(viewOfTableLabel), findsNWidgets(2));
  100. });
  101. });
  102. }