database_cell_test.dart 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185
  1. import 'package:appflowy_backend/protobuf/flowy-database2/field_entities.pbenum.dart';
  2. import 'package:flutter_test/flutter_test.dart';
  3. import 'package:integration_test/integration_test.dart';
  4. import 'util/database_test_op.dart';
  5. import 'util/util.dart';
  6. void main() {
  7. IntegrationTestWidgetsFlutterBinding.ensureInitialized();
  8. group('grid cell', () {
  9. const location = 'appflowy';
  10. setUp(() async {
  11. await TestFolder.cleanTestLocation(location);
  12. await TestFolder.setTestLocation(location);
  13. });
  14. tearDown(() async {
  15. await TestFolder.cleanTestLocation(location);
  16. });
  17. tearDownAll(() async {
  18. await TestFolder.cleanTestLocation(null);
  19. });
  20. testWidgets('edit text cell', (tester) async {
  21. await tester.initializeAppFlowy();
  22. await tester.tapGoButton();
  23. await tester.tapAddButton();
  24. await tester.tapCreateGridButton();
  25. await tester.editCell(
  26. rowIndex: 0,
  27. fieldType: FieldType.RichText,
  28. input: 'hello world',
  29. );
  30. await tester.assertCellContent(
  31. rowIndex: 0,
  32. fieldType: FieldType.RichText,
  33. content: 'hello world',
  34. );
  35. await tester.pumpAndSettle();
  36. });
  37. testWidgets('edit number cell', (tester) async {
  38. await tester.initializeAppFlowy();
  39. await tester.tapGoButton();
  40. await tester.tapAddButton();
  41. await tester.tapCreateGridButton();
  42. const fieldType = FieldType.Number;
  43. // Create a number field
  44. await tester.createField(fieldType, fieldType.name);
  45. await tester.editCell(
  46. rowIndex: 0,
  47. fieldType: fieldType,
  48. input: '-1',
  49. );
  50. // edit the next cell to force the previous cell at row 0 to lose focus
  51. await tester.editCell(
  52. rowIndex: 1,
  53. fieldType: fieldType,
  54. input: '0.2',
  55. );
  56. // -1 -> -1
  57. await tester.assertCellContent(
  58. rowIndex: 0,
  59. fieldType: fieldType,
  60. content: '-1',
  61. );
  62. // edit the next cell to force the previous cell at row 1 to lose focus
  63. await tester.editCell(
  64. rowIndex: 2,
  65. fieldType: fieldType,
  66. input: '.1',
  67. );
  68. // 0.2 -> 0.2
  69. await tester.assertCellContent(
  70. rowIndex: 1,
  71. fieldType: fieldType,
  72. content: '0.2',
  73. );
  74. // edit the next cell to force the previous cell at row 2 to lose focus
  75. await tester.editCell(
  76. rowIndex: 0,
  77. fieldType: fieldType,
  78. input: '',
  79. );
  80. // .1 -> 0.1
  81. await tester.assertCellContent(
  82. rowIndex: 2,
  83. fieldType: fieldType,
  84. content: '0.1',
  85. );
  86. await tester.pumpAndSettle();
  87. });
  88. testWidgets('edit checkbox cell', (tester) async {
  89. await tester.initializeAppFlowy();
  90. await tester.tapGoButton();
  91. await tester.tapAddButton();
  92. await tester.tapCreateGridButton();
  93. await tester.assertCheckboxCell(rowIndex: 0, isSelected: false);
  94. await tester.tapCheckboxCellInGrid(rowIndex: 0);
  95. await tester.assertCheckboxCell(rowIndex: 0, isSelected: true);
  96. await tester.tapCheckboxCellInGrid(rowIndex: 1);
  97. await tester.tapCheckboxCellInGrid(rowIndex: 2);
  98. await tester.assertCheckboxCell(rowIndex: 1, isSelected: true);
  99. await tester.assertCheckboxCell(rowIndex: 2, isSelected: true);
  100. await tester.pumpAndSettle();
  101. });
  102. testWidgets('edit create time cell', (tester) async {
  103. await tester.initializeAppFlowy();
  104. await tester.tapGoButton();
  105. await tester.tapAddButton();
  106. await tester.tapCreateGridButton();
  107. const fieldType = FieldType.CreatedTime;
  108. // Create a create time field
  109. // The create time field is not editable
  110. await tester.createField(fieldType, fieldType.name);
  111. await tester.tapCellInGrid(rowIndex: 0, fieldType: fieldType);
  112. await tester.findDateEditor(findsNothing);
  113. await tester.pumpAndSettle();
  114. });
  115. testWidgets('edit last time cell', (tester) async {
  116. await tester.initializeAppFlowy();
  117. await tester.tapGoButton();
  118. await tester.tapAddButton();
  119. await tester.tapCreateGridButton();
  120. const fieldType = FieldType.LastEditedTime;
  121. // Create a last time field
  122. // The last time field is not editable
  123. await tester.createField(fieldType, fieldType.name);
  124. await tester.tapCellInGrid(rowIndex: 0, fieldType: fieldType);
  125. await tester.findDateEditor(findsNothing);
  126. await tester.pumpAndSettle();
  127. });
  128. testWidgets('edit time cell', (tester) async {
  129. await tester.initializeAppFlowy();
  130. await tester.tapGoButton();
  131. await tester.tapAddButton();
  132. await tester.tapCreateGridButton();
  133. const fieldType = FieldType.DateTime;
  134. await tester.createField(fieldType, fieldType.name);
  135. // Tap the cell to invoke the field editor
  136. await tester.tapCellInGrid(rowIndex: 0, fieldType: fieldType);
  137. await tester.findDateEditor(findsOneWidget);
  138. // Select the date
  139. await tester.selectDay(content: 3);
  140. await tester.pumpAndSettle();
  141. });
  142. });
  143. }