empty_document_test.dart 5.1 KB

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