-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
LA-2185 added integration test for login
- Loading branch information
1 parent
9271c7e
commit 494427c
Showing
4 changed files
with
128 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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), | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
}, | ||
); | ||
} |