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/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/adaptive/floating_tab_button.dart'; import '../../artifacts/domain/artifact_fixtures.dart'; class _FakeGateway implements ApiGateway { _FakeGateway(this.detail); final JsonMap detail; @override Stream get frames => const Stream.empty(); @override Future call(String type, [JsonMap fields = const {}]) { if (type != 'get_run') throw UnsupportedError(type); return Future.value({'run_detail': detail}); } } JsonMap _run({required List steps}) => { 'id': 21, 'title': 'Artifacts wiring run', 'name': 'gallery', 'status': 'succeeded', 'steps': steps, }; Future _pumpDetail( WidgetTester tester, RunsController controller, ApiGateway gateway, ) async { tester.view.physicalSize = const Size(500, 1200); tester.view.devicePixelRatio = 1; addTearDown(tester.view.reset); final view = RunDetailView( controller: controller, gateway: gateway, onBack: () {}, ); await tester.pumpWidget(MaterialApp(home: Scaffold(body: view))); await tester.pumpAndSettle(); } Future _loaded(ApiGateway gateway) async { final controller = RunsController(RunsRepository(gateway)); await controller.select(21); return controller; } void main() { testWidgets('the action opens the recorded groups', (tester) async { final gateway = _FakeGateway( _run( steps: [ step( stage: 'implementer', sequence: 1, artifacts: [ artifact('build.log', contentType: 'text/plain', sizeBytes: 2337), ], ), step( stage: 'reviewer', sequence: 2, artifacts: [ artifact('shot.png', contentType: 'image/png', sizeBytes: 80544), ], ), ], ), ); final controller = await _loaded(gateway); addTearDown(controller.dispose); await _pumpDetail(tester, controller, gateway); expect( find.byKey(const ValueKey('run-detail-tab-artifacts')), findsOneWidget, ); await tester.ensureVisible( find.byKey(const ValueKey('run-detail-tab-artifacts')), ); await tester.pumpAndSettle(); await tester.tap(find.byKey(const ValueKey('run-detail-tab-artifacts'))); await tester.pumpAndSettle(); // Artifact groups start open: the files show without a tap. expect(find.text('Artifacts · 2 recorded'), findsOneWidget); expect(find.text('build.log'), findsOneWidget); expect(find.text('shot.png'), findsOneWidget); expect(find.text('implementer · visit 1'), findsOneWidget); expect(find.text('reviewer · visit 1'), findsOneWidget); }); /// The Artifacts tab keeps its place on a run with none: disabled, badged /// `0`, and its tooltip (and accessibility hint) says why. Future expectDisabledArtifacts(WidgetTester tester, String why) async { final tab = find.byKey(const ValueKey('run-detail-tab-artifacts')); expect(tab, findsOneWidget); final button = tester.widget(tab); expect(button.enabled, isFalse); expect(button.tooltip, why); expect( find.descendant( of: tab, matching: find.byKey(const ValueKey('run-detail-artifacts-count')), ), findsOneWidget, ); expect(find.descendant(of: tab, matching: find.text('0')), findsOneWidget); // A tap does not open an empty gallery: Summary stays. await tester.tap(tab, warnIfMissed: false); await tester.pumpAndSettle(); expect(find.text(why), findsNothing); // Changes, after it, keeps its place. final order = [ for (final name in ['summary', 'timeline', 'artifacts', 'changes']) tester.getCenter(find.byKey(ValueKey('run-detail-tab-$name'))).dx, ]; expect(order, orderedEquals([...order]..sort())); } testWidgets('a run without steps keeps a disabled Artifacts tab', ( tester, ) async { final gateway = _FakeGateway(_run(steps: const [])); final controller = await _loaded(gateway); addTearDown(controller.dispose); await _pumpDetail(tester, controller, gateway); await expectDisabledArtifacts( tester, 'No artifacts recorded for this run.', ); }); testWidgets('a recorded empty capture keeps its explicit wording', ( tester, ) async { final gateway = _FakeGateway( _run( steps: [step(stage: 'reviewer', visit: 1, artifacts: const [])], ), ); final controller = await _loaded(gateway); addTearDown(controller.dispose); await _pumpDetail(tester, controller, gateway); await expectDisabledArtifacts( tester, 'No artifacts recorded for this run.', ); }); testWidgets('an unavailable capture is never reported as empty', ( tester, ) async { final gateway = _FakeGateway( _run(steps: [step(stage: 'reviewer', visit: 1, includeArtifacts: false)]), ); final controller = await _loaded(gateway); addTearDown(controller.dispose); await _pumpDetail(tester, controller, gateway); await expectDisabledArtifacts(tester, 'Artifacts · capture unavailable'); }); }