| 
									
										
										
										
											2023-06-12 20:32:55 +08:00
										 |  |  | import 'package:appflowy/generated/locale_keys.g.dart'; | 
					
						
							| 
									
										
										
										
											2024-05-09 13:32:35 +08:00
										 |  |  | import 'package:appflowy/mobile/presentation/page_item/mobile_view_item.dart'; | 
					
						
							| 
									
										
										
										
											2024-10-02 20:13:19 +08:00
										 |  |  | import 'package:appflowy/mobile/presentation/presentation.dart'; | 
					
						
							| 
									
										
										
										
											2024-01-24 15:15:57 +01:00
										 |  |  | import 'package:appflowy/plugins/database/widgets/row/row_detail.dart'; | 
					
						
							| 
									
										
										
										
											2023-06-12 20:32:55 +08:00
										 |  |  | import 'package:appflowy/plugins/document/presentation/banner.dart'; | 
					
						
							| 
									
										
										
										
											2024-09-25 22:44:59 +08:00
										 |  |  | import 'package:appflowy/plugins/document/presentation/editor_plugins/header/document_cover_widget.dart'; | 
					
						
							| 
									
										
										
										
											2023-06-27 15:17:51 +08:00
										 |  |  | import 'package:appflowy/plugins/document/presentation/editor_plugins/header/emoji_icon_widget.dart'; | 
					
						
							| 
									
										
										
										
											2023-08-02 18:50:51 +05:30
										 |  |  | import 'package:appflowy/workspace/application/sidebar/folder/folder_bloc.dart'; | 
					
						
							| 
									
										
										
										
											2023-06-12 20:32:55 +08:00
										 |  |  | import 'package:appflowy/workspace/presentation/home/home_stack.dart'; | 
					
						
							| 
									
										
										
										
											2023-07-31 19:06:01 +07:00
										 |  |  | import 'package:appflowy/workspace/presentation/home/menu/view/view_item.dart'; | 
					
						
							| 
									
										
										
										
											2024-01-24 15:15:57 +01:00
										 |  |  | import 'package:appflowy/workspace/presentation/notifications/widgets/notification_item.dart'; | 
					
						
							|  |  |  | import 'package:appflowy/workspace/presentation/widgets/date_picker/widgets/reminder_selector.dart'; | 
					
						
							| 
									
										
										
										
											2023-11-09 13:11:13 +08:00
										 |  |  | import 'package:appflowy/workspace/presentation/widgets/view_title_bar.dart'; | 
					
						
							| 
									
										
										
										
											2023-12-31 07:29:40 +08:00
										 |  |  | import 'package:appflowy_backend/protobuf/flowy-folder/view.pb.dart'; | 
					
						
							| 
									
										
										
										
											2023-06-12 20:32:55 +08:00
										 |  |  | import 'package:easy_localization/easy_localization.dart'; | 
					
						
							|  |  |  | import 'package:flowy_infra_ui/flowy_infra_ui.dart'; | 
					
						
							| 
									
										
										
										
											2024-05-09 13:32:35 +08:00
										 |  |  | import 'package:flutter/material.dart'; | 
					
						
							| 
									
										
										
										
											2023-06-12 20:32:55 +08:00
										 |  |  | import 'package:flutter_test/flutter_test.dart'; | 
					
						
							| 
									
										
										
										
											2024-09-12 14:40:19 +08:00
										 |  |  | import 'package:universal_platform/universal_platform.dart'; | 
					
						
							| 
									
										
										
										
											2023-06-12 20:32:55 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-12-26 02:03:42 +08:00
										 |  |  | import 'util.dart'; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-07-31 19:06:01 +07:00
										 |  |  | // const String readme = 'Read me';
 | 
					
						
							| 
									
										
										
										
											2023-11-13 12:00:03 +08:00
										 |  |  | const String gettingStarted = 'Getting started'; | 
					
						
							| 
									
										
										
										
											2023-06-12 20:32:55 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | extension Expectation on WidgetTester { | 
					
						
							|  |  |  |   /// Expect to see the home page and with a default read me page.
 | 
					
						
							| 
									
										
										
										
											2023-12-27 11:42:39 +08:00
										 |  |  |   Future<void> expectToSeeHomePageWithGetStartedPage() async { | 
					
						
							| 
									
										
										
										
											2024-10-02 20:13:19 +08:00
										 |  |  |     if (UniversalPlatform.isDesktopOrWeb) { | 
					
						
							|  |  |  |       final finder = find.byType(HomeStack); | 
					
						
							|  |  |  |       await pumpUntilFound(finder); | 
					
						
							|  |  |  |       expect(finder, findsOneWidget); | 
					
						
							|  |  |  |     } else if (UniversalPlatform.isMobile) { | 
					
						
							|  |  |  |       final finder = find.byType(MobileHomePage); | 
					
						
							|  |  |  |       await pumpUntilFound(finder); | 
					
						
							|  |  |  |       expect(finder, findsOneWidget); | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2023-12-26 02:03:42 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  |     final docFinder = find.textContaining(gettingStarted); | 
					
						
							|  |  |  |     await pumpUntilFound(docFinder); | 
					
						
							| 
									
										
										
										
											2023-06-12 20:32:55 +08:00
										 |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-12-27 11:42:39 +08:00
										 |  |  |   Future<void> expectToSeeHomePage() async { | 
					
						
							|  |  |  |     final finder = find.byType(HomeStack); | 
					
						
							|  |  |  |     await pumpUntilFound(finder); | 
					
						
							|  |  |  |     expect(finder, findsOneWidget); | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-06-12 20:32:55 +08:00
										 |  |  |   /// Expect to see the page name on the home page.
 | 
					
						
							| 
									
										
										
										
											2023-07-31 19:06:01 +07:00
										 |  |  |   void expectToSeePageName( | 
					
						
							|  |  |  |     String name, { | 
					
						
							|  |  |  |     String? parentName, | 
					
						
							|  |  |  |     ViewLayoutPB layout = ViewLayoutPB.Document, | 
					
						
							|  |  |  |     ViewLayoutPB parentLayout = ViewLayoutPB.Document, | 
					
						
							|  |  |  |   }) { | 
					
						
							|  |  |  |     final pageName = findPageName( | 
					
						
							|  |  |  |       name, | 
					
						
							|  |  |  |       layout: layout, | 
					
						
							|  |  |  |       parentName: parentName, | 
					
						
							|  |  |  |       parentLayout: parentLayout, | 
					
						
							|  |  |  |     ); | 
					
						
							| 
									
										
										
										
											2023-06-12 20:32:55 +08:00
										 |  |  |     expect(pageName, findsOneWidget); | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   /// Expect not to see the page name on the home page.
 | 
					
						
							| 
									
										
										
										
											2023-07-31 19:06:01 +07:00
										 |  |  |   void expectNotToSeePageName( | 
					
						
							|  |  |  |     String name, { | 
					
						
							|  |  |  |     String? parentName, | 
					
						
							|  |  |  |     ViewLayoutPB layout = ViewLayoutPB.Document, | 
					
						
							|  |  |  |     ViewLayoutPB parentLayout = ViewLayoutPB.Document, | 
					
						
							|  |  |  |   }) { | 
					
						
							|  |  |  |     final pageName = findPageName( | 
					
						
							|  |  |  |       name, | 
					
						
							|  |  |  |       layout: layout, | 
					
						
							|  |  |  |       parentName: parentName, | 
					
						
							|  |  |  |       parentLayout: parentLayout, | 
					
						
							|  |  |  |     ); | 
					
						
							| 
									
										
										
										
											2023-06-12 20:32:55 +08:00
										 |  |  |     expect(pageName, findsNothing); | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   /// Expect to see the document banner.
 | 
					
						
							|  |  |  |   void expectToSeeDocumentBanner() { | 
					
						
							|  |  |  |     expect(find.byType(DocumentBanner), findsOneWidget); | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   /// Expect not to see the document banner.
 | 
					
						
							|  |  |  |   void expectNotToSeeDocumentBanner() { | 
					
						
							|  |  |  |     expect(find.byType(DocumentBanner), findsNothing); | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   /// Expect to the markdown file export success dialog.
 | 
					
						
							|  |  |  |   void expectToExportSuccess() { | 
					
						
							|  |  |  |     final exportSuccess = find.byWidgetPredicate( | 
					
						
							|  |  |  |       (widget) => | 
					
						
							|  |  |  |           widget is FlowyText && | 
					
						
							| 
									
										
										
										
											2023-06-16 15:32:28 +08:00
										 |  |  |           widget.text == LocaleKeys.settings_files_exportFileSuccess.tr(), | 
					
						
							| 
									
										
										
										
											2023-06-12 20:32:55 +08:00
										 |  |  |     ); | 
					
						
							|  |  |  |     expect(exportSuccess, findsOneWidget); | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-06-27 15:17:51 +08:00
										 |  |  |   /// Expect to see the document header toolbar empty
 | 
					
						
							|  |  |  |   void expectToSeeEmptyDocumentHeaderToolbar() { | 
					
						
							|  |  |  |     final addCover = find.textContaining( | 
					
						
							|  |  |  |       LocaleKeys.document_plugins_cover_addCover.tr(), | 
					
						
							|  |  |  |     ); | 
					
						
							|  |  |  |     final addIcon = find.textContaining( | 
					
						
							|  |  |  |       LocaleKeys.document_plugins_cover_addIcon.tr(), | 
					
						
							|  |  |  |     ); | 
					
						
							|  |  |  |     expect(addCover, findsNothing); | 
					
						
							|  |  |  |     expect(addIcon, findsNothing); | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   void expectToSeeDocumentIcon(String? emoji) { | 
					
						
							|  |  |  |     if (emoji == null) { | 
					
						
							|  |  |  |       final iconWidget = find.byType(EmojiIconWidget); | 
					
						
							|  |  |  |       expect(iconWidget, findsNothing); | 
					
						
							|  |  |  |       return; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |     final iconWidget = find.byWidgetPredicate( | 
					
						
							|  |  |  |       (widget) => widget is EmojiIconWidget && widget.emoji == emoji, | 
					
						
							|  |  |  |     ); | 
					
						
							|  |  |  |     expect(iconWidget, findsOneWidget); | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-11-02 15:24:17 +08:00
										 |  |  |   void expectDocumentIconNotNull() { | 
					
						
							|  |  |  |     final iconWidget = find.byWidgetPredicate( | 
					
						
							|  |  |  |       (widget) => widget is EmojiIconWidget && widget.emoji.isNotEmpty, | 
					
						
							|  |  |  |     ); | 
					
						
							|  |  |  |     expect(iconWidget, findsOneWidget); | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-07-01 23:13:09 +08:00
										 |  |  |   void expectToSeeDocumentCover(CoverType type) { | 
					
						
							| 
									
										
										
										
											2023-06-27 15:17:51 +08:00
										 |  |  |     final findCover = find.byWidgetPredicate( | 
					
						
							| 
									
										
										
										
											2023-07-01 23:13:09 +08:00
										 |  |  |       (widget) => widget is DocumentCover && widget.coverType == type, | 
					
						
							| 
									
										
										
										
											2023-06-27 15:17:51 +08:00
										 |  |  |     ); | 
					
						
							|  |  |  |     expect(findCover, findsOneWidget); | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   void expectToSeeNoDocumentCover() { | 
					
						
							|  |  |  |     final findCover = find.byType(DocumentCover); | 
					
						
							|  |  |  |     expect(findCover, findsNothing); | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   void expectChangeCoverAndDeleteButton() { | 
					
						
							|  |  |  |     final findChangeCover = find.text( | 
					
						
							|  |  |  |       LocaleKeys.document_plugins_cover_changeCover.tr(), | 
					
						
							|  |  |  |     ); | 
					
						
							|  |  |  |     final findRemoveIcon = find.byType(DeleteCoverButton); | 
					
						
							|  |  |  |     expect(findChangeCover, findsOneWidget); | 
					
						
							|  |  |  |     expect(findRemoveIcon, findsOneWidget); | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-06-14 06:14:41 -05:00
										 |  |  |   /// Expect to see a text
 | 
					
						
							|  |  |  |   void expectToSeeText(String text) { | 
					
						
							|  |  |  |     Finder textWidget = find.textContaining(text, findRichText: true); | 
					
						
							|  |  |  |     if (textWidget.evaluate().isEmpty) { | 
					
						
							|  |  |  |       textWidget = find.byWidgetPredicate( | 
					
						
							| 
									
										
										
										
											2023-06-16 15:32:28 +08:00
										 |  |  |         (widget) => widget is FlowyText && widget.text == text, | 
					
						
							| 
									
										
										
										
											2023-06-14 06:14:41 -05:00
										 |  |  |       ); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |     expect(textWidget, findsOneWidget); | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-08-02 18:50:51 +05:30
										 |  |  |   /// Find if the page is favorite
 | 
					
						
							|  |  |  |   Finder findFavoritePageName( | 
					
						
							|  |  |  |     String name, { | 
					
						
							|  |  |  |     ViewLayoutPB layout = ViewLayoutPB.Document, | 
					
						
							|  |  |  |     String? parentName, | 
					
						
							|  |  |  |     ViewLayoutPB parentLayout = ViewLayoutPB.Document, | 
					
						
							| 
									
										
										
										
											2024-04-30 14:09:08 +02:00
										 |  |  |   }) => | 
					
						
							|  |  |  |       find.byWidgetPredicate( | 
					
						
							|  |  |  |         (widget) => | 
					
						
							|  |  |  |             widget is SingleInnerViewItem && | 
					
						
							|  |  |  |             widget.view.isFavorite && | 
					
						
							| 
									
										
										
										
											2024-05-27 08:51:49 +08:00
										 |  |  |             widget.spaceType == FolderSpaceType.favorite && | 
					
						
							| 
									
										
										
										
											2024-04-30 14:09:08 +02:00
										 |  |  |             widget.view.name == name && | 
					
						
							|  |  |  |             widget.view.layout == layout, | 
					
						
							|  |  |  |         skipOffstage: false, | 
					
						
							|  |  |  |       ); | 
					
						
							| 
									
										
										
										
											2023-08-02 18:50:51 +05:30
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-04-30 14:09:08 +02:00
										 |  |  |   Finder findAllFavoritePages() => find.byWidgetPredicate( | 
					
						
							|  |  |  |         (widget) => | 
					
						
							|  |  |  |             widget is SingleInnerViewItem && | 
					
						
							|  |  |  |             widget.view.isFavorite && | 
					
						
							| 
									
										
										
										
											2024-05-27 08:51:49 +08:00
										 |  |  |             widget.spaceType == FolderSpaceType.favorite, | 
					
						
							| 
									
										
										
										
											2024-04-30 14:09:08 +02:00
										 |  |  |       ); | 
					
						
							| 
									
										
										
										
											2023-11-09 13:11:13 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-07-31 19:06:01 +07:00
										 |  |  |   Finder findPageName( | 
					
						
							|  |  |  |     String name, { | 
					
						
							|  |  |  |     ViewLayoutPB layout = ViewLayoutPB.Document, | 
					
						
							|  |  |  |     String? parentName, | 
					
						
							|  |  |  |     ViewLayoutPB parentLayout = ViewLayoutPB.Document, | 
					
						
							|  |  |  |   }) { | 
					
						
							| 
									
										
										
										
											2024-09-12 14:40:19 +08:00
										 |  |  |     if (UniversalPlatform.isDesktop) { | 
					
						
							| 
									
										
										
										
											2024-05-09 13:32:35 +08:00
										 |  |  |       if (parentName == null) { | 
					
						
							|  |  |  |         return find.byWidgetPredicate( | 
					
						
							|  |  |  |           (widget) => | 
					
						
							|  |  |  |               widget is SingleInnerViewItem && | 
					
						
							|  |  |  |               widget.view.name == name && | 
					
						
							|  |  |  |               widget.view.layout == layout, | 
					
						
							|  |  |  |           skipOffstage: false, | 
					
						
							|  |  |  |         ); | 
					
						
							|  |  |  |       } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       return find.descendant( | 
					
						
							|  |  |  |         of: find.byWidgetPredicate( | 
					
						
							|  |  |  |           (widget) => | 
					
						
							|  |  |  |               widget is InnerViewItem && | 
					
						
							|  |  |  |               widget.view.name == parentName && | 
					
						
							|  |  |  |               widget.view.layout == parentLayout, | 
					
						
							|  |  |  |           skipOffstage: false, | 
					
						
							|  |  |  |         ), | 
					
						
							|  |  |  |         matching: findPageName(name, layout: layout), | 
					
						
							| 
									
										
										
										
											2023-07-31 19:06:01 +07:00
										 |  |  |       ); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-05-09 13:32:35 +08:00
										 |  |  |     return find.byWidgetPredicate( | 
					
						
							|  |  |  |       (widget) => | 
					
						
							|  |  |  |           widget is SingleMobileInnerViewItem && | 
					
						
							|  |  |  |           widget.view.name == name && | 
					
						
							|  |  |  |           widget.view.layout == layout, | 
					
						
							|  |  |  |       skipOffstage: false, | 
					
						
							| 
									
										
										
										
											2023-06-12 20:32:55 +08:00
										 |  |  |     ); | 
					
						
							|  |  |  |   } | 
					
						
							| 
									
										
										
										
											2023-11-02 15:24:17 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-11-09 13:11:13 +08:00
										 |  |  |   void expectViewHasIcon(String name, ViewLayoutPB layout, String emoji) { | 
					
						
							|  |  |  |     final pageName = findPageName( | 
					
						
							|  |  |  |       name, | 
					
						
							|  |  |  |       layout: layout, | 
					
						
							|  |  |  |     ); | 
					
						
							| 
									
										
										
										
											2023-11-02 15:24:17 +08:00
										 |  |  |     final icon = find.descendant( | 
					
						
							|  |  |  |       of: pageName, | 
					
						
							|  |  |  |       matching: find.text(emoji), | 
					
						
							|  |  |  |     ); | 
					
						
							|  |  |  |     expect(icon, findsOneWidget); | 
					
						
							|  |  |  |   } | 
					
						
							| 
									
										
										
										
											2023-11-09 13:11:13 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  |   void expectViewTitleHasIcon(String name, ViewLayoutPB layout, String emoji) { | 
					
						
							|  |  |  |     final icon = find.descendant( | 
					
						
							|  |  |  |       of: find.byType(ViewTitleBar), | 
					
						
							|  |  |  |       matching: find.text(emoji), | 
					
						
							|  |  |  |     ); | 
					
						
							|  |  |  |     expect(icon, findsOneWidget); | 
					
						
							|  |  |  |   } | 
					
						
							| 
									
										
										
										
											2024-01-24 15:15:57 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  |   void expectSelectedReminder(ReminderOption option) { | 
					
						
							|  |  |  |     final findSelectedText = find.descendant( | 
					
						
							|  |  |  |       of: find.byType(ReminderSelector), | 
					
						
							|  |  |  |       matching: find.text(option.label), | 
					
						
							|  |  |  |     ); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     expect(findSelectedText, findsOneWidget); | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   void expectNotificationItems(int amount) { | 
					
						
							|  |  |  |     final findItems = find.byType(NotificationItem); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     expect(findItems, findsNWidgets(amount)); | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   void expectToSeeRowDetailsPageDialog() { | 
					
						
							|  |  |  |     expect( | 
					
						
							|  |  |  |       find.descendant( | 
					
						
							|  |  |  |         of: find.byType(RowDetailPage), | 
					
						
							|  |  |  |         matching: find.byType(SimpleDialog), | 
					
						
							|  |  |  |       ), | 
					
						
							|  |  |  |       findsOneWidget, | 
					
						
							|  |  |  |     ); | 
					
						
							|  |  |  |   } | 
					
						
							| 
									
										
										
										
											2023-06-12 20:32:55 +08:00
										 |  |  | } |