document_with_database_test.dart 5.6 KB

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