database_field_test.dart 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209
  1. import 'package:appflowy/plugins/database_view/grid/presentation/grid_page.dart';
  2. import 'package:appflowy/plugins/database_view/grid/presentation/widgets/header/type_option/select_option.dart';
  3. import 'package:appflowy_backend/protobuf/flowy-database2/field_entities.pbenum.dart';
  4. import 'package:appflowy_backend/protobuf/flowy-folder2/protobuf.dart';
  5. import 'package:flutter/material.dart';
  6. import 'package:flutter_test/flutter_test.dart';
  7. import 'package:integration_test/integration_test.dart';
  8. import 'util/database_test_op.dart';
  9. import 'util/util.dart';
  10. void main() {
  11. IntegrationTestWidgetsFlutterBinding.ensureInitialized();
  12. group('grid page', () {
  13. testWidgets('rename existing field', (tester) async {
  14. await tester.initializeAppFlowy();
  15. await tester.tapGoButton();
  16. await tester.createNewPageWithName(layout: ViewLayoutPB.Grid);
  17. // Invoke the field editor
  18. await tester.tapGridFieldWithName('Name');
  19. await tester.tapEditPropertyButton();
  20. await tester.renameField('hello world');
  21. await tester.dismissFieldEditor();
  22. await tester.tapGridFieldWithName('hello world');
  23. await tester.pumpAndSettle();
  24. });
  25. testWidgets('update field type of existing field', (tester) async {
  26. await tester.initializeAppFlowy();
  27. await tester.tapGoButton();
  28. await tester.createNewPageWithName(layout: ViewLayoutPB.Grid);
  29. // Invoke the field editor
  30. await tester.tapGridFieldWithName('Type');
  31. await tester.tapEditPropertyButton();
  32. await tester.tapTypeOptionButton();
  33. await tester.selectFieldType(FieldType.Checkbox);
  34. await tester.dismissFieldEditor();
  35. await tester.assertFieldTypeWithFieldName(
  36. 'Type',
  37. FieldType.Checkbox,
  38. );
  39. await tester.pumpAndSettle();
  40. });
  41. testWidgets('create a field and rename it', (tester) async {
  42. await tester.initializeAppFlowy();
  43. await tester.tapGoButton();
  44. // create a new grid
  45. await tester.createNewPageWithName(layout: ViewLayoutPB.Grid);
  46. // create a field
  47. await tester.createField(FieldType.Checklist, 'checklist');
  48. // check the field is created successfully
  49. await tester.findFieldWithName('checklist');
  50. await tester.pumpAndSettle();
  51. });
  52. testWidgets('delete field', (tester) async {
  53. await tester.initializeAppFlowy();
  54. await tester.tapGoButton();
  55. await tester.createNewPageWithName(layout: ViewLayoutPB.Grid);
  56. // create a field
  57. await tester.createField(FieldType.Checkbox, 'New field 1');
  58. // Delete the field
  59. await tester.tapGridFieldWithName('New field 1');
  60. await tester.tapDeletePropertyButton();
  61. // confirm delete
  62. await tester.tapDialogOkButton();
  63. await tester.noFieldWithName('New field 1');
  64. await tester.pumpAndSettle();
  65. });
  66. testWidgets('duplicate field', (tester) async {
  67. await tester.initializeAppFlowy();
  68. await tester.tapGoButton();
  69. await tester.createNewPageWithName(layout: ViewLayoutPB.Grid);
  70. // create a field
  71. await tester.scrollToRight(find.byType(GridPage));
  72. await tester.tapNewPropertyButton();
  73. await tester.renameField('New field 1');
  74. await tester.dismissFieldEditor();
  75. // Delete the field
  76. await tester.tapGridFieldWithName('New field 1');
  77. await tester.tapDuplicatePropertyButton();
  78. await tester.findFieldWithName('New field 1 (copy)');
  79. await tester.pumpAndSettle();
  80. });
  81. testWidgets('hide field', (tester) async {
  82. await tester.initializeAppFlowy();
  83. await tester.tapGoButton();
  84. await tester.createNewPageWithName(layout: ViewLayoutPB.Grid);
  85. // create a field
  86. await tester.scrollToRight(find.byType(GridPage));
  87. await tester.tapNewPropertyButton();
  88. await tester.renameField('New field 1');
  89. await tester.dismissFieldEditor();
  90. // Delete the field
  91. await tester.tapGridFieldWithName('New field 1');
  92. await tester.tapHidePropertyButton();
  93. await tester.noFieldWithName('New field 1');
  94. await tester.pumpAndSettle();
  95. });
  96. testWidgets('create checklist field ', (tester) async {
  97. await tester.initializeAppFlowy();
  98. await tester.tapGoButton();
  99. await tester.createNewPageWithName(layout: ViewLayoutPB.Grid);
  100. await tester.scrollToRight(find.byType(GridPage));
  101. await tester.tapNewPropertyButton();
  102. // Open the type option menu
  103. await tester.tapTypeOptionButton();
  104. await tester.selectFieldType(FieldType.Checklist);
  105. // After update the field type, the cells should be updated
  106. await tester.findCellByFieldType(FieldType.Checklist);
  107. await tester.pumpAndSettle();
  108. });
  109. testWidgets('create list of fields', (tester) async {
  110. await tester.initializeAppFlowy();
  111. await tester.tapGoButton();
  112. await tester.createNewPageWithName(layout: ViewLayoutPB.Grid);
  113. for (final fieldType in [
  114. FieldType.Checklist,
  115. FieldType.DateTime,
  116. FieldType.Number,
  117. FieldType.URL,
  118. FieldType.MultiSelect,
  119. FieldType.LastEditedTime,
  120. FieldType.CreatedTime,
  121. FieldType.Checkbox,
  122. ]) {
  123. await tester.scrollToRight(find.byType(GridPage));
  124. await tester.tapNewPropertyButton();
  125. await tester.renameField(fieldType.name);
  126. // Open the type option menu
  127. await tester.tapTypeOptionButton();
  128. await tester.selectFieldType(fieldType);
  129. await tester.dismissFieldEditor();
  130. // After update the field type, the cells should be updated
  131. await tester.findCellByFieldType(fieldType);
  132. await tester.pumpAndSettle();
  133. }
  134. });
  135. testWidgets('add option', (tester) async {
  136. await tester.initializeAppFlowy();
  137. await tester.tapGoButton();
  138. await tester.createNewPageWithName(
  139. layout: ViewLayoutPB.Grid,
  140. );
  141. // Invoke the field editor
  142. await tester.tapGridFieldWithName('Type');
  143. await tester.tapEditPropertyButton();
  144. // tap 'add option' button
  145. await tester.tapAddSelectOptionButton();
  146. const text = 'Hello AppFlowy';
  147. final inputField = find.descendant(
  148. of: find.byType(CreateOptionTextField),
  149. matching: find.byType(TextField),
  150. );
  151. await tester.enterText(inputField, text);
  152. await tester.pumpAndSettle();
  153. await tester.testTextInput.receiveAction(TextInputAction.done);
  154. await tester.pumpAndSettle(const Duration(seconds: 1));
  155. // check the result
  156. tester.expectToSeeText(text);
  157. });
  158. });
  159. }