Skip to content

Commit

Permalink
LA-2185 added integration test for login
Browse files Browse the repository at this point in the history
  • Loading branch information
KhaledNjim committed Dec 18, 2024
1 parent 9271c7e commit 494427c
Show file tree
Hide file tree
Showing 4 changed files with 128 additions and 0 deletions.
15 changes: 15 additions & 0 deletions integration_test/base/base_scenario.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import 'package:flutter_test/flutter_test.dart';
import 'package:patrol/patrol.dart';

abstract class BaseScenario {
final PatrolIntegrationTester $;

const BaseScenario(this.$);

Future<void> execute();

Future<void> expectViewVisible(PatrolFinder patrolFinder) async {
await $.waitUntilVisible(patrolFinder);
expect(patrolFinder, findsWidgets);
}
}
48 changes: 48 additions & 0 deletions integration_test/base/test_base.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
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';

class TestBase {
void runPatrolTest({
required String description,
required Function(PatrolIntegrationTester $) test,
}) {
patrolTest(description,
config: const PatrolTesterConfig(
settlePolicy: SettlePolicy.trySettle,
visibleTimeout: Duration(minutes: 1),
),
nativeAutomatorConfig: const NativeAutomatorConfig(
findTimeout: Duration(seconds: 10),
),
framePolicy: LiveTestWidgetsFlutterBindingFramePolicy.fullyLive,
($) async {
await initTwakeChat($);
final originalOnError = FlutterError.onError!;
FlutterError.onError = (FlutterErrorDetails details) {
originalOnError(details);
};
await test($);
});
}

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),
);
}
}
46 changes: 46 additions & 0 deletions integration_test/scenarios/login_scenario.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
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';

class LoginScenario extends BaseScenario {
final String username;

final String serverUrl;

final String password;

LoginScenario(
super.$, {
required this.username,
required this.serverUrl,
required this.password,
});
@override
Future<void> execute() async {
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 $.native.tap(
Selector(
text: 'Sign in',
instance: 1,
),
);
await expectViewVisible($(ChatList));
}
}
19 changes: 19 additions & 0 deletions integration_test/tests/login/login_test.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import '../../base/test_base.dart';
import '../../scenarios/login_scenario.dart';

void main() {
TestBase().runPatrolTest(
description:
'Should see chat list after successful login',
test: ($) async {
final loginScenario = LoginScenario(
$,
username: const String.fromEnvironment('USERNAME'),
serverUrl: const String.fromEnvironment('SERVER_URL'),
password: const String.fromEnvironment('PASSWORD'),
);

await loginScenario.execute();
},
);
}

0 comments on commit 494427c

Please sign in to comment.