import 'package:flutter/material.dart'; import 'package:lucide_icons_flutter/lucide_icons.dart'; import 'package:flutter_screenutil/flutter_screenutil.dart'; import 'package:flutter_test/flutter_test.dart'; import 'package:miler/views/helpers/constants/Colorconstants.dart'; import 'package:miler/views/helpers/widgets/app_widgets.dart'; import 'package:miler/views/helpers/widgets/miler_app_bar.dart'; /// Two rules the bars now share, and both are the kind that quietly comes /// undone the next time someone adds a screen: /// /// • **One line.** The bar carries the page's name and nothing under it. Every /// caption that used to sit there duplicated a figure the page itself showed /// louder and lower down, and two sources for one number is how they drift. /// /// • **One surface.** A frosted brand wash, not a solid slab, so a tab and a /// pushed page read as the same app at the top of the screen. void main() { Future pump(WidgetTester tester, Widget page) async { tester.view.physicalSize = const Size(390 * 3, 844 * 3); tester.view.devicePixelRatio = 3.0; addTearDown(tester.view.resetPhysicalSize); addTearDown(tester.view.resetDevicePixelRatio); await tester.pumpWidget( ScreenUtilInit( designSize: const Size(390, 844), builder: (_, _) => MaterialApp(home: page), ), ); await tester.pumpAndSettle(); } group('MilerAppBar', () { testWidgets('shows the page name and nothing beneath it', (tester) async { await pump( tester, const Scaffold(appBar: MilerAppBar(title: 'Activity')), ); expect(find.text('Activity'), findsOneWidget); expect( tester.widgetList(find.byType(Text)), hasLength(1), reason: 'the caption under the title is gone from every bar', ); }); // ── The wash gave way to the brand ── // // The four tabs wore a 7% frosted brand wash flattened against white while // Home wore solid brand. Switching tab therefore changed the colour of the // top 76pt of the phone AND the colour of the status-bar glyphs, which // reads as arriving in a different app rather than a different page. // // One ground now, and everything on it inverts. The wash survives as // `milerGlassSurface()` for the sheets, which sit over content and still // want it. testWidgets('is solid brand, so every tab shares one chrome', ( tester, ) async { await pump( tester, const Scaffold(appBar: MilerAppBar(title: 'Activity')), ); final bar = tester.widget(find.byType(AppBar)); expect(bar.backgroundColor, ColorConstants.primary); expect( bar.flexibleSpace, isNull, reason: 'a solid ground needs no surface layered over it', ); }); testWidgets('inverts everything drawn on it', (tester) async { await pump( tester, const Scaffold(appBar: MilerAppBar(title: 'Activity', showBack: true)), ); final title = tester.widget(find.text('Activity')); expect( title.style?.color, Colors.white, reason: 'white on #960019 is the only combination that clears AA here', ); final back = tester.widget(find.byIcon(LucideIcons.arrowLeft)); expect(back.color, Colors.white); final bar = tester.widget(find.byType(AppBar)); expect( bar.systemOverlayStyle?.statusBarIconBrightness, Brightness.light, reason: 'dark glyphs on maroon is the one contrast failure a rider ' 'cannot work around by tilting the phone', ); }); testWidgets('closes with no rule under it', (tester) async { await pump( tester, const Scaffold(appBar: MilerAppBar(title: 'Activity')), ); // The wash is a surface, and a surface against an untinted page is // already an edge. A hairline under it drew that boundary a second time — // the same doubled-up border this app has been pulling out of its cards. final bar = tester.widget(find.byType(AppBar)); expect(bar.bottom, isNull); }); testWidgets('keeps a trailing slot for the pages that need one', ( tester, ) async { await pump( tester, Scaffold( appBar: MilerAppBar( title: 'My Bookings', trailing: const Icon(Icons.map_rounded), ), ), ); expect(find.byIcon(Icons.map_rounded), findsOneWidget); }); }); group('the pushed-page bar', () { // The rule is unchanged and is the whole point of this file: a pushed page // and a tab must be the same object at the top of the phone. Only the // answer changed — both are solid brand now, rather than both being a wash. testWidgets('is the same ground as the tab bars', (tester) async { await pump( tester, Scaffold(appBar: milerPageBar('Rewards', onBack: () {})), ); final bar = tester.widget(find.byType(AppBar)); expect(bar.backgroundColor, ColorConstants.primary); expect(bar.flexibleSpace, isNull); expect(bar.bottom, isNull, reason: 'no rule under the bar here either'); }); }); // The wash survives as `milerGlassSurface()`, which the SHEETS use — they sit // over scrolling content and genuinely want a translucent surface, where a // bar sits over nothing and does not. This still pins what the wash has to // be, wherever it is used. test('the wash is a brand tint light enough to carry near-black type', () { // Flattened against white, which is what the sheets composite it over. final flat = Color.alphaBlend(ColorConstants.glassRed, Colors.white); expect( flat.computeLuminance(), greaterThan(0.85), reason: 'a saturated red surface would force white text onto a mid-tone ' 'red, the weakest contrast pairing in the palette', ); }); }