Skip to content

Commit

Permalink
fixup! LA-2185 added integration test for login
Browse files Browse the repository at this point in the history
  • Loading branch information
KhaledNjim committed Dec 23, 2024
1 parent 494427c commit 5e28b61
Show file tree
Hide file tree
Showing 5 changed files with 85 additions and 41 deletions.
9 changes: 9 additions & 0 deletions integration_test/base/core_robot.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import 'package:patrol/patrol.dart';

abstract class CoreRobot {
final PatrolIntegrationTester $;

CoreRobot(this.$);

dynamic ignoreException() => $.tester.takeException();
}
29 changes: 8 additions & 21 deletions integration_test/base/test_base.dart
Original file line number Diff line number Diff line change
@@ -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({
Expand All @@ -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);
Expand All @@ -32,17 +29,7 @@ class TestBase {
});
}

Future<void> 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<void> initTwakeChat() async {
app.main();
}
}
53 changes: 53 additions & 0 deletions integration_test/robots/login_robot.dart
Original file line number Diff line number Diff line change
@@ -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<void> grantNotificationPermission(
NativeAutomator nativeAutomator,
) async {
if (await nativeAutomator.isPermissionDialogVisible(
timeout: const Duration(seconds: 15),
)) {
await nativeAutomator.grantPermissionWhenInUse();
}
}

Future<void> tapOnUseYourCompanyServer() async {
await $('Use your company server').tap();
}

Future<void> enterServerUrl(String serverUrl) async {
await $.enterText($(HomeserverTextField), serverUrl);
}

Future<void> confirmServerUrl() async {
await $.tap($('Continue'));
}

Future<void> enterUsernameSsoLogin(String username) async {
await $.native.enterText(
Selector(resourceId: 'login'),
text: username,
);
}

Future<void> enterPasswordSsoLogin(String password) async {
await $.native.enterText(
Selector(resourceId: 'password'),
text: password,
);
}

Future<void> pressSignInSsoLogin() async {
await $.native.tap(
Selector(
text: 'Sign in',
instance: 1,
),
);
}
}
32 changes: 14 additions & 18 deletions integration_test/scenarios/login_scenario.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -20,27 +20,23 @@ class LoginScenario extends BaseScenario {
});
@override
Future<void> 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));
}
}
3 changes: 1 addition & 2 deletions integration_test/tests/login/login_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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(
$,
Expand Down

0 comments on commit 5e28b61

Please sign in to comment.