| 
									
										
										
										
											2023-02-26 16:27:17 +08:00
										 |  |  | import 'package:appflowy/generated/locale_keys.g.dart'; | 
					
						
							| 
									
										
										
										
											2023-10-12 06:54:08 +02:00
										 |  |  | import 'package:appflowy/workspace/application/settings/appearance/appearance_cubit.dart'; | 
					
						
							| 
									
										
										
										
											2023-06-11 14:19:44 +08:00
										 |  |  | import 'package:appflowy/workspace/application/settings/prelude.dart'; | 
					
						
							| 
									
										
										
										
											2023-12-26 02:03:42 +08:00
										 |  |  | import 'package:appflowy/workspace/presentation/home/menu/sidebar/sidebar_user.dart'; | 
					
						
							| 
									
										
										
										
											2023-02-26 16:27:17 +08:00
										 |  |  | import 'package:appflowy/workspace/presentation/settings/settings_dialog.dart'; | 
					
						
							| 
									
										
										
										
											2023-06-11 14:19:44 +08:00
										 |  |  | import 'package:appflowy/workspace/presentation/settings/widgets/settings_menu_element.dart'; | 
					
						
							| 
									
										
										
										
											2023-02-26 16:27:17 +08:00
										 |  |  | import 'package:appflowy/workspace/presentation/settings/widgets/settings_user_view.dart'; | 
					
						
							| 
									
										
										
										
											2022-12-20 11:14:42 +08:00
										 |  |  | import 'package:easy_localization/easy_localization.dart'; | 
					
						
							| 
									
										
										
										
											2023-09-23 10:55:05 +08:00
										 |  |  | import 'package:flutter/material.dart'; | 
					
						
							| 
									
										
										
										
											2022-12-20 11:14:42 +08:00
										 |  |  | import 'package:flutter_test/flutter_test.dart'; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | import 'base.dart'; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | extension AppFlowySettings on WidgetTester { | 
					
						
							|  |  |  |   /// Open settings page
 | 
					
						
							|  |  |  |   Future<void> openSettings() async { | 
					
						
							| 
									
										
										
										
											2023-12-26 02:03:42 +08:00
										 |  |  |     final settingsButton = find.byType(UserSettingButton); | 
					
						
							| 
									
										
										
										
											2022-12-20 11:14:42 +08:00
										 |  |  |     expect(settingsButton, findsOneWidget); | 
					
						
							|  |  |  |     await tapButton(settingsButton); | 
					
						
							|  |  |  |     final settingsDialog = find.byType(SettingsDialog); | 
					
						
							|  |  |  |     expect(settingsDialog, findsOneWidget); | 
					
						
							|  |  |  |     return; | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-03-20 13:29:17 +00:00
										 |  |  |   /// Open the page that insides the settings page
 | 
					
						
							| 
									
										
										
										
											2022-12-20 11:14:42 +08:00
										 |  |  |   Future<void> openSettingsPage(SettingsPage page) async { | 
					
						
							| 
									
										
										
										
											2023-06-11 14:19:44 +08:00
										 |  |  |     final button = find.byWidgetPredicate( | 
					
						
							|  |  |  |       (widget) => widget is SettingsMenuElement && widget.page == page, | 
					
						
							|  |  |  |     ); | 
					
						
							| 
									
										
										
										
											2022-12-20 11:14:42 +08:00
										 |  |  |     expect(button, findsOneWidget); | 
					
						
							|  |  |  |     await tapButton(button); | 
					
						
							|  |  |  |     return; | 
					
						
							| 
									
										
										
										
											2023-08-22 15:40:22 +08:00
										 |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   Future<void> expectNoSettingsPage(SettingsPage page) async { | 
					
						
							|  |  |  |     final button = find.byWidgetPredicate( | 
					
						
							|  |  |  |       (widget) => widget is SettingsMenuElement && widget.page == page, | 
					
						
							|  |  |  |     ); | 
					
						
							|  |  |  |     expect(button, findsNothing); | 
					
						
							|  |  |  |     return; | 
					
						
							| 
									
										
										
										
											2022-12-20 11:14:42 +08:00
										 |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   /// Restore the AppFlowy data storage location
 | 
					
						
							|  |  |  |   Future<void> restoreLocation() async { | 
					
						
							| 
									
										
										
										
											2023-03-20 13:29:17 +00:00
										 |  |  |     final button = | 
					
						
							| 
									
										
										
										
											2023-06-11 14:19:44 +08:00
										 |  |  |         find.byTooltip(LocaleKeys.settings_files_recoverLocationTooltips.tr()); | 
					
						
							| 
									
										
										
										
											2023-03-20 13:29:17 +00:00
										 |  |  |     expect(button, findsOneWidget); | 
					
						
							|  |  |  |     await tapButton(button); | 
					
						
							| 
									
										
										
										
											2022-12-20 11:14:42 +08:00
										 |  |  |     return; | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   Future<void> tapOpenFolderButton() async { | 
					
						
							| 
									
										
										
										
											2023-03-20 13:29:17 +00:00
										 |  |  |     final button = find.text(LocaleKeys.settings_files_open.tr()); | 
					
						
							|  |  |  |     expect(button, findsOneWidget); | 
					
						
							|  |  |  |     await tapButton(button); | 
					
						
							| 
									
										
										
										
											2022-12-20 11:14:42 +08:00
										 |  |  |     return; | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   Future<void> tapCustomLocationButton() async { | 
					
						
							| 
									
										
										
										
											2023-06-11 14:19:44 +08:00
										 |  |  |     final button = find.byTooltip( | 
					
						
							|  |  |  |       LocaleKeys.settings_files_changeLocationTooltips.tr(), | 
					
						
							|  |  |  |     ); | 
					
						
							| 
									
										
										
										
											2023-03-20 13:29:17 +00:00
										 |  |  |     expect(button, findsOneWidget); | 
					
						
							|  |  |  |     await tapButton(button); | 
					
						
							| 
									
										
										
										
											2022-12-20 11:14:42 +08:00
										 |  |  |     return; | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   /// Enter user name
 | 
					
						
							|  |  |  |   Future<void> enterUserName(String name) async { | 
					
						
							|  |  |  |     final uni = find.byType(UserNameInput); | 
					
						
							|  |  |  |     expect(uni, findsOneWidget); | 
					
						
							|  |  |  |     await tap(uni); | 
					
						
							|  |  |  |     await enterText(uni, name); | 
					
						
							|  |  |  |     await wait(300); //
 | 
					
						
							|  |  |  |     await testTextInput.receiveAction(TextInputAction.done); | 
					
						
							|  |  |  |     await pumpAndSettle(); | 
					
						
							|  |  |  |   } | 
					
						
							| 
									
										
										
										
											2023-09-23 10:55:05 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  |   // go to settings page and switch the layout direction
 | 
					
						
							|  |  |  |   Future<void> switchLayoutDirectionMode( | 
					
						
							|  |  |  |     LayoutDirection layoutDirection, | 
					
						
							|  |  |  |   ) async { | 
					
						
							|  |  |  |     await openSettings(); | 
					
						
							|  |  |  |     await openSettingsPage(SettingsPage.appearance); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     final button = find.byKey(const ValueKey('layout_direction_option_button')); | 
					
						
							|  |  |  |     expect(button, findsOneWidget); | 
					
						
							|  |  |  |     await tapButton(button); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     switch (layoutDirection) { | 
					
						
							|  |  |  |       case LayoutDirection.ltrLayout: | 
					
						
							|  |  |  |         final ltrButton = find.text( | 
					
						
							|  |  |  |           LocaleKeys.settings_appearance_layoutDirection_ltr.tr(), | 
					
						
							|  |  |  |         ); | 
					
						
							|  |  |  |         await tapButton(ltrButton); | 
					
						
							|  |  |  |         break; | 
					
						
							|  |  |  |       case LayoutDirection.rtlLayout: | 
					
						
							|  |  |  |         final rtlButton = find.text( | 
					
						
							|  |  |  |           LocaleKeys.settings_appearance_layoutDirection_rtl.tr(), | 
					
						
							|  |  |  |         ); | 
					
						
							|  |  |  |         await tapButton(rtlButton); | 
					
						
							|  |  |  |         break; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     // tap anywhere to close the settings page
 | 
					
						
							|  |  |  |     await tapAt(Offset.zero); | 
					
						
							|  |  |  |     await pumpAndSettle(); | 
					
						
							|  |  |  |   } | 
					
						
							| 
									
										
										
										
											2022-12-20 11:14:42 +08:00
										 |  |  | } |