Files
doormile_milderapp/test/stop_verify_layout_test.dart
2026-08-11 13:16:33 +05:30

103 lines
3.8 KiB
Dart

import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:miler/views/Dashboard/pickups/stop_verify.dart';
/// The verification page is filled in at a doorstep, one-handed, often by
/// someone who has turned the system font up. It was rebuilt to remove the
/// nested boxes it used to be made of, and the pieces that replaced them —
/// a step counter in the app bar, a full-width parcel list, six OTP tiles, a
/// label/value review — are all row layouts with fixed-width parts, which is
/// exactly the shape that overflows when the text grows.
///
/// A screenshot on the developer's own phone at 1.0x cannot catch that, so it
/// is measured here: every leg, on the narrowest phone the app supports, at
/// every text scale Android offers.
void main() {
Future<void> pump(
WidgetTester tester,
Map<String, dynamic> stop, {
double width = 360,
double textScale = 1.0,
}) async {
tester.view.physicalSize = Size(width * 3, 780 * 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(
builder: (context, child) => MediaQuery(
data: MediaQuery.of(context)
.copyWith(textScaler: TextScaler.linear(textScale)),
child: child!,
),
home: StopVerificationPage(pickup: stop),
),
),
);
await tester.pumpAndSettle();
}
Map<String, dynamic> stopOf(String type, {int delivery = 0, int pickup = 0}) =>
<String, dynamic>{
'orderid': 'T-1',
'type': type,
'pickupcustomer': 'Venkateswara Traders & General Merchants',
'pickupaddress':
'12/3B, Second Cross Street, Ram Nagar, Near Bus Stand, '
'Coimbatore, Tamil Nadu 641009',
if (delivery > 0) 'deliveryqty': '$delivery',
if (pickup > 0) 'pickupqty': '$pickup',
'Quantity': '${pickup > 0 ? pickup : delivery}',
'collectionamt': '2450',
};
for (final scale in const [1.0, 1.3, 1.5, 2.0]) {
testWidgets('the collect leg lays out at ${scale}x', (tester) async {
await pump(tester, stopOf('pickup', pickup: 3), textScale: scale);
expect(tester.takeException(), isNull);
});
testWidgets('the hand-over leg lays out at ${scale}x', (tester) async {
await pump(tester, stopOf('delivery', delivery: 4), textScale: scale);
expect(tester.takeException(), isNull);
});
}
testWidgets('the whole collect leg is reachable by scrolling',
(tester) async {
await pump(tester, stopOf('pickup', pickup: 2));
// The last section of the longest leg. If the scroll view were sized wrong
// — which is the failure mode of a Column inside a Column inside an
// Expanded — this would never come into view.
await tester.dragUntilVisible(
find.text('PICKUP CODE'),
find.byType(SingleChildScrollView),
const Offset(0, -200),
);
expect(find.text('PICKUP CODE'), findsOneWidget);
expect(tester.takeException(), isNull);
});
testWidgets('the action bar never scrolls away with the form',
(tester) async {
await pump(tester, stopOf('pickup', pickup: 2));
final barAtRest = tester.getRect(find.text('Take a photo of the parcels'));
await tester.drag(find.byType(SingleChildScrollView), const Offset(0, -400));
await tester.pumpAndSettle();
// The blocking hint lives in the pinned bar, so it is still exactly where
// it was: what the rider must do next cannot scroll off a doorstep screen.
expect(
tester.getRect(find.text('Take a photo of the parcels')),
barAtRest,
);
});
}