import 'package:flutter/material.dart'; import 'package:flutter_screenutil/flutter_screenutil.dart'; import 'package:flutter_test/flutter_test.dart'; import 'package:slide_to_submit_button/slide_to_submit_button.dart'; import 'package:miler/views/Dashboard/home/duty_sheet.dart'; /// The duty sheet used to say one thing — "You will stop receiving bookings" — /// and leave out the two that actually catch a rider out: tracking stops, and /// the app will refuse to take him off duty while he is still holding work. It /// also carried a wifi glyph, which says "network problem" on a screen about /// whether he is working. void main() { Future pump( WidgetTester tester, { required bool goingOnline, Future Function()? onConfirm, }) 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: Align( alignment: Alignment.bottomCenter, child: DutySheet( goingOnline: goingOnline, onConfirm: onConfirm ?? () async => true, ), ), ), ), ), ); // The hint arrow loops forever, so there is nothing to settle into. await tester.pump(const Duration(milliseconds: 300)); } testWidgets('going on duty names the state it is heading for', ( tester, ) async { await pump(tester, goingOnline: true); expect(find.text('Go on duty?'), findsOneWidget); // The strip shows the move: leaving Off duty, arriving at On duty. expect(find.text('Off duty'), findsOneWidget); expect(find.text('On duty'), findsOneWidget); expect(find.text('Slide to go on duty'), findsOneWidget); // Duty is not connectivity. expect(find.byIcon(Icons.wifi), findsNothing); expect(find.byIcon(Icons.wifi_off), findsNothing); }); testWidgets('going off duty lists what stops, including the refusal', ( tester, ) async { await pump(tester, goingOnline: false); expect(find.text('Go off duty?'), findsOneWidget); expect(find.text('No new trips until you are back on'), findsOneWidget); expect(find.text('Live tracking pauses'), findsOneWidget); // The one the old sheet sprang on him only after he had slid it. expect( find.text('Any booking you are holding must be finished first'), findsOneWidget, ); }); testWidgets('a completed slide runs the toggle', (tester) async { var calls = 0; await pump( tester, goingOnline: true, onConfirm: () async { calls++; return true; }, ); // The knob, not the arrow in the state strip above it. final knob = find.descendant( of: find.byType(SlideToSubmit), matching: find.byIcon(Icons.arrow_forward_rounded), ); await tester.drag(knob, const Offset(400, 0)); await tester.pump(); await tester.pump(); expect(calls, 1); }); testWidgets('a short slide does not', (tester) async { var calls = 0; await pump( tester, goingOnline: false, onConfirm: () async { calls++; return true; }, ); final knob = find.descendant( of: find.byType(SlideToSubmit), matching: find.byIcon(Icons.arrow_forward_rounded), ); await tester.drag(knob, const Offset(40, 0)); await tester.pump(); await tester.pump(); expect(calls, 0, reason: 'ending the day takes a deliberate gesture'); }); }