database_field_test.dart 6.5 KB

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