import 'package:flutter/cupertino.dart'; import 'package:flutter/material.dart'; import 'package:flutter_test/flutter_test.dart'; import 'package:pipelines_app/ui/adaptive/floating_bar_layout.dart'; import 'package:pipelines_app/ui/layout/section_heading.dart'; import 'package:pipelines_app/ui/layout/sticky_section.dart'; class _Host extends StatefulWidget { const _Host(); @override State<_Host> createState() => _HostState(); } class _HostState extends State<_Host> { bool open = true; @override Widget build(BuildContext context) => CustomScrollView( slivers: [ const SliverTopBarClearance(), StickySection( title: 'Input', open: open, onToggle: () => setState(() => open = !open), body: Column(children: [for (var i = 0; i < 80; i++) Text('line $i')]), ), const SliverToBoxAdapter(child: SizedBox(height: 900)), ], ); } void main() { testWidgets( 'the title stays pinned while its content scrolls and closes it', (tester) async { tester.view.physicalSize = const Size(390, 600); tester.view.devicePixelRatio = 1; addTearDown(tester.view.reset); await tester.pumpWidget(const MaterialApp(home: Scaffold(body: _Host()))); await tester.drag(find.byType(CustomScrollView), const Offset(0, -800)); await tester.pumpAndSettle(); // Deep in the content, the title is still at the top. expect(tester.getTopLeft(find.text('line 0')).dy, lessThan(0)); expect(tester.getTopLeft(find.text('Input')).dy, lessThan(40)); await tester.tap(find.text('Input')); await tester.pumpAndSettle(); expect(find.text('line 40'), findsNothing); }, ); for (final host in ['Material', 'Cupertino']) { testWidgets('pins an opaque section edge below the top bar in $host', ( tester, ) async { tester.view.physicalSize = const Size(390, 600); tester.view.devicePixelRatio = 1; addTearDown(tester.view.reset); final child = MediaQuery( data: const MediaQueryData(padding: EdgeInsets.only(top: 64)), child: _Host(), ); await tester.pumpWidget( host == 'Cupertino' ? CupertinoApp(home: child) : MaterialApp(home: Scaffold(body: child)), ); await tester.drag(find.byType(CustomScrollView), const Offset(0, -800)); await tester.pumpAndSettle(); final title = tester.widget( find.byType(StickySectionTitle), ); expect(title.pinned, isTrue); expect( find.byWidgetPredicate( (widget) => widget is Positioned && widget.top == -64, ), findsOneWidget, ); }); } testWidgets('a tap anywhere on the title strip toggles the section', ( tester, ) async { tester.view.physicalSize = const Size(390, 600); tester.view.devicePixelRatio = 1; addTearDown(tester.view.reset); await tester.pumpWidget(const MaterialApp(home: Scaffold(body: _Host()))); expect(tester.getTopLeft(find.text('Input')).dx, 16); expect(find.text('line 0'), findsOneWidget); // Empty space well right of the short title, left of the chevron. final strip = tester.getRect(find.byType(StickySectionTitle)); await tester.tapAt(Offset(strip.center.dx + 60, strip.center.dy)); await tester.pumpAndSettle(); expect(find.text('line 0'), findsNothing); }); testWidgets('section headings use a quiet label without a filled band', ( tester, ) async { await tester.pumpWidget( const MaterialApp( home: Scaffold(body: SectionHeading(title: 'Today')), ), ); final heading = tester.widget(find.text('Today')); final scheme = Theme.of(tester.element(find.text('Today'))).colorScheme; expect(heading.style!.color, scheme.onSurfaceVariant); expect(heading.style!.fontWeight, FontWeight.w600); expect(heading.style!.letterSpacing, 0.4); expect(find.byType(DecoratedBox), findsNothing); }); }