import 'dart:async'; import 'package:flutter/cupertino.dart'; import 'package:flutter/material.dart'; import 'package:flutter_test/flutter_test.dart'; import 'package:pipelines_app/core/api_gateway.dart'; import 'package:pipelines_app/core/transport/connection_state.dart'; import 'package:pipelines_app/features/runs/actions/retry_wording.dart'; import 'retry_test_support.dart'; void main() { testWidgets('confirm cannot submit twice while the retry is in flight', ( tester, ) async { final reply = Completer(); final gateway = FakeRetryGateway((type, fields) => reply.future); final changed = []; await pumpRetry(tester, gateway: gateway, changed: changed); await tester.tap(find.byKey(retryActionKey)); await tester.pumpAndSettle(); final confirm = find.byKey(retryConfirmKey); await tester.tap(confirm); await tester.tap(confirm); await tester.pump(); expect(gateway.retries, hasLength(1)); expect( tester.widget(find.byKey(retryConfirmKey)).onPressed, isNull, ); expect( tester.widget(find.byKey(retryKeepKey)).onPressed, isNull, ); expect(find.byType(AlertDialog), findsOneWidget); reply.complete({'run_detail': retriedRun()}); await tester.pumpAndSettle(); expect(find.byType(AlertDialog), findsNothing); expect(changed, hasLength(1)); }); testWidgets('a late retry reply after disposal is ignored safely', ( tester, ) async { final reply = Completer(); final gateway = FakeRetryGateway((type, fields) => reply.future); final changed = []; await pumpRetry(tester, gateway: gateway, changed: changed); await tester.tap(find.byKey(retryActionKey)); await tester.pumpAndSettle(); await tester.tap(find.byKey(retryConfirmKey)); await tester.pump(); expect(gateway.retries, hasLength(1)); await tester.pumpWidget(const SizedBox()); reply.complete({'run_detail': retriedRun()}); await tester.pump(); expect(tester.takeException(), isNull); expect(changed, isEmpty); }); testWidgets('a late resync after disposal is ignored safely', (tester) async { final resync = Completer(); final gateway = FakeRetryGateway((type, fields) { if (type == 'retry_run') throw const ProtocolError('refused'); return resync.future; }); final changed = []; await pumpRetry(tester, gateway: gateway, changed: changed); await tester.tap(find.byKey(retryActionKey)); await tester.pumpAndSettle(); await tester.tap(find.byKey(retryConfirmKey)); await tester.pump(); expect(gateway.calls.map((call) => call.type), ['retry_run', 'get_run']); await tester.pumpWidget(const SizedBox()); resync.complete({'run_detail': retriedRun()}); await tester.pump(); expect(tester.takeException(), isNull); expect(changed, isEmpty); }); testWidgets('both confirmations fit 2x text at a narrow width', ( tester, ) async { tester.view.physicalSize = const Size(320, 480); tester.view.devicePixelRatio = 1; addTearDown(tester.view.resetPhysicalSize); addTearDown(tester.view.resetDevicePixelRatio); for (final cupertino in [false, true]) { final gateway = FakeRetryGateway( (type, fields) async => {'run_detail': retriedRun()}, ); await pumpRetry( tester, gateway: gateway, changed: [], cupertino: cupertino, textScale: 2, ); await tester.tap(find.byKey(retryActionKey)); await tester.pumpAndSettle(); expect(tester.takeException(), isNull, reason: 'cupertino=$cupertino'); expect(find.text(retryDialogTitle(7)), findsOneWidget); expect(find.text(retryDialogMessage), findsOneWidget); expect( cupertino ? find.byType(CupertinoAlertDialog) : find.byType(AlertDialog), findsOneWidget, ); await tester.tap(find.byKey(retryRestartKey)); await tester.pumpAndSettle(); expect(tester.takeException(), isNull, reason: 'restart=$cupertino'); expect(find.text(restartDialogTitle(7)), findsOneWidget); expect(find.text(restartDialogMessage), findsOneWidget); await tester.tap(find.byKey(retryKeepKey)); await tester.pumpAndSettle(); expect(gateway.calls, isEmpty); } }); }