database_share_test.dart 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215
  1. import 'dart:io';
  2. import 'package:appflowy_backend/protobuf/flowy-database2/field_entities.pbenum.dart';
  3. import 'package:flutter/services.dart';
  4. import 'package:flutter_test/flutter_test.dart';
  5. import 'package:integration_test/integration_test.dart';
  6. import 'util/database_test_op.dart';
  7. import 'util/mock/mock_file_picker.dart';
  8. import 'util/util.dart';
  9. import 'package:path/path.dart' as p;
  10. void main() {
  11. IntegrationTestWidgetsFlutterBinding.ensureInitialized();
  12. group('database', () {
  13. const location = 'import_files';
  14. setUp(() async {
  15. await TestFolder.cleanTestLocation(location);
  16. await TestFolder.setTestLocation(location);
  17. });
  18. tearDown(() async {
  19. await TestFolder.cleanTestLocation(location);
  20. });
  21. tearDownAll(() async {
  22. await TestFolder.cleanTestLocation(null);
  23. });
  24. testWidgets('import v0.2.0 database data', (tester) async {
  25. await tester.initializeAppFlowy();
  26. await tester.tapGoButton();
  27. // expect to see a readme page
  28. tester.expectToSeePageName(readme);
  29. await tester.tapAddButton();
  30. await tester.tapImportButton();
  31. final testFileNames = ['v020.afdb'];
  32. final fileLocation = await tester.currentFileLocation();
  33. for (final fileName in testFileNames) {
  34. final str = await rootBundle.loadString(
  35. p.join(
  36. 'assets/test/workspaces/database',
  37. fileName,
  38. ),
  39. );
  40. File(p.join(fileLocation, fileName)).writeAsStringSync(str);
  41. }
  42. // mock get files
  43. await mockPickFilePaths(testFileNames, name: location);
  44. await tester.tapDatabaseRawDataButton();
  45. await tester.openPage('v020');
  46. // check the import content
  47. // await tester.assertCellContent(
  48. // rowIndex: 7,
  49. // fieldType: FieldType.RichText,
  50. // // fieldName: 'Name',
  51. // content: '',
  52. // );
  53. // check the text cell
  54. final textCells = <String>['A', 'B', 'C', 'D', 'E', '', '', '', '', ''];
  55. for (final (index, content) in textCells.indexed) {
  56. await tester.assertCellContent(
  57. rowIndex: index,
  58. fieldType: FieldType.RichText,
  59. content: content,
  60. );
  61. }
  62. // check the checkbox cell
  63. final checkboxCells = <bool>[
  64. true,
  65. true,
  66. true,
  67. true,
  68. true,
  69. false,
  70. false,
  71. false,
  72. false,
  73. false
  74. ];
  75. for (final (index, content) in checkboxCells.indexed) {
  76. await tester.assertCheckboxCell(
  77. rowIndex: index,
  78. isSelected: content,
  79. );
  80. }
  81. // check the number cell
  82. final numberCells = <String>[
  83. '-1',
  84. '-2',
  85. '0.1',
  86. '0.2',
  87. '1',
  88. '2',
  89. '10',
  90. '11',
  91. '12',
  92. ''
  93. ];
  94. for (final (index, content) in numberCells.indexed) {
  95. await tester.assertCellContent(
  96. rowIndex: index,
  97. fieldType: FieldType.Number,
  98. content: content,
  99. );
  100. }
  101. // check the url cell
  102. final urlCells = <String>[
  103. 'appflowy.io',
  104. 'no url',
  105. 'appflowy.io',
  106. 'https://github.com/AppFlowy-IO/',
  107. '',
  108. '',
  109. ];
  110. for (final (index, content) in urlCells.indexed) {
  111. await tester.assertCellContent(
  112. rowIndex: index,
  113. fieldType: FieldType.URL,
  114. content: content,
  115. );
  116. }
  117. // check the single select cell
  118. final singleSelectCells = <String>[
  119. 's1',
  120. 's2',
  121. 's3',
  122. 's4',
  123. 's5',
  124. '',
  125. '',
  126. '',
  127. '',
  128. '',
  129. ];
  130. for (final (index, content) in singleSelectCells.indexed) {
  131. await tester.assertSingleSelectOption(
  132. rowIndex: index,
  133. content: content,
  134. );
  135. }
  136. // check the multi select cell
  137. final List<List<String>> multiSelectCells = [
  138. ['m1'],
  139. ['m1', 'm2'],
  140. ['m1', 'm2', 'm3'],
  141. ['m1', 'm2', 'm3'],
  142. ['m1', 'm2', 'm3', 'm4', 'm5'],
  143. [],
  144. [],
  145. [],
  146. [],
  147. [],
  148. ];
  149. for (final (index, contents) in multiSelectCells.indexed) {
  150. await tester.assertMultiSelectOption(
  151. rowIndex: index,
  152. contents: contents,
  153. );
  154. }
  155. // check the checklist cell
  156. final List<double> checklistCells = [
  157. 0.6,
  158. 0.3,
  159. 1.0,
  160. 0.0,
  161. 0.0,
  162. 0.0,
  163. 0.0,
  164. 0.0,
  165. 0.0,
  166. 0.0,
  167. ];
  168. for (final (index, percent) in checklistCells.indexed) {
  169. await tester.assertChecklistCellInGrid(
  170. rowIndex: index,
  171. percent: percent,
  172. );
  173. }
  174. // check the date cell
  175. final List<String> dateCells = [
  176. 'Jun 01, 2023',
  177. 'Jun 02, 2023',
  178. 'Jun 03, 2023',
  179. 'Jun 04, 2023',
  180. 'Jun 05, 2023',
  181. 'Jun 05, 2023',
  182. 'Jun 16, 2023',
  183. '',
  184. '',
  185. ''
  186. ];
  187. for (final (index, content) in dateCells.indexed) {
  188. await tester.assertDateCellInGrid(
  189. rowIndex: index,
  190. fieldType: FieldType.DateTime,
  191. content: content,
  192. );
  193. }
  194. });
  195. });
  196. }