diff --git a/integration_test/base/core_robot.dart b/integration_test/base/core_robot.dart new file mode 100644 index 000000000..7ceee8ff6 --- /dev/null +++ b/integration_test/base/core_robot.dart @@ -0,0 +1,9 @@ +import 'package:patrol/patrol.dart'; + +abstract class CoreRobot { + final PatrolIntegrationTester $; + + CoreRobot(this.$); + + dynamic ignoreException() => $.tester.takeException(); +} diff --git a/integration_test/base/test_base.dart b/integration_test/base/test_base.dart index c4f7f57e8..5bef48cf2 100644 --- a/integration_test/base/test_base.dart +++ b/integration_test/base/test_base.dart @@ -1,12 +1,7 @@ -import 'package:fluffychat/di/global/get_it_initializer.dart'; -import 'package:fluffychat/utils/client_manager.dart'; -import 'package:fluffychat/widgets/twake_app.dart'; import 'package:flutter/foundation.dart'; import 'package:flutter_test/flutter_test.dart'; -import 'package:go_router/go_router.dart'; -import 'package:hive_flutter/hive_flutter.dart'; -import 'package:media_kit/media_kit.dart'; import 'package:patrol/patrol.dart'; +import 'package:fluffychat/main.dart' as app; class TestBase { void runPatrolTest({ @@ -15,15 +10,17 @@ class TestBase { }) { patrolTest(description, config: const PatrolTesterConfig( - settlePolicy: SettlePolicy.trySettle, + printLogs: true, visibleTimeout: Duration(minutes: 1), ), nativeAutomatorConfig: const NativeAutomatorConfig( - findTimeout: Duration(seconds: 10), + connectionTimeout: Duration(minutes: 1, seconds: 10), + findTimeout: Duration(seconds: 60), + keyboardBehavior: KeyboardBehavior.alternative, ), framePolicy: LiveTestWidgetsFlutterBindingFramePolicy.fullyLive, ($) async { - await initTwakeChat($); + await initTwakeChat(); final originalOnError = FlutterError.onError!; FlutterError.onError = (FlutterErrorDetails details) { originalOnError(details); @@ -32,17 +29,7 @@ class TestBase { }); } - Future initTwakeChat(PatrolIntegrationTester $) async { - MediaKit.ensureInitialized(); - GoRouter.optionURLReflectsImperativeAPIs = true; - await Hive.initFlutter(); - GetItInitializer().setUp(); - final clients = await ClientManager.getClients(); - final firstClient = clients.firstOrNull; - await firstClient?.roomsLoading; - await firstClient?.accountDataLoading; - await $.pumpWidgetAndSettle( - TwakeApp(clients: clients), - ); + Future initTwakeChat() async { + app.main(); } } diff --git a/integration_test/robots/login_robot.dart b/integration_test/robots/login_robot.dart new file mode 100644 index 000000000..4d5aa3f49 --- /dev/null +++ b/integration_test/robots/login_robot.dart @@ -0,0 +1,53 @@ +import 'package:fluffychat/pages/homeserver_picker/homeserver_picker_view.dart'; +import 'package:patrol/patrol.dart'; + +import '../base/core_robot.dart'; + +class LoginRobot extends CoreRobot { + LoginRobot(super.$); + + Future grantNotificationPermission( + NativeAutomator nativeAutomator, + ) async { + if (await nativeAutomator.isPermissionDialogVisible( + timeout: const Duration(seconds: 15), + )) { + await nativeAutomator.grantPermissionWhenInUse(); + } + } + + Future tapOnUseYourCompanyServer() async { + await $('Use your company server').tap(); + } + + Future enterServerUrl(String serverUrl) async { + await $.enterText($(HomeserverTextField), serverUrl); + } + + Future confirmServerUrl() async { + await $.tap($('Continue')); + } + + Future enterUsernameSsoLogin(String username) async { + await $.native.enterText( + Selector(resourceId: 'login'), + text: username, + ); + } + + Future enterPasswordSsoLogin(String password) async { + await $.native.enterText( + Selector(resourceId: 'password'), + text: password, + ); + } + + Future pressSignInSsoLogin() async { + await $.native.tap( + Selector( + text: 'Sign in', + instance: 1, + ), + ); + } +} diff --git a/integration_test/scenarios/login_scenario.dart b/integration_test/scenarios/login_scenario.dart index f23ac8053..0fe6bfeda 100644 --- a/integration_test/scenarios/login_scenario.dart +++ b/integration_test/scenarios/login_scenario.dart @@ -2,8 +2,8 @@ import 'package:fluffychat/pages/chat_list/chat_list.dart'; import 'package:fluffychat/pages/homeserver_picker/homeserver_picker_view.dart'; import 'package:fluffychat/pages/twake_welcome/twake_welcome.dart'; import 'package:flutter_test/flutter_test.dart'; -import 'package:patrol/patrol.dart'; import '../base/base_scenario.dart'; +import '../robots/login_robot.dart'; class LoginScenario extends BaseScenario { final String username; @@ -20,27 +20,23 @@ class LoginScenario extends BaseScenario { }); @override Future execute() async { + final loginRobot = LoginRobot($); await $.waitUntilVisible($(TwakeWelcome)); await expectViewVisible($(TwakeWelcome)); - await $('Use your company server').tap(); - await $.waitUntilVisible($(HomeserverPickerView)); - await $.enterText($(HomeserverTextField), serverUrl); - await $.tap($('Continue')); - - await $.native.enterTextByIndex( - username, - index: 0, - ); - await $.native.enterTextByIndex( - password, - index: 1, + await loginRobot.tapOnUseYourCompanyServer(); + await $.waitUntilVisible( + $(HomeserverPickerView), ); - await $.native.tap( - Selector( - text: 'Sign in', - instance: 1, - ), + await loginRobot.enterServerUrl(serverUrl); + await loginRobot.confirmServerUrl(); + + await loginRobot.enterUsernameSsoLogin(username); + await loginRobot.enterPasswordSsoLogin(password); + await loginRobot.pressSignInSsoLogin(); + await $.waitUntilVisible( + $(HomeserverPickerView), ); + await loginRobot.grantNotificationPermission($.nativeAutomator); await expectViewVisible($(ChatList)); } } diff --git a/integration_test/tests/login/login_test.dart b/integration_test/tests/login/login_test.dart index cd33ba0e5..1fa2f0cc3 100644 --- a/integration_test/tests/login/login_test.dart +++ b/integration_test/tests/login/login_test.dart @@ -3,8 +3,7 @@ import '../../scenarios/login_scenario.dart'; void main() { TestBase().runPatrolTest( - description: - 'Should see chat list after successful login', + description: 'Should see chat list after successful login', test: ($) async { final loginScenario = LoginScenario( $,