218 lines
8.0 KiB
Dart
218 lines
8.0 KiB
Dart
import 'package:flutter/material.dart';
|
|
import 'package:lucide_icons_flutter/lucide_icons.dart';
|
|
import 'package:flutter_screenutil/flutter_screenutil.dart';
|
|
import 'package:flutter_test/flutter_test.dart';
|
|
|
|
import 'package:miler/data/service_profile.dart';
|
|
import 'package:miler/views/Dashboard/home/route_timeline.dart';
|
|
import 'package:miler/views/Dashboard/home/trip.dart';
|
|
import 'package:miler/views/Dashboard/home/trip_card.dart';
|
|
import 'package:miler/views/helpers/constants/Colorconstants.dart';
|
|
|
|
/// ─────────────────────────────────────────────────────────────────────────
|
|
/// ONE GRID, MEASURED
|
|
///
|
|
/// Home is read by running the eye down two columns: names on the left, bags
|
|
/// and figures on the right. Every point of drift in either costs a fixation,
|
|
/// and drift is invisible in code review — it comes from nested padding that
|
|
/// each looks correct where it is written.
|
|
///
|
|
/// The select-all was 36pt off the name axis, because the row is railed by its
|
|
/// caller *and* reserved a second rail inside the widget: two corrections for
|
|
/// one indent. Then it was 2pt off, because the rail it sits in is 2 wider
|
|
/// than the order rows' own. Both were found by measuring, not by reading.
|
|
/// ─────────────────────────────────────────────────────────────────────────
|
|
void main() {
|
|
tearDown(() => ServiceProfile.setActive(ServiceProfile.parcel));
|
|
|
|
Map<String, dynamic> meal(String id, String who, {int step = 1}) => {
|
|
'orderid': id,
|
|
'type': 'delivery',
|
|
'step': step,
|
|
'pickupcustomer': who,
|
|
'kitchenid': 'K1',
|
|
'kitchenname': 'Vidhya Kitchen',
|
|
'sourcename': 'Vidhya Kitchen',
|
|
'pickupcontactno': '9787698259',
|
|
'pickupaddress': '4 Cross, RS Puram, Coimbatore',
|
|
'dropaddress': '12 SNS Colony, Peelamedu, Coimbatore 641004',
|
|
'Quantity': '1',
|
|
};
|
|
|
|
Future<void> pumpHome(
|
|
WidgetTester tester, {
|
|
double width = 390,
|
|
double textScale = 1.0,
|
|
int orders = 3,
|
|
}) async {
|
|
ServiceProfile.setActive(ServiceProfile.milkMan);
|
|
// A real phone's geometry. A taller view with the same design size scales
|
|
// every `.h` by the ratio and makes every measurement here a fiction —
|
|
// which is exactly how a "116dp row" was once reported on a 62dp row.
|
|
tester.view.physicalSize = Size(width * 3, 844 * 3);
|
|
tester.view.devicePixelRatio = 3.0;
|
|
addTearDown(tester.view.reset);
|
|
|
|
final trip = Trip.fromStops(
|
|
id: 'run',
|
|
stops: [
|
|
for (var i = 1; i <= orders; i++) meal('$i', 'Customer $i', step: i),
|
|
],
|
|
);
|
|
|
|
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: Scaffold(
|
|
backgroundColor: ColorConstants.daylightSurface,
|
|
body: SingleChildScrollView(
|
|
child: TripCard(
|
|
trip: trip,
|
|
onToggleSelect: (_) {},
|
|
onSelectAll: (_) {},
|
|
onStopTap: (_) {},
|
|
onCallStop: (_) {},
|
|
),
|
|
),
|
|
),
|
|
),
|
|
),
|
|
);
|
|
await tester.pumpAndSettle();
|
|
}
|
|
|
|
group('the two columns', () {
|
|
testWidgets('every customer name starts on one axis', (tester) async {
|
|
await pumpHome(tester, orders: 4);
|
|
final lefts = [
|
|
for (var i = 1; i <= 4; i++)
|
|
tester.getRect(find.text('Customer $i')).left,
|
|
];
|
|
for (final l in lefts) {
|
|
expect(l, closeTo(lefts.first, 0.5));
|
|
}
|
|
});
|
|
|
|
testWidgets('every order row ends on one axis', (tester) async {
|
|
// ── What this used to measure ──
|
|
//
|
|
// The right edge of `Bag 1 … Bag 4`, which was a tag the app derived from
|
|
// each row's position. That numbering is gone — it was the app's own
|
|
// arithmetic drawn as a physical reference, beside a rail already
|
|
// numbering the same rows — so the column it formed is gone with it.
|
|
//
|
|
// The rule it existed to protect is not: whatever closes a step row, the
|
|
// rows close together. A ragged right edge down a list of people is what
|
|
// makes a route unscannable, and it is now the chevrons that hold that
|
|
// edge.
|
|
await pumpHome(tester, orders: 4);
|
|
final rights = tester
|
|
.widgetList<Icon>(find.byIcon(LucideIcons.chevronRight))
|
|
.map((i) => tester.getRect(find.byWidget(i)).right)
|
|
.toList();
|
|
expect(rights.length, greaterThanOrEqualTo(4));
|
|
for (final r in rights) {
|
|
expect(r, closeTo(rights.first, 0.5));
|
|
}
|
|
});
|
|
|
|
testWidgets('the select-all closes the row it belongs to', (tester) async {
|
|
await pumpHome(tester);
|
|
|
|
// ── The axis it answers to is the right one now ──
|
|
//
|
|
// This pinned the label to the *name* axis, when the control headed its
|
|
// list from the left. Inside a group it is a control over a list rather
|
|
// than a heading for one, so it sits on the edge a list's own controls
|
|
// use — the same right edge the chevrons below it already keep. What must
|
|
// not happen is that it floats between the two.
|
|
final label = tester.getRect(find.text('Select all 3')).right;
|
|
final list = tester.getRect(find.byType(RouteTimeline)).right;
|
|
expect(
|
|
label,
|
|
closeTo(list, 4),
|
|
reason: 'the select-all ends at $label, the list at $list',
|
|
);
|
|
});
|
|
|
|
testWidgets('the kitchen and its state share one axis', (tester) async {
|
|
await pumpHome(tester);
|
|
expect(
|
|
tester.getRect(find.textContaining('Pending')).left,
|
|
closeTo(tester.getRect(find.text('Vidhya Kitchen')).left, 0.5),
|
|
);
|
|
});
|
|
});
|
|
|
|
group('type ranks the page', () {
|
|
testWidgets('the kitchen outranks the customer, which outranks the area', (
|
|
tester,
|
|
) async {
|
|
await pumpHome(tester);
|
|
|
|
final kitchen = tester.widget<Text>(find.text('Vidhya Kitchen')).style!;
|
|
final name = tester.widget<Text>(find.text('Customer 1')).style!;
|
|
final area = tester.widget<Text>(find.text('Peelamedu').first).style!;
|
|
|
|
expect(kitchen.fontSize, 19);
|
|
expect(kitchen.fontWeight, FontWeight.w700);
|
|
expect(name.fontSize, 15);
|
|
expect(area.fontSize, 12.5);
|
|
|
|
// A customer row must never overpower the heading it sits under.
|
|
expect(name.fontSize!, lessThan(kitchen.fontSize!));
|
|
expect(area.fontSize!, lessThan(name.fontSize!));
|
|
expect(area.fontSize!, greaterThanOrEqualTo(12));
|
|
});
|
|
});
|
|
|
|
group('rows grow, they do not clip', () {
|
|
for (final (width, scale) in const [
|
|
(390.0, 1.0),
|
|
(390.0, 2.0),
|
|
(375.0, 1.0),
|
|
(375.0, 2.0),
|
|
(320.0, 1.0),
|
|
(320.0, 2.0),
|
|
]) {
|
|
testWidgets('${width.toInt()}px @ ${scale}x lays out clean', (
|
|
tester,
|
|
) async {
|
|
await pumpHome(tester, width: width, textScale: scale, orders: 4);
|
|
expect(
|
|
tester.takeException(),
|
|
isNull,
|
|
reason: 'no overflow at ${width.toInt()}px / ${scale}x',
|
|
);
|
|
});
|
|
}
|
|
|
|
testWidgets('a one-line row clears the touch floor and grows at 2x', (
|
|
tester,
|
|
) async {
|
|
await pumpHome(tester);
|
|
final at1x = tester.getRect(find.byType(PickupTimelineStep).first).height;
|
|
expect(
|
|
at1x,
|
|
greaterThanOrEqualTo(44),
|
|
reason: 'a step is reachable with a gloved thumb',
|
|
);
|
|
|
|
await pumpHome(tester, textScale: 2.0);
|
|
final at2x = tester.getRect(find.byType(PickupTimelineStep).first).height;
|
|
expect(
|
|
at2x,
|
|
greaterThan(at1x),
|
|
reason: 'density comes from removing furniture, never from clipping',
|
|
);
|
|
});
|
|
});
|
|
}
|