document_with_database_test.dart 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. import 'package:appflowy/plugins/database_view/board/presentation/board_page.dart';
  2. import 'package:appflowy/plugins/database_view/calendar/presentation/calendar_page.dart';
  3. import 'package:appflowy/plugins/database_view/grid/presentation/grid_page.dart';
  4. import 'package:appflowy/plugins/document/presentation/editor_plugins/base/link_to_page_widget.dart';
  5. import 'package:appflowy_backend/protobuf/flowy-folder2/protobuf.dart';
  6. import 'package:appflowy_editor/appflowy_editor.dart';
  7. import 'package:flowy_infra/uuid.dart';
  8. import 'package:flutter_test/flutter_test.dart';
  9. import 'package:integration_test/integration_test.dart';
  10. import '../util/util.dart';
  11. void main() {
  12. IntegrationTestWidgetsFlutterBinding.ensureInitialized();
  13. group('database view in document', () {
  14. const location = 'database_view';
  15. setUp(() async {
  16. await TestFolder.cleanTestLocation(location);
  17. await TestFolder.setTestLocation(location);
  18. });
  19. tearDown(() async {
  20. await TestFolder.cleanTestLocation(null);
  21. });
  22. testWidgets('insert a referenced grid', (tester) async {
  23. await tester.initializeAppFlowy();
  24. await tester.tapGoButton();
  25. await insertReferenceDatabase(tester, ViewLayoutPB.Grid);
  26. // validate the referenced grid is inserted
  27. expect(
  28. find.descendant(
  29. of: find.byType(AppFlowyEditor),
  30. matching: find.byType(GridPage),
  31. ),
  32. findsOneWidget,
  33. );
  34. });
  35. testWidgets('insert a referenced board', (tester) async {
  36. await tester.initializeAppFlowy();
  37. await tester.tapGoButton();
  38. await insertReferenceDatabase(tester, ViewLayoutPB.Board);
  39. // validate the referenced board is inserted
  40. expect(
  41. find.descendant(
  42. of: find.byType(AppFlowyEditor),
  43. matching: find.byType(BoardPage),
  44. ),
  45. findsOneWidget,
  46. );
  47. });
  48. testWidgets('insert a referenced calendar', (tester) async {
  49. await tester.initializeAppFlowy();
  50. await tester.tapGoButton();
  51. await insertReferenceDatabase(tester, ViewLayoutPB.Calendar);
  52. // validate the referenced grid is inserted
  53. expect(
  54. find.descendant(
  55. of: find.byType(AppFlowyEditor),
  56. matching: find.byType(CalendarPage),
  57. ),
  58. findsOneWidget,
  59. );
  60. });
  61. });
  62. }
  63. /// Insert a referenced database of [layout] into the document
  64. Future<void> insertReferenceDatabase(
  65. WidgetTester tester,
  66. ViewLayoutPB layout,
  67. ) async {
  68. // create a new grid
  69. final id = uuid();
  70. final name = '${layout.name}_$id';
  71. await tester.createNewPageWithName(
  72. layout,
  73. name,
  74. );
  75. // create a new document
  76. await tester.createNewPageWithName(
  77. ViewLayoutPB.Document,
  78. 'insert_a_reference_${layout.name}',
  79. );
  80. // tap the first line of the document
  81. await tester.editor.tapLineOfEditorAt(0);
  82. // insert a referenced view
  83. await tester.editor.showSlashMenu();
  84. await tester.editor.tapSlashMenuItemWithName(
  85. layout.referencedMenuName,
  86. );
  87. final linkToPageMenu = find.byType(LinkToPageMenu);
  88. expect(linkToPageMenu, findsOneWidget);
  89. final referencedDatabase = find.descendant(
  90. of: linkToPageMenu,
  91. matching: find.findTextInFlowyText(name),
  92. );
  93. expect(referencedDatabase, findsOneWidget);
  94. await tester.tapButton(referencedDatabase);
  95. }