import 'package:flutter/widgets.dart'; import 'package:flutter_test/flutter_test.dart'; import 'package:pipelines_app/features/runs/ui/run_more_menu.dart'; import 'package:pipelines_app/core/transport/connection_state.dart'; import 'package:pipelines_app/features/runs/actions/retry_wording.dart'; import 'run_retry_wiring_support.dart'; void main() { testWidgets('a reply without an id never opens a guessed run', ( tester, ) async { final gateway = RetryWiringGateway(); addTearDown(gateway.framesController.close); final opened = []; await mountRetryScreen( tester, gateway, cupertino: false, onRunSelected: opened.add, ); await confirmRetry(tester); gateway.retries.last.complete({ 'run_detail': {'title': 'Unknown run', 'status': 'running'}, }); await tester.pumpAndSettle(); expect(opened, isEmpty); expect(find.text(retryFailedTitle), findsOneWidget); expect(find.text('Unknown run'), findsNothing); expect(gateway.calls.where((call) => call.type == 'get_run'), hasLength(1)); }); testWidgets('a refused retry stays on the failed run', (tester) async { final gateway = RetryWiringGateway(); addTearDown(gateway.framesController.close); final opened = []; await mountRetryScreen( tester, gateway, cupertino: false, onRunSelected: opened.add, ); await confirmRetry(tester); gateway.refuseRetry(const ProtocolError('the run is still executing')); await tester.pumpAndSettle(); expect(find.text('the run is still executing'), findsOneWidget); expect(opened, isEmpty); expect(find.text(retryFailedTitle), findsOneWidget); await tester.tap(find.byKey(retryKeepKey)); await tester.pumpAndSettle(); expect(await retryOffered(tester), isTrue); }); testWidgets('a retry reply that lands after leaving is ignored', ( tester, ) async { final gateway = RetryWiringGateway(); addTearDown(gateway.framesController.close); final opened = []; await mountRetryScreen( tester, gateway, cupertino: false, onRunSelected: opened.add, ); await confirmRetry(tester); expect(gateway.retryCalls, hasLength(1)); await tester.pumpWidget(const SizedBox.shrink()); gateway.acceptRetry(retryCreatedDetail()); await tester.pump(); expect(tester.takeException(), isNull); expect(opened, isEmpty); expect(gateway.calls.where((call) => call.type == 'get_run'), hasLength(1)); }); testWidgets('a reply naming the source run opens nothing', (tester) async { final gateway = RetryWiringGateway(); addTearDown(gateway.framesController.close); final opened = []; await mountRetryScreen( tester, gateway, cupertino: false, onRunSelected: opened.add, ); await confirmRetry(tester); gateway.acceptRetry(retryCreatedDetail(id: 7)); await tester.pumpAndSettle(); // The accepted detail still folds, but its id is the source run, so there // is no new run to open and no second read. expect(opened, isEmpty); expect(find.text(retryCreatedTitle), findsOneWidget); expect(gateway.calls.where((call) => call.type == 'get_run'), hasLength(1)); }); testWidgets('a failed run that is still executing exposes no retry', ( tester, ) async { final gateway = RetryWiringGateway(executing: true); addTearDown(gateway.framesController.close); await mountRetryScreen(tester, gateway, cupertino: false); expect(find.byKey(runMoreMenuKey), findsOneWidget); expect(await retryOffered(tester), isFalse); }); }