document_with_database_test.dart 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201
  1. import 'package:appflowy/generated/locale_keys.g.dart';
  2. import 'package:appflowy/plugins/database_view/board/presentation/board_page.dart';
  3. import 'package:appflowy/plugins/database_view/calendar/presentation/calendar_page.dart';
  4. import 'package:appflowy/plugins/database_view/grid/presentation/grid_page.dart';
  5. import 'package:appflowy/plugins/database_view/widgets/row/cells/text_cell/text_cell.dart';
  6. import 'package:appflowy/plugins/document/presentation/editor_plugins/base/link_to_page_widget.dart';
  7. import 'package:appflowy/workspace/presentation/home/menu/view/view_item.dart';
  8. import 'package:appflowy_backend/protobuf/flowy-folder2/protobuf.dart';
  9. import 'package:appflowy_editor/appflowy_editor.dart';
  10. import 'package:easy_localization/easy_localization.dart';
  11. import 'package:flowy_infra/uuid.dart';
  12. import 'package:flutter_test/flutter_test.dart';
  13. import 'package:integration_test/integration_test.dart';
  14. import '../util/util.dart';
  15. void main() {
  16. IntegrationTestWidgetsFlutterBinding.ensureInitialized();
  17. group('database view in document', () {
  18. testWidgets('insert a referenced grid', (tester) async {
  19. await tester.initializeAppFlowy();
  20. await tester.tapGoButton();
  21. await insertReferenceDatabase(tester, ViewLayoutPB.Grid);
  22. // validate the referenced grid is inserted
  23. expect(
  24. find.descendant(
  25. of: find.byType(AppFlowyEditor),
  26. matching: find.byType(GridPage),
  27. ),
  28. findsOneWidget,
  29. );
  30. // https://github.com/AppFlowy-IO/AppFlowy/issues/3533
  31. // test: the selection of editor should be clear when editing the grid
  32. await tester.editor.updateSelection(
  33. Selection.collapsed(
  34. Position(path: [1]),
  35. ),
  36. );
  37. final gridTextCell = find.byType(GridTextCell).first;
  38. await tester.tapButton(gridTextCell);
  39. expect(tester.editor.getCurrentEditorState().selection, isNull);
  40. });
  41. testWidgets('insert a referenced board', (tester) async {
  42. await tester.initializeAppFlowy();
  43. await tester.tapGoButton();
  44. await insertReferenceDatabase(tester, ViewLayoutPB.Board);
  45. // validate the referenced board is inserted
  46. expect(
  47. find.descendant(
  48. of: find.byType(AppFlowyEditor),
  49. matching: find.byType(BoardPage),
  50. ),
  51. findsOneWidget,
  52. );
  53. });
  54. testWidgets('insert a referenced calendar', (tester) async {
  55. await tester.initializeAppFlowy();
  56. await tester.tapGoButton();
  57. await insertReferenceDatabase(tester, ViewLayoutPB.Calendar);
  58. // validate the referenced grid is inserted
  59. expect(
  60. find.descendant(
  61. of: find.byType(AppFlowyEditor),
  62. matching: find.byType(CalendarPage),
  63. ),
  64. findsOneWidget,
  65. );
  66. });
  67. testWidgets('create a grid inside a document', (tester) async {
  68. await tester.initializeAppFlowy();
  69. await tester.tapGoButton();
  70. await createInlineDatabase(tester, ViewLayoutPB.Grid);
  71. // validate the referenced grid is inserted
  72. expect(
  73. find.descendant(
  74. of: find.byType(AppFlowyEditor),
  75. matching: find.byType(GridPage),
  76. ),
  77. findsOneWidget,
  78. );
  79. });
  80. testWidgets('create a board inside a document', (tester) async {
  81. await tester.initializeAppFlowy();
  82. await tester.tapGoButton();
  83. await createInlineDatabase(tester, ViewLayoutPB.Board);
  84. // validate the referenced grid is inserted
  85. expect(
  86. find.descendant(
  87. of: find.byType(AppFlowyEditor),
  88. matching: find.byType(BoardPage),
  89. ),
  90. findsOneWidget,
  91. );
  92. });
  93. testWidgets('create a calendar inside a document', (tester) async {
  94. await tester.initializeAppFlowy();
  95. await tester.tapGoButton();
  96. await createInlineDatabase(tester, ViewLayoutPB.Calendar);
  97. // validate the referenced grid is inserted
  98. expect(
  99. find.descendant(
  100. of: find.byType(AppFlowyEditor),
  101. matching: find.byType(CalendarPage),
  102. ),
  103. findsOneWidget,
  104. );
  105. });
  106. });
  107. }
  108. /// Insert a referenced database of [layout] into the document
  109. Future<void> insertReferenceDatabase(
  110. WidgetTester tester,
  111. ViewLayoutPB layout,
  112. ) async {
  113. // create a new grid
  114. final id = uuid();
  115. final name = '${layout.name}_$id';
  116. await tester.createNewPageWithName(
  117. name: name,
  118. layout: layout,
  119. openAfterCreated: false,
  120. );
  121. // create a new document
  122. await tester.createNewPageWithName(
  123. name: 'insert_a_reference_${layout.name}',
  124. layout: ViewLayoutPB.Document,
  125. openAfterCreated: true,
  126. );
  127. // tap the first line of the document
  128. await tester.editor.tapLineOfEditorAt(0);
  129. // insert a referenced view
  130. await tester.editor.showSlashMenu();
  131. await tester.editor.tapSlashMenuItemWithName(
  132. layout.referencedMenuName,
  133. );
  134. final linkToPageMenu = find.byType(LinkToPageMenu);
  135. expect(linkToPageMenu, findsOneWidget);
  136. final referencedDatabase = find.descendant(
  137. of: linkToPageMenu,
  138. matching: find.findTextInFlowyText(name),
  139. );
  140. expect(referencedDatabase, findsOneWidget);
  141. await tester.tapButton(referencedDatabase);
  142. }
  143. Future<void> createInlineDatabase(
  144. WidgetTester tester,
  145. ViewLayoutPB layout,
  146. ) async {
  147. // create a new document
  148. final documentName = 'insert_a_inline_${layout.name}';
  149. await tester.createNewPageWithName(
  150. name: documentName,
  151. layout: ViewLayoutPB.Document,
  152. openAfterCreated: true,
  153. );
  154. // tap the first line of the document
  155. await tester.editor.tapLineOfEditorAt(0);
  156. // insert a referenced view
  157. await tester.editor.showSlashMenu();
  158. final name = switch (layout) {
  159. ViewLayoutPB.Grid => LocaleKeys.document_slashMenu_grid_createANewGrid.tr(),
  160. ViewLayoutPB.Board =>
  161. LocaleKeys.document_slashMenu_board_createANewBoard.tr(),
  162. ViewLayoutPB.Calendar =>
  163. LocaleKeys.document_slashMenu_calendar_createANewCalendar.tr(),
  164. _ => '',
  165. };
  166. await tester.editor.tapSlashMenuItemWithName(
  167. name,
  168. );
  169. await tester.pumpAndSettle();
  170. final childViews = tester
  171. .widget<SingleInnerViewItem>(tester.findPageName(documentName))
  172. .view
  173. .childViews;
  174. expect(childViews.length, 1);
  175. }