mirror of https://github.com/immich-app/immich.git
feat(mobile): Add integration tests (#1359)
parent
e5d798581c
commit
f4c90426a5
@ -0,0 +1,44 @@
|
||||
name: Flutter Integration Tests
|
||||
|
||||
on:
|
||||
push:
|
||||
branches: [ "main" ]
|
||||
pull_request:
|
||||
|
||||
jobs:
|
||||
build:
|
||||
runs-on: macos-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v2
|
||||
- uses: actions/setup-java@v2
|
||||
with:
|
||||
distribution: 'adopt'
|
||||
java-version: '11'
|
||||
- name: Cache android SDK
|
||||
uses: actions/cache@v2
|
||||
id: android-sdk
|
||||
with:
|
||||
key: android-sdk
|
||||
path: |
|
||||
/usr/local/lib/android/
|
||||
~/.android
|
||||
- name: Setup Android SDK
|
||||
if: steps.android-sdk.outputs.cache-hit != 'true'
|
||||
uses: android-actions/setup-android@v2
|
||||
- name: Setup Flutter SDK
|
||||
uses: subosito/flutter-action@v1
|
||||
with:
|
||||
channel: 'stable'
|
||||
- name: Run integration tests
|
||||
uses: reactivecircus/android-emulator-runner@v2.27.0
|
||||
with:
|
||||
working-directory: ./mobile
|
||||
api-level: 29
|
||||
arch: x86_64
|
||||
profile: pixel
|
||||
target: default
|
||||
emulator-options: -no-window -gpu swiftshader_indirect -no-snapshot -noaudio -no-boot-anim
|
||||
disable-linux-hw-accel: false
|
||||
script: |
|
||||
flutter pub get
|
||||
flutter test integration_test
|
||||
@ -0,0 +1,36 @@
|
||||
import 'package:easy_localization/easy_localization.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
|
||||
import '../test_utils/general_helper.dart';
|
||||
import '../test_utils/login_helper.dart';
|
||||
|
||||
void main() async {
|
||||
await ImmichTestHelper.initialize();
|
||||
|
||||
group("Login input validation test", () {
|
||||
immichWidgetTest("Test http warning message", (tester) async {
|
||||
await ImmichTestLoginHelper.waitForLoginScreen(tester);
|
||||
await ImmichTestLoginHelper.acknowledgeNewServerVersion(tester);
|
||||
|
||||
// Test https URL
|
||||
await ImmichTestLoginHelper.enterLoginCredentials(
|
||||
tester,
|
||||
server: "https://demo.immich.app/api",
|
||||
);
|
||||
|
||||
await tester.pump(const Duration(milliseconds: 300));
|
||||
|
||||
expect(find.text("login_form_err_http_insecure".tr()), findsNothing);
|
||||
|
||||
// Test http URL
|
||||
await ImmichTestLoginHelper.enterLoginCredentials(
|
||||
tester,
|
||||
server: "http://demo.immich.app/api",
|
||||
);
|
||||
|
||||
await tester.pump(const Duration(milliseconds: 300));
|
||||
|
||||
expect(find.text("login_form_err_http_insecure".tr()), findsOneWidget);
|
||||
});
|
||||
});
|
||||
}
|
||||
@ -0,0 +1,40 @@
|
||||
|
||||
import 'package:easy_localization/easy_localization.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:hive/hive.dart';
|
||||
import 'package:immich_mobile/main.dart';
|
||||
import 'package:integration_test/integration_test.dart';
|
||||
|
||||
import 'package:immich_mobile/main.dart' as app;
|
||||
|
||||
class ImmichTestHelper {
|
||||
|
||||
static Future<IntegrationTestWidgetsFlutterBinding> initialize() async {
|
||||
final binding = IntegrationTestWidgetsFlutterBinding.ensureInitialized();
|
||||
binding.framePolicy = LiveTestWidgetsFlutterBindingFramePolicy.fullyLive;
|
||||
|
||||
// Load hive, localization...
|
||||
await app.initApp();
|
||||
|
||||
return binding;
|
||||
}
|
||||
|
||||
static Future<void> loadApp(WidgetTester tester) async {
|
||||
// Clear all data from Hive
|
||||
await Hive.deleteFromDisk();
|
||||
await app.openBoxes();
|
||||
// Load main Widget
|
||||
await tester.pumpWidget(app.getMainWidget());
|
||||
// Post run tasks
|
||||
await tester.pumpAndSettle();
|
||||
await EasyLocalization.ensureInitialized();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void immichWidgetTest(String description, Future<void> Function(WidgetTester) test) {
|
||||
testWidgets(description, (widgetTester) async {
|
||||
await ImmichTestHelper.loadApp(widgetTester);
|
||||
await test(widgetTester);
|
||||
});
|
||||
}
|
||||
@ -0,0 +1,55 @@
|
||||
import 'dart:async';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
|
||||
class ImmichTestLoginHelper {
|
||||
static Future<void> waitForLoginScreen(WidgetTester tester,
|
||||
{int timeoutSeconds = 20}) async {
|
||||
for (var i = 0; i < timeoutSeconds; i++) {
|
||||
// Search for "IMMICH" test in the app bar
|
||||
final result = find.text("IMMICH");
|
||||
if (tester.any(result)) {
|
||||
// Wait 5s until everything settled
|
||||
await tester.pump(const Duration(seconds: 5));
|
||||
return;
|
||||
}
|
||||
|
||||
// Wait 1s before trying again
|
||||
await Future.delayed(const Duration(seconds: 1));
|
||||
}
|
||||
|
||||
fail("Timeout while waiting for login screen");
|
||||
}
|
||||
|
||||
static Future<bool> acknowledgeNewServerVersion(WidgetTester tester) async {
|
||||
final result = find.text("Acknowledge");
|
||||
if (!tester.any(result)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
await tester.tap(result);
|
||||
await tester.pump();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
static Future<void> enterLoginCredentials(
|
||||
WidgetTester tester, {
|
||||
String server = "",
|
||||
String email = "",
|
||||
String password = "",
|
||||
}) async {
|
||||
final loginForms = find.byType(TextFormField);
|
||||
|
||||
await tester.pump(const Duration(milliseconds: 500));
|
||||
await tester.enterText(loginForms.at(0), email);
|
||||
|
||||
await tester.pump(const Duration(milliseconds: 500));
|
||||
await tester.enterText(loginForms.at(1), password);
|
||||
|
||||
await tester.pump(const Duration(milliseconds: 500));
|
||||
await tester.enterText(loginForms.at(2), server);
|
||||
|
||||
await tester.pump(const Duration(milliseconds: 500));
|
||||
}
|
||||
}
|
||||
Loading…
Reference in New Issue