import "package:flutter/widgets.dart"; import "package:flutter_test/flutter_test.dart"; import "package:garage_ui/garage_ui.dart"; import "support/test_scheme.dart"; // ChromeBar's height was a hardcoded 30 that didnt move with the tier. At // normal that left a 27px control 1.5px of margin, and at product the bar came // out SHORTER than the 33px buttons meant to sit in it - a header its own // contents didnt fit. It takes the density's token now. Future _barHeight(WidgetTester tester, Density density) async { await tester.pumpWidget( Directionality( textDirection: TextDirection.ltr, child: GarageTheme( data: ThemeData(colorScheme: testScheme, density: density), child: const Align( alignment: Alignment.topCenter, child: ChromeBar(child: SizedBox.shrink()), ), ), ), ); await tester.pump(); return tester.getSize(find.byType(ChromeBar)).height; } void main() { for (final density in const [ Density(), Density.normal(), Density.product(), ]) { final label = "${density.controlHeight.toInt()}px controls"; test("a chrome bar clears its own controls ($label)", () { // one controlGap above and one below - the same air a button gets from // the button beside it expect( density.chromeBarHeight, density.controlHeight + density.controlGap * 2, ); // the thing that was actually broken: the bar has to be able to hold // the control, not merely be near its size expect( density.chromeBarHeight, greaterThan(density.controlHeight), reason: "a control wouldnt fit inside its own chrome", ); }); testWidgets("ChromeBar takes that height with none given ($label)", ( tester, ) async { expect(await _barHeight(tester, density), density.chromeBarHeight); }); } testWidgets("an explicit height still wins", (tester) async { await tester.pumpWidget( Directionality( textDirection: TextDirection.ltr, child: GarageTheme( data: ThemeData( colorScheme: testScheme, density: const Density.product(), ), child: const Align( alignment: Alignment.topCenter, child: ChromeBar(height: 52, child: SizedBox.shrink()), ), ), ), ); await tester.pump(); expect(tester.getSize(find.byType(ChromeBar)).height, 52); }); }