database_test_op.dart 45 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468
  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/header/type_option/timestamp.dart';
  28. import 'package:appflowy/plugins/database_view/grid/presentation/widgets/row/row.dart';
  29. import 'package:appflowy/plugins/database_view/grid/presentation/widgets/sort/create_sort_list.dart';
  30. import 'package:appflowy/plugins/database_view/grid/presentation/widgets/sort/order_panel.dart';
  31. import 'package:appflowy/plugins/database_view/grid/presentation/widgets/sort/sort_editor.dart';
  32. import 'package:appflowy/plugins/database_view/grid/presentation/widgets/sort/sort_menu.dart';
  33. import 'package:appflowy/plugins/database_view/grid/presentation/widgets/toolbar/filter_button.dart';
  34. import 'package:appflowy/plugins/database_view/grid/presentation/widgets/toolbar/grid_layout.dart';
  35. import 'package:appflowy/plugins/database_view/grid/presentation/widgets/toolbar/sort_button.dart';
  36. import 'package:appflowy/plugins/database_view/tar_bar/tab_bar_header.dart';
  37. import 'package:appflowy/plugins/database_view/tar_bar/tar_bar_add_button.dart';
  38. import 'package:appflowy/plugins/database_view/widgets/database_layout_ext.dart';
  39. import 'package:appflowy/plugins/database_view/widgets/field/grid_property.dart';
  40. import 'package:appflowy/plugins/database_view/widgets/row/accessory/cell_accessory.dart';
  41. import 'package:appflowy/plugins/database_view/widgets/row/cells/cells.dart';
  42. import 'package:appflowy/plugins/database_view/widgets/row/cells/checklist_cell/checklist_cell_editor.dart';
  43. import 'package:appflowy/plugins/database_view/widgets/row/cells/checklist_cell/checklist_progress_bar.dart';
  44. import 'package:appflowy/plugins/database_view/widgets/row/cells/date_cell/date_editor.dart';
  45. import 'package:appflowy/plugins/database_view/widgets/row/cells/select_option_cell/extension.dart';
  46. import 'package:appflowy/plugins/database_view/widgets/row/cells/select_option_cell/select_option_editor.dart';
  47. import 'package:appflowy/plugins/database_view/widgets/row/cells/select_option_cell/text_field.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(IncludeTimeButton);
  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> toggleDateRange() async {
  310. final findDateEditor = find.byType(EndTimeButton);
  311. final findToggle = find.byType(Toggle);
  312. final finder = find.descendant(
  313. of: findDateEditor,
  314. matching: findToggle,
  315. );
  316. await tapButton(finder);
  317. }
  318. Future<void> changeDateFormat() async {
  319. final findDateEditor = find.byType(DateCellEditor);
  320. final findDateTimeOptionButton = find.byType(DateTypeOptionButton);
  321. final finder = find.descendant(
  322. of: findDateEditor,
  323. matching: findDateTimeOptionButton,
  324. );
  325. await tapButton(finder);
  326. final findDateFormatButton = find.byType(DateFormatButton);
  327. await tapButton(findDateFormatButton);
  328. final findNewDateFormat = find.text("Day/Month/Year");
  329. await tapButton(findNewDateFormat);
  330. }
  331. Future<void> changeTimeFormat() async {
  332. final findDateEditor = find.byType(DateCellEditor);
  333. final findDateTimeOptionButton = find.byType(DateTypeOptionButton);
  334. final finder = find.descendant(
  335. of: findDateEditor,
  336. matching: findDateTimeOptionButton,
  337. );
  338. await tapButton(finder);
  339. final findDateFormatButton = find.byType(TimeFormatButton);
  340. await tapButton(findDateFormatButton);
  341. final findNewDateFormat = find.text("12 hour");
  342. await tapButton(findNewDateFormat);
  343. }
  344. Future<void> clearDate() async {
  345. final findDateEditor = find.byType(DateCellEditor);
  346. final findClearButton = find.byType(ClearDateButton);
  347. final finder = find.descendant(
  348. of: findDateEditor,
  349. matching: findClearButton,
  350. );
  351. await tapButton(finder);
  352. }
  353. Future<void> tapSelectOptionCellInGrid({
  354. required int rowIndex,
  355. required FieldType fieldType,
  356. }) async {
  357. assert(
  358. fieldType == FieldType.SingleSelect || fieldType == FieldType.MultiSelect,
  359. );
  360. final findRow = find.byType(GridRow);
  361. final findCell = finderForFieldType(fieldType);
  362. final cell = find.descendant(
  363. of: findRow.at(rowIndex),
  364. matching: findCell,
  365. );
  366. await tapButton(cell);
  367. }
  368. /// The [SelectOptionCellEditor] must be opened first.
  369. Future<void> createOption({
  370. required String name,
  371. }) async {
  372. final findEditor = find.byType(SelectOptionCellEditor);
  373. expect(findEditor, findsOneWidget);
  374. final findTextField = find.byType(SelectOptionTextField);
  375. expect(findTextField, findsOneWidget);
  376. await enterText(findTextField, name);
  377. await pump();
  378. await testTextInput.receiveAction(TextInputAction.done);
  379. await pumpAndSettle();
  380. }
  381. Future<void> selectOption({
  382. required String name,
  383. }) async {
  384. final option = find.byWidgetPredicate(
  385. (widget) => widget is SelectOptionTagCell && widget.option.name == name,
  386. );
  387. await tapButton(option);
  388. }
  389. Future<void> findSelectOptionWithNameInGrid({
  390. required int rowIndex,
  391. required String name,
  392. }) async {
  393. final findRow = find.byType(GridRow);
  394. final option = find.byWidgetPredicate(
  395. (widget) => widget is SelectOptionTag && widget.name == name,
  396. );
  397. final cell = find.descendant(
  398. of: findRow.at(rowIndex),
  399. matching: option,
  400. );
  401. expect(cell, findsOneWidget);
  402. }
  403. Future<void> assertNumberOfSelectedOptionsInGrid({
  404. required int rowIndex,
  405. required Matcher matcher,
  406. }) async {
  407. final findRow = find.byType(GridRow);
  408. final options = find.byWidgetPredicate(
  409. (widget) => widget is SelectOptionTag,
  410. );
  411. final cell = find.descendant(
  412. of: findRow.at(rowIndex),
  413. matching: options,
  414. );
  415. expect(cell, matcher);
  416. }
  417. Future<void> tapChecklistCellInGrid({required int rowIndex}) async {
  418. final findRow = find.byType(GridRow);
  419. final findCell = finderForFieldType(FieldType.Checklist);
  420. final cell = find.descendant(
  421. of: findRow.at(rowIndex),
  422. matching: findCell,
  423. );
  424. await tapButton(cell);
  425. }
  426. void assertChecklistEditorVisible({required bool visible}) {
  427. final editor = find.byType(GridChecklistCellEditor);
  428. if (visible) {
  429. expect(editor, findsOneWidget);
  430. } else {
  431. expect(editor, findsNothing);
  432. }
  433. }
  434. Future<void> createNewChecklistTask({
  435. required String name,
  436. enter = false,
  437. button = false,
  438. }) async {
  439. assert(!(enter && button));
  440. final textField = find.descendant(
  441. of: find.byType(NewTaskItem),
  442. matching: find.byType(TextField),
  443. );
  444. await enterText(textField, name);
  445. await pumpAndSettle();
  446. if (enter) {
  447. await testTextInput.receiveAction(TextInputAction.done);
  448. await pumpAndSettle();
  449. } else {
  450. await tapButton(
  451. find.descendant(
  452. of: find.byType(NewTaskItem),
  453. matching: find.byType(FlowyTextButton),
  454. ),
  455. );
  456. }
  457. }
  458. void assertChecklistTaskInEditor({
  459. required int index,
  460. required String name,
  461. required bool isChecked,
  462. }) {
  463. final task = find.byType(ChecklistItem).at(index);
  464. final widget = this.widget<ChecklistItem>(task);
  465. assert(
  466. widget.option.data.name == name && widget.option.isSelected == isChecked,
  467. );
  468. }
  469. Future<void> renameChecklistTask({
  470. required int index,
  471. required String name,
  472. }) async {
  473. final textField = find
  474. .descendant(
  475. of: find.byType(ChecklistItem),
  476. matching: find.byType(TextField),
  477. )
  478. .at(index);
  479. await enterText(textField, name);
  480. await testTextInput.receiveAction(TextInputAction.done);
  481. await pumpAndSettle();
  482. }
  483. Future<void> checkChecklistTask({required int index}) async {
  484. final button = find.descendant(
  485. of: find.byType(ChecklistItem).at(index),
  486. matching: find.byWidgetPredicate(
  487. (widget) => widget is FlowySvg && widget.svg == FlowySvgs.uncheck_s,
  488. ),
  489. );
  490. await tapButton(button);
  491. }
  492. Future<void> deleteChecklistTask({required int index}) async {
  493. final task = find.byType(ChecklistItem).at(index);
  494. await startGesture(getCenter(task), kind: PointerDeviceKind.mouse);
  495. await pumpAndSettle();
  496. final button = find.byWidgetPredicate(
  497. (widget) => widget is FlowySvg && widget.svg == FlowySvgs.delete_s,
  498. );
  499. await tapButton(button);
  500. }
  501. Future<void> openFirstRowDetailPage() async {
  502. await hoverOnFirstRowOfGrid();
  503. final expandButton = find.byType(PrimaryCellAccessory);
  504. expect(expandButton, findsOneWidget);
  505. await tapButton(expandButton);
  506. }
  507. void assertRowDetailPageOpened() async {
  508. final findRowDetailPage = find.byType(RowDetailPage);
  509. expect(findRowDetailPage, findsOneWidget);
  510. }
  511. Future<void> dismissRowDetailPage() async {
  512. // use tap empty area instead of clicking ESC to dismiss the row detail page
  513. // sometimes, the ESC key is not working.
  514. await simulateKeyEvent(LogicalKeyboardKey.escape);
  515. await pumpAndSettle();
  516. final findRowDetailPage = find.byType(RowDetailPage);
  517. if (findRowDetailPage.evaluate().isNotEmpty) {
  518. await tapAt(const Offset(0, 0));
  519. await pumpAndSettle();
  520. }
  521. }
  522. Future<void> editTitleInRowDetailPage(String title) async {
  523. final titleField = find.byType(GridTextCell);
  524. await enterText(titleField, title);
  525. await pumpAndSettle();
  526. }
  527. Future<void> hoverRowBanner() async {
  528. final banner = find.byType(RowBanner);
  529. expect(banner, findsOneWidget);
  530. await startGesture(
  531. getCenter(banner),
  532. kind: PointerDeviceKind.mouse,
  533. );
  534. await pumpAndSettle();
  535. }
  536. Future<void> openEmojiPicker() async {
  537. await tapButton(find.byType(EmojiPickerButton));
  538. await tapButton(find.byType(EmojiSelectionMenu));
  539. }
  540. Future<void> tapDateCellInRowDetailPage() async {
  541. final findDateCell = find.byType(GridDateCell);
  542. await tapButton(findDateCell);
  543. }
  544. Future<void> tapGridFieldWithNameInRowDetailPage(String name) async {
  545. final fields = find.byWidgetPredicate(
  546. (widget) => widget is FieldCellButton && widget.field.name == name,
  547. );
  548. final field = find.descendant(
  549. of: find.byType(RowDetailPage),
  550. matching: fields,
  551. );
  552. await tapButton(field);
  553. await pumpAndSettle();
  554. }
  555. Future<void> duplicateRowInRowDetailPage() async {
  556. final duplicateButton = find.byType(RowDetailPageDuplicateButton);
  557. await tapButton(duplicateButton);
  558. }
  559. Future<void> deleteRowInRowDetailPage() async {
  560. final deleteButton = find.byType(RowDetailPageDeleteButton);
  561. await tapButton(deleteButton);
  562. }
  563. Future<TestGesture> hoverOnFieldInRowDetail({required int index}) async {
  564. final fieldButtons = find.byType(FieldCellButton);
  565. final button = find
  566. .descendant(of: find.byType(RowDetailPage), matching: fieldButtons)
  567. .at(index);
  568. return startGesture(
  569. getCenter(button),
  570. kind: PointerDeviceKind.mouse,
  571. );
  572. }
  573. Future<void> reorderFieldInRowDetail({required double offset}) async {
  574. final thumb = find
  575. .byWidgetPredicate(
  576. (widget) => widget is ReorderableDragStartListener && widget.enabled,
  577. )
  578. .first;
  579. await drag(
  580. thumb,
  581. Offset(0, offset),
  582. kind: PointerDeviceKind.mouse,
  583. );
  584. await pumpAndSettle();
  585. }
  586. Future<void> scrollGridByOffset(Offset offset) async {
  587. await drag(find.byType(GridPage), offset);
  588. await pumpAndSettle();
  589. }
  590. Future<void> scrollRowDetailByOffset(Offset offset) async {
  591. await drag(find.byType(RowDetailPage), offset);
  592. await pumpAndSettle();
  593. }
  594. Future<void> scrollToRight(Finder find) async {
  595. final size = getSize(find);
  596. await drag(find, Offset(-size.width, 0));
  597. await pumpAndSettle(const Duration(milliseconds: 500));
  598. }
  599. Future<void> tapNewPropertyButton() async {
  600. await tapButtonWithName(LocaleKeys.grid_field_newProperty.tr());
  601. await pumpAndSettle();
  602. }
  603. Future<void> tapGridFieldWithName(String name) async {
  604. final field = find.byWidgetPredicate(
  605. (widget) => widget is FieldCellButton && widget.field.name == name,
  606. );
  607. await tapButton(field);
  608. await pumpAndSettle();
  609. }
  610. /// Should call [tapGridFieldWithName] first.
  611. Future<void> tapEditPropertyButton() async {
  612. await tapButtonWithName(LocaleKeys.grid_field_editProperty.tr());
  613. await pumpAndSettle(const Duration(milliseconds: 200));
  614. }
  615. /// Should call [tapGridFieldWithName] first.
  616. Future<void> tapDeletePropertyButton() async {
  617. final field = find.byWidgetPredicate(
  618. (widget) =>
  619. widget is FieldActionCell && widget.action == FieldAction.delete,
  620. );
  621. await tapButton(field);
  622. }
  623. /// Should call [tapGridFieldWithName] first.
  624. Future<void> tapDialogOkButton() async {
  625. final field = find.byWidgetPredicate(
  626. (widget) =>
  627. widget is PrimaryTextButton &&
  628. widget.label == LocaleKeys.button_OK.tr(),
  629. );
  630. await tapButton(field);
  631. }
  632. /// Should call [tapGridFieldWithName] first.
  633. Future<void> tapDuplicatePropertyButton() async {
  634. final field = find.byWidgetPredicate(
  635. (widget) =>
  636. widget is FieldActionCell && widget.action == FieldAction.duplicate,
  637. );
  638. await tapButton(field);
  639. }
  640. /// Should call [tapGridFieldWithName] first.
  641. Future<void> tapHidePropertyButton() async {
  642. final field = find.byWidgetPredicate(
  643. (widget) =>
  644. widget is FieldActionCell && widget.action == FieldAction.hide,
  645. );
  646. await tapButton(field);
  647. }
  648. Future<void> tapHidePropertyButtonInFieldEditor() async {
  649. final button = find.byType(HideFieldButton);
  650. await tapButton(button);
  651. }
  652. Future<void> tapRowDetailPageRowActionButton() async {
  653. await tapButton(find.byType(RowActionButton));
  654. }
  655. Future<void> tapRowDetailPageCreatePropertyButton() async {
  656. await tapButton(find.byType(CreateRowFieldButton));
  657. }
  658. Future<void> tapRowDetailPageDeleteRowButton() async {
  659. await tapButton(find.byType(RowDetailPageDeleteButton));
  660. }
  661. Future<void> tapRowDetailPageDuplicateRowButton() async {
  662. await tapButton(find.byType(RowDetailPageDuplicateButton));
  663. }
  664. Future<void> tapTypeOptionButton() async {
  665. await tapButton(find.byType(SwitchFieldButton));
  666. }
  667. Future<void> tapEscButton() async {
  668. await sendKeyEvent(LogicalKeyboardKey.escape);
  669. }
  670. /// Must call [tapTypeOptionButton] first.
  671. Future<void> selectFieldType(FieldType fieldType) async {
  672. final fieldTypeCell = find.byType(FieldTypeCell);
  673. final fieldTypeButton = find.descendant(
  674. of: fieldTypeCell,
  675. matching: find.byWidgetPredicate(
  676. (widget) => widget is FlowyText && widget.text == fieldType.title(),
  677. ),
  678. );
  679. await tapButton(fieldTypeButton);
  680. }
  681. /// Each field has its own cell, so we can find the corresponding cell by
  682. /// the field type after create a new field.
  683. Future<void> findCellByFieldType(FieldType fieldType) async {
  684. final finder = finderForFieldType(fieldType);
  685. expect(finder, findsWidgets);
  686. }
  687. Future<void> assertNumberOfFieldsInGridPage(int num) async {
  688. expect(find.byType(GridFieldCell), findsNWidgets(num));
  689. }
  690. Future<void> assertNumberOfRowsInGridPage(int num) async {
  691. expect(
  692. find.byType(GridRow, skipOffstage: false),
  693. findsNWidgets(num),
  694. );
  695. }
  696. Future<void> assertDocumentExistInRowDetailPage() async {
  697. expect(find.byType(RowDocument), findsOneWidget);
  698. }
  699. /// Check the field type of the [FieldCellButton] is the same as the name.
  700. Future<void> assertFieldTypeWithFieldName(
  701. String name,
  702. FieldType fieldType,
  703. ) async {
  704. final field = find.byWidgetPredicate(
  705. (widget) =>
  706. widget is FieldCellButton &&
  707. widget.field.fieldType == fieldType &&
  708. widget.field.name == name,
  709. );
  710. expect(field, findsOneWidget);
  711. }
  712. void assertFirstFieldInRowDetailByType(FieldType fieldType) {
  713. final firstField = find
  714. .descendant(
  715. of: find.byType(RowDetailPage),
  716. matching: find.byType(FieldCellButton),
  717. )
  718. .first;
  719. final widget = this.widget<FieldCellButton>(firstField);
  720. expect(widget.field.fieldType, fieldType);
  721. }
  722. Future<void> findFieldWithName(String name) async {
  723. final field = find.byWidgetPredicate(
  724. (widget) => widget is FieldCellButton && widget.field.name == name,
  725. );
  726. expect(field, findsOneWidget);
  727. }
  728. Future<void> noFieldWithName(String name) async {
  729. final field = find.byWidgetPredicate(
  730. (widget) => widget is FieldCellButton && widget.field.name == name,
  731. );
  732. expect(field, findsNothing);
  733. }
  734. Future<void> renameField(String newName) async {
  735. final textField = find.byType(FieldNameTextField);
  736. expect(textField, findsOneWidget);
  737. await enterText(textField, newName);
  738. await pumpAndSettle();
  739. }
  740. Future<void> dismissFieldEditor() async {
  741. await sendKeyEvent(LogicalKeyboardKey.escape);
  742. await pumpAndSettle(const Duration(milliseconds: 200));
  743. }
  744. Future<void> findFieldEditor(dynamic matcher) async {
  745. final finder = find.byType(FieldEditor);
  746. expect(finder, matcher);
  747. }
  748. Future<void> findDateEditor(dynamic matcher) async {
  749. final finder = find.byType(DateCellEditor);
  750. expect(finder, matcher);
  751. }
  752. Future<void> findSelectOptionEditor(dynamic matcher) async {
  753. final finder = find.byType(SelectOptionCellEditor);
  754. expect(finder, matcher);
  755. }
  756. Future<void> dismissCellEditor() async {
  757. await sendKeyEvent(LogicalKeyboardKey.escape);
  758. await pumpAndSettle();
  759. }
  760. Future<void> tapCreateRowButtonInGrid() async {
  761. await tapButton(find.byType(GridAddRowButton));
  762. }
  763. Future<void> tapCreateRowButtonInRowMenuOfGrid() async {
  764. await tapButton(find.byType(InsertRowButton));
  765. }
  766. Future<void> tapRowMenuButtonInGrid() async {
  767. await tapButton(find.byType(RowMenuButton));
  768. }
  769. /// Should call [tapRowMenuButtonInGrid] first.
  770. Future<void> tapDeleteOnRowMenu() async {
  771. await tapButtonWithName(LocaleKeys.grid_row_delete.tr());
  772. }
  773. Future<void> assertRowCountInGridPage(int num) async {
  774. final text = find.byWidgetPredicate(
  775. (widget) => widget is FlowyText && widget.text == rowCountString(num),
  776. );
  777. expect(text, findsOneWidget);
  778. }
  779. Future<void> createField(FieldType fieldType, String name) async {
  780. await scrollToRight(find.byType(GridPage));
  781. await tapNewPropertyButton();
  782. await renameField(name);
  783. await tapTypeOptionButton();
  784. await selectFieldType(fieldType);
  785. await dismissFieldEditor();
  786. }
  787. Future<void> tapDatabaseSettingButton() async {
  788. await tapButton(find.byType(SettingButton));
  789. }
  790. Future<void> tapDatabaseFilterButton() async {
  791. await tapButton(find.byType(FilterButton));
  792. }
  793. Future<void> tapDatabaseSortButton() async {
  794. await tapButton(find.byType(SortButton));
  795. }
  796. Future<void> tapCreateFilterByFieldType(
  797. FieldType fieldType,
  798. String title,
  799. ) async {
  800. final findFilter = find.byWidgetPredicate(
  801. (widget) =>
  802. widget is GridFilterPropertyCell &&
  803. widget.fieldInfo.fieldType == fieldType &&
  804. widget.fieldInfo.name == title,
  805. );
  806. await tapButton(findFilter);
  807. }
  808. Future<void> tapFilterButtonInGrid(String filterName) async {
  809. final findFilter = find.byType(FilterMenuItem);
  810. final button = find.descendant(
  811. of: findFilter,
  812. matching: find.text(filterName),
  813. );
  814. await tapButton(button);
  815. }
  816. Future<void> tapCreateSortByFieldType(
  817. FieldType fieldType,
  818. String title,
  819. ) async {
  820. final findSort = find.byWidgetPredicate(
  821. (widget) =>
  822. widget is GridSortPropertyCell &&
  823. widget.fieldInfo.fieldType == fieldType &&
  824. widget.fieldInfo.name == title,
  825. );
  826. await tapButton(findSort);
  827. }
  828. // Must call [tapSortMenuInSettingBar] first.
  829. Future<void> tapCreateSortByFieldTypeInSortMenu(
  830. FieldType fieldType,
  831. String title,
  832. ) async {
  833. await tapButton(find.byType(DatabaseAddSortButton));
  834. final findSort = find.byWidgetPredicate(
  835. (widget) =>
  836. widget is GridSortPropertyCell &&
  837. widget.fieldInfo.fieldType == fieldType &&
  838. widget.fieldInfo.name == title,
  839. );
  840. await tapButton(findSort);
  841. await pumpAndSettle();
  842. }
  843. Future<void> tapSortMenuInSettingBar() async {
  844. await tapButton(find.byType(SortMenu));
  845. await pumpAndSettle();
  846. }
  847. /// Must call [tapSortMenuInSettingBar] first.
  848. Future<void> tapSortButtonByName(String name) async {
  849. final findSortItem = find.byWidgetPredicate(
  850. (widget) =>
  851. widget is DatabaseSortItem && widget.sortInfo.fieldInfo.name == name,
  852. );
  853. await tapButton(findSortItem);
  854. }
  855. /// Must call [tapSortButtonByName] first.
  856. Future<void> tapSortByDescending() async {
  857. await tapButton(
  858. find.descendant(
  859. of: find.byType(OrderPannelItem),
  860. matching: find.byWidgetPredicate(
  861. (widget) =>
  862. widget is FlowyText &&
  863. widget.text == LocaleKeys.grid_sort_descending.tr(),
  864. ),
  865. ),
  866. );
  867. await sendKeyEvent(LogicalKeyboardKey.escape);
  868. await pumpAndSettle();
  869. }
  870. /// Must call [tapSortMenuInSettingBar] first.
  871. Future<void> tapAllSortButton() async {
  872. await tapButton(find.byType(DatabaseDeleteSortButton));
  873. }
  874. Future<void> scrollOptionFilterListByOffset(Offset offset) async {
  875. await drag(find.byType(SelectOptionFilterEditor), offset);
  876. await pumpAndSettle();
  877. }
  878. Future<void> enterTextInTextFilter(String text) async {
  879. final findEditor = find.byType(TextFilterEditor);
  880. final findTextField = find.descendant(
  881. of: findEditor,
  882. matching: find.byType(FlowyTextField),
  883. );
  884. await enterText(findTextField, text);
  885. await pumpAndSettle(const Duration(milliseconds: 300));
  886. }
  887. Future<void> tapDisclosureButtonInFinder(Finder finder) async {
  888. final findDisclosure = find.descendant(
  889. of: finder,
  890. matching: find.byType(DisclosureButton),
  891. );
  892. await tapButton(findDisclosure);
  893. }
  894. /// must call [tapDisclosureButtonInFinder] first.
  895. Future<void> tapDeleteFilterButtonInGrid() async {
  896. await tapButton(find.text(LocaleKeys.grid_settings_deleteFilter.tr()));
  897. }
  898. Future<void> tapCheckboxFilterButtonInGrid() async {
  899. await tapButton(find.byType(CheckboxFilterConditionList));
  900. }
  901. Future<void> tapChecklistFilterButtonInGrid() async {
  902. await tapButton(find.byType(ChecklistFilterConditionList));
  903. }
  904. /// The [SelectOptionFilterList] must show up first.
  905. Future<void> tapOptionFilterWithName(String name) async {
  906. final findCell = find.descendant(
  907. of: find.byType(SelectOptionFilterList),
  908. matching: find.byWidgetPredicate(
  909. (widget) =>
  910. widget is SelectOptionFilterCell && widget.option.name == name,
  911. skipOffstage: false,
  912. ),
  913. skipOffstage: false,
  914. );
  915. expect(findCell, findsOneWidget);
  916. await tapButton(findCell, warnIfMissed: false);
  917. }
  918. Future<void> tapCheckedButtonOnCheckboxFilter() async {
  919. final button = find.descendant(
  920. of: find.byType(HoverButton),
  921. matching: find.text(LocaleKeys.grid_checkboxFilter_isChecked.tr()),
  922. );
  923. await tapButton(button);
  924. }
  925. Future<void> tapUnCheckedButtonOnCheckboxFilter() async {
  926. final button = find.descendant(
  927. of: find.byType(HoverButton),
  928. matching: find.text(LocaleKeys.grid_checkboxFilter_isUnchecked.tr()),
  929. );
  930. await tapButton(button);
  931. }
  932. Future<void> tapCompletedButtonOnChecklistFilter() async {
  933. final button = find.descendant(
  934. of: find.byType(HoverButton),
  935. matching: find.text(LocaleKeys.grid_checklistFilter_isComplete.tr()),
  936. );
  937. await tapButton(button);
  938. }
  939. Future<void> tapUnCompletedButtonOnChecklistFilter() async {
  940. final button = find.descendant(
  941. of: find.byType(HoverButton),
  942. matching: find.text(LocaleKeys.grid_checklistFilter_isIncomplted.tr()),
  943. );
  944. await tapButton(button);
  945. }
  946. /// Should call [tapDatabaseSettingButton] first.
  947. Future<void> tapViewPropertiesButton() async {
  948. final findSettingItem = find.byType(DatabaseSettingItem);
  949. final findLayoutButton = find.byWidgetPredicate(
  950. (widget) =>
  951. widget is FlowyText &&
  952. widget.text == DatabaseSettingAction.showProperties.title(),
  953. );
  954. final button = find.descendant(
  955. of: findSettingItem,
  956. matching: findLayoutButton,
  957. );
  958. await tapButton(button);
  959. }
  960. /// Should call [tapDatabaseSettingButton] first.
  961. Future<void> tapDatabaseLayoutButton() async {
  962. final findSettingItem = find.byType(DatabaseSettingItem);
  963. final findLayoutButton = find.byWidgetPredicate(
  964. (widget) =>
  965. widget is FlowyText &&
  966. widget.text == DatabaseSettingAction.showLayout.title(),
  967. );
  968. final button = find.descendant(
  969. of: findSettingItem,
  970. matching: findLayoutButton,
  971. );
  972. await tapButton(button);
  973. }
  974. Future<void> tapCalendarLayoutSettingButton() async {
  975. final findSettingItem = find.byType(DatabaseSettingItem);
  976. final findLayoutButton = find.byWidgetPredicate(
  977. (widget) =>
  978. widget is FlowyText &&
  979. widget.text == DatabaseSettingAction.showCalendarLayout.title(),
  980. );
  981. final button = find.descendant(
  982. of: findSettingItem,
  983. matching: findLayoutButton,
  984. );
  985. await tapButton(button);
  986. }
  987. Future<void> tapFirstDayOfWeek() async {
  988. await tapButton(find.byType(FirstDayOfWeek));
  989. }
  990. Future<void> tapFirstDayOfWeekStartFromSunday() async {
  991. final finder = find.byWidgetPredicate(
  992. (widget) => widget is StartFromButton && widget.dayIndex == 0,
  993. );
  994. await tapButton(finder);
  995. }
  996. Future<void> tapFirstDayOfWeekStartFromMonday() async {
  997. final finder = find.byWidgetPredicate(
  998. (widget) => widget is StartFromButton && widget.dayIndex == 1,
  999. );
  1000. await tapButton(finder);
  1001. // Dismiss the popover overlay in cause of obscure the tapButton
  1002. // in the next test case.
  1003. await sendKeyEvent(LogicalKeyboardKey.escape);
  1004. await pumpAndSettle(const Duration(milliseconds: 200));
  1005. }
  1006. void assertFirstDayOfWeekStartFromMonday() {
  1007. final finder = find.byWidgetPredicate(
  1008. (widget) =>
  1009. widget is StartFromButton &&
  1010. widget.dayIndex == 1 &&
  1011. widget.isSelected == true,
  1012. );
  1013. expect(finder, findsOneWidget);
  1014. }
  1015. void assertFirstDayOfWeekStartFromSunday() {
  1016. final finder = find.byWidgetPredicate(
  1017. (widget) =>
  1018. widget is StartFromButton &&
  1019. widget.dayIndex == 0 &&
  1020. widget.isSelected == true,
  1021. );
  1022. expect(finder, findsOneWidget);
  1023. }
  1024. Future<void> scrollToToday() async {
  1025. final todayCell = find.byWidgetPredicate(
  1026. (widget) => widget is CalendarDayCard && widget.isToday,
  1027. );
  1028. final scrollable = find
  1029. .descendant(
  1030. of: find.byType(MonthView<CalendarDayEvent>),
  1031. matching: find.byWidgetPredicate(
  1032. (widget) => widget is Scrollable && widget.axis == Axis.vertical,
  1033. ),
  1034. )
  1035. .first;
  1036. await scrollUntilVisible(
  1037. todayCell,
  1038. 300,
  1039. scrollable: scrollable,
  1040. );
  1041. await pumpAndSettle(const Duration(milliseconds: 300));
  1042. }
  1043. Future<void> hoverOnTodayCalendarCell() async {
  1044. final todayCell = find.byWidgetPredicate(
  1045. (widget) => widget is CalendarDayCard && widget.isToday,
  1046. );
  1047. await hoverOnWidget(todayCell);
  1048. }
  1049. Future<void> tapAddCalendarEventButton() async {
  1050. final findFlowyButton = find.byType(FlowyIconButton);
  1051. final findNewEventButton = find.byType(NewEventButton);
  1052. final button = find.descendant(
  1053. of: findNewEventButton,
  1054. matching: findFlowyButton,
  1055. );
  1056. await tapButton(button);
  1057. }
  1058. /// Checks for a certain number of events. Parameters [date] and [title] can
  1059. /// also be provided to restrict the scope of the search
  1060. void assertNumberOfEventsInCalendar(int number, {String? title}) {
  1061. Finder findEvents = find.byType(EventCard);
  1062. if (title != null) {
  1063. findEvents = find.descendant(of: findEvents, matching: find.text(title));
  1064. }
  1065. expect(findEvents, findsNWidgets(number));
  1066. }
  1067. void assertNumberOfEventsOnSpecificDay(
  1068. int number,
  1069. DateTime date, {
  1070. String? title,
  1071. }) {
  1072. final findDayCell = find.byWidgetPredicate(
  1073. (widget) =>
  1074. widget is CalendarDayCard &&
  1075. isSameDay(
  1076. widget.date,
  1077. date,
  1078. ),
  1079. );
  1080. Finder findEvents = find.descendant(
  1081. of: findDayCell,
  1082. matching: find.byType(EventCard),
  1083. );
  1084. if (title != null) {
  1085. findEvents = find.descendant(of: findEvents, matching: find.text(title));
  1086. }
  1087. expect(findEvents, findsNWidgets(number));
  1088. }
  1089. Future<void> doubleClickCalendarCell(DateTime date) async {
  1090. final todayCell = find.byWidgetPredicate(
  1091. (widget) => widget is CalendarDayCard && isSameDay(date, widget.date),
  1092. );
  1093. final location = getTopLeft(todayCell).translate(10, 10);
  1094. await doubleTapAt(location);
  1095. }
  1096. Future<void> openCalendarEvent({required index, DateTime? date}) async {
  1097. final findDayCell = find.byWidgetPredicate(
  1098. (widget) =>
  1099. widget is CalendarDayCard &&
  1100. isSameDay(widget.date, date ?? DateTime.now()),
  1101. );
  1102. final cards = find.descendant(
  1103. of: findDayCell,
  1104. matching: find.byType(EventCard),
  1105. );
  1106. await tapButton(cards.at(index));
  1107. }
  1108. Future<void> dragDropRescheduleCalendarEvent(DateTime startDate) async {
  1109. final findEventCard = find.byType(EventCard);
  1110. await drag(findEventCard.first, const Offset(0, 300));
  1111. await pumpAndSettle();
  1112. }
  1113. Future<void> tapCreateLinkedDatabaseViewButton(AddButtonAction action) async {
  1114. final findAddButton = find.byType(AddDatabaseViewButton);
  1115. await tapButton(findAddButton);
  1116. final findCreateButton = find.byWidgetPredicate(
  1117. (widget) =>
  1118. widget is TarBarAddButtonActionCell && widget.action == action,
  1119. );
  1120. await tapButton(findCreateButton);
  1121. }
  1122. Future<void> tapTabBarLinkedViewByViewName(String name) async {
  1123. final viewButton = findTabBarLinkViewByViewName(name);
  1124. await tapButton(viewButton);
  1125. }
  1126. Finder findTabBarLinkViewByViewLayout(ViewLayoutPB layout) {
  1127. return find.byWidgetPredicate(
  1128. (widget) => widget is TabBarItemButton && widget.view.layout == layout,
  1129. );
  1130. }
  1131. Finder findTabBarLinkViewByViewName(String name) {
  1132. return find.byWidgetPredicate(
  1133. (widget) => widget is TabBarItemButton && widget.view.name == name,
  1134. );
  1135. }
  1136. Future<void> renameLinkedView(Finder linkedView, String name) async {
  1137. await tap(linkedView, buttons: kSecondaryButton);
  1138. await pumpAndSettle();
  1139. await tapButton(
  1140. find.byWidgetPredicate(
  1141. (widget) =>
  1142. widget is ActionCellWidget &&
  1143. widget.action == TabBarViewAction.rename,
  1144. ),
  1145. );
  1146. await enterText(
  1147. find.descendant(
  1148. of: find.byType(FlowyFormTextInput),
  1149. matching: find.byType(TextFormField),
  1150. ),
  1151. name,
  1152. );
  1153. final field = find.byWidgetPredicate(
  1154. (widget) =>
  1155. widget is PrimaryTextButton &&
  1156. widget.label == LocaleKeys.button_OK.tr(),
  1157. );
  1158. await tapButton(field);
  1159. }
  1160. Future<void> deleteDatebaseView(Finder linkedView) async {
  1161. await tap(linkedView, buttons: kSecondaryButton);
  1162. await pumpAndSettle();
  1163. await tapButton(
  1164. find.byWidgetPredicate(
  1165. (widget) =>
  1166. widget is ActionCellWidget &&
  1167. widget.action == TabBarViewAction.delete,
  1168. ),
  1169. );
  1170. final okButton = find.byWidgetPredicate(
  1171. (widget) =>
  1172. widget is PrimaryTextButton &&
  1173. widget.label == LocaleKeys.button_OK.tr(),
  1174. );
  1175. await tapButton(okButton);
  1176. }
  1177. Future<void> assertCurrentDatabaseTagIs(DatabaseLayoutPB layout) async {
  1178. switch (layout) {
  1179. case DatabaseLayoutPB.Board:
  1180. expect(find.byType(BoardPage), findsOneWidget);
  1181. break;
  1182. case DatabaseLayoutPB.Calendar:
  1183. expect(find.byType(CalendarPage), findsOneWidget);
  1184. break;
  1185. case DatabaseLayoutPB.Grid:
  1186. expect(find.byType(GridPage), findsOneWidget);
  1187. break;
  1188. default:
  1189. throw Exception('Unknown database layout type: $layout');
  1190. }
  1191. }
  1192. Future<void> selectDatabaseLayoutType(DatabaseLayoutPB layout) async {
  1193. final findLayoutCell = find.byType(DatabaseViewLayoutCell);
  1194. final findText = find.byWidgetPredicate(
  1195. (widget) => widget is FlowyText && widget.text == layout.layoutName(),
  1196. );
  1197. final button = find.descendant(
  1198. of: findLayoutCell,
  1199. matching: findText,
  1200. );
  1201. await tapButton(button);
  1202. }
  1203. Future<void> assertCurrentDatabaseLayoutType(DatabaseLayoutPB layout) async {
  1204. expect(finderForDatabaseLayoutType(layout), findsOneWidget);
  1205. }
  1206. Future<void> tapDatabaseRawDataButton() async {
  1207. await tapButtonWithName(LocaleKeys.importPanel_database.tr());
  1208. }
  1209. Future<void> tapAddSelectOptionButton() async {
  1210. await tapButtonWithName(LocaleKeys.grid_field_addSelectOption.tr());
  1211. }
  1212. Future<void> tapViewTogglePropertyVisibilityButtonByName(
  1213. String fieldName,
  1214. ) async {
  1215. final field = find.byWidgetPredicate(
  1216. (widget) =>
  1217. widget is GridPropertyCell && widget.fieldInfo.name == fieldName,
  1218. );
  1219. final toggleVisibilityButton =
  1220. find.descendant(of: field, matching: find.byType(FlowyIconButton));
  1221. await tapButton(toggleVisibilityButton);
  1222. }
  1223. }
  1224. Finder finderForDatabaseLayoutType(DatabaseLayoutPB layout) {
  1225. switch (layout) {
  1226. case DatabaseLayoutPB.Board:
  1227. return find.byType(BoardPage);
  1228. case DatabaseLayoutPB.Calendar:
  1229. return find.byType(CalendarPage);
  1230. case DatabaseLayoutPB.Grid:
  1231. return find.byType(GridPage);
  1232. default:
  1233. throw Exception('Unknown database layout type: $layout');
  1234. }
  1235. }
  1236. Finder finderForFieldType(FieldType fieldType) {
  1237. switch (fieldType) {
  1238. case FieldType.Checkbox:
  1239. return find.byType(GridCheckboxCell, skipOffstage: false);
  1240. case FieldType.DateTime:
  1241. return find.byType(GridDateCell, skipOffstage: false);
  1242. case FieldType.LastEditedTime:
  1243. case FieldType.CreatedTime:
  1244. return find.byType(GridTimestampCell, skipOffstage: false);
  1245. case FieldType.SingleSelect:
  1246. return find.byType(GridSingleSelectCell, skipOffstage: false);
  1247. case FieldType.MultiSelect:
  1248. return find.byType(GridMultiSelectCell, skipOffstage: false);
  1249. case FieldType.Checklist:
  1250. return find.byType(GridChecklistCell, skipOffstage: false);
  1251. case FieldType.Number:
  1252. return find.byType(GridNumberCell, skipOffstage: false);
  1253. case FieldType.RichText:
  1254. return find.byType(GridTextCell, skipOffstage: false);
  1255. case FieldType.URL:
  1256. return find.byType(GridURLCell, skipOffstage: false);
  1257. default:
  1258. throw Exception('Unknown field type: $fieldType');
  1259. }
  1260. }