import 'package:flutter/cupertino.dart'; import 'package:flutter/material.dart'; import 'package:flutter_test/flutter_test.dart'; import 'package:pipelines_app/features/runs/actions/cancel_wording.dart'; import 'package:pipelines_app/features/runs/actions/retry_wording.dart'; import 'package:pipelines_app/features/runs/actions/title_wording.dart'; import 'package:pipelines_app/features/runs/ui/run_detail_actions.dart'; import 'run_retry_wiring_support.dart'; void main() { testWidgets('a hidden retry adds no extra gap for Rename and Cancel', ( tester, ) async { final gateway = RetryWiringGateway(); addTearDown(gateway.framesController.close); await tester.pumpWidget( MaterialApp( home: Scaffold( body: Padding( padding: const EdgeInsets.all(16), child: RunDetailActions( run: retryCreatedDetail(id: 7), gateway: gateway, onRunChanged: (_) {}, ), ), ), ), ); await tester.pumpAndSettle(); // Retry is not eligible on the running run and must not consume spacing. expect(find.byKey(retryActionKey), findsNothing); final rename = tester.getRect(find.byKey(runTitleActionKey)); final cancel = tester.getRect(find.byKey(cancelActionKey)); expect(cancel.left - rename.right, closeTo(8, 0.5)); }); for (final cupertino in [false, true]) { testWidgets('adjacent actions keep native spacing at 320 px ($cupertino)', ( tester, ) async { tester.view.physicalSize = const Size(320, 480); tester.view.devicePixelRatio = 1; addTearDown(tester.view.resetPhysicalSize); addTearDown(tester.view.resetDevicePixelRatio); final gateway = RetryWiringGateway(); addTearDown(gateway.framesController.close); final row = Padding( padding: const EdgeInsets.all(16), child: RunDetailActions( run: retryFailedDetail(), gateway: gateway, onRunChanged: (_) {}, ), ); await tester.pumpWidget( cupertino ? CupertinoApp( home: CupertinoPageScaffold(child: SafeArea(child: row)), ) : MaterialApp(home: Scaffold(body: row)), ); await tester.pumpAndSettle(); expectNativeActionSpacing(tester); }); } for (final cupertino in [false, true]) { testWidgets('320 px at 2x keeps Rename and Retry reachable ($cupertino)', ( tester, ) async { tester.view.physicalSize = const Size(320, 480); tester.view.devicePixelRatio = 1; addTearDown(tester.view.resetPhysicalSize); addTearDown(tester.view.resetDevicePixelRatio); final gateway = RetryWiringGateway(); addTearDown(gateway.framesController.close); Widget scale(BuildContext context, Widget? app) => MediaQuery( data: MediaQuery.of( context, ).copyWith(textScaler: const TextScaler.linear(2)), child: app!, ); // The action row itself, in the detail's 16 px inset, so the narrow // accessibility state is measured without unrelated header controls. final row = Padding( padding: const EdgeInsets.all(16), child: RunDetailActions( run: retryFailedDetail(), gateway: gateway, onRunChanged: (_) {}, ), ); await tester.pumpWidget( cupertino ? CupertinoApp( builder: scale, home: CupertinoPageScaffold(child: SafeArea(child: row)), ) : MaterialApp( builder: scale, home: Scaffold(body: row), ), ); await tester.pumpAndSettle(); expect(find.byKey(runTitleActionKey).hitTestable(), findsOneWidget); expect(find.byKey(retryActionKey).hitTestable(), findsOneWidget); final rect = tester.getRect(find.byKey(retryActionKey)); expect(rect.left, greaterThanOrEqualTo(0)); expect(rect.right, lessThanOrEqualTo(320)); expectNativeActionSpacing(tester); await tester.tap(find.byKey(retryActionKey)); await tester.pumpAndSettle(); expect(find.text(retryDialogTitle(7)), findsOneWidget); await tester.tap(find.byKey(retryKeepKey)); await tester.pumpAndSettle(); expect(gateway.retryCalls, isEmpty); }); } } /// Asserts the action row uses the detail's native 8 dp / 4 dp spacing. /// /// The row previously had no `spacing`, leaving the outlined Rename border /// touching the filled Retry button; browser measurement at 320 px reported a /// 0.008 px gap. A hidden action must not consume spacing either. void expectNativeActionSpacing(WidgetTester tester) { final rename = tester.getRect(find.byKey(runTitleActionKey)); final retry = tester.getRect(find.byKey(retryActionKey)); final sameRow = retry.top < rename.bottom && rename.top < retry.bottom; if (sameRow) { expect( retry.left - rename.right, greaterThanOrEqualTo(8 - 0.01), reason: 'side-by-side actions need the 8 dp Wrap spacing', ); } else { expect( retry.top - rename.bottom, greaterThanOrEqualTo(4 - 0.01), reason: 'wrapped actions need the 4 dp Wrap run spacing', ); } }