Files
Immich/mobile/test/unit/presentation/app_update_settings_test.dart
T

89 lines
3.8 KiB
Dart

import 'dart:io';
import 'package:flutter_test/flutter_test.dart';
import 'package:immich_mobile/services/app_update.service.dart';
import 'package:immich_mobile/widgets/settings/app_update_settings.dart';
import 'package:mocktail/mocktail.dart';
import 'package:package_info_plus/package_info_plus.dart';
import 'presentation_context.dart';
class _Updater extends Mock implements AppUpdateService {}
void main() {
late PresentationContext context;
late _Updater updater;
final release = AppRelease(
'3.3.3-local.2',
3030401,
'Release notes',
Uri.parse('https://argus.kusoft.xyz/test'),
100,
'a' * 64,
);
setUp(() async {
context = await PresentationContext.create();
updater = _Updater();
when(() => updater.installedVersion()).thenAnswer(
(_) async => PackageInfo(
appName: 'Immich',
packageName: 'app.alextran.immich',
version: '3.3.3-local.1',
buildNumber: '3030400',
),
);
});
tearDown(() async => context.dispose());
testWidgets('downloaded update can be installed after granting permission without downloading again', (tester) async {
final apk = File('/cache/immich-updates/update.apk');
registerFallbackValue((double progress) {});
when(() => updater.check()).thenAnswer((_) async => release);
when(() => updater.download(release, any())).thenAnswer((_) async => apk);
when(() => updater.install(apk, release)).thenAnswer((_) async => false);
when(() => updater.openInstallPermission()).thenAnswer((_) async {});
await tester.pumpTestWidget(context, AppUpdateSettings(service: updater));
await tester.tap(find.text('Check for updates'));
await tester.pumpAndSettle();
await tester.ensureVisible(find.text('Download and install'));
await tester.tap(find.text('Download and install'));
await tester.pumpAndSettle();
expect(find.textContaining('Allow Immich to install apps'), findsOneWidget);
await tester.ensureVisible(find.text('Allow installation'));
await tester.tap(find.text('Allow installation'));
await tester.pumpAndSettle();
verify(() => updater.openInstallPermission()).called(1);
when(() => updater.install(apk, release)).thenAnswer((_) async => true);
await tester.ensureVisible(find.text('Install update'));
await tester.tap(find.text('Install update'));
await tester.pumpAndSettle();
expect(find.text('Complete the update in the Android installer.'), findsOneWidget);
verify(() => updater.download(release, any())).called(1);
verify(() => updater.install(apk, release)).called(2);
});
testWidgets('checking is user initiated and a current version has no install action', (tester) async {
when(() => updater.check()).thenAnswer((_) async => null);
await tester.pumpTestWidget(context, AppUpdateSettings(service: updater));
verifyNever(() => updater.check());
await tester.tap(find.text('Check for updates'));
await tester.pumpAndSettle();
expect(find.text('You are up to date.'), findsOneWidget);
expect(find.text('Download and install'), findsNothing);
});
testWidgets('a check error offers retry without an install button', (tester) async {
when(() => updater.check()).thenThrow(const SocketException('offline'));
await tester.pumpTestWidget(context, AppUpdateSettings(service: updater));
await tester.tap(find.text('Check for updates'));
await tester.pumpAndSettle();
expect(find.textContaining('Could not check for updates'), findsOneWidget);
expect(find.text('Download and install'), findsNothing);
when(() => updater.check()).thenAnswer((_) async => release);
await tester.tap(find.text('Check for updates'));
await tester.pumpAndSettle();
expect(find.text('Release notes'), findsOneWidget);
expect(find.text('Download and install'), findsOneWidget);
});
}