database_field_test.dart 5.9 KB

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