import 'package:flutter/material.dart'; import 'package:flutter_screenutil/flutter_screenutil.dart'; import 'package:flutter_test/flutter_test.dart'; import 'package:miler/views/Dashboard/home/trip_empty_state.dart'; /// An unfilled trip tab used to render a bordered white card with a grey /// glyph in it — a piece of content that had arrived empty. It is the page /// itself now, so the assertion that matters is that no card comes back: a /// `Container` with a `Border` around the whole state is the thing being /// removed, and a redesign that quietly reintroduces one should fail here. void main() { Future pump( WidgetTester tester, { required bool offline, VoidCallback? onGoOnDuty, }) async { tester.view.physicalSize = const Size(1170, 2532); 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: Scaffold( body: TripEmptyState( tripLabel: 'Trip 2', offline: offline, onGoOnDuty: onGoOnDuty, ), ), ), ), ); // Not `pumpAndSettle`: the halo breathes on a repeating controller, so // there is deliberately no steady state to settle into. await tester.pump(const Duration(milliseconds: 300)); } /// Any decoration carrying a border, anywhere in the state. Finder borderedBoxes() => find.byWidgetPredicate((w) { if (w is! Container) return false; final d = w.decoration; return d is BoxDecoration && d.border != null; }); testWidgets('names the trip the tabs name, and draws no card', ( tester, ) async { await pump(tester, offline: false); expect(find.text('Trip 2 not assigned yet'), findsOneWidget); expect(borderedBoxes(), findsNothing); }); testWidgets('says the app is still waiting rather than offering nothing', ( tester, ) async { await pump(tester, offline: false); expect(find.text('Waiting for your hub'), findsOneWidget); }); testWidgets('off duty is a different sentence with the action that fixes it', ( tester, ) async { var tapped = false; await pump(tester, offline: true, onGoOnDuty: () => tapped = true); expect(find.text('You are off duty'), findsOneWidget); // Nothing is coming until he goes on duty, so the wait is not claimed. expect(find.text('Waiting for your hub'), findsNothing); await tester.tap(find.text('Go on duty')); await tester.pump(); expect(tapped, isTrue); }); }