expectation.dart 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196
  1. import 'package:appflowy/generated/locale_keys.g.dart';
  2. import 'package:appflowy/plugins/document/presentation/banner.dart';
  3. import 'package:appflowy/plugins/document/presentation/editor_plugins/header/document_header_node_widget.dart';
  4. import 'package:appflowy/plugins/document/presentation/editor_plugins/header/emoji_icon_widget.dart';
  5. import 'package:appflowy/workspace/application/sidebar/folder/folder_bloc.dart';
  6. import 'package:appflowy/workspace/presentation/home/home_stack.dart';
  7. import 'package:appflowy/workspace/presentation/home/menu/view/view_item.dart';
  8. import 'package:appflowy_backend/protobuf/flowy-folder2/view.pb.dart';
  9. import 'package:easy_localization/easy_localization.dart';
  10. import 'package:flowy_infra_ui/flowy_infra_ui.dart';
  11. import 'package:flutter_test/flutter_test.dart';
  12. // const String readme = 'Read me';
  13. const String gettingStarted = '⭐️ Getting started';
  14. extension Expectation on WidgetTester {
  15. /// Expect to see the home page and with a default read me page.
  16. void expectToSeeHomePage() {
  17. expect(find.byType(HomeStack), findsOneWidget);
  18. expect(find.textContaining(gettingStarted), findsWidgets);
  19. }
  20. /// Expect to see the page name on the home page.
  21. void expectToSeePageName(
  22. String name, {
  23. String? parentName,
  24. ViewLayoutPB layout = ViewLayoutPB.Document,
  25. ViewLayoutPB parentLayout = ViewLayoutPB.Document,
  26. }) {
  27. final pageName = findPageName(
  28. name,
  29. layout: layout,
  30. parentName: parentName,
  31. parentLayout: parentLayout,
  32. );
  33. expect(pageName, findsOneWidget);
  34. }
  35. /// Expect not to see the page name on the home page.
  36. void expectNotToSeePageName(
  37. String name, {
  38. String? parentName,
  39. ViewLayoutPB layout = ViewLayoutPB.Document,
  40. ViewLayoutPB parentLayout = ViewLayoutPB.Document,
  41. }) {
  42. final pageName = findPageName(
  43. name,
  44. layout: layout,
  45. parentName: parentName,
  46. parentLayout: parentLayout,
  47. );
  48. expect(pageName, findsNothing);
  49. }
  50. /// Expect to see the document banner.
  51. void expectToSeeDocumentBanner() {
  52. expect(find.byType(DocumentBanner), findsOneWidget);
  53. }
  54. /// Expect not to see the document banner.
  55. void expectNotToSeeDocumentBanner() {
  56. expect(find.byType(DocumentBanner), findsNothing);
  57. }
  58. /// Expect to the markdown file export success dialog.
  59. void expectToExportSuccess() {
  60. final exportSuccess = find.byWidgetPredicate(
  61. (widget) =>
  62. widget is FlowyText &&
  63. widget.text == LocaleKeys.settings_files_exportFileSuccess.tr(),
  64. );
  65. expect(exportSuccess, findsOneWidget);
  66. }
  67. /// Expect to see the add button and icon button in the cover toolbar
  68. void expectToSeePluginAddCoverAndIconButton() {
  69. final addCover = find.textContaining(
  70. LocaleKeys.document_plugins_cover_addCover.tr(),
  71. );
  72. final addIcon = find.textContaining(
  73. LocaleKeys.document_plugins_cover_addIcon.tr(),
  74. );
  75. expect(addCover, findsOneWidget);
  76. expect(addIcon, findsOneWidget);
  77. }
  78. /// Expect to see the document header toolbar empty
  79. void expectToSeeEmptyDocumentHeaderToolbar() {
  80. final addCover = find.textContaining(
  81. LocaleKeys.document_plugins_cover_addCover.tr(),
  82. );
  83. final addIcon = find.textContaining(
  84. LocaleKeys.document_plugins_cover_addIcon.tr(),
  85. );
  86. expect(addCover, findsNothing);
  87. expect(addIcon, findsNothing);
  88. }
  89. void expectToSeeDocumentIcon(String? emoji) {
  90. if (emoji == null) {
  91. final iconWidget = find.byType(EmojiIconWidget);
  92. expect(iconWidget, findsNothing);
  93. return;
  94. }
  95. final iconWidget = find.byWidgetPredicate(
  96. (widget) => widget is EmojiIconWidget && widget.emoji == emoji,
  97. );
  98. expect(iconWidget, findsOneWidget);
  99. }
  100. void expectToSeeDocumentCover(CoverType type) {
  101. final findCover = find.byWidgetPredicate(
  102. (widget) => widget is DocumentCover && widget.coverType == type,
  103. );
  104. expect(findCover, findsOneWidget);
  105. }
  106. void expectToSeeNoDocumentCover() {
  107. final findCover = find.byType(DocumentCover);
  108. expect(findCover, findsNothing);
  109. }
  110. void expectChangeCoverAndDeleteButton() {
  111. final findChangeCover = find.text(
  112. LocaleKeys.document_plugins_cover_changeCover.tr(),
  113. );
  114. final findRemoveIcon = find.byType(DeleteCoverButton);
  115. expect(findChangeCover, findsOneWidget);
  116. expect(findRemoveIcon, findsOneWidget);
  117. }
  118. /// Expect to see the user name on the home page
  119. void expectToSeeUserName(String name) {
  120. final userName = find.byWidgetPredicate(
  121. (widget) => widget is FlowyText && widget.text == name,
  122. );
  123. expect(userName, findsOneWidget);
  124. }
  125. /// Expect to see a text
  126. void expectToSeeText(String text) {
  127. Finder textWidget = find.textContaining(text, findRichText: true);
  128. if (textWidget.evaluate().isEmpty) {
  129. textWidget = find.byWidgetPredicate(
  130. (widget) => widget is FlowyText && widget.text == text,
  131. );
  132. }
  133. expect(textWidget, findsOneWidget);
  134. }
  135. /// Find if the page is favorite
  136. Finder findFavoritePageName(
  137. String name, {
  138. ViewLayoutPB layout = ViewLayoutPB.Document,
  139. String? parentName,
  140. ViewLayoutPB parentLayout = ViewLayoutPB.Document,
  141. }) {
  142. return find.byWidgetPredicate(
  143. (widget) =>
  144. widget is ViewItem &&
  145. widget.view.isFavorite &&
  146. widget.categoryType == FolderCategoryType.favorite &&
  147. widget.view.name == name &&
  148. widget.view.layout == layout,
  149. skipOffstage: false,
  150. );
  151. }
  152. Finder findPageName(
  153. String name, {
  154. ViewLayoutPB layout = ViewLayoutPB.Document,
  155. String? parentName,
  156. ViewLayoutPB parentLayout = ViewLayoutPB.Document,
  157. }) {
  158. if (parentName == null) {
  159. return find.byWidgetPredicate(
  160. (widget) =>
  161. widget is SingleInnerViewItem &&
  162. widget.view.name == name &&
  163. widget.view.layout == layout,
  164. skipOffstage: false,
  165. );
  166. }
  167. return find.descendant(
  168. of: find.byWidgetPredicate(
  169. (widget) =>
  170. widget is ViewItem &&
  171. widget.view.name == parentName &&
  172. widget.view.layout == parentLayout,
  173. skipOffstage: false,
  174. ),
  175. matching: findPageName(name, layout: layout),
  176. );
  177. }
  178. }