expectation.dart 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. import 'package:appflowy/generated/locale_keys.g.dart';
  2. import 'package:appflowy/plugins/document/presentation/banner.dart';
  3. import 'package:appflowy/workspace/presentation/home/home_stack.dart';
  4. import 'package:appflowy/workspace/presentation/home/menu/app/section/item.dart';
  5. import 'package:easy_localization/easy_localization.dart';
  6. import 'package:flowy_infra_ui/flowy_infra_ui.dart';
  7. import 'package:flutter_test/flutter_test.dart';
  8. const String readme = 'Read me';
  9. extension Expectation on WidgetTester {
  10. /// Expect to see the home page and with a default read me page.
  11. void expectToSeeHomePage() {
  12. expect(find.byType(HomeStack), findsOneWidget);
  13. expect(find.textContaining(readme), findsOneWidget);
  14. }
  15. /// Expect to see the page name on the home page.
  16. void expectToSeePageName(String name) {
  17. final pageName = findPageName(name);
  18. expect(pageName, findsOneWidget);
  19. }
  20. /// Expect not to see the page name on the home page.
  21. void expectNotToSeePageName(String name) {
  22. final pageName = findPageName(name);
  23. expect(pageName, findsNothing);
  24. }
  25. /// Expect to see the document banner.
  26. void expectToSeeDocumentBanner() {
  27. expect(find.byType(DocumentBanner), findsOneWidget);
  28. }
  29. /// Expect not to see the document banner.
  30. void expectNotToSeeDocumentBanner() {
  31. expect(find.byType(DocumentBanner), findsNothing);
  32. }
  33. /// Expect to the markdown file export success dialog.
  34. void expectToExportSuccess() {
  35. final exportSuccess = find.byWidgetPredicate(
  36. (widget) =>
  37. widget is FlowyText &&
  38. widget.title == LocaleKeys.settings_files_exportFileSuccess.tr(),
  39. );
  40. expect(exportSuccess, findsOneWidget);
  41. }
  42. /// Expect to see the add button and icon button inside the document.
  43. void expectToSeePluginAddCoverAndIconButton() {
  44. final addCover = find.textContaining(
  45. LocaleKeys.document_plugins_cover_addCover.tr(),
  46. );
  47. final addIcon = find.textContaining(
  48. LocaleKeys.document_plugins_cover_addIcon.tr(),
  49. );
  50. expect(addCover, findsOneWidget);
  51. expect(addIcon, findsOneWidget);
  52. }
  53. /// Expect to see the user name on the home page
  54. void expectToSeeUserName(String name) {
  55. final userName = find.byWidgetPredicate(
  56. (widget) => widget is FlowyText && widget.title == name,
  57. );
  58. expect(userName, findsOneWidget);
  59. }
  60. /// Find the page name on the home page.
  61. Finder findPageName(String name) {
  62. return find.byWidgetPredicate(
  63. (widget) => widget is ViewSectionItem && widget.view.name == name,
  64. );
  65. }
  66. }