2023-02-19 10:50:36 -07:00
|
|
|
import 'dart:async';
|
|
|
|
|
2023-01-21 20:43:28 -07:00
|
|
|
import 'package:easy_localization/easy_localization.dart';
|
|
|
|
import 'package:flutter_test/flutter_test.dart';
|
|
|
|
import 'package:hive/hive.dart';
|
2023-02-09 10:32:08 -07:00
|
|
|
import 'package:immich_mobile/shared/models/store.dart';
|
2023-01-21 20:43:28 -07:00
|
|
|
import 'package:integration_test/integration_test.dart';
|
2023-02-09 10:32:08 -07:00
|
|
|
import 'package:isar/isar.dart';
|
2023-01-26 07:40:19 -07:00
|
|
|
// ignore: depend_on_referenced_packages
|
2023-01-25 09:10:04 -07:00
|
|
|
import 'package:meta/meta.dart';
|
2023-01-21 20:43:28 -07:00
|
|
|
import 'package:immich_mobile/main.dart' as app;
|
|
|
|
|
2023-01-25 09:10:04 -07:00
|
|
|
import 'login_helper.dart';
|
|
|
|
|
2023-01-21 20:43:28 -07:00
|
|
|
class ImmichTestHelper {
|
2023-01-25 09:10:04 -07:00
|
|
|
final WidgetTester tester;
|
|
|
|
|
|
|
|
ImmichTestHelper(this.tester);
|
|
|
|
|
|
|
|
ImmichTestLoginHelper? _loginHelper;
|
|
|
|
|
|
|
|
ImmichTestLoginHelper get loginHelper {
|
|
|
|
_loginHelper ??= ImmichTestLoginHelper(tester);
|
|
|
|
return _loginHelper!;
|
|
|
|
}
|
|
|
|
|
2023-01-21 20:43:28 -07: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 10:32:08 -07: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-21 20:43:28 -07:00
|
|
|
// Load main Widget
|
2023-02-09 10:32:08 -07:00
|
|
|
await tester.pumpWidget(app.getMainWidget(db));
|
2023-01-21 20:43:28 -07:00
|
|
|
// Post run tasks
|
|
|
|
await EasyLocalization.ensureInitialized();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-01-25 09:10:04 -07:00
|
|
|
@isTest
|
2023-01-26 07:40:19 -07: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,
|
|
|
|
);
|
|
|
|
}
|
2023-02-19 10:50:36 -07:00
|
|
|
|
|
|
|
Future<void> pumpUntilFound(
|
|
|
|
WidgetTester tester,
|
|
|
|
Finder finder, {
|
|
|
|
Duration timeout = const Duration(seconds: 120),
|
|
|
|
}) async {
|
|
|
|
bool found = false;
|
|
|
|
final timer = Timer(timeout, () => throw TimeoutException("Pump until has timed out"));
|
|
|
|
while (found != true) {
|
|
|
|
await tester.pump();
|
|
|
|
found = tester.any(finder);
|
|
|
|
}
|
|
|
|
timer.cancel();
|
|
|
|
}
|