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/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/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); 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}); } } 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); final controller = RunsController( RunsRepository( _FakeGateway({ 'id': 21, 'title': 'Nightly build', 'name': 'nightly', 'status': status, 'executing': false, 'pipeline_id': 10, 'version': 3, }), ), ); await controller.select(21); final view = RunDetailView( controller: controller, gateway: _FakeGateway(const {}), onBack: () {}, onOpenPipeline: onOpenPipeline, ); await tester.pumpWidget( cupertino ? CupertinoApp(home: CupertinoPageScaffold(child: view)) : MaterialApp(home: Scaffold(body: view)), ); 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 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); }); 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(await _menuOffersRetry(tester), isFalse); }); } }