database_test_op.dart 45 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471
  1. import 'dart:io';
  2. import 'package:appflowy/generated/flowy_svgs.g.dart';
  3. import 'package:appflowy/generated/locale_keys.g.dart';
  4. import 'package:appflowy/plugins/database_view/board/presentation/board_page.dart';
  5. import 'package:appflowy/plugins/database_view/calendar/application/calendar_bloc.dart';
  6. import 'package:appflowy/plugins/database_view/calendar/presentation/calendar_day.dart';
  7. import 'package:appflowy/plugins/database_view/calendar/presentation/calendar_event_card.dart';
  8. import 'package:appflowy/plugins/database_view/calendar/presentation/calendar_page.dart';
  9. import 'package:appflowy/plugins/database_view/calendar/presentation/toolbar/calendar_layout_setting.dart';
  10. import 'package:appflowy/plugins/database_view/grid/presentation/grid_page.dart';
  11. import 'package:appflowy/plugins/database_view/grid/presentation/widgets/filter/choicechip/checkbox.dart';
  12. import 'package:appflowy/plugins/database_view/grid/presentation/widgets/filter/choicechip/checklist/checklist.dart';
  13. import 'package:appflowy/plugins/database_view/grid/presentation/widgets/filter/choicechip/select_option/option_list.dart';
  14. import 'package:appflowy/plugins/database_view/grid/presentation/widgets/filter/choicechip/select_option/select_option.dart';
  15. import 'package:appflowy/plugins/database_view/grid/presentation/widgets/filter/choicechip/text.dart';
  16. import 'package:appflowy/plugins/database_view/grid/presentation/widgets/filter/create_filter_list.dart';
  17. import 'package:appflowy/plugins/database_view/grid/presentation/widgets/filter/disclosure_button.dart';
  18. import 'package:appflowy/plugins/database_view/grid/presentation/widgets/filter/filter_menu_item.dart';
  19. import 'package:appflowy/plugins/database_view/grid/presentation/widgets/footer/grid_footer.dart';
  20. import 'package:appflowy/plugins/database_view/grid/presentation/widgets/header/field_cell.dart';
  21. import 'package:appflowy/plugins/database_view/grid/presentation/widgets/header/field_cell_action_sheet.dart';
  22. import 'package:appflowy/plugins/database_view/grid/presentation/widgets/header/field_editor.dart';
  23. import 'package:appflowy/plugins/database_view/grid/presentation/widgets/header/field_type_extension.dart';
  24. import 'package:appflowy/plugins/database_view/grid/presentation/widgets/header/field_type_list.dart';
  25. import 'package:appflowy/plugins/database_view/grid/presentation/widgets/header/field_type_option_editor.dart';
  26. import 'package:appflowy/plugins/database_view/grid/presentation/widgets/header/type_option/date.dart';
  27. import 'package:appflowy/plugins/database_view/grid/presentation/widgets/row/row.dart';
  28. import 'package:appflowy/plugins/database_view/grid/presentation/widgets/sort/create_sort_list.dart';
  29. import 'package:appflowy/plugins/database_view/grid/presentation/widgets/sort/order_panel.dart';
  30. import 'package:appflowy/plugins/database_view/grid/presentation/widgets/sort/sort_editor.dart';
  31. import 'package:appflowy/plugins/database_view/grid/presentation/widgets/sort/sort_menu.dart';
  32. import 'package:appflowy/plugins/database_view/grid/presentation/widgets/toolbar/filter_button.dart';
  33. import 'package:appflowy/plugins/database_view/grid/presentation/widgets/toolbar/grid_layout.dart';
  34. import 'package:appflowy/plugins/database_view/grid/presentation/widgets/toolbar/sort_button.dart';
  35. import 'package:appflowy/plugins/database_view/tar_bar/tab_bar_header.dart';
  36. import 'package:appflowy/plugins/database_view/tar_bar/tar_bar_add_button.dart';
  37. import 'package:appflowy/plugins/database_view/widgets/database_layout_ext.dart';
  38. import 'package:appflowy/plugins/database_view/widgets/field/grid_property.dart';
  39. import 'package:appflowy/plugins/database_view/widgets/row/accessory/cell_accessory.dart';
  40. import 'package:appflowy/plugins/database_view/widgets/row/cells/cells.dart';
  41. import 'package:appflowy/plugins/database_view/widgets/row/cells/checklist_cell/checklist_cell_editor.dart';
  42. import 'package:appflowy/plugins/database_view/widgets/row/cells/checklist_cell/checklist_progress_bar.dart';
  43. import 'package:appflowy/plugins/database_view/widgets/row/cells/date_cell/date_editor.dart';
  44. import 'package:appflowy/plugins/database_view/widgets/row/cells/select_option_cell/extension.dart';
  45. import 'package:appflowy/plugins/database_view/widgets/row/cells/select_option_cell/select_option_editor.dart';
  46. import 'package:appflowy/plugins/database_view/widgets/row/cells/select_option_cell/text_field.dart';
  47. import 'package:appflowy/plugins/database_view/widgets/row/cells/timestamp_cell/timestamp_cell.dart';
  48. import 'package:appflowy/plugins/database_view/widgets/row/row_action.dart';
  49. import 'package:appflowy/plugins/database_view/widgets/row/row_banner.dart';
  50. import 'package:appflowy/plugins/database_view/widgets/row/row_detail.dart';
  51. import 'package:appflowy/plugins/database_view/widgets/row/row_document.dart';
  52. import 'package:appflowy/plugins/database_view/widgets/row/row_property.dart';
  53. import 'package:appflowy/plugins/database_view/widgets/setting/database_setting.dart';
  54. import 'package:appflowy/plugins/database_view/widgets/setting/setting_button.dart';
  55. import 'package:appflowy/plugins/document/presentation/editor_plugins/emoji_picker/emoji_menu_item.dart';
  56. import 'package:appflowy/workspace/presentation/widgets/pop_up_action.dart';
  57. import 'package:appflowy/workspace/presentation/widgets/toggle/toggle.dart';
  58. import 'package:appflowy_backend/protobuf/flowy-database2/field_entities.pbenum.dart';
  59. import 'package:appflowy_backend/protobuf/flowy-database2/setting_entities.pbenum.dart';
  60. import 'package:appflowy_backend/protobuf/flowy-folder2/view.pb.dart';
  61. import 'package:calendar_view/calendar_view.dart';
  62. import 'package:easy_localization/easy_localization.dart';
  63. import 'package:flowy_infra_ui/flowy_infra_ui.dart';
  64. import 'package:flowy_infra_ui/style_widget/text_input.dart';
  65. import 'package:flowy_infra_ui/widget/buttons/primary_button.dart';
  66. import 'package:flutter/gestures.dart';
  67. import 'package:flutter/material.dart';
  68. import 'package:flutter/services.dart';
  69. import 'package:flutter_test/flutter_test.dart';
  70. import 'package:path/path.dart' as p;
  71. import 'package:table_calendar/table_calendar.dart';
  72. import 'base.dart';
  73. import 'common_operations.dart';
  74. import 'expectation.dart';
  75. import 'mock/mock_file_picker.dart';
  76. extension AppFlowyDatabaseTest on WidgetTester {
  77. Future<void> openV020database() async {
  78. final context = await initializeAppFlowy();
  79. await tapGoButton();
  80. // expect to see a readme page
  81. expectToSeePageName(gettingStarted);
  82. await tapAddViewButton();
  83. await tapImportButton();
  84. final testFileNames = ['v020.afdb'];
  85. final paths = <String>[];
  86. for (final fileName in testFileNames) {
  87. // Don't use the p.join to build the path that used in loadString. It
  88. // is not working on windows.
  89. final str = await rootBundle
  90. .loadString("assets/test/workspaces/database/$fileName");
  91. // Write the content to the file.
  92. final path = p.join(
  93. context.applicationDataDirectory,
  94. fileName,
  95. );
  96. paths.add(path);
  97. File(path).writeAsStringSync(str);
  98. }
  99. // mock get files
  100. await mockPickFilePaths(
  101. paths: paths,
  102. );
  103. await tapDatabaseRawDataButton();
  104. await pumpAndSettle();
  105. await openPage('v020', layout: ViewLayoutPB.Grid);
  106. }
  107. Future<void> hoverOnFirstRowOfGrid() async {
  108. final findRow = find.byType(GridRow);
  109. expect(findRow, findsWidgets);
  110. final firstRow = findRow.first;
  111. await hoverOnWidget(firstRow);
  112. }
  113. Future<void> editCell({
  114. required int rowIndex,
  115. required FieldType fieldType,
  116. required String input,
  117. int cellIndex = 0,
  118. }) async {
  119. final cell = cellFinder(rowIndex, fieldType, cellIndex: cellIndex);
  120. expect(cell, findsOneWidget);
  121. await enterText(cell, input);
  122. await pumpAndSettle();
  123. }
  124. ///
  125. Finder cellFinder(int rowIndex, FieldType fieldType, {int cellIndex = 0}) {
  126. final findRow = find.byType(GridRow, skipOffstage: false);
  127. final findCell = finderForFieldType(fieldType);
  128. return find
  129. .descendant(
  130. of: findRow.at(rowIndex),
  131. matching: findCell,
  132. skipOffstage: false,
  133. )
  134. .at(cellIndex);
  135. }
  136. Future<void> tapCheckboxCellInGrid({
  137. required int rowIndex,
  138. }) async {
  139. final cell = cellFinder(rowIndex, FieldType.Checkbox);
  140. final button = find.descendant(
  141. of: cell,
  142. matching: find.byType(FlowyIconButton),
  143. );
  144. expect(cell, findsOneWidget);
  145. await tapButton(button);
  146. }
  147. Future<void> assertCheckboxCell({
  148. required int rowIndex,
  149. required bool isSelected,
  150. }) async {
  151. final cell = cellFinder(rowIndex, FieldType.Checkbox);
  152. var finder = find.byType(CheckboxCellUncheck);
  153. if (isSelected) {
  154. finder = find.byType(CheckboxCellCheck);
  155. }
  156. expect(
  157. find.descendant(
  158. of: cell,
  159. matching: finder,
  160. ),
  161. findsOneWidget,
  162. );
  163. }
  164. Future<void> tapCellInGrid({
  165. required int rowIndex,
  166. required FieldType fieldType,
  167. }) async {
  168. final cell = cellFinder(rowIndex, fieldType);
  169. expect(cell, findsOneWidget);
  170. await tapButton(cell, warnIfMissed: false);
  171. }
  172. /// The [fieldName] must be unique in the grid.
  173. Future<void> assertCellContent({
  174. required int rowIndex,
  175. required FieldType fieldType,
  176. required String content,
  177. int cellIndex = 0,
  178. }) async {
  179. final findCell = cellFinder(rowIndex, fieldType, cellIndex: cellIndex);
  180. final findContent = find.descendant(
  181. of: findCell,
  182. matching: find.text(content),
  183. skipOffstage: false,
  184. );
  185. final text = find.descendant(
  186. of: find.byType(TextField),
  187. matching: findContent,
  188. skipOffstage: false,
  189. );
  190. expect(text, findsOneWidget);
  191. }
  192. Future<void> assertSingleSelectOption({
  193. required int rowIndex,
  194. required String content,
  195. }) async {
  196. final findCell = cellFinder(rowIndex, FieldType.SingleSelect);
  197. if (content.isNotEmpty) {
  198. final finder = find.descendant(
  199. of: findCell,
  200. matching: find.byWidgetPredicate(
  201. (widget) => widget is SelectOptionTag && widget.name == content,
  202. ),
  203. );
  204. expect(finder, findsOneWidget);
  205. }
  206. }
  207. Future<void> assertMultiSelectOption({
  208. required int rowIndex,
  209. required List<String> contents,
  210. }) async {
  211. final findCell = cellFinder(rowIndex, FieldType.MultiSelect);
  212. for (final content in contents) {
  213. if (content.isNotEmpty) {
  214. final finder = find.descendant(
  215. of: findCell,
  216. matching: find.byWidgetPredicate(
  217. (widget) => widget is SelectOptionTag && widget.name == content,
  218. ),
  219. );
  220. expect(finder, findsOneWidget);
  221. }
  222. }
  223. }
  224. /// null percent means no progress bar should be found
  225. Future<void> assertChecklistCellInGrid({
  226. required int rowIndex,
  227. required double? percent,
  228. }) async {
  229. final findCell = cellFinder(rowIndex, FieldType.Checklist);
  230. if (percent == null) {
  231. final finder = find.descendant(
  232. of: findCell,
  233. matching: find.byType(ChecklistProgressBar),
  234. );
  235. expect(finder, findsNothing);
  236. } else {
  237. final finder = find.descendant(
  238. of: findCell,
  239. matching: find.byWidgetPredicate(
  240. (widget) {
  241. if (widget is ChecklistProgressBar) {
  242. return widget.percent == percent;
  243. }
  244. return false;
  245. },
  246. ),
  247. );
  248. expect(finder, findsOneWidget);
  249. }
  250. }
  251. Future<void> assertDateCellInGrid({
  252. required int rowIndex,
  253. required String content,
  254. }) async {
  255. final findRow = find.byType(GridRow, skipOffstage: false);
  256. final findCell = find.descendant(
  257. of: findRow.at(rowIndex),
  258. matching: find.byType(GridDateCell),
  259. skipOffstage: false,
  260. );
  261. final dateCellText = find.descendant(
  262. of: findCell,
  263. matching: find.byType(GridDateCellText),
  264. );
  265. final text = find.descendant(
  266. of: dateCellText,
  267. matching: find.byWidgetPredicate(
  268. (widget) {
  269. if (widget is FlowyText) {
  270. return widget.text == content;
  271. }
  272. return false;
  273. },
  274. ),
  275. skipOffstage: false,
  276. );
  277. expect(text, findsOneWidget);
  278. }
  279. Future<void> selectDay({
  280. required int content,
  281. }) async {
  282. final findCalendar = find.byType(TableCalendar);
  283. final findDay = find.text(content.toString());
  284. final finder = find.descendant(
  285. of: findCalendar,
  286. matching: findDay,
  287. );
  288. // if the day is very near the beginning or the end of the month,
  289. // it may overlap with the same day in the next or previous month,
  290. // respectively because it was spilling over. This will lead to 2
  291. // widgets being found and thus cannot be tapped correctly.
  292. if (content < 15) {
  293. // e.g., Jan 2 instead of Feb 2
  294. await tapButton(finder.first);
  295. } else {
  296. // e.g. Jun 28 instead of May 28
  297. await tapButton(finder.last);
  298. }
  299. }
  300. Future<void> toggleIncludeTime() async {
  301. final findDateEditor = find.byType(DateCellEditor);
  302. final findToggle = find.byType(Toggle);
  303. final finder = find.descendant(
  304. of: findDateEditor,
  305. matching: findToggle,
  306. );
  307. await tapButton(finder);
  308. }
  309. Future<void> changeDateFormat() async {
  310. final findDateEditor = find.byType(DateCellEditor);
  311. final findDateTimeOptionButton = find.byType(DateTypeOptionButton);
  312. final finder = find.descendant(
  313. of: findDateEditor,
  314. matching: findDateTimeOptionButton,
  315. );
  316. await tapButton(finder);
  317. final findDateFormatButton = find.byType(DateFormatButton);
  318. await tapButton(findDateFormatButton);
  319. final findNewDateFormat = find.text("Day/Month/Year");
  320. await tapButton(findNewDateFormat);
  321. }
  322. Future<void> changeTimeFormat() async {
  323. final findDateEditor = find.byType(DateCellEditor);
  324. final findDateTimeOptionButton = find.byType(DateTypeOptionButton);
  325. final finder = find.descendant(
  326. of: findDateEditor,
  327. matching: findDateTimeOptionButton,
  328. );
  329. await tapButton(finder);
  330. final findDateFormatButton = find.byType(TimeFormatButton);
  331. await tapButton(findDateFormatButton);
  332. final findNewDateFormat = find.text("12 hour");
  333. await tapButton(findNewDateFormat);
  334. }
  335. Future<void> clearDate() async {
  336. final findDateEditor = find.byType(DateCellEditor);
  337. final findClearButton = find.byType(ClearDateButton);
  338. final finder = find.descendant(
  339. of: findDateEditor,
  340. matching: findClearButton,
  341. );
  342. await tapButton(finder);
  343. }
  344. Future<void> tapSelectOptionCellInGrid({
  345. required int rowIndex,
  346. required FieldType fieldType,
  347. }) async {
  348. assert(
  349. fieldType == FieldType.SingleSelect || fieldType == FieldType.MultiSelect,
  350. );
  351. final findRow = find.byType(GridRow);
  352. final findCell = finderForFieldType(fieldType);
  353. final cell = find.descendant(
  354. of: findRow.at(rowIndex),
  355. matching: findCell,
  356. );
  357. await tapButton(cell);
  358. }
  359. /// The [SelectOptionCellEditor] must be opened first.
  360. Future<void> createOption({
  361. required String name,
  362. }) async {
  363. final findEditor = find.byType(SelectOptionCellEditor);
  364. expect(findEditor, findsOneWidget);
  365. final findTextField = find.byType(SelectOptionTextField);
  366. expect(findTextField, findsOneWidget);
  367. await enterText(findTextField, name);
  368. await pump();
  369. await testTextInput.receiveAction(TextInputAction.done);
  370. await pumpAndSettle();
  371. }
  372. Future<void> selectOption({
  373. required String name,
  374. }) async {
  375. final option = find.byWidgetPredicate(
  376. (widget) => widget is SelectOptionTagCell && widget.option.name == name,
  377. );
  378. await tapButton(option);
  379. }
  380. Future<void> findSelectOptionWithNameInGrid({
  381. required int rowIndex,
  382. required String name,
  383. }) async {
  384. final findRow = find.byType(GridRow);
  385. final option = find.byWidgetPredicate(
  386. (widget) => widget is SelectOptionTag && widget.name == name,
  387. );
  388. final cell = find.descendant(
  389. of: findRow.at(rowIndex),
  390. matching: option,
  391. );
  392. expect(cell, findsOneWidget);
  393. }
  394. Future<void> assertNumberOfSelectedOptionsInGrid({
  395. required int rowIndex,
  396. required Matcher matcher,
  397. }) async {
  398. final findRow = find.byType(GridRow);
  399. final options = find.byWidgetPredicate(
  400. (widget) => widget is SelectOptionTag,
  401. );
  402. final cell = find.descendant(
  403. of: findRow.at(rowIndex),
  404. matching: options,
  405. );
  406. expect(cell, matcher);
  407. }
  408. Future<void> tapChecklistCellInGrid({required int rowIndex}) async {
  409. final findRow = find.byType(GridRow);
  410. final findCell = finderForFieldType(FieldType.Checklist);
  411. final cell = find.descendant(
  412. of: findRow.at(rowIndex),
  413. matching: findCell,
  414. );
  415. await tapButton(cell);
  416. }
  417. void assertChecklistEditorVisible({required bool visible}) {
  418. final editor = find.byType(GridChecklistCellEditor);
  419. if (visible) {
  420. expect(editor, findsOneWidget);
  421. } else {
  422. expect(editor, findsNothing);
  423. }
  424. }
  425. void assertNewCheckListTaskEditorVisible({required bool visible}) {
  426. final editor = find.byType(NewTaskItem);
  427. if (visible) {
  428. expect(editor, findsOneWidget);
  429. } else {
  430. expect(editor, findsNothing);
  431. }
  432. }
  433. Future<void> createNewChecklistTask({
  434. required String name,
  435. enter = false,
  436. button = false,
  437. }) async {
  438. assert(!(enter && button));
  439. final textField = find.descendant(
  440. of: find.byType(NewTaskItem),
  441. matching: find.byType(TextField),
  442. );
  443. await enterText(textField, name);
  444. await pumpAndSettle(const Duration(milliseconds: 300));
  445. if (enter) {
  446. await testTextInput.receiveAction(TextInputAction.done);
  447. await pumpAndSettle(const Duration(milliseconds: 300));
  448. } else {
  449. await tapButton(
  450. find.descendant(
  451. of: find.byType(NewTaskItem),
  452. matching: find.byType(FlowyTextButton),
  453. ),
  454. );
  455. }
  456. }
  457. void assertChecklistTaskInEditor({
  458. required int index,
  459. required String name,
  460. required bool isChecked,
  461. }) {
  462. final task = find.byType(ChecklistItem).at(index);
  463. final widget = this.widget<ChecklistItem>(task);
  464. assert(
  465. widget.option.data.name == name && widget.option.isSelected == isChecked,
  466. );
  467. }
  468. Future<void> renameChecklistTask({
  469. required int index,
  470. required String name,
  471. }) async {
  472. final textField = find
  473. .descendant(
  474. of: find.byType(ChecklistItem),
  475. matching: find.byType(TextField),
  476. )
  477. .at(index);
  478. await enterText(textField, name);
  479. await testTextInput.receiveAction(TextInputAction.done);
  480. await pumpAndSettle(const Duration(milliseconds: 300));
  481. }
  482. Future<void> tapChecklistNewTaskButton() async {
  483. await tapButton(find.byType(ChecklistNewTaskButton));
  484. }
  485. Future<void> checkChecklistTask({required int index}) async {
  486. final button = find.descendant(
  487. of: find.byType(ChecklistItem).at(index),
  488. matching: find.byWidgetPredicate(
  489. (widget) => widget is FlowySvg && widget.svg == FlowySvgs.uncheck_s,
  490. ),
  491. );
  492. await tapButton(button);
  493. }
  494. Future<void> deleteChecklistTask({required int index}) async {
  495. final task = find.byType(ChecklistItem).at(index);
  496. await startGesture(getCenter(task), kind: PointerDeviceKind.mouse);
  497. await pumpAndSettle();
  498. final button = find.byWidgetPredicate(
  499. (widget) => widget is FlowySvg && widget.svg == FlowySvgs.delete_s,
  500. );
  501. await tapButton(button);
  502. }
  503. Future<void> openFirstRowDetailPage() async {
  504. await hoverOnFirstRowOfGrid();
  505. final expandButton = find.byType(PrimaryCellAccessory);
  506. expect(expandButton, findsOneWidget);
  507. await tapButton(expandButton);
  508. }
  509. void assertRowDetailPageOpened() async {
  510. final findRowDetailPage = find.byType(RowDetailPage);
  511. expect(findRowDetailPage, findsOneWidget);
  512. }
  513. Future<void> dismissRowDetailPage() async {
  514. // use tap empty area instead of clicking ESC to dismiss the row detail page
  515. // sometimes, the ESC key is not working.
  516. await simulateKeyEvent(LogicalKeyboardKey.escape);
  517. await pumpAndSettle();
  518. final findRowDetailPage = find.byType(RowDetailPage);
  519. if (findRowDetailPage.evaluate().isNotEmpty) {
  520. await tapAt(const Offset(0, 0));
  521. await pumpAndSettle();
  522. }
  523. }
  524. Future<void> editTitleInRowDetailPage(String title) async {
  525. final titleField = find.byType(GridTextCell);
  526. await enterText(titleField, title);
  527. await pumpAndSettle();
  528. }
  529. Future<void> hoverRowBanner() async {
  530. final banner = find.byType(RowBanner);
  531. expect(banner, findsOneWidget);
  532. await startGesture(
  533. getCenter(banner),
  534. kind: PointerDeviceKind.mouse,
  535. );
  536. await pumpAndSettle();
  537. }
  538. Future<void> openEmojiPicker() async {
  539. await tapButton(find.byType(EmojiPickerButton));
  540. await tapButton(find.byType(EmojiSelectionMenu));
  541. }
  542. Future<void> tapDateCellInRowDetailPage() async {
  543. final findDateCell = find.byType(GridDateCell);
  544. await tapButton(findDateCell);
  545. }
  546. Future<void> tapGridFieldWithNameInRowDetailPage(String name) async {
  547. final fields = find.byWidgetPredicate(
  548. (widget) => widget is FieldCellButton && widget.field.name == name,
  549. );
  550. final field = find.descendant(
  551. of: find.byType(RowDetailPage),
  552. matching: fields,
  553. );
  554. await tapButton(field);
  555. await pumpAndSettle();
  556. }
  557. Future<void> duplicateRowInRowDetailPage() async {
  558. final duplicateButton = find.byType(RowDetailPageDuplicateButton);
  559. await tapButton(duplicateButton);
  560. }
  561. Future<void> deleteRowInRowDetailPage() async {
  562. final deleteButton = find.byType(RowDetailPageDeleteButton);
  563. await tapButton(deleteButton);
  564. }
  565. Future<TestGesture> hoverOnFieldInRowDetail({required int index}) async {
  566. final fieldButtons = find.byType(FieldCellButton);
  567. final button = find
  568. .descendant(of: find.byType(RowDetailPage), matching: fieldButtons)
  569. .at(index);
  570. return startGesture(
  571. getCenter(button),
  572. kind: PointerDeviceKind.mouse,
  573. );
  574. }
  575. Future<void> reorderFieldInRowDetail({required double offset}) async {
  576. final thumb = find
  577. .byWidgetPredicate(
  578. (widget) => widget is ReorderableDragStartListener && widget.enabled,
  579. )
  580. .first;
  581. await drag(
  582. thumb,
  583. Offset(0, offset),
  584. kind: PointerDeviceKind.mouse,
  585. );
  586. await pumpAndSettle();
  587. }
  588. Future<void> scrollGridByOffset(Offset offset) async {
  589. await drag(find.byType(GridPage), offset);
  590. await pumpAndSettle();
  591. }
  592. Future<void> scrollRowDetailByOffset(Offset offset) async {
  593. await drag(find.byType(RowDetailPage), offset);
  594. await pumpAndSettle();
  595. }
  596. Future<void> scrollToRight(Finder find) async {
  597. final size = getSize(find);
  598. await drag(find, Offset(-size.width, 0));
  599. await pumpAndSettle(const Duration(milliseconds: 500));
  600. }
  601. Future<void> tapNewPropertyButton() async {
  602. await tapButtonWithName(LocaleKeys.grid_field_newProperty.tr());
  603. await pumpAndSettle();
  604. }
  605. Future<void> tapGridFieldWithName(String name) async {
  606. final field = find.byWidgetPredicate(
  607. (widget) => widget is FieldCellButton && widget.field.name == name,
  608. );
  609. await tapButton(field);
  610. await pumpAndSettle();
  611. }
  612. /// Should call [tapGridFieldWithName] first.
  613. Future<void> tapEditPropertyButton() async {
  614. await tapButtonWithName(LocaleKeys.grid_field_editProperty.tr());
  615. await pumpAndSettle(const Duration(milliseconds: 200));
  616. }
  617. /// Should call [tapGridFieldWithName] first.
  618. Future<void> tapDeletePropertyButton() async {
  619. final field = find.byWidgetPredicate(
  620. (widget) =>
  621. widget is FieldActionCell && widget.action == FieldAction.delete,
  622. );
  623. await tapButton(field);
  624. }
  625. /// Should call [tapGridFieldWithName] first.
  626. Future<void> tapDialogOkButton() async {
  627. final field = find.byWidgetPredicate(
  628. (widget) =>
  629. widget is PrimaryTextButton &&
  630. widget.label == LocaleKeys.button_OK.tr(),
  631. );
  632. await tapButton(field);
  633. }
  634. /// Should call [tapGridFieldWithName] first.
  635. Future<void> tapDuplicatePropertyButton() async {
  636. final field = find.byWidgetPredicate(
  637. (widget) =>
  638. widget is FieldActionCell && widget.action == FieldAction.duplicate,
  639. );
  640. await tapButton(field);
  641. }
  642. /// Should call [tapGridFieldWithName] first.
  643. Future<void> tapHidePropertyButton() async {
  644. final field = find.byWidgetPredicate(
  645. (widget) =>
  646. widget is FieldActionCell && widget.action == FieldAction.hide,
  647. );
  648. await tapButton(field);
  649. }
  650. Future<void> tapHidePropertyButtonInFieldEditor() async {
  651. final button = find.byType(HideFieldButton);
  652. await tapButton(button);
  653. }
  654. Future<void> tapRowDetailPageRowActionButton() async {
  655. await tapButton(find.byType(RowActionButton));
  656. }
  657. Future<void> tapRowDetailPageCreatePropertyButton() async {
  658. await tapButton(find.byType(CreateRowFieldButton));
  659. }
  660. Future<void> tapRowDetailPageDeleteRowButton() async {
  661. await tapButton(find.byType(RowDetailPageDeleteButton));
  662. }
  663. Future<void> tapRowDetailPageDuplicateRowButton() async {
  664. await tapButton(find.byType(RowDetailPageDuplicateButton));
  665. }
  666. Future<void> tapTypeOptionButton() async {
  667. await tapButton(find.byType(SwitchFieldButton));
  668. }
  669. Future<void> tapEscButton() async {
  670. await sendKeyEvent(LogicalKeyboardKey.escape);
  671. }
  672. /// Must call [tapTypeOptionButton] first.
  673. Future<void> selectFieldType(FieldType fieldType) async {
  674. final fieldTypeCell = find.byType(FieldTypeCell);
  675. final fieldTypeButton = find.descendant(
  676. of: fieldTypeCell,
  677. matching: find.byWidgetPredicate(
  678. (widget) => widget is FlowyText && widget.text == fieldType.title(),
  679. ),
  680. );
  681. await tapButton(fieldTypeButton);
  682. }
  683. /// Each field has its own cell, so we can find the corresponding cell by
  684. /// the field type after create a new field.
  685. Future<void> findCellByFieldType(FieldType fieldType) async {
  686. final finder = finderForFieldType(fieldType);
  687. expect(finder, findsWidgets);
  688. }
  689. Future<void> assertNumberOfFieldsInGridPage(int num) async {
  690. expect(find.byType(GridFieldCell), findsNWidgets(num));
  691. }
  692. Future<void> assertNumberOfRowsInGridPage(int num) async {
  693. expect(
  694. find.byType(GridRow, skipOffstage: false),
  695. findsNWidgets(num),
  696. );
  697. }
  698. Future<void> assertDocumentExistInRowDetailPage() async {
  699. expect(find.byType(RowDocument), findsOneWidget);
  700. }
  701. /// Check the field type of the [FieldCellButton] is the same as the name.
  702. Future<void> assertFieldTypeWithFieldName(
  703. String name,
  704. FieldType fieldType,
  705. ) async {
  706. final field = find.byWidgetPredicate(
  707. (widget) =>
  708. widget is FieldCellButton &&
  709. widget.field.fieldType == fieldType &&
  710. widget.field.name == name,
  711. );
  712. expect(field, findsOneWidget);
  713. }
  714. void assertFirstFieldInRowDetailByType(FieldType fieldType) {
  715. final firstField = find
  716. .descendant(
  717. of: find.byType(RowDetailPage),
  718. matching: find.byType(FieldCellButton),
  719. )
  720. .first;
  721. final widget = this.widget<FieldCellButton>(firstField);
  722. expect(widget.field.fieldType, fieldType);
  723. }
  724. Future<void> findFieldWithName(String name) async {
  725. final field = find.byWidgetPredicate(
  726. (widget) => widget is FieldCellButton && widget.field.name == name,
  727. );
  728. expect(field, findsOneWidget);
  729. }
  730. Future<void> noFieldWithName(String name) async {
  731. final field = find.byWidgetPredicate(
  732. (widget) => widget is FieldCellButton && widget.field.name == name,
  733. );
  734. expect(field, findsNothing);
  735. }
  736. Future<void> renameField(String newName) async {
  737. final textField = find.byType(FieldNameTextField);
  738. expect(textField, findsOneWidget);
  739. await enterText(textField, newName);
  740. await pumpAndSettle();
  741. }
  742. Future<void> dismissFieldEditor() async {
  743. await sendKeyEvent(LogicalKeyboardKey.escape);
  744. await pumpAndSettle(const Duration(milliseconds: 200));
  745. }
  746. Future<void> findFieldEditor(dynamic matcher) async {
  747. final finder = find.byType(FieldEditor);
  748. expect(finder, matcher);
  749. }
  750. Future<void> findDateEditor(dynamic matcher) async {
  751. final finder = find.byType(DateCellEditor);
  752. expect(finder, matcher);
  753. }
  754. Future<void> findSelectOptionEditor(dynamic matcher) async {
  755. final finder = find.byType(SelectOptionCellEditor);
  756. expect(finder, matcher);
  757. }
  758. Future<void> dismissCellEditor() async {
  759. await sendKeyEvent(LogicalKeyboardKey.escape);
  760. await pumpAndSettle();
  761. }
  762. Future<void> tapCreateRowButtonInGrid() async {
  763. await tapButton(find.byType(GridAddRowButton));
  764. }
  765. Future<void> tapCreateRowButtonInRowMenuOfGrid() async {
  766. await tapButton(find.byType(InsertRowButton));
  767. }
  768. Future<void> tapRowMenuButtonInGrid() async {
  769. await tapButton(find.byType(RowMenuButton));
  770. }
  771. /// Should call [tapRowMenuButtonInGrid] first.
  772. Future<void> tapDeleteOnRowMenu() async {
  773. await tapButtonWithName(LocaleKeys.grid_row_delete.tr());
  774. }
  775. Future<void> assertRowCountInGridPage(int num) async {
  776. final text = find.byWidgetPredicate(
  777. (widget) => widget is FlowyText && widget.text == rowCountString(num),
  778. );
  779. expect(text, findsOneWidget);
  780. }
  781. Future<void> createField(FieldType fieldType, String name) async {
  782. await scrollToRight(find.byType(GridPage));
  783. await tapNewPropertyButton();
  784. await renameField(name);
  785. await tapTypeOptionButton();
  786. await selectFieldType(fieldType);
  787. await dismissFieldEditor();
  788. }
  789. Future<void> tapDatabaseSettingButton() async {
  790. await tapButton(find.byType(SettingButton));
  791. }
  792. Future<void> tapDatabaseFilterButton() async {
  793. await tapButton(find.byType(FilterButton));
  794. }
  795. Future<void> tapDatabaseSortButton() async {
  796. await tapButton(find.byType(SortButton));
  797. }
  798. Future<void> tapCreateFilterByFieldType(
  799. FieldType fieldType,
  800. String title,
  801. ) async {
  802. final findFilter = find.byWidgetPredicate(
  803. (widget) =>
  804. widget is GridFilterPropertyCell &&
  805. widget.fieldInfo.fieldType == fieldType &&
  806. widget.fieldInfo.name == title,
  807. );
  808. await tapButton(findFilter);
  809. }
  810. Future<void> tapFilterButtonInGrid(String filterName) async {
  811. final findFilter = find.byType(FilterMenuItem);
  812. final button = find.descendant(
  813. of: findFilter,
  814. matching: find.text(filterName),
  815. );
  816. await tapButton(button);
  817. }
  818. Future<void> tapCreateSortByFieldType(
  819. FieldType fieldType,
  820. String title,
  821. ) async {
  822. final findSort = find.byWidgetPredicate(
  823. (widget) =>
  824. widget is GridSortPropertyCell &&
  825. widget.fieldInfo.fieldType == fieldType &&
  826. widget.fieldInfo.name == title,
  827. );
  828. await tapButton(findSort);
  829. }
  830. // Must call [tapSortMenuInSettingBar] first.
  831. Future<void> tapCreateSortByFieldTypeInSortMenu(
  832. FieldType fieldType,
  833. String title,
  834. ) async {
  835. await tapButton(find.byType(DatabaseAddSortButton));
  836. final findSort = find.byWidgetPredicate(
  837. (widget) =>
  838. widget is GridSortPropertyCell &&
  839. widget.fieldInfo.fieldType == fieldType &&
  840. widget.fieldInfo.name == title,
  841. );
  842. await tapButton(findSort);
  843. await pumpAndSettle();
  844. }
  845. Future<void> tapSortMenuInSettingBar() async {
  846. await tapButton(find.byType(SortMenu));
  847. await pumpAndSettle();
  848. }
  849. /// Must call [tapSortMenuInSettingBar] first.
  850. Future<void> tapSortButtonByName(String name) async {
  851. final findSortItem = find.byWidgetPredicate(
  852. (widget) =>
  853. widget is DatabaseSortItem && widget.sortInfo.fieldInfo.name == name,
  854. );
  855. await tapButton(findSortItem);
  856. }
  857. /// Must call [tapSortButtonByName] first.
  858. Future<void> tapSortByDescending() async {
  859. await tapButton(
  860. find.descendant(
  861. of: find.byType(OrderPannelItem),
  862. matching: find.byWidgetPredicate(
  863. (widget) =>
  864. widget is FlowyText &&
  865. widget.text == LocaleKeys.grid_sort_descending.tr(),
  866. ),
  867. ),
  868. );
  869. await sendKeyEvent(LogicalKeyboardKey.escape);
  870. await pumpAndSettle();
  871. }
  872. /// Must call [tapSortMenuInSettingBar] first.
  873. Future<void> tapAllSortButton() async {
  874. await tapButton(find.byType(DatabaseDeleteSortButton));
  875. }
  876. Future<void> scrollOptionFilterListByOffset(Offset offset) async {
  877. await drag(find.byType(SelectOptionFilterEditor), offset);
  878. await pumpAndSettle();
  879. }
  880. Future<void> enterTextInTextFilter(String text) async {
  881. final findEditor = find.byType(TextFilterEditor);
  882. final findTextField = find.descendant(
  883. of: findEditor,
  884. matching: find.byType(FlowyTextField),
  885. );
  886. await enterText(findTextField, text);
  887. await pumpAndSettle(const Duration(milliseconds: 300));
  888. }
  889. Future<void> tapDisclosureButtonInFinder(Finder finder) async {
  890. final findDisclosure = find.descendant(
  891. of: finder,
  892. matching: find.byType(DisclosureButton),
  893. );
  894. await tapButton(findDisclosure);
  895. }
  896. /// must call [tapDisclosureButtonInFinder] first.
  897. Future<void> tapDeleteFilterButtonInGrid() async {
  898. await tapButton(find.text(LocaleKeys.grid_settings_deleteFilter.tr()));
  899. }
  900. Future<void> tapCheckboxFilterButtonInGrid() async {
  901. await tapButton(find.byType(CheckboxFilterConditionList));
  902. }
  903. Future<void> tapChecklistFilterButtonInGrid() async {
  904. await tapButton(find.byType(ChecklistFilterConditionList));
  905. }
  906. /// The [SelectOptionFilterList] must show up first.
  907. Future<void> tapOptionFilterWithName(String name) async {
  908. final findCell = find.descendant(
  909. of: find.byType(SelectOptionFilterList),
  910. matching: find.byWidgetPredicate(
  911. (widget) =>
  912. widget is SelectOptionFilterCell && widget.option.name == name,
  913. skipOffstage: false,
  914. ),
  915. skipOffstage: false,
  916. );
  917. expect(findCell, findsOneWidget);
  918. await tapButton(findCell, warnIfMissed: false);
  919. }
  920. Future<void> tapCheckedButtonOnCheckboxFilter() async {
  921. final button = find.descendant(
  922. of: find.byType(HoverButton),
  923. matching: find.text(LocaleKeys.grid_checkboxFilter_isChecked.tr()),
  924. );
  925. await tapButton(button);
  926. }
  927. Future<void> tapUnCheckedButtonOnCheckboxFilter() async {
  928. final button = find.descendant(
  929. of: find.byType(HoverButton),
  930. matching: find.text(LocaleKeys.grid_checkboxFilter_isUnchecked.tr()),
  931. );
  932. await tapButton(button);
  933. }
  934. Future<void> tapCompletedButtonOnChecklistFilter() async {
  935. final button = find.descendant(
  936. of: find.byType(HoverButton),
  937. matching: find.text(LocaleKeys.grid_checklistFilter_isComplete.tr()),
  938. );
  939. await tapButton(button);
  940. }
  941. Future<void> tapUnCompletedButtonOnChecklistFilter() async {
  942. final button = find.descendant(
  943. of: find.byType(HoverButton),
  944. matching: find.text(LocaleKeys.grid_checklistFilter_isIncomplted.tr()),
  945. );
  946. await tapButton(button);
  947. }
  948. /// Should call [tapDatabaseSettingButton] first.
  949. Future<void> tapViewPropertiesButton() async {
  950. final findSettingItem = find.byType(DatabaseSettingItem);
  951. final findLayoutButton = find.byWidgetPredicate(
  952. (widget) =>
  953. widget is FlowyText &&
  954. widget.text == DatabaseSettingAction.showProperties.title(),
  955. );
  956. final button = find.descendant(
  957. of: findSettingItem,
  958. matching: findLayoutButton,
  959. );
  960. await tapButton(button);
  961. }
  962. /// Should call [tapDatabaseSettingButton] first.
  963. Future<void> tapDatabaseLayoutButton() async {
  964. final findSettingItem = find.byType(DatabaseSettingItem);
  965. final findLayoutButton = find.byWidgetPredicate(
  966. (widget) =>
  967. widget is FlowyText &&
  968. widget.text == DatabaseSettingAction.showLayout.title(),
  969. );
  970. final button = find.descendant(
  971. of: findSettingItem,
  972. matching: findLayoutButton,
  973. );
  974. await tapButton(button);
  975. }
  976. Future<void> tapCalendarLayoutSettingButton() async {
  977. final findSettingItem = find.byType(DatabaseSettingItem);
  978. final findLayoutButton = find.byWidgetPredicate(
  979. (widget) =>
  980. widget is FlowyText &&
  981. widget.text == DatabaseSettingAction.showCalendarLayout.title(),
  982. );
  983. final button = find.descendant(
  984. of: findSettingItem,
  985. matching: findLayoutButton,
  986. );
  987. await tapButton(button);
  988. }
  989. Future<void> tapFirstDayOfWeek() async {
  990. await tapButton(find.byType(FirstDayOfWeek));
  991. }
  992. Future<void> tapFirstDayOfWeekStartFromSunday() async {
  993. final finder = find.byWidgetPredicate(
  994. (widget) => widget is StartFromButton && widget.dayIndex == 0,
  995. );
  996. await tapButton(finder);
  997. }
  998. Future<void> tapFirstDayOfWeekStartFromMonday() async {
  999. final finder = find.byWidgetPredicate(
  1000. (widget) => widget is StartFromButton && widget.dayIndex == 1,
  1001. );
  1002. await tapButton(finder);
  1003. // Dismiss the popover overlay in cause of obscure the tapButton
  1004. // in the next test case.
  1005. await sendKeyEvent(LogicalKeyboardKey.escape);
  1006. await pumpAndSettle(const Duration(milliseconds: 200));
  1007. }
  1008. void assertFirstDayOfWeekStartFromMonday() {
  1009. final finder = find.byWidgetPredicate(
  1010. (widget) =>
  1011. widget is StartFromButton &&
  1012. widget.dayIndex == 1 &&
  1013. widget.isSelected == true,
  1014. );
  1015. expect(finder, findsOneWidget);
  1016. }
  1017. void assertFirstDayOfWeekStartFromSunday() {
  1018. final finder = find.byWidgetPredicate(
  1019. (widget) =>
  1020. widget is StartFromButton &&
  1021. widget.dayIndex == 0 &&
  1022. widget.isSelected == true,
  1023. );
  1024. expect(finder, findsOneWidget);
  1025. }
  1026. Future<void> scrollToToday() async {
  1027. final todayCell = find.byWidgetPredicate(
  1028. (widget) => widget is CalendarDayCard && widget.isToday,
  1029. );
  1030. final scrollable = find
  1031. .descendant(
  1032. of: find.byType(MonthView<CalendarDayEvent>),
  1033. matching: find.byWidgetPredicate(
  1034. (widget) => widget is Scrollable && widget.axis == Axis.vertical,
  1035. ),
  1036. )
  1037. .first;
  1038. await scrollUntilVisible(
  1039. todayCell,
  1040. 300,
  1041. scrollable: scrollable,
  1042. );
  1043. await pumpAndSettle(const Duration(milliseconds: 300));
  1044. }
  1045. Future<void> hoverOnTodayCalendarCell() async {
  1046. final todayCell = find.byWidgetPredicate(
  1047. (widget) => widget is CalendarDayCard && widget.isToday,
  1048. );
  1049. await hoverOnWidget(todayCell);
  1050. }
  1051. Future<void> tapAddCalendarEventButton() async {
  1052. final findFlowyButton = find.byType(FlowyIconButton);
  1053. final findNewEventButton = find.byType(NewEventButton);
  1054. final button = find.descendant(
  1055. of: findNewEventButton,
  1056. matching: findFlowyButton,
  1057. );
  1058. await tapButton(button);
  1059. }
  1060. /// Checks for a certain number of events. Parameters [date] and [title] can
  1061. /// also be provided to restrict the scope of the search
  1062. void assertNumberOfEventsInCalendar(int number, {String? title}) {
  1063. Finder findEvents = find.byType(EventCard);
  1064. if (title != null) {
  1065. findEvents = find.descendant(of: findEvents, matching: find.text(title));
  1066. }
  1067. expect(findEvents, findsNWidgets(number));
  1068. }
  1069. void assertNumberOfEventsOnSpecificDay(
  1070. int number,
  1071. DateTime date, {
  1072. String? title,
  1073. }) {
  1074. final findDayCell = find.byWidgetPredicate(
  1075. (widget) =>
  1076. widget is CalendarDayCard &&
  1077. isSameDay(
  1078. widget.date,
  1079. date,
  1080. ),
  1081. );
  1082. Finder findEvents = find.descendant(
  1083. of: findDayCell,
  1084. matching: find.byType(EventCard),
  1085. );
  1086. if (title != null) {
  1087. findEvents = find.descendant(of: findEvents, matching: find.text(title));
  1088. }
  1089. expect(findEvents, findsNWidgets(number));
  1090. }
  1091. Future<void> doubleClickCalendarCell(DateTime date) async {
  1092. final todayCell = find.byWidgetPredicate(
  1093. (widget) => widget is CalendarDayCard && isSameDay(date, widget.date),
  1094. );
  1095. final location = getTopLeft(todayCell).translate(10, 10);
  1096. await doubleTapAt(location);
  1097. }
  1098. Future<void> openCalendarEvent({required index, DateTime? date}) async {
  1099. final findDayCell = find.byWidgetPredicate(
  1100. (widget) =>
  1101. widget is CalendarDayCard &&
  1102. isSameDay(widget.date, date ?? DateTime.now()),
  1103. );
  1104. final cards = find.descendant(
  1105. of: findDayCell,
  1106. matching: find.byType(EventCard),
  1107. );
  1108. await tapButton(cards.at(index));
  1109. }
  1110. Future<void> dragDropRescheduleCalendarEvent(DateTime startDate) async {
  1111. final findEventCard = find.byType(EventCard);
  1112. await drag(findEventCard.first, const Offset(0, 300));
  1113. await pumpAndSettle();
  1114. }
  1115. Future<void> tapCreateLinkedDatabaseViewButton(AddButtonAction action) async {
  1116. final findAddButton = find.byType(AddDatabaseViewButton);
  1117. await tapButton(findAddButton);
  1118. final findCreateButton = find.byWidgetPredicate(
  1119. (widget) =>
  1120. widget is TarBarAddButtonActionCell && widget.action == action,
  1121. );
  1122. await tapButton(findCreateButton);
  1123. }
  1124. Future<void> tapTabBarLinkedViewByViewName(String name) async {
  1125. final viewButton = findTabBarLinkViewByViewName(name);
  1126. await tapButton(viewButton);
  1127. }
  1128. Finder findTabBarLinkViewByViewLayout(ViewLayoutPB layout) {
  1129. return find.byWidgetPredicate(
  1130. (widget) => widget is TabBarItemButton && widget.view.layout == layout,
  1131. );
  1132. }
  1133. Finder findTabBarLinkViewByViewName(String name) {
  1134. return find.byWidgetPredicate(
  1135. (widget) => widget is TabBarItemButton && widget.view.name == name,
  1136. );
  1137. }
  1138. Future<void> renameLinkedView(Finder linkedView, String name) async {
  1139. await tap(linkedView, buttons: kSecondaryButton);
  1140. await pumpAndSettle();
  1141. await tapButton(
  1142. find.byWidgetPredicate(
  1143. (widget) =>
  1144. widget is ActionCellWidget &&
  1145. widget.action == TabBarViewAction.rename,
  1146. ),
  1147. );
  1148. await enterText(
  1149. find.descendant(
  1150. of: find.byType(FlowyFormTextInput),
  1151. matching: find.byType(TextFormField),
  1152. ),
  1153. name,
  1154. );
  1155. final field = find.byWidgetPredicate(
  1156. (widget) =>
  1157. widget is PrimaryTextButton &&
  1158. widget.label == LocaleKeys.button_OK.tr(),
  1159. );
  1160. await tapButton(field);
  1161. }
  1162. Future<void> deleteDatebaseView(Finder linkedView) async {
  1163. await tap(linkedView, buttons: kSecondaryButton);
  1164. await pumpAndSettle();
  1165. await tapButton(
  1166. find.byWidgetPredicate(
  1167. (widget) =>
  1168. widget is ActionCellWidget &&
  1169. widget.action == TabBarViewAction.delete,
  1170. ),
  1171. );
  1172. final okButton = find.byWidgetPredicate(
  1173. (widget) =>
  1174. widget is PrimaryTextButton &&
  1175. widget.label == LocaleKeys.button_OK.tr(),
  1176. );
  1177. await tapButton(okButton);
  1178. }
  1179. Future<void> assertCurrentDatabaseTagIs(DatabaseLayoutPB layout) async {
  1180. switch (layout) {
  1181. case DatabaseLayoutPB.Board:
  1182. expect(find.byType(BoardPage), findsOneWidget);
  1183. break;
  1184. case DatabaseLayoutPB.Calendar:
  1185. expect(find.byType(CalendarPage), findsOneWidget);
  1186. break;
  1187. case DatabaseLayoutPB.Grid:
  1188. expect(find.byType(GridPage), findsOneWidget);
  1189. break;
  1190. default:
  1191. throw Exception('Unknown database layout type: $layout');
  1192. }
  1193. }
  1194. Future<void> selectDatabaseLayoutType(DatabaseLayoutPB layout) async {
  1195. final findLayoutCell = find.byType(DatabaseViewLayoutCell);
  1196. final findText = find.byWidgetPredicate(
  1197. (widget) => widget is FlowyText && widget.text == layout.layoutName(),
  1198. );
  1199. final button = find.descendant(
  1200. of: findLayoutCell,
  1201. matching: findText,
  1202. );
  1203. await tapButton(button);
  1204. }
  1205. Future<void> assertCurrentDatabaseLayoutType(DatabaseLayoutPB layout) async {
  1206. expect(finderForDatabaseLayoutType(layout), findsOneWidget);
  1207. }
  1208. Future<void> tapDatabaseRawDataButton() async {
  1209. await tapButtonWithName(LocaleKeys.importPanel_database.tr());
  1210. }
  1211. Future<void> tapAddSelectOptionButton() async {
  1212. await tapButtonWithName(LocaleKeys.grid_field_addSelectOption.tr());
  1213. }
  1214. Future<void> tapViewTogglePropertyVisibilityButtonByName(
  1215. String fieldName,
  1216. ) async {
  1217. final field = find.byWidgetPredicate(
  1218. (widget) =>
  1219. widget is GridPropertyCell && widget.fieldInfo.name == fieldName,
  1220. );
  1221. final toggleVisibilityButton =
  1222. find.descendant(of: field, matching: find.byType(FlowyIconButton));
  1223. await tapButton(toggleVisibilityButton);
  1224. }
  1225. }
  1226. Finder finderForDatabaseLayoutType(DatabaseLayoutPB layout) {
  1227. switch (layout) {
  1228. case DatabaseLayoutPB.Board:
  1229. return find.byType(BoardPage);
  1230. case DatabaseLayoutPB.Calendar:
  1231. return find.byType(CalendarPage);
  1232. case DatabaseLayoutPB.Grid:
  1233. return find.byType(GridPage);
  1234. default:
  1235. throw Exception('Unknown database layout type: $layout');
  1236. }
  1237. }
  1238. Finder finderForFieldType(FieldType fieldType) {
  1239. switch (fieldType) {
  1240. case FieldType.Checkbox:
  1241. return find.byType(GridCheckboxCell, skipOffstage: false);
  1242. case FieldType.DateTime:
  1243. return find.byType(GridDateCell, skipOffstage: false);
  1244. case FieldType.LastEditedTime:
  1245. case FieldType.CreatedTime:
  1246. return find.byType(GridTimestampCell, skipOffstage: false);
  1247. case FieldType.SingleSelect:
  1248. return find.byType(GridSingleSelectCell, skipOffstage: false);
  1249. case FieldType.MultiSelect:
  1250. return find.byType(GridMultiSelectCell, skipOffstage: false);
  1251. case FieldType.Checklist:
  1252. return find.byType(GridChecklistCell, skipOffstage: false);
  1253. case FieldType.Number:
  1254. return find.byType(GridNumberCell, skipOffstage: false);
  1255. case FieldType.RichText:
  1256. return find.byType(GridTextCell, skipOffstage: false);
  1257. case FieldType.URL:
  1258. return find.byType(GridURLCell, skipOffstage: false);
  1259. default:
  1260. throw Exception('Unknown field type: $fieldType');
  1261. }
  1262. }