import 'package:doormile_cx/ui/tokens.dart'; import 'package:doormile_cx/ui/widgets/chrome.dart'; import 'package:flutter/material.dart'; import 'package:flutter_test/flutter_test.dart'; /// The top bar's one piece of behaviour. /// /// It reads the [ScrollNotificationObserver] that [Scaffold] installs, which is /// a framework detail rather than something this app owns — so it is worth a /// test. If a Flutter upgrade moves that observer, the bar silently goes back /// to being a flat slab and nothing else in the suite would notice. void main() { Color? barColour(WidgetTester tester) { final box = tester.widget( find .descendant( of: find.byType(DmTopBar), matching: find.byType(AnimatedContainer), ) .first, ); return (box.decoration as BoxDecoration?)?.color; } testWidgets('the bar lifts off the canvas once content is under it', (tester) async { await tester.pumpWidget( MaterialApp( home: Scaffold( backgroundColor: DmColors.canvas, appBar: const DmTopBar(title: 'Probe'), body: ListView( children: [ for (var i = 0; i < 40; i++) const SizedBox(height: 40), ], ), ), ), ); await tester.pumpAndSettle(); // At rest it is the page: no line, no edge, nothing to notice. expect(barColour(tester), DmColors.canvas); await tester.drag(find.byType(ListView), const Offset(0, -300)); await tester.pumpAndSettle(); expect(barColour(tester), DmColors.surface); // And back again, so the top of a page is never wearing a line for // content that has scrolled away. await tester.drag(find.byType(ListView), const Offset(0, 600)); await tester.pumpAndSettle(); expect(barColour(tester), DmColors.canvas); }); }