import 'package:flutter/material.dart'; import 'package:flutter_test/flutter_test.dart'; import 'package:pipelines_app/features/pipelines/pipeline_repository.dart'; import 'package:pipelines_app/features/pipelines/pipelines_controller.dart'; import 'package:pipelines_app/features/pipelines/widgets/pipeline_detail_panel.dart'; import 'package:pipelines_app/features/pipelines/widgets/pipeline_summary_view.dart'; import 'package:pipelines_app/ui/layout/reading_width.dart'; import '../../features/pipelines/fixtures.dart'; import '../../features/pipelines/test_helpers.dart'; import '../../features/runs/ui/run_detail_graph_support.dart'; import '../../features/runs/ui/run_detail_visit_support.dart'; /// Reading bodies (run Summary, stage page sections, pipeline Summary) keep /// [kReadingMaxWidth] from the leading edge on a wide window and the full /// width on a phone. void main() { Future setSize(WidgetTester tester, Size size) async { tester.view.physicalSize = size; tester.view.devicePixelRatio = 1; addTearDown(tester.view.reset); } testWidgets('ReadingWidth caps from the leading edge and keeps its child ' 'across the cap', (tester) async { await setSize(tester, const Size(1200, 600)); final scroll = ScrollController(); addTearDown(scroll.dispose); await tester.pumpWidget( MaterialApp( home: ReadingWidth( child: ListView( key: const Key('body'), controller: scroll, children: [ for (var index = 0; index < 50; index++) SizedBox(height: 40, child: Text('row $index')), ], ), ), ), ); final wide = tester.getRect(find.byKey(const Key('body'))); expect(wide.left, 0); expect(wide.width, kReadingMaxWidth); expect(wide.height, 600); scroll.jumpTo(300); await tester.pump(); await setSize(tester, const Size(500, 600)); await tester.pump(); expect(tester.getRect(find.byKey(const Key('body'))).width, 500); expect(scroll.offset, 300, reason: 'the body was not remounted'); }); for (final platform in RunDetailTestPlatform.values) { testWidgets('${platform.name} 1200: run Summary is capped', (tester) async { await pumpRunDetail(tester, platform, size: const Size(1200, 800)); final body = tester.getRect( find.byKey(const Key('run-detail-tab-body-summary')), ); expect(body.left, 0); expect(body.width, kReadingMaxWidth); }); testWidgets('${platform.name} 390: run Summary keeps the full width', ( tester, ) async { await pumpRunDetail(tester, platform, size: const Size(390, 844)); final body = tester.getRect( find.byKey(const Key('run-detail-tab-body-summary')), ); expect(body.width, 390); }); testWidgets('${platform.name} 1200: stage page Summary is capped', ( tester, ) async { await openVisit(tester, platform, size: const Size(1200, 900)); final body = tester.getRect( find.byKey(const Key('run-visit-body-summary')), ); expect(body.left, 0); expect(body.width, kReadingMaxWidth); // The section's trailing copy button sits within the cap. final copy = find.byKey(const ValueKey('run-visit-copy-Input')); expect(tester.getRect(copy).right, lessThanOrEqualTo(kReadingMaxWidth)); }); } testWidgets('1200: pipeline Summary is capped, the pane still scrolls', ( tester, ) async { await setSize(tester, const Size(1200, 800)); final gateway = gatewayFor(PipelineFixture()); final controller = PipelinesController(PipelinesRepository(gateway)); addTearDown(controller.dispose); await controller.openPipeline(1); await tester.pumpWidget( MaterialApp( home: Scaffold( body: PipelineDetailPanel( controller: controller, gateway: gateway, showBack: false, ), ), ), ); await tester.pumpAndSettle(); final summary = tester.getRect(find.byType(PipelineSummaryView)); expect(summary.left, 0); expect(summary.width, kReadingMaxWidth); }); }