import 'package:flutter/material.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', ); }); testWidgets('wears the frosted brand wash, not a solid fill', (tester) async { await pump(tester, const Scaffold(appBar: MilerAppBar(title: 'Activity'))); final bar = tester.widget(find.byType(AppBar)); expect(bar.backgroundColor, Colors.transparent); expect(bar.flexibleSpace, isNotNull); // A blur is the difference between glass and a tinted box: content // passing under the bar softens instead of sliding under a lid. expect(find.byType(BackdropFilter), findsOneWidget); }); 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('appTopBar', () { testWidgets('uses the same wash as the tab bars', (tester) async { await pump(tester, Scaffold(appBar: milerPageBar('Rewards', onBack: () {}))); final bar = tester.widget(find.byType(AppBar)); expect(bar.backgroundColor, Colors.transparent); expect(find.byType(BackdropFilter), findsOneWidget); expect(bar.bottom, isNull, reason: 'no rule under the glass here either'); }); }); test('the wash is a brand tint light enough to carry near-black type', () { // Flattened against white, which is what both the real bars and Home's // pinned header composite it over. final flat = Color.alphaBlend(ColorConstants.glassRed, Colors.white); expect( flat.computeLuminance(), greaterThan(0.85), reason: 'a saturated red bar would force white text onto a mid-tone red, ' 'the weakest contrast pairing in the palette', ); }); }