diff --git a/app/lib/application/pipelines_app.dart b/app/lib/application/pipelines_app.dart index 081e207e..d11d4b72 100644 --- a/app/lib/application/pipelines_app.dart +++ b/app/lib/application/pipelines_app.dart @@ -439,6 +439,8 @@ class _PipelinesAppState extends State onPipelineFilterChanged: (id) => _delegate.goTo( id == null ? AppRoute.runs : AppRoute.runsForPipeline(id), ), + onOpenPipeline: (id, version) => + _delegate.goTo(AppRoute.pipeline(id, version: version)), ), ), AppDestination.chat: (_) => ChatDestination( diff --git a/app/lib/application/runs_destination.dart b/app/lib/application/runs_destination.dart index 005b2243..c4254694 100644 --- a/app/lib/application/runs_destination.dart +++ b/app/lib/application/runs_destination.dart @@ -3,6 +3,7 @@ import 'package:flutter/material.dart'; import '../features/attention/notify/notification_controller.dart'; import '../features/attention/runtime/attention_controller.dart'; import '../features/runs/screen.dart'; +import '../features/runs/ui/run_pipeline_link.dart'; import '../ui/adaptive/host.dart'; import 'app_session.dart'; import 'connection_status.dart'; @@ -27,6 +28,7 @@ class RunsDestination extends StatelessWidget { this.onRunSelected, this.onBack, this.onPipelineFilterChanged, + this.onOpenPipeline, this.listRefreshToken = 0, this.notifications, this.attention, @@ -50,6 +52,7 @@ class RunsDestination extends StatelessWidget { final ValueChanged? onRunSelected; final ValueChanged? onBack; final ValueChanged? onPipelineFilterChanged; + final OpenPipeline? onOpenPipeline; /// Advances when a launch was accepted elsewhere. The mounted Runs screen /// re-reads its list once; no row is inserted locally. @@ -107,5 +110,6 @@ class RunsDestination extends StatelessWidget { onRunSelected: onRunSelected, onBack: onBack, onPipelineFilterChanged: onPipelineFilterChanged, + onOpenPipeline: onOpenPipeline, ); } diff --git a/app/lib/features/runs/actions/retry_action.dart b/app/lib/features/runs/actions/retry_action.dart index b342058d..8fec7a34 100644 --- a/app/lib/features/runs/actions/retry_action.dart +++ b/app/lib/features/runs/actions/retry_action.dart @@ -6,7 +6,6 @@ import '../data/runs_repository.dart'; import 'action_refusal.dart'; import 'retry_dialog.dart'; import 'retry_eligibility.dart'; -import 'retry_intent.dart'; import 'retry_wording.dart'; /// The run detail's deliberate retry entry point. @@ -42,26 +41,20 @@ class RetryRunAction extends StatefulWidget { class _RetryRunActionState extends State { bool _dialogOpen = false; - Future? _resync; - bool _usesCupertino(BuildContext context) { - final material = Localizations.of( - context, - MaterialLocalizations, - ); - return material == null; - } + bool _usesCupertino(BuildContext context) => _cupertinoLocale(context); Future _open() async { - final id = retryRunId(widget.run); - if (id == null || !canRetryRun(widget.run) || _dialogOpen) return; + if (_dialogOpen) return; _dialogOpen = true; try { - await showRetryRunPrompt( - context: context, - runId: id, - cupertino: _usesCupertino(context), - onSubmit: (intent) => _submit(id, intent), + await openRetryRunPrompt( + context, + run: widget.run, + gateway: widget.gateway, + onRunChanged: widget.onRunChanged, + onRunOpened: widget.onRunOpened, + owns: (id) => mounted && retryRunId(widget.run) == id, ); } finally { _dialogOpen = false; @@ -69,51 +62,6 @@ class _RetryRunActionState extends State { } } - Future _submit(num id, RetryIntent intent) async { - final repository = RunsRepository(widget.gateway); - try { - final run = await repository.retryRun( - id, - requestKey: intent.requestKey, - mode: intent.mode.wireMode, - ); - if (!mounted) return null; - if (_owns(id)) { - widget.onRunChanged(run); - final opened = retryRunId(run); - if (opened != null && opened != id) widget.onRunOpened?.call(opened); - } - return null; - } catch (error) { - return ActionRefusal( - describeRetryError(error), - stillPossible: _resyncRun(id), - ); - } - } - - bool _owns(num id) => mounted && retryRunId(widget.run) == id; - - /// One bounded re-read per refusal. A refusal that arrives while a read is - /// already in flight observes that same read instead of starting another. - Future _resyncRun(num id) { - return _resync ??= _readRun(id); - } - - Future _readRun(num id) async { - try { - final run = await RunsRepository(widget.gateway).getRun(id); - if (!_owns(id)) return null; - widget.onRunChanged(run); - return canRetryRun(run); - } catch (_) { - // Unknown server truth: keep the refusal and leave a deliberate retry. - return null; - } finally { - _resync = null; - } - } - @override Widget build(BuildContext context) { if (retryRunId(widget.run) == null || !canRetryRun(widget.run)) { @@ -134,3 +82,65 @@ class _RetryRunActionState extends State { ); } } + +bool _cupertinoLocale(BuildContext context) => + Localizations.of(context, MaterialLocalizations) == + null; + +/// Opens the retry prompt for a failed [run]; only its confirm sends +/// `retry_run`. An accepted reply reaches [onRunChanged] while [owns] still +/// holds, and a new run id opens through [onRunOpened]. A refusal re-reads the +/// run once so the prompt can say whether retrying is still possible. Shared +/// by the button and the run detail's more menu. +Future openRetryRunPrompt( + BuildContext context, { + required JsonMap run, + required ApiGateway gateway, + required ValueChanged onRunChanged, + required bool Function(num id) owns, + ValueChanged? onRunOpened, +}) async { + final id = retryRunId(run); + if (id == null || !canRetryRun(run)) return; + final repository = RunsRepository(gateway); + Future? resync; + Future readRun() async { + try { + final current = await repository.getRun(id); + if (!owns(id)) return null; + onRunChanged(current); + return canRetryRun(current); + } catch (_) { + // Unknown server truth: keep the refusal and leave a deliberate retry. + return null; + } finally { + resync = null; + } + } + + await showRetryRunPrompt( + context: context, + runId: id, + cupertino: _cupertinoLocale(context), + onSubmit: (intent) async { + try { + final updated = await repository.retryRun( + id, + requestKey: intent.requestKey, + mode: intent.mode.wireMode, + ); + if (owns(id)) { + onRunChanged(updated); + final opened = retryRunId(updated); + if (opened != null && opened != id) onRunOpened?.call(opened); + } + return null; + } catch (error) { + return ActionRefusal( + describeRetryError(error), + stillPossible: resync ??= readRun(), + ); + } + }, + ); +} diff --git a/app/lib/features/runs/screen.dart b/app/lib/features/runs/screen.dart index 33ee84da..c491a935 100644 --- a/app/lib/features/runs/screen.dart +++ b/app/lib/features/runs/screen.dart @@ -10,6 +10,7 @@ import '../attention/runtime/attention_store.dart'; import 'actions/decision_action.dart'; import 'data/runs_repository.dart'; import 'domain/run_decisions.dart'; +import 'ui/run_pipeline_link.dart'; import 'ui/run_detail_view.dart'; import 'ui/runs_controller.dart'; import 'ui/runs_list.dart'; @@ -34,6 +35,7 @@ class RunsScreen extends StatefulWidget { this.onRunSelected, this.onBack, this.onPipelineFilterChanged, + this.onOpenPipeline, this.attentionStore = const SharedPreferencesAttentionStore(), this.attentionNow, this.notifications, @@ -68,6 +70,9 @@ class RunsScreen extends StatefulWidget { final ValueChanged? onBack; final ValueChanged? onPipelineFilterChanged; + /// Opens a pipeline from the run detail's pipeline name. + final OpenPipeline? onOpenPipeline; + /// Persisted attention dismissals and the clock for its local-day window. /// The app uses SharedPreferences; tests and fixtures inject a memory store. final AttentionStore attentionStore; @@ -249,6 +254,7 @@ class _RunsScreenState extends State { gateway: widget.gateway, onBack: _back, onRunOpened: _select, + onOpenPipeline: widget.onOpenPipeline, initialStageKey: widget.initialStageKey, initialVisit: widget.initialVisit, ), diff --git a/app/lib/features/runs/ui/run_detail_cupertino.dart b/app/lib/features/runs/ui/run_detail_cupertino.dart index a31006aa..9a2bd54a 100644 --- a/app/lib/features/runs/ui/run_detail_cupertino.dart +++ b/app/lib/features/runs/ui/run_detail_cupertino.dart @@ -7,6 +7,7 @@ import 'run_changes_action.dart'; import 'run_detail_content.dart'; import 'run_detail_tabs.dart'; import 'run_more_menu.dart'; +import 'run_pipeline_link.dart'; /// The runs detail with standard Cupertino controls. It has no Material /// ancestor: the host header keeps native navigation, actions and notices, and @@ -16,7 +17,8 @@ Widget buildCupertinoRunDetail({ required BuildContext context, required JsonMap run, required Widget headerActions, - Widget? statusAction, + ValueChanged? onRunOpened, + OpenPipeline? onOpenPipeline, required bool detailLoading, required String? error, required bool copying, @@ -71,6 +73,7 @@ Widget buildCupertinoRunDetail({ gateway: gateway, onRunChanged: onRunChanged, cupertino: true, + onRunOpened: onRunOpened, ), ], ), @@ -89,7 +92,6 @@ Widget buildCupertinoRunDetail({ state: runStateOf(run['status']), label: runStatusLabel(run), ), - ?statusAction, ], ), const SizedBox(height: 4), @@ -98,7 +100,17 @@ Widget buildCupertinoRunDetail({ style: theme.textTheme.navLargeTitleTextStyle, ), const SizedBox(height: 4), - Text('Run ${run['id']} · Pipeline ${detailPipeline(run)}'), + Wrap( + crossAxisAlignment: WrapCrossAlignment.center, + children: [ + Text('Run ${run['id']} · Pipeline '), + RunPipelineLink( + run: run, + cupertino: true, + onOpenPipeline: onOpenPipeline, + ), + ], + ), ], ), ), diff --git a/app/lib/features/runs/ui/run_detail_material.dart b/app/lib/features/runs/ui/run_detail_material.dart index f6f3bc72..5bb1b711 100644 --- a/app/lib/features/runs/ui/run_detail_material.dart +++ b/app/lib/features/runs/ui/run_detail_material.dart @@ -7,6 +7,7 @@ import 'run_changes_action.dart'; import 'run_detail_content.dart'; import 'run_detail_tabs.dart'; import 'run_more_menu.dart'; +import 'run_pipeline_link.dart'; /// The runs detail with standard Material controls. /// @@ -16,7 +17,8 @@ Widget buildMaterialRunDetail({ required BuildContext context, required JsonMap run, required Widget headerActions, - Widget? statusAction, + ValueChanged? onRunOpened, + OpenPipeline? onOpenPipeline, required bool detailLoading, required String? error, required bool copying, @@ -69,6 +71,7 @@ Widget buildMaterialRunDetail({ gateway: gateway, onRunChanged: onRunChanged, cupertino: false, + onRunOpened: onRunOpened, ), ], ), @@ -86,7 +89,6 @@ Widget buildMaterialRunDetail({ state: runStateOf(run['status']), label: runStatusLabel(run), ), - ?statusAction, ], ), ), @@ -103,7 +105,17 @@ Widget buildMaterialRunDetail({ crossAxisAlignment: WrapCrossAlignment.center, children: [ Text('Run ${run['id']}'), - Text('Pipeline ${detailPipeline(run)}'), + Wrap( + crossAxisAlignment: WrapCrossAlignment.center, + children: [ + const Text('Pipeline '), + RunPipelineLink( + run: run, + cupertino: false, + onOpenPipeline: onOpenPipeline, + ), + ], + ), headerActions, ], ), diff --git a/app/lib/features/runs/ui/run_detail_view.dart b/app/lib/features/runs/ui/run_detail_view.dart index 09b350eb..2201f42c 100644 --- a/app/lib/features/runs/ui/run_detail_view.dart +++ b/app/lib/features/runs/ui/run_detail_view.dart @@ -5,9 +5,8 @@ import 'package:flutter/services.dart'; import '../../../core/api_gateway.dart'; import '../../../core/transport/pipelines_client.dart'; import '../../../ui/adaptive/host.dart'; -import '../actions/retry_action.dart'; -import '../actions/retry_eligibility.dart'; import 'run_detail_actions.dart'; +import 'run_pipeline_link.dart'; import 'run_detail_content.dart'; import 'run_detail_cupertino.dart'; import 'run_detail_material.dart'; @@ -20,6 +19,7 @@ class RunDetailView extends StatefulWidget { required this.gateway, required this.onBack, this.onRunOpened, + this.onOpenPipeline, this.initialStageKey, this.initialVisit, }); @@ -34,6 +34,9 @@ class RunDetailView extends StatefulWidget { /// the server-identified new run. Null keeps the detail on the retried run. final ValueChanged? onRunOpened; + /// Opens the run's pipeline from its name in the header. + final OpenPipeline? onOpenPipeline; + /// The route's stage and visit, forwarded to the tab body so a `/runs/:id/ /// stage/:key[?visit=N]` deep link opens that recorded visit. Null is the /// plain detail. @@ -64,21 +67,13 @@ class _RunDetailViewState extends State { onRunOpened: widget.onRunOpened, retry: false, ); - // Retry sits next to the status it answers, and only for a failed run. - final statusAction = retryRunId(run) != null && canRetryRun(run) - ? RetryRunAction( - run: run, - gateway: widget.gateway, - onRunChanged: widget.controller.acceptRunDetail, - onRunOpened: widget.onRunOpened, - ) - : null; return cupertino ? buildCupertinoRunDetail( context: context, run: run, headerActions: headerActions, - statusAction: statusAction, + onRunOpened: widget.onRunOpened, + onOpenPipeline: widget.onOpenPipeline, detailLoading: widget.controller.detailLoading, error: widget.controller.error, copying: _copying, @@ -95,7 +90,8 @@ class _RunDetailViewState extends State { context: context, run: run, headerActions: headerActions, - statusAction: statusAction, + onRunOpened: widget.onRunOpened, + onOpenPipeline: widget.onOpenPipeline, detailLoading: widget.controller.detailLoading, error: widget.controller.error, copying: _copying, diff --git a/app/lib/features/runs/ui/run_more_menu.dart b/app/lib/features/runs/ui/run_more_menu.dart index 4f6be94e..124fc86f 100644 --- a/app/lib/features/runs/ui/run_more_menu.dart +++ b/app/lib/features/runs/ui/run_more_menu.dart @@ -3,6 +3,9 @@ import 'package:flutter/material.dart'; import '../../../core/api_gateway.dart'; import '../../schedules/ui/run/schedule_run_action.dart'; +import '../actions/retry_action.dart'; +import '../actions/retry_eligibility.dart'; +import '../actions/retry_wording.dart'; import '../actions/title_action.dart'; import '../actions/title_wording.dart'; @@ -10,12 +13,21 @@ const runMoreMenuKey = ValueKey('run-more-menu'); /// Whether the run has anything for its more menu. bool showRunMoreMenu(JsonMap run) => - runTitleId(run) != null || canScheduleRun(run); + runTitleId(run) != null || canScheduleRun(run) || _canRetry(run); -enum _RunMoreItem { rename, schedule } +bool _canRetry(JsonMap run) => retryRunId(run) != null && canRetryRun(run); -/// The run detail's more menu: Rename and Schedule this run, which act on the -/// run's pipeline record rather than its progress, kept out of the header. +enum _RunMoreItem { retry, rename, schedule } + +/// Each item keeps the key its standalone button had. +Key _keyOf(_RunMoreItem item) => switch (item) { + _RunMoreItem.retry => retryActionKey, + _RunMoreItem.rename => runTitleActionKey, + _RunMoreItem.schedule => scheduleRunActionKey, +}; + +/// The run detail's more menu: Retry (failed runs only), Rename and Schedule +/// this run, kept out of the header. /// This widget stays mounted while a picked flow runs, so the flow's result /// still reaches the current run. class RunMoreMenu extends StatefulWidget { @@ -25,6 +37,7 @@ class RunMoreMenu extends StatefulWidget { required this.gateway, required this.onRunChanged, required this.cupertino, + this.onRunOpened, }); final JsonMap run; @@ -32,6 +45,9 @@ class RunMoreMenu extends StatefulWidget { final ValueChanged onRunChanged; final bool cupertino; + /// Opens the new run an accepted retry names. + final ValueChanged? onRunOpened; + @override State createState() => _RunMoreMenuState(); } @@ -40,12 +56,23 @@ class _RunMoreMenuState extends State { JsonMap get run => widget.run; List<(_RunMoreItem, String)> get _items => [ + // Retry is offered only for a failed run that is no longer executing. + if (_canRetry(run)) (_RunMoreItem.retry, retryActionLabel), if (runTitleId(run) != null) (_RunMoreItem.rename, runTitleActionLabel), if (canScheduleRun(run)) (_RunMoreItem.schedule, scheduleRunActionLabel), ]; void _pick(BuildContext context, _RunMoreItem item) { switch (item) { + case _RunMoreItem.retry: + openRetryRunPrompt( + context, + run: run, + gateway: widget.gateway, + onRunChanged: widget.onRunChanged, + onRunOpened: widget.onRunOpened, + owns: (owned) => mounted && retryRunId(widget.run) == owned, + ); case _RunMoreItem.rename: openRunTitleEditor( context, @@ -72,7 +99,7 @@ class _RunMoreMenuState extends State { onSelected: (item) => _pick(context, item), itemBuilder: (_) => [ for (final (item, label) in items) - PopupMenuItem(value: item, child: Text(label)), + PopupMenuItem(key: _keyOf(item), value: item, child: Text(label)), ], ); } @@ -91,6 +118,7 @@ class _RunMoreMenuState extends State { actions: [ for (final (item, label) in items) CupertinoActionSheetAction( + key: _keyOf(item), onPressed: () => Navigator.of(sheet).pop(item), child: Text(label), ), diff --git a/app/lib/features/runs/ui/run_pipeline_link.dart b/app/lib/features/runs/ui/run_pipeline_link.dart new file mode 100644 index 00000000..2dd8539b --- /dev/null +++ b/app/lib/features/runs/ui/run_pipeline_link.dart @@ -0,0 +1,66 @@ +import 'package:flutter/cupertino.dart'; +import 'package:flutter/material.dart'; + +import '../../../core/api_gateway.dart'; +import 'run_detail_content.dart'; + +/// Opens a pipeline at a version; 0 means its latest. +typedef OpenPipeline = void Function(int pipelineId, int version); + +const runPipelineLinkKey = ValueKey('run-pipeline-link'); + +/// The run's pipeline id, or null when the server recorded none. +int? runPipelineId(JsonMap run) { + final id = run['pipeline_id']; + return id is num && id > 0 && id == id.truncate() ? id.toInt() : null; +} + +/// The run's pipeline name, a link to that pipeline at the run's pinned +/// version when the run names one and the host can navigate. +class RunPipelineLink extends StatelessWidget { + const RunPipelineLink({ + super.key, + required this.run, + required this.cupertino, + this.onOpenPipeline, + }); + + final JsonMap run; + final bool cupertino; + final OpenPipeline? onOpenPipeline; + + @override + Widget build(BuildContext context) { + final name = detailPipeline(run); + final id = runPipelineId(run); + final open = onOpenPipeline; + if (id == null || open == null) return Text(name); + final version = run['version']; + void go() => open(id, version is num ? version.toInt() : 0); + final label = Text( + name, + style: const TextStyle(decoration: TextDecoration.underline), + ); + return Semantics( + link: true, + label: 'Open pipeline $name', + excludeSemantics: true, + child: cupertino + ? CupertinoButton( + key: runPipelineLinkKey, + padding: EdgeInsets.zero, + minimumSize: Size.zero, + onPressed: go, + child: label, + ) + : InkWell( + key: runPipelineLinkKey, + onTap: go, + child: DefaultTextStyle.merge( + style: TextStyle(color: Theme.of(context).colorScheme.primary), + child: label, + ), + ), + ); + } +} diff --git a/app/test/features/runs/ui/run_retry_placement_test.dart b/app/test/features/runs/ui/run_detail_header_test.dart similarity index 58% rename from app/test/features/runs/ui/run_retry_placement_test.dart rename to app/test/features/runs/ui/run_detail_header_test.dart index 49f0ae68..27f103c5 100644 --- a/app/test/features/runs/ui/run_retry_placement_test.dart +++ b/app/test/features/runs/ui/run_detail_header_test.dart @@ -5,7 +5,8 @@ import 'package:pipelines_app/core/api_gateway.dart'; import 'package:pipelines_app/features/runs/data/runs_repository.dart'; import 'package:pipelines_app/features/runs/ui/run_detail_view.dart'; import 'package:pipelines_app/features/runs/ui/runs_controller.dart'; -import 'package:pipelines_app/ui/status/run_status_icon.dart'; +import 'package:pipelines_app/features/runs/ui/run_more_menu.dart'; +import 'package:pipelines_app/features/runs/ui/run_pipeline_link.dart'; class _FakeGateway implements ApiGateway { _FakeGateway(this.detail); @@ -21,7 +22,12 @@ class _FakeGateway implements ApiGateway { } } -Future _pump(WidgetTester tester, String status, bool cupertino) async { +Future _pump( + WidgetTester tester, + String status, + bool cupertino, { + OpenPipeline? onOpenPipeline, +}) async { tester.view.physicalSize = const Size(390, 900); tester.view.devicePixelRatio = 1; addTearDown(tester.view.reset); @@ -33,6 +39,8 @@ Future _pump(WidgetTester tester, String status, bool cupertino) async { 'name': 'nightly', 'status': status, 'executing': false, + 'pipeline_id': 10, + 'version': 3, }), ), ); @@ -41,6 +49,7 @@ Future _pump(WidgetTester tester, String status, bool cupertino) async { controller: controller, gateway: _FakeGateway(const {}), onBack: () {}, + onOpenPipeline: onOpenPipeline, ); await tester.pumpWidget( cupertino @@ -50,23 +59,42 @@ Future _pump(WidgetTester tester, String status, bool cupertino) async { await tester.pumpAndSettle(); } +Future _menuOffersRetry(WidgetTester tester) async { + await tester.tap(find.byKey(runMoreMenuKey)); + await tester.pumpAndSettle(); + return find.text('Retry').evaluate().isNotEmpty; +} + void main() { for (final cupertino in [false, true]) { final host = cupertino ? 'cupertino' : 'material'; - testWidgets('$host: Retry sits beside the failed status', (tester) async { + testWidgets('$host: Retry is a more-menu option for a failed run', ( + tester, + ) async { await _pump(tester, 'failed', cupertino); + // Not in the header itself. + expect(find.text('Retry'), findsNothing); + expect(await _menuOffersRetry(tester), isTrue); + }); - final retry = find.text('Retry'); - expect(retry, findsOneWidget); - final kicker = tester.getRect(find.byType(RunStatusKicker)); - final button = tester.getRect(retry); - expect(button.center.dy, moreOrLessEquals(kicker.center.dy, epsilon: 8)); - expect(button.left, greaterThan(kicker.right)); + testWidgets('$host: the pipeline name opens that pipeline at the run\'s ' + 'version', (tester) async { + final opened = <(int, int)>[]; + await _pump( + tester, + 'succeeded', + cupertino, + onOpenPipeline: (id, version) => opened.add((id, version)), + ); + await tester.tap(find.byKey(runPipelineLinkKey)); + await tester.pump(); + expect(opened, [(10, 3)]); + expect(find.bySemanticsLabel('Open pipeline nightly'), findsOneWidget); }); testWidgets('$host: a succeeded run offers no Retry', (tester) async { await _pump(tester, 'succeeded', cupertino); - expect(find.text('Retry'), findsNothing); + expect(await _menuOffersRetry(tester), isFalse); }); } } diff --git a/app/test/features/runs/ui/run_retry_guard_test.dart b/app/test/features/runs/ui/run_retry_guard_test.dart index da6be633..40650570 100644 --- a/app/test/features/runs/ui/run_retry_guard_test.dart +++ b/app/test/features/runs/ui/run_retry_guard_test.dart @@ -52,7 +52,7 @@ void main() { expect(find.text(retryFailedTitle), findsOneWidget); await tester.tap(find.byKey(retryKeepKey)); await tester.pumpAndSettle(); - expect(find.byKey(retryActionKey), findsOneWidget); + expect(await retryOffered(tester), isTrue); }); testWidgets('a retry reply that lands after leaving is ignored', ( @@ -109,6 +109,6 @@ void main() { await mountRetryScreen(tester, gateway, cupertino: false); expect(find.byKey(runMoreMenuKey), findsOneWidget); - expect(find.byKey(retryActionKey), findsNothing); + expect(await retryOffered(tester), isFalse); }); } diff --git a/app/test/features/runs/ui/run_retry_wiring_support.dart b/app/test/features/runs/ui/run_retry_wiring_support.dart index d590e617..688e6283 100644 --- a/app/test/features/runs/ui/run_retry_wiring_support.dart +++ b/app/test/features/runs/ui/run_retry_wiring_support.dart @@ -3,6 +3,7 @@ import 'dart:async'; import 'package:flutter/cupertino.dart'; import 'package:flutter/material.dart'; import 'package:flutter_test/flutter_test.dart'; +import 'package:pipelines_app/features/runs/ui/run_more_menu.dart'; import 'package:pipelines_app/core/api_gateway.dart'; import 'package:pipelines_app/features/runs/actions/retry_wording.dart'; import 'package:pipelines_app/features/runs/screen.dart'; @@ -105,9 +106,27 @@ Future mountRetryScreen( await tester.pumpAndSettle(); } -Future confirmRetry(WidgetTester tester) async { +/// Retry lives in the run detail's more menu. +Future openRetry(WidgetTester tester) async { + await tester.tap(find.byKey(runMoreMenuKey)); + await tester.pumpAndSettle(); await tester.tap(find.byKey(retryActionKey)); await tester.pumpAndSettle(); +} + +/// Whether the more menu offers Retry; the menu is closed again afterwards. +Future retryOffered(WidgetTester tester) async { + if (find.byKey(runMoreMenuKey).evaluate().isEmpty) return false; + await tester.tap(find.byKey(runMoreMenuKey)); + await tester.pumpAndSettle(); + final offered = find.byKey(retryActionKey).evaluate().isNotEmpty; + await tester.tapAt(const Offset(2, 2)); + await tester.pumpAndSettle(); + return offered; +} + +Future confirmRetry(WidgetTester tester) async { + await openRetry(tester); await tester.tap(find.byKey(retryConfirmKey)); await tester.pump(); } diff --git a/app/test/features/runs/ui/run_retry_wiring_test.dart b/app/test/features/runs/ui/run_retry_wiring_test.dart index 3aaf7870..f4a0fd6a 100644 --- a/app/test/features/runs/ui/run_retry_wiring_test.dart +++ b/app/test/features/runs/ui/run_retry_wiring_test.dart @@ -22,12 +22,11 @@ void main() { expect(find.text(retryFailedTitle), findsOneWidget); expect(find.byKey(runMoreMenuKey), findsOneWidget); - expect(find.byKey(retryActionKey), findsOneWidget); + expect(await retryOffered(tester), isTrue); expect(find.byKey(cancelActionKey), findsNothing); expect(gateway.retryCalls, isEmpty); - await tester.tap(find.byKey(retryActionKey)); - await tester.pumpAndSettle(); + await openRetry(tester); expect(find.text(retryDialogTitle(7)), findsOneWidget); expect(find.text(retryDialogMessage), findsOneWidget); expect(gateway.retryCalls, isEmpty); @@ -36,7 +35,7 @@ void main() { await tester.pumpAndSettle(); expect(gateway.retryCalls, isEmpty); expect(opened, isEmpty); - expect(find.byKey(retryActionKey), findsOneWidget); + expect(await retryOffered(tester), isTrue); await confirmRetry(tester); expect(gateway.retryCalls, hasLength(1)); @@ -58,7 +57,7 @@ void main() { expect(opened, [8]); expect(find.text(retryCreatedTitle), findsOneWidget); expect(find.text(retryFailedTitle), findsNothing); - expect(find.byKey(retryActionKey), findsNothing); + expect(await retryOffered(tester), isFalse); expect( gateway.calls.where((call) => call.type == 'get_run').last.fields, {'run_id': 8}, @@ -80,8 +79,7 @@ void main() { onRunSelected: opened.add, ); - await tester.tap(find.byKey(retryActionKey)); - await tester.pumpAndSettle(); + await openRetry(tester); await tester.tap(find.byKey(retryRestartKey)); await tester.pumpAndSettle(); expect(find.text(restartDialogTitle(7)), findsOneWidget);