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

103 lines
3.0 KiB
Dart

import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:miler/views/Dashboard/pickups/stop_verify.dart';
/// The review step is the last screen before a stop is closed, and the only
/// thing the rider does on it is check figures. It used to spend a full line on
/// each — an icon, a caption and a value — for values that are almost always
/// four characters, so six facts ran past the fold and he had to scroll a
/// *confirmation* screen to see what he was confirming.
///
/// The packing rule is what fixed that, and it is asserted here rather than on
/// screen: the review sits behind a camera gate no widget test can pass.
void main() {
ReviewFact narrow(String label, String value) =>
ReviewFact(label, value, icon: Icons.circle);
ReviewFact wide(String label, String value) =>
ReviewFact(label, value, icon: Icons.circle, wide: true);
List<List<String>> labels(List<List<ReviewFact>> rows) =>
[for (final r in rows) [for (final f in r) f.label]];
test('two short facts share a row', () {
final rows = packReviewFacts([
narrow('Parcels', '3 of 3'),
narrow('Weight', '4.5 kg'),
]);
expect(labels(rows), [
['Parcels', 'Weight'],
]);
});
test('a sentence takes its own row', () {
// Wrapping a recipient's name or a damage note into half a column is how a
// grid turns back into a wall of text.
final rows = packReviewFacts([
narrow('Parcels', '3 of 3'),
narrow('Weight', '4.5 kg'),
wide('Note', 'Corner of the second box is crushed'),
]);
expect(labels(rows), [
['Parcels', 'Weight'],
['Note'],
]);
});
test('a wide fact does not drag its neighbour onto its row', () {
final rows = packReviewFacts([
wide('Received by', 'Ramesh Kumar · Security'),
narrow('OTP', '482156'),
]);
expect(labels(rows), [
['Received by'],
['OTP'],
]);
});
test('empty values are dropped, not rendered as dashes', () {
final rows = packReviewFacts([
narrow('Parcels', '3 of 3'),
narrow('Pickup code', ''),
narrow('Weight', '4.5 kg'),
]);
expect(labels(rows), [
['Parcels', 'Weight'],
]);
});
test('order is meaning, so nothing is re-sorted to pack tighter', () {
final rows = packReviewFacts([
narrow('Parcels', '3 of 3'),
wide('Note', 'Shutter was half down'),
narrow('Weight', '4.5 kg'),
narrow('Condition', 'Sealed & intact'),
]);
// A tighter packing exists — pair Parcels with Weight and push the note
// down — and it is deliberately not taken.
expect(labels(rows), [
['Parcels'],
['Note'],
['Weight', 'Condition'],
]);
});
test('the collect leg fits in three rows instead of six', () {
final rows = packReviewFacts([
narrow('Parcels', '3 of 3'),
narrow('Weight', '4.5 kg'),
narrow('Condition', 'Sealed & intact'),
narrow('Pickup code', '482156'),
wide('Note', 'Customer only had two ready'),
]);
expect(rows, hasLength(3));
});
}