database_row_page_test.dart 9.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299
  1. import 'package:appflowy/plugins/database_view/widgets/row/row_banner.dart';
  2. import 'package:appflowy_backend/protobuf/flowy-database2/field_entities.pbenum.dart';
  3. import 'package:appflowy_backend/protobuf/flowy-folder2/view.pb.dart';
  4. import 'package:appflowy_editor/appflowy_editor.dart';
  5. import 'package:flowy_infra_ui/style_widget/text.dart';
  6. import 'package:flutter/material.dart';
  7. import 'package:flutter_test/flutter_test.dart';
  8. import 'package:integration_test/integration_test.dart';
  9. import 'util/database_test_op.dart';
  10. import 'util/emoji.dart';
  11. import 'util/util.dart';
  12. void main() {
  13. IntegrationTestWidgetsFlutterBinding.ensureInitialized();
  14. group('grid', () {
  15. testWidgets('row details page opens', (tester) async {
  16. await tester.initializeAppFlowy();
  17. await tester.tapGoButton();
  18. // Create a new grid
  19. await tester.createNewPageWithName(layout: ViewLayoutPB.Grid);
  20. // Hover first row and then open the row page
  21. await tester.openFirstRowDetailPage();
  22. // Make sure that the row page is opened
  23. tester.assertRowDetailPageOpened();
  24. });
  25. testWidgets('insert emoji in the row detail page', (tester) async {
  26. await tester.initializeAppFlowy();
  27. await tester.tapGoButton();
  28. // Create a new grid
  29. await tester.createNewPageWithName(layout: ViewLayoutPB.Grid);
  30. // Hover first row and then open the row page
  31. await tester.openFirstRowDetailPage();
  32. await tester.hoverRowBanner();
  33. await tester.openEmojiPicker();
  34. await tester.switchToEmojiList();
  35. await tester.tapEmoji('😀');
  36. // After select the emoji, the EmojiButton will show up
  37. await tester.tapButton(find.byType(EmojiButton));
  38. });
  39. testWidgets('update emoji in the row detail page', (tester) async {
  40. await tester.initializeAppFlowy();
  41. await tester.tapGoButton();
  42. // Create a new grid
  43. await tester.createNewPageWithName(layout: ViewLayoutPB.Grid);
  44. // Hover first row and then open the row page
  45. await tester.openFirstRowDetailPage();
  46. await tester.hoverRowBanner();
  47. await tester.openEmojiPicker();
  48. await tester.switchToEmojiList();
  49. await tester.tapEmoji('😀');
  50. // Update existing selected emoji
  51. await tester.tapButton(find.byType(EmojiButton));
  52. await tester.switchToEmojiList();
  53. await tester.tapEmoji('😅');
  54. // The emoji already displayed in the row banner
  55. final emojiText = find.byWidgetPredicate(
  56. (widget) => widget is FlowyText && widget.text == '😅',
  57. );
  58. // The number of emoji should be two. One in the row displayed in the grid
  59. // one in the row detail page.
  60. expect(emojiText, findsNWidgets(2));
  61. });
  62. testWidgets('remove emoji in the row detail page', (tester) async {
  63. await tester.initializeAppFlowy();
  64. await tester.tapGoButton();
  65. // Create a new grid
  66. await tester.createNewPageWithName(layout: ViewLayoutPB.Grid);
  67. // Hover first row and then open the row page
  68. await tester.openFirstRowDetailPage();
  69. await tester.hoverRowBanner();
  70. await tester.openEmojiPicker();
  71. await tester.switchToEmojiList();
  72. await tester.tapEmoji('😀');
  73. // Remove the emoji
  74. await tester.tapButton(find.byType(RemoveEmojiButton));
  75. final emojiText = find.byWidgetPredicate(
  76. (widget) => widget is FlowyText && widget.text == '😀',
  77. );
  78. expect(emojiText, findsNothing);
  79. });
  80. testWidgets('create list of fields in row detail page', (tester) async {
  81. await tester.initializeAppFlowy();
  82. await tester.tapGoButton();
  83. // Create a new grid
  84. await tester.createNewPageWithName(layout: ViewLayoutPB.Grid);
  85. // Hover first row and then open the row page
  86. await tester.openFirstRowDetailPage();
  87. for (final fieldType in [
  88. FieldType.Checklist,
  89. FieldType.DateTime,
  90. FieldType.Number,
  91. FieldType.URL,
  92. FieldType.MultiSelect,
  93. FieldType.LastEditedTime,
  94. FieldType.CreatedTime,
  95. FieldType.Checkbox,
  96. ]) {
  97. await tester.tapRowDetailPageCreatePropertyButton();
  98. await tester.renameField(fieldType.name);
  99. // Open the type option menu
  100. await tester.tapTypeOptionButton();
  101. await tester.selectFieldType(fieldType);
  102. await tester.dismissFieldEditor();
  103. // After update the field type, the cells should be updated
  104. await tester.findCellByFieldType(fieldType);
  105. await tester.scrollRowDetailByOffset(const Offset(0, -50));
  106. }
  107. });
  108. testWidgets('change order of fields and cells', (tester) async {
  109. await tester.initializeAppFlowy();
  110. await tester.tapGoButton();
  111. // Create a new grid
  112. await tester.createNewPageWithName(layout: ViewLayoutPB.Grid);
  113. // Hover first row and then open the row page
  114. await tester.openFirstRowDetailPage();
  115. // Assert that the first field in the row details page is the select
  116. // option tyoe
  117. tester.assertFirstFieldInRowDetailByType(FieldType.SingleSelect);
  118. // Reorder first field in list
  119. final gesture = await tester.hoverOnFieldInRowDetail(index: 0);
  120. await tester.pumpAndSettle();
  121. await tester.reorderFieldInRowDetail(offset: 30);
  122. // Orders changed, now the checkbox is first
  123. tester.assertFirstFieldInRowDetailByType(FieldType.Checkbox);
  124. await gesture.removePointer();
  125. await tester.pumpAndSettle();
  126. // Reorder second field in list
  127. await tester.hoverOnFieldInRowDetail(index: 1);
  128. await tester.pumpAndSettle();
  129. await tester.reorderFieldInRowDetail(offset: -30);
  130. // First field is now back to select option
  131. tester.assertFirstFieldInRowDetailByType(FieldType.SingleSelect);
  132. });
  133. testWidgets('check document exists in row detail page', (tester) async {
  134. await tester.initializeAppFlowy();
  135. await tester.tapGoButton();
  136. // Create a new grid
  137. await tester.createNewPageWithName(layout: ViewLayoutPB.Grid);
  138. // Hover first row and then open the row page
  139. await tester.openFirstRowDetailPage();
  140. // Each row detail page should have a document
  141. await tester.assertDocumentExistInRowDetailPage();
  142. });
  143. testWidgets('update the contents of the document and re-open it',
  144. (tester) async {
  145. await tester.initializeAppFlowy();
  146. await tester.tapGoButton();
  147. // Create a new grid
  148. await tester.createNewPageWithName(layout: ViewLayoutPB.Grid);
  149. // Hover first row and then open the row page
  150. await tester.openFirstRowDetailPage();
  151. // Wait for the document to be loaded
  152. await tester.wait(500);
  153. // Focus on the editor
  154. final textBlock = find.byType(TextBlockComponentWidget);
  155. await tester.tapAt(tester.getCenter(textBlock));
  156. await tester.pumpAndSettle();
  157. // Input some text
  158. const inputText = 'Hello World';
  159. await tester.ime.insertText(inputText);
  160. expect(
  161. find.textContaining(inputText, findRichText: true),
  162. findsOneWidget,
  163. );
  164. // Tap outside to dismiss the field
  165. await tester.tapAt(Offset.zero);
  166. await tester.pumpAndSettle();
  167. // Re-open the document
  168. await tester.openFirstRowDetailPage();
  169. expect(
  170. find.textContaining(inputText, findRichText: true),
  171. findsOneWidget,
  172. );
  173. });
  174. testWidgets(
  175. 'check if the title wraps properly when a long text is inserted',
  176. (tester) async {
  177. await tester.initializeAppFlowy();
  178. await tester.tapGoButton();
  179. // Create a new grid
  180. await tester.createNewPageWithName(layout: ViewLayoutPB.Grid);
  181. // Hover first row and then open the row page
  182. await tester.openFirstRowDetailPage();
  183. // Wait for the document to be loaded
  184. await tester.wait(500);
  185. // Focus on the editor
  186. final textField = find
  187. .descendant(
  188. of: find.byType(SimpleDialog),
  189. matching: find.byType(TextField),
  190. )
  191. .first;
  192. // Input a long text
  193. await tester.enterText(textField, 'Long text' * 25);
  194. await tester.pumpAndSettle();
  195. // Tap outside to dismiss the field
  196. await tester.tapAt(Offset.zero);
  197. await tester.pumpAndSettle();
  198. // Check if there is any overflow in the widget tree
  199. expect(tester.takeException(), isNull);
  200. // Re-open the document
  201. await tester.openFirstRowDetailPage();
  202. // Check again if there is any overflow in the widget tree
  203. expect(tester.takeException(), isNull);
  204. });
  205. testWidgets('delete row in row detail page', (tester) async {
  206. await tester.initializeAppFlowy();
  207. await tester.tapGoButton();
  208. // Create a new grid
  209. await tester.createNewPageWithName(layout: ViewLayoutPB.Grid);
  210. // Hover first row and then open the row page
  211. await tester.openFirstRowDetailPage();
  212. await tester.tapRowDetailPageRowActionButton();
  213. await tester.tapRowDetailPageDeleteRowButton();
  214. await tester.tapEscButton();
  215. await tester.assertNumberOfRowsInGridPage(2);
  216. });
  217. testWidgets('duplicate row in row detail page', (tester) async {
  218. await tester.initializeAppFlowy();
  219. await tester.tapGoButton();
  220. // Create a new grid
  221. await tester.createNewPageWithName(layout: ViewLayoutPB.Grid);
  222. // Hover first row and then open the row page
  223. await tester.openFirstRowDetailPage();
  224. await tester.tapRowDetailPageRowActionButton();
  225. await tester.tapRowDetailPageDuplicateRowButton();
  226. await tester.tapEscButton();
  227. await tester.assertNumberOfRowsInGridPage(4);
  228. });
  229. });
  230. }