import 'package:flutter/material.dart'; import 'package:flutter/rendering.dart'; import 'package:flutter_test/flutter_test.dart'; import 'package:pipelines_app/ui/adaptive/glass_pill.dart'; import 'package:pipelines_app/ui/adaptive/segmented_bar.dart'; List _keys(WidgetTester tester) => tester.layers .whereType() .map((layer) => layer.backdropKey) .toList(); void main() { testWidgets('a bar\'s pieces share one backdrop read; the expanded title ' 'reads its own', (tester) async { await tester.pumpWidget( MaterialApp( home: Scaffold( extendBodyBehindAppBar: true, appBar: SegmentedBar( title: 'Release train run', subtitle: 'Run 7', expandableTitle: true, leading: const BackButton(), actions: [ IconButton(icon: const Icon(Icons.more_vert), onPressed: () {}), ], ), body: const SizedBox.expand(), ), ), ); final pieces = _keys(tester); expect(pieces, hasLength(3)); final shared = pieces.first; expect(shared, isNotNull); expect(pieces, everyElement(same(shared))); await tester.tap(find.text('Release train run')); await tester.pumpAndSettle(); final keys = _keys(tester); expect(keys, hasLength(4)); final expanded = keys.where((k) => !identical(k, shared)).toList(); expect(expanded, hasLength(1)); expect(expanded.single, isNotNull); }); testWidgets('a lone piece reads the backdrop on its own', (tester) async { await tester.pumpWidget( const MaterialApp( home: Center(child: GlassPill(child: Text('Tabs'))), ), ); expect(_keys(tester), [isNull]); }); }