database_test_op.dart 47 KB

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