import 'package:flutter/material.dart'; import 'package:flutter_test/flutter_test.dart'; import 'package:pipelines_app/core/api_gateway.dart'; import 'package:pipelines_app/core/transport/pipelines_client.dart'; import 'package:pipelines_app/features/artifacts/ui/artifact_viewer_page.dart'; import 'package:pipelines_app/features/search/search_screen.dart'; import '../core/transport/pipelines_client_test.dart' show FakeChannel; import 'search_wiring_test.dart' show closeViewer, expectArtifactsTabSelecting, openArtifactHit, pumpApp, replyRunDetailFor, replyRunList, searchSelectionDetail; /// The real Search screen, tapped on a phone-sized window. /// /// On a narrow window the open run is its own page on the app's navigator /// rather than a pane under the shell, which is where the search selection /// once went missing: the run opened at its plain Summary. These tests drive /// the whole path (Search tab, typed query, server results, row tap, run /// read) rather than injecting a selection into the detail. void main() { Future openPhoneApp( WidgetTester tester, FakeChannel channel, { required bool cupertino, }) async { tester.view.physicalSize = const Size(390, 844); tester.view.devicePixelRatio = 1; addTearDown(tester.view.resetPhysicalSize); addTearDown(tester.view.resetDevicePixelRatio); final provider = PlatformRouteInformationProvider( initialRouteInformation: RouteInformation(uri: Uri.parse('/runs')), ); addTearDown(provider.dispose); await pumpApp( tester, channel: channel, client: PipelinesClient(channelFactory: (_) => channel), provider: provider, cupertino: cupertino, ); await replyRunList(tester, channel); return provider; } for (final cupertino in [false, true]) { final platform = cupertino ? 'Cupertino' : 'Material'; testWidgets('$platform phone: an artifact hit opens that artifact in the ' 'viewer, and Back shows it on the run Artifacts tab', (tester) async { final channel = FakeChannel()..readyCompleter.complete(); final provider = await openPhoneApp( tester, channel, cupertino: cupertino, ); await openArtifactHit(tester, channel); expect(provider.value.uri.path, '/runs/7'); await replyRunDetailFor(tester, channel, searchSelectionDetail()); await tester.pumpAndSettle(); expect(find.byType(SearchScreen), findsNothing); final viewer = tester.widget( find.byType(ArtifactViewerPage), ); expect(viewer.selectedIdentity, contains('report.txt')); expect(find.text('report.txt'), findsWidgets); await closeViewer(tester); expectArtifactsTabSelecting(tester, '/artifacts/7/2/report.txt'); await tester.pumpWidget(const SizedBox.shrink()); await tester.pump(); }); testWidgets('$platform phone: an artifact the run no longer lists opens ' 'its Artifacts tab with a notice', (tester) async { final channel = FakeChannel()..readyCompleter.complete(); await openPhoneApp(tester, channel, cupertino: cupertino); await openArtifactHit(tester, channel); final detail = searchSelectionDetail(); final steps = [ for (final step in detail['steps'] as List) Map.from(step as Map), ]; steps[1]['artifacts'] = [ { 'name': 'other.txt', 'content_type': 'text/plain', 'size_bytes': 3, 'url': '/artifacts/7/2/other.txt', }, ]; await replyRunDetailFor(tester, channel, {...detail, 'steps': steps}); await tester.pumpAndSettle(); expect(find.byType(ArtifactViewerPage), findsNothing); expect( find.byKey(const ValueKey('run-detail-artifacts-7')), findsOneWidget, ); expect( find.text('That artifact is no longer available.'), findsOneWidget, ); await tester.pumpWidget(const SizedBox.shrink()); await tester.pump(); }); } }