@Tags(['shots']) library; import 'dart:io'; import 'package:flutter/material.dart'; import 'package:flutter/services.dart'; import 'package:flutter_screenutil/flutter_screenutil.dart'; import 'package:flutter_test/flutter_test.dart'; import 'support/golden_fonts.dart'; import 'package:shared_preferences/shared_preferences.dart'; import 'package:miler/data/service_profile.dart'; import 'package:miler/views/Dashboard/pickups/shipment_capture.dart'; import 'package:miler/views/Dashboard/pickups/stop_verify.dart'; import 'package:miler/views/helpers/constants/Font_constant.dart'; /// Reference shots of the logistics verification flow. /// /// This screen is the longest form in the app and the only one a rider fills /// in standing at somebody's gate. It is also the one that had never been /// looked at as a picture — every change to it was reasoned about in code and /// verified by a layout assertion, which catches an overflow and says nothing /// at all about whether the thing reads. void main() { setUpAll(() async { await loadGoldenFonts(); const icons = '/opt/homebrew/share/flutter/bin/cache/artifacts/material_fonts/' 'MaterialIcons-Regular.otf'; if (File(icons).existsSync()) { final il = FontLoader('MaterialIcons') ..addFont( File(icons).readAsBytes().then((b) => ByteData.view(b.buffer)), ); await il.load(); } }); setUp(() { SharedPreferences.setMockInitialValues({'userid': 38}); ServiceProfile.setActive(ServiceProfile.parcel); }); Future page(WidgetTester tester, String name, Widget screen) async { tester.view.physicalSize = const Size(390 * 3, 1500 * 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(debugShowCheckedModeBanner: false, home: screen), ), ); await tester.pumpAndSettle(); expect(tester.takeException(), isNull); await expectLater( find.byType(MaterialApp), matchesGoldenFile('shots/verify_$name.png'), ); } Future shot( WidgetTester tester, String name, Map stop, ) async { tester.view.physicalSize = const Size(390 * 3, 1500 * 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( debugShowCheckedModeBanner: false, home: StopVerificationPage(pickup: stop), ), ), ); await tester.pumpAndSettle(); expect(tester.takeException(), isNull); await expectLater( find.byType(MaterialApp), matchesGoldenFile('shots/verify_$name.png'), ); } testWidgets('a logistics pickup, untouched', (tester) async { await shot(tester, 'pickup', { 'orderid': 'DM-BK-501CB551', 'pickupid': 75, 'type': 'pickup', 'orderstatus': 'accepted', 'pickupcustomer': 'Rajesh Textiles', 'pickupaddress': '14 Cross Cut Road, Gandhipuram, Coimbatore 641012', 'pickupcontactno': '9787698259', 'parcels': [ {'parcelid': 1}, {'parcelid': 2}, ], 'collectionamt': 2450, }); }); testWidgets('the shipment desk, untouched', (tester) async { await page( tester, 'shipment', const ShipmentCapturePage( pickup: { 'orderid': 'DM-BK-501CB551', 'pickupid': 75, 'pickupcustomer': 'Rajesh Textiles', 'pickupaddress': '14 Cross Cut Road, Gandhipuram, Coimbatore', 'pickuppincode': '641012', 'dropaddress': '22 Race Course Road, Coimbatore', 'droppincode': '641018', }, ), ); }); testWidgets('a delivery, untouched', (tester) async { await shot(tester, 'delivery', { 'orderid': 'DM-BK-501CB552', 'pickupid': 76, 'type': 'delivery', 'orderstatus': 'outfordelivery', 'pickupcustomer': 'Meena Sundaram', 'dropaddress': '22 Race Course Road, Coimbatore 641018', 'pickupcontactno': '9787698260', 'parcels': [ {'parcelid': 1}, ], }); }); }