import 'dart:async'; import 'package:flutter/material.dart'; import 'package:flutter_test/flutter_test.dart'; import 'package:pipelines_app/core/api_gateway.dart'; import 'package:pipelines_app/features/runs/actions/decision_wording.dart'; import 'package:pipelines_app/features/runs/screen.dart'; import 'package:pipelines_app/ui/adaptive/glass_pill.dart'; class _DecisionGateway implements ApiGateway { final events = StreamController.broadcast(); final decisions = []; final reply = Completer(); final JsonMap run = { 'id': 9, 'title': 'Human checkpoint', 'name': 'fixture', 'status': 'waiting', 'executing': false, 'current_stage': 'gate', 'graph': { 'stages': [ { 'key': 'gate', 'type': 'human', 'edges': {'approve': '#success'}, }, ], }, 'steps': [ { 'sequence': 1, 'stage': 'gate', 'status': 'waiting', 'output': { 'prompt': 'Please review this recorded checkpoint.', 'options': ['approve'], }, }, ], }; @override Stream get frames => events.stream; @override Future call(String type, [JsonMap fields = const {}]) => switch (type) { 'list_runs' => Future.value({ 'runs': [run], }), 'get_run' => Future.value({'run_detail': run}), 'decide_run' => _decide(fields), _ => Future.error(UnsupportedError(type)), }; Future _decide(JsonMap fields) { decisions.add(fields); return reply.future; } } void main() { testWidgets('actual detail exposes and confirms recorded decision', ( tester, ) async { final gateway = _DecisionGateway(); addTearDown(gateway.events.close); final screen = RunsScreen(gateway: gateway, initialRunId: 9); await tester.pumpWidget(MaterialApp(home: Scaffold(body: screen))); await tester.pumpAndSettle(); expect(find.text(decisionWaitingTitle), findsOneWidget); // The web's decision banner spans the header's glass strip (under // the top bar, 12 in from the pane) at the strip's 12px inset, with // Decide trailing. final banner = tester.getRect(find.byKey(const Key('run-decision-banner'))); final strip = tester.getRect( find.descendant( of: find.byKey(const Key('run-detail-header')), matching: find.byType(GlassPill), ), ); final pane = tester.getRect(find.byKey(const ValueKey('list-detail-body'))); expect(strip.left, pane.left + 12); expect(strip.right, pane.right - 12); expect(banner.left, strip.left + 12); expect(banner.right, strip.right - 12); expect( tester.getCenter(find.byKey(decisionActionKey)).dx, greaterThan(banner.center.dx), ); await tester.tap(find.byKey(decisionActionKey)); await tester.pumpAndSettle(); expect( find.text('Please review this recorded checkpoint.'), findsOneWidget, ); await tester.tap(find.text('approve')); await tester.enterText(find.byKey(decisionFeedbackKey), ' checked '); await tester.pump(); expect(gateway.decisions, isEmpty); await tester.tap(find.text(decisionConfirmLabel)); await tester.pump(); expect(gateway.decisions.single, { 'run_id': 9, 'stage': 'gate', 'option': 'approve', 'feedback': 'checked', }); gateway.reply.complete({ 'run_detail': { ...gateway.run, 'status': 'succeeded', 'executing': false, }, }); await tester.pumpAndSettle(); expect(find.byKey(decisionActionKey), findsNothing); expect(find.text(decisionWaitingTitle), findsNothing); expect(find.text('succeeded'), findsOneWidget); await tester.pumpWidget(const SizedBox.shrink()); }); }