import 'dart:async'; import 'package:flutter/material.dart'; import 'package:flutter_test/flutter_test.dart'; import 'package:pipelines_app/features/updates/app_updates.dart'; import 'package:pipelines_app/features/updates/launch_update_dialog.dart'; void main() { for (final (platform, sentence, action) in [ ('linux', 'installs it and restarts', 'Install and restart'), ('macos', 'extract the archive', 'Download'), ]) { testWidgets('$platform prompt identifies source and its action', ( tester, ) async { await tester.pumpWidget( MaterialApp( home: Builder( builder: (context) => TextButton( onPressed: () => showLaunchUpdateDialog( context, web: false, nativePlatform: platform, sourceName: 'Home Linux', ), child: const Text('Check'), ), ), ), ); await tester.tap(find.text('Check')); await tester.pumpAndSettle(); expect(find.textContaining('from Home Linux'), findsOneWidget); expect(find.textContaining(sentence), findsOneWidget); expect(find.text(action), findsOneWidget); expect(find.textContaining('Android'), findsNothing); }); } testWidgets('update failure uses a Material alert', (tester) async { await tester.pumpWidget( MaterialApp( home: Builder( builder: (context) => TextButton( onPressed: () => showLaunchUpdateFailure(context, 'boom'), child: const Text('Fail'), ), ), ), ); await tester.tap(find.text('Fail')); await tester.pumpAndSettle(); expect(find.byType(AlertDialog), findsOneWidget); expect(find.text('Update failed'), findsOneWidget); expect(find.text('boom'), findsOneWidget); expect(find.text('OK'), findsOneWidget); }); testWidgets('install progress uses a Material alert and progress bar', ( tester, ) async { final finished = Completer(); late BuildContext dialogContext; await tester.pumpWidget( MaterialApp( home: Builder( builder: (context) { dialogContext = context; return const SizedBox(); }, ), ), ); final install = installLaunchUpdate( dialogContext, AppUpdate( versionCode: 2, versionName: '2.0', apk: Uri.parse('https://example.test/app.apk'), ), installer: (update, {onProgress}) async { onProgress?.call(0.5); await finished.future; }, ); await tester.pumpAndSettle(); expect(find.byType(AlertDialog), findsOneWidget); expect(find.byType(LinearProgressIndicator), findsOneWidget); expect(find.text('App update'), findsOneWidget); expect(find.text('Downloading update… 50%'), findsOneWidget); finished.complete(); await tester.pumpAndSettle(); expect(find.byType(AlertDialog), findsNothing); await install; }); }