common_operations.dart 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163
  1. import 'dart:ui';
  2. import 'package:appflowy/generated/locale_keys.g.dart';
  3. import 'package:appflowy/plugins/document/presentation/share/share_button.dart';
  4. import 'package:appflowy/user/presentation/skip_log_in_screen.dart';
  5. import 'package:appflowy/workspace/presentation/home/menu/app/header/add_button.dart';
  6. import 'package:appflowy/workspace/presentation/home/menu/app/section/item.dart';
  7. import 'package:appflowy_editor/appflowy_editor.dart';
  8. import 'package:easy_localization/easy_localization.dart';
  9. import 'package:flowy_infra_ui/widget/buttons/primary_button.dart';
  10. import 'package:flutter/material.dart';
  11. import 'package:flutter_test/flutter_test.dart';
  12. import 'util.dart';
  13. extension CommonOperations on WidgetTester {
  14. /// Get current file location of AppFlowy.
  15. Future<String> currentFileLocation() async {
  16. return TestFolder.currentLocation();
  17. }
  18. /// Tap the GetStart button on the launch page.
  19. Future<void> tapGoButton() async {
  20. final goButton = find.byType(GoButton);
  21. await tapButton(goButton);
  22. }
  23. /// Tap the + button on the home page.
  24. Future<void> tapAddButton() async {
  25. final addButton = find.byType(AddButton);
  26. await tapButton(addButton);
  27. }
  28. /// Tap the create document button.
  29. ///
  30. /// Must call [tapAddButton] first.
  31. Future<void> tapCreateDocumentButton() async {
  32. await tapButtonWithName(LocaleKeys.document_menuName.tr());
  33. }
  34. /// Tap the import button.
  35. ///
  36. /// Must call [tapAddButton] first.
  37. Future<void> tapImportButton() async {
  38. await tapButtonWithName(LocaleKeys.moreAction_import.tr());
  39. }
  40. /// Tap the import from text & markdown button.
  41. ///
  42. /// Must call [tapImportButton] first.
  43. Future<void> tapTextAndMarkdownButton() async {
  44. await tapButtonWithName(LocaleKeys.importPanel_textAndMarkdown.tr());
  45. }
  46. /// Hover on the widget.
  47. Future<void> hoverOnWidget(
  48. Finder finder, {
  49. Offset? offset,
  50. }) async {
  51. final gesture = await createGesture(kind: PointerDeviceKind.mouse);
  52. await gesture.addPointer(location: Offset.zero);
  53. addTearDown(gesture.removePointer);
  54. await pump();
  55. await gesture.moveTo(offset ?? getCenter(finder));
  56. await pumpAndSettle();
  57. }
  58. /// Hover on the page name.
  59. Future<void> hoverOnPageName(String name) async {
  60. await hoverOnWidget(findPageName(name));
  61. }
  62. /// Tap the ... button beside the page name.
  63. ///
  64. /// Must call [hoverOnPageName] first.
  65. Future<void> tapPageOptionButton() async {
  66. final optionButton = find.byType(ViewDisclosureButton);
  67. await tapButton(optionButton);
  68. }
  69. /// Tap the delete page button.
  70. ///
  71. /// Must call [tapPageOptionButton] first.
  72. Future<void> tapDeletePageButton() async {
  73. await tapPageOptionButton();
  74. await tapButtonWithName(ViewDisclosureAction.delete.name);
  75. }
  76. /// Tap the rename page button.
  77. ///
  78. /// Must call [tapPageOptionButton] first.
  79. Future<void> tapRenamePageButton() async {
  80. await tapPageOptionButton();
  81. await tapButtonWithName(ViewDisclosureAction.rename.name);
  82. }
  83. /// Rename the page.
  84. ///
  85. /// Must call [tapPageOptionButton] first.
  86. Future<void> renamePage(String name) async {
  87. await tapRenamePageButton();
  88. await enterText(find.byType(TextFormField), name);
  89. await tapOKButton();
  90. }
  91. Future<void> tapOKButton() async {
  92. final okButton = find.byWidgetPredicate(
  93. (widget) =>
  94. widget is PrimaryTextButton &&
  95. widget.label == LocaleKeys.button_OK.tr(),
  96. );
  97. await tapButton(okButton);
  98. }
  99. /// Tap the restore button.
  100. ///
  101. /// the restore button will show after the current page is deleted.
  102. Future<void> tapRestoreButton() async {
  103. final restoreButton = find.textContaining(
  104. LocaleKeys.deletePagePrompt_restore.tr(),
  105. );
  106. await tapButton(restoreButton);
  107. }
  108. /// Tap the delete permanently button.
  109. ///
  110. /// the restore button will show after the current page is deleted.
  111. Future<void> tapDeletePermanentlyButton() async {
  112. final restoreButton = find.textContaining(
  113. LocaleKeys.deletePagePrompt_deletePermanent.tr(),
  114. );
  115. await tapButton(restoreButton);
  116. }
  117. /// Tap the share button above the document page.
  118. Future<void> tapShareButton() async {
  119. final shareButton = find.byWidgetPredicate(
  120. (widget) => widget is DocumentShareButton,
  121. );
  122. await tapButton(shareButton);
  123. }
  124. /// Tap the export markdown button
  125. ///
  126. /// Must call [tapShareButton] first.
  127. Future<void> tapMarkdownButton() async {
  128. final markdownButton = find.textContaining(
  129. LocaleKeys.shareAction_markdown.tr(),
  130. );
  131. await tapButton(markdownButton);
  132. }
  133. /// Hover on cover plugin button above the document
  134. Future<void> hoverOnCoverPluginAddButton() async {
  135. final editor = find.byWidgetPredicate(
  136. (widget) => widget is AppFlowyEditor,
  137. );
  138. await hoverOnWidget(
  139. editor,
  140. offset: getTopLeft(editor).translate(20, 20),
  141. );
  142. }
  143. }