2023-01-22 05:43:28 +02:00
|
|
|
import 'package:easy_localization/easy_localization.dart';
|
|
|
|
import 'package:flutter_test/flutter_test.dart';
|
|
|
|
import 'package:hive/hive.dart';
|
2023-02-09 19:32:08 +02:00
|
|
|
import 'package:immich_mobile/shared/models/store.dart';
|
2023-01-22 05:43:28 +02:00
|
|
|
import 'package:integration_test/integration_test.dart';
|
2023-02-09 19:32:08 +02:00
|
|
|
import 'package:isar/isar.dart';
|
2023-01-26 16:40:19 +02:00
|
|
|
// ignore: depend_on_referenced_packages
|
2023-01-25 18:10:04 +02:00
|
|
|
import 'package:meta/meta.dart';
|
2023-01-22 05:43:28 +02:00
|
|
|
import 'package:immich_mobile/main.dart' as app;
|
|
|
|
|
2023-01-25 18:10:04 +02:00
|
|
|
import 'login_helper.dart';
|
|
|
|
|
2023-01-22 05:43:28 +02:00
|
|
|
class ImmichTestHelper {
|
2023-01-25 18:10:04 +02:00
|
|
|
final WidgetTester tester;
|
|
|
|
|
|
|
|
ImmichTestHelper(this.tester);
|
|
|
|
|
|
|
|
ImmichTestLoginHelper? _loginHelper;
|
|
|
|
|
|
|
|
ImmichTestLoginHelper get loginHelper {
|
|
|
|
_loginHelper ??= ImmichTestLoginHelper(tester);
|
|
|
|
return _loginHelper!;
|
|
|
|
}
|
|
|
|
|
2023-01-22 05:43:28 +02:00
|
|
|
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();
|
2023-02-09 19:32:08 +02:00
|
|
|
// Clear all data from Isar (reuse existing instance if available)
|
|
|
|
final db = Isar.getInstance() ?? await app.loadDb();
|
|
|
|
await Store.clear();
|
|
|
|
await db.writeTxn(() => db.clear());
|
2023-01-22 05:43:28 +02:00
|
|
|
// Load main Widget
|
2023-02-09 19:32:08 +02:00
|
|
|
await tester.pumpWidget(app.getMainWidget(db));
|
2023-01-22 05:43:28 +02:00
|
|
|
// Post run tasks
|
|
|
|
await tester.pumpAndSettle();
|
|
|
|
await EasyLocalization.ensureInitialized();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-01-25 18:10:04 +02:00
|
|
|
@isTest
|
2023-01-26 16:40:19 +02:00
|
|
|
void immichWidgetTest(
|
|
|
|
String description,
|
|
|
|
Future<void> Function(WidgetTester, ImmichTestHelper) test,
|
|
|
|
) {
|
|
|
|
testWidgets(
|
|
|
|
description,
|
|
|
|
(widgetTester) async {
|
|
|
|
await ImmichTestHelper.loadApp(widgetTester);
|
|
|
|
await test(widgetTester, ImmichTestHelper(widgetTester));
|
|
|
|
},
|
|
|
|
semanticsEnabled: false,
|
|
|
|
);
|
|
|
|
}
|