document_with_database_test.dart 3.2 KB

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