empty_document_test.dart 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  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. tearDown(() async => await service.tearDown());
  32. tearDownAll(() async => await service.tearDownAll());
  33. testWidgets('/board shortcut creates a new board and view of the board',
  34. (tester) async {
  35. await tester.initializeAppFlowy();
  36. // Needs tab to obtain focus for the app flowy editor.
  37. // by default the tap appears at the center of the widget.
  38. final Finder editor = find.byType(AppFlowyEditor);
  39. await tester.tap(editor);
  40. await tester.pumpAndSettle();
  41. // tester.sendText() cannot be used since the editor
  42. // does not contain any EditableText widgets.
  43. // to interact with the app during an integration test,
  44. // simulate physical keyboard events.
  45. await FlowyTestKeyboard.simulateKeyDownEvent(
  46. [
  47. LogicalKeyboardKey.slash,
  48. LogicalKeyboardKey.keyB,
  49. LogicalKeyboardKey.keyO,
  50. LogicalKeyboardKey.keyA,
  51. LogicalKeyboardKey.keyR,
  52. LogicalKeyboardKey.keyD,
  53. LogicalKeyboardKey.arrowDown,
  54. ],
  55. tester: tester,
  56. );
  57. // Checks whether the options in the selection menu
  58. // for /board exist.
  59. expect(find.byType(SelectionMenuItemWidget), findsAtLeastNWidgets(2));
  60. // Finalizes the slash command that creates the board.
  61. await FlowyTestKeyboard.simulateKeyDownEvent(
  62. [
  63. LogicalKeyboardKey.enter,
  64. ],
  65. tester: tester,
  66. );
  67. await tester.pumpAndSettle();
  68. // Checks whether new board is referenced and properly on the page.
  69. expect(find.byType(BuiltInPageWidget), findsOneWidget);
  70. // Checks whether the new database was created
  71. const newBoardLabel = "Untitled";
  72. expect(find.text(newBoardLabel), findsOneWidget);
  73. // Checks whether a view of the database was created
  74. const viewOfBoardLabel = "View of Untitled";
  75. expect(find.text(viewOfBoardLabel), findsNWidgets(2));
  76. });
  77. testWidgets('/grid shortcut creates a new grid and view of the grid',
  78. (tester) async {
  79. await tester.initializeAppFlowy();
  80. // Needs tab to obtain focus for the app flowy editor.
  81. // by default the tap appears at the center of the widget.
  82. final Finder editor = find.byType(AppFlowyEditor);
  83. await tester.tap(editor);
  84. await tester.pumpAndSettle();
  85. // tester.sendText() cannot be used since the editor
  86. // does not contain any EditableText widgets.
  87. // to interact with the app during an integration test,
  88. // simulate physical keyboard events.
  89. await FlowyTestKeyboard.simulateKeyDownEvent(
  90. [
  91. LogicalKeyboardKey.slash,
  92. LogicalKeyboardKey.keyG,
  93. LogicalKeyboardKey.keyR,
  94. LogicalKeyboardKey.keyI,
  95. LogicalKeyboardKey.keyD,
  96. LogicalKeyboardKey.arrowDown,
  97. ],
  98. tester: tester,
  99. );
  100. // Checks whether the options in the selection menu
  101. // for /grid exist.
  102. expect(find.byType(SelectionMenuItemWidget), findsAtLeastNWidgets(2));
  103. // Finalizes the slash command that creates the board.
  104. await FlowyTestKeyboard.simulateKeyDownEvent(
  105. [
  106. LogicalKeyboardKey.enter,
  107. ],
  108. tester: tester,
  109. );
  110. await tester.pumpAndSettle();
  111. // Checks whether new board is referenced and properly on the page.
  112. expect(find.byType(BuiltInPageWidget), findsOneWidget);
  113. // Checks whether the new database was created
  114. const newTableLabel = "Untitled";
  115. expect(find.text(newTableLabel), findsOneWidget);
  116. // Checks whether a view of the database was created
  117. const viewOfTableLabel = "View of Untitled";
  118. expect(find.text(viewOfTableLabel), findsNWidgets(2));
  119. });
  120. });
  121. }