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';
|
2023-11-19 09:04:44 -07:00
|
|
|
import 'package:hooks_riverpod/hooks_riverpod.dart';
|
2023-02-09 10:32:08 -07:00
|
|
|
import 'package:immich_mobile/shared/models/store.dart';
|
2023-11-19 09:04:44 -07:00
|
|
|
import 'package:immich_mobile/shared/providers/db.provider.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 {
|
2023-03-22 18:36:44 -07:00
|
|
|
await EasyLocalization.ensureInitialized();
|
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-11-19 09:04:44 -07:00
|
|
|
await tester.pumpWidget(
|
|
|
|
ProviderScope(
|
|
|
|
overrides: [dbProvider.overrideWithValue(db)],
|
2023-11-28 21:20:00 -07:00
|
|
|
child: const app.MainWidget(),
|
2023-11-19 09:04:44 -07:00
|
|
|
),
|
|
|
|
);
|
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(
|
2023-03-22 18:36:44 -07:00
|
|
|
WidgetTester tester,
|
|
|
|
Finder finder, {
|
|
|
|
Duration timeout = const Duration(seconds: 120),
|
|
|
|
}) async {
|
2023-02-19 10:50:36 -07:00
|
|
|
bool found = false;
|
2023-03-22 18:36:44 -07:00
|
|
|
final timer =
|
|
|
|
Timer(timeout, () => throw TimeoutException("Pump until has timed out"));
|
2023-02-19 10:50:36 -07:00
|
|
|
while (found != true) {
|
|
|
|
await tester.pump();
|
|
|
|
found = tester.any(finder);
|
|
|
|
}
|
|
|
|
timer.cancel();
|
|
|
|
}
|