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

96 lines
3.9 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/home/trip.dart';
import 'package:miler/views/Dashboard/home/trip_brief_strip.dart';
import 'package:miler/views/Dashboard/home/trip_card.dart';
/// ─────────────────────────────────────────────────────────────────────────
/// The trip brief and the hub row have to survive every phone and every
/// accessibility text size.
///
/// This exists because both of them broke in exactly that way while being
/// written. Putting "VIEW ROUTE" on the START · HUB row overflowed the row by
/// 6.2px at the design width — a `Row` of two natural-width children with a
/// `Spacer` between them has no give at all, and the failure only appears once
/// the two happen to be too wide together. The brief has the same shape of risk
/// in two places: four figures sharing one row, and a value like `₹1,23,456`
/// that is far wider than the `₹450` anyone tests with by hand.
///
/// So this sweeps the four widths the app actually ships to against the text
/// scales Android exposes in Settings, and asserts only one thing: nothing
/// throws. Overflow in Flutter is a layout *exception*, so that single
/// assertion catches all of it.
/// ─────────────────────────────────────────────────────────────────────────
void main() {
/// 320 is the narrowest Android phone still in the field; 430 is a Pro Max.
const widths = [320.0, 360.0, 390.0, 430.0];
/// 2.0 is the top of Android's font-size slider.
const textScales = [1.0, 1.3, 1.5, 2.0];
/// A worst-case trip: six stops, and a cash figure with enough digits to
/// stress the narrowest of the four figure columns.
Trip bigTrip() => Trip.fromStops(
id: 't1',
stops: [
for (var i = 0; i < 6; i++)
{
'orderid': 'S$i',
'type': 'pickup',
'pickupcustomer': 'Sri Balaji Stores',
'pickupaddress': '19, Thadagam Road, Venkitapuram, Coimbatore',
'Quantity': '3',
'collectionamt': '123456',
'expected_pickup_time': DateTime.now().toIso8601String(),
},
],
);
for (final width in widths) {
for (final scale in textScales) {
testWidgets('lays out at ${width.toInt()}pt / ${scale}x', (tester) async {
tester.view.physicalSize = Size(width * 3, 844 * 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(
home: MediaQuery(
data: MediaQueryData(textScaler: TextScaler.linear(scale)),
child: Scaffold(
body: SingleChildScrollView(
child: TripCard(
trip: bigTrip(),
// Supplied, so the hub row carries VIEW ROUTE — the
// element that overflowed.
onViewRoute: () {},
),
),
),
),
),
),
);
await tester.pumpAndSettle();
expect(
tester.takeException(),
isNull,
reason: 'collapsed brief overflowed at ${width}pt / ${scale}x',
);
await tester.tap(find.byType(TripBriefStrip));
await tester.pumpAndSettle();
expect(
tester.takeException(),
isNull,
reason: 'open brief overflowed at ${width}pt / ${scale}x',
);
});
}
}
}