Files
doormile_milderapp/test/completed_store_test.dart
Thiru-tenext d7348e253f Miler rider app: surface system, visible design language, backend lifecycle
Design system
- MilerSurface ladder (canvas → working → raised → floating) with MilerPanel
  as layer 1; canvas moved to #DEE3EA so white separates at 1.290:1.
- Visible vocabulary applied across Home, Deliveries, Activity, Account and
  the sheets: hero heads (tabular numeral + small caption, clamped at 1.3x),
  canvas wells for anything that opens, small filled tags for shelf labels,
  demoted placeholders. Recorded in DESIGN_SYSTEM.md §6.
- One icon family: 222 Material glyphs migrated to Lucide; none left outside
  lib/xpress.
- Colour semantics corrected: amber only for what is genuinely owed, brand red
  reserved for the live stop, disabled primaries go neutral rather than pale.

Data and lifecycle
- lib/data/lifecycle.dart reads mutations for what they prove; route_order.dart
  makes admin sequence the single ordering authority; service_day.dart, and
  stop_area.dart rewritten against live Coimbatore addresses (digit-token
  stripping, city stoplist, street suffixes, stammer collapse).
- countLabel states the load once, in bags.

Testing
- 1440 tests passing; golden shot harnesses for Home, Deliveries, Activity,
  sheets and verify, with test/failures/ now gitignored (diff debris).
- New pins: home_gutter_test, stop_area_test, plus updated structural bounds.

Note: this commit also carries pre-existing working-tree deletions that were
present before this work (API_SPEC.md, README.md, demo test fixtures).

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
2026-08-22 05:40:35 +05:30

181 lines
6.4 KiB
Dart

import 'dart:convert';
import 'package:flutter_test/flutter_test.dart';
import 'package:shared_preferences/shared_preferences.dart';
import 'package:miler/Models/stop_status.dart';
import 'package:miler/data/accepted_store.dart';
/// Finishing a stop is optimistic — the rider is moved on whether or not the
/// status call lands, and the queue endpoints will not report the stop as
/// finished for a poll or two (never, on demo data). This store is the only
/// record in between, and the Activity tab is empty without it.
void main() {
TestWidgetsFlutterBinding.ensureInitialized();
Map<String, dynamic> booking(String id) => {
'orderid': id,
'pickupcustomer': 'Sri Balaji Stores',
'pickupaddress': '19, Thadagam Road, Coimbatore',
};
String today() {
final t = DateTime.now();
return '${t.year}-${t.month.toString().padLeft(2, '0')}-'
'${t.day.toString().padLeft(2, '0')}';
}
setUp(() => SharedPreferences.setMockInitialValues({}));
test('a finished stop is readable, and reads as finished', () async {
await addCompletedBookings([booking('A')]);
final done = await getCompletedBookings();
expect(done, hasLength(1));
expect(done.first['orderid'], 'A');
expect(
stopStatusOf(done.first).isFinishedPickup,
isTrue,
reason: 'Activity filters on the same test Bookings drops a stop with',
);
expect(done.first['completedat'], isNotNull);
});
test('a cancelled stop is stored as cancelled, not picked', () async {
await addCompletedBookings([booking('B')], cancelled: true);
final done = await getCompletedBookings();
expect(done.first['orderstatus'], 'cancelled');
expect(stopStatusOf(done.first).isCancelled, isTrue);
});
test('newest first', () async {
await addCompletedBookings([booking('A')]);
await Future<void>.delayed(const Duration(milliseconds: 5));
await addCompletedBookings([booking('B')]);
final done = await getCompletedBookings();
expect(done.map((b) => b['orderid']).toList(), ['B', 'A']);
});
test('the same stop twice is one row', () async {
await addCompletedBookings([booking('A')]);
await addCompletedBookings([booking('A')]);
expect(await getCompletedBookings(), hasLength(1));
});
// ── What Home stamps over a lagging queue ──
//
// Home reads these ids and rewrites `orderstatus` to 'picked' on any stop the
// queue is still reporting as live. Without it the row the rider has just
// confirmed sits on Home wearing its LIVE mark until the backend catches up,
// which reads as the confirm not having worked.
test('the finished ids are readable on their own', () async {
await addCompletedBookings([booking('A')]);
await addCompletedBookings([booking('B')], cancelled: true);
// Both count as closed: a stop written off is as finished, for Home's
// purposes, as one picked up.
expect(await getCompletedOrderIds(), {'A', 'B'});
});
test('nothing finished is an empty set, not a null', () async {
expect(await getCompletedOrderIds(), isEmpty);
});
// ── The timings ──
//
// Activity's stop detail can only answer "when did I get there" and "how long
// did that door take" if the two stamps survive the stop being closed. They
// live in prefs keys the *next* stop overwrites, so completion is the only
// moment they can be captured — and capturing a stale one is worse than
// capturing none, because another stop's clock reads as fact.
group('timings', () {
Map<String, dynamic> withPickup(String id) => {
...booking(id),
'pickupid': '77',
};
test(
'the departure and arrival stamps are carried onto the record',
() async {
SharedPreferences.setMockInitialValues({
kStopStartedKey('77'): '2026-08-06T09:12:00.000',
kStopArrivedKey('77'): '2026-08-06T09:31:00.000',
});
await addCompletedBookings([withPickup('A')]);
final done = await getCompletedBookings();
expect(done.single['startedat'], '2026-08-06T09:12:00.000');
expect(done.single['arrivedat'], '2026-08-06T09:31:00.000');
},
);
test(
'the keys are cleared, so the next stop cannot inherit them',
() async {
SharedPreferences.setMockInitialValues({
kStopStartedKey('77'): '2026-08-06T09:12:00.000',
kStopArrivedKey('77'): '2026-08-06T09:31:00.000',
});
await addCompletedBookings([withPickup('A')]);
final prefs = await SharedPreferences.getInstance();
expect(prefs.getString(kStopStartedKey('77')), isNull);
expect(prefs.getString(kStopArrivedKey('77')), isNull);
// A second stop sharing the pickup id — a resumed skip worked twice in
// one day — must not report the first attempt's clock.
await addCompletedBookings([withPickup('B')]);
final second = (await getCompletedBookings()).firstWhere(
(b) => b['orderid'] == 'B',
);
expect(second['startedat'], isNull);
},
);
test(
'a stop closed without ever opening the map claims no timings',
() async {
// Bulk-completed from Home: nothing wrote a departure, so nothing is
// claimed, and the detail panel says "not recorded" instead of inventing
// a figure that cannot be caught.
await addCompletedBookings([withPickup('A')]);
final done = await getCompletedBookings();
expect(done.single['startedat'], isNull);
expect(done.single['arrivedat'], isNull);
},
);
});
// The store is per-day: yesterday's work is not today's activity, and a store
// that never forgets grows for the life of the install.
test('yesterday is dropped, today is kept', () async {
SharedPreferences.setMockInitialValues({});
await debugSeedStore(
'completed_bookings',
jsonEncode([
{
...booking('OLD'),
'completedday': '2020-01-01',
'orderstatus': 'picked',
},
{...booking('NEW'), 'completedday': today(), 'orderstatus': 'picked'},
]),
);
final done = await getCompletedBookings();
expect(done.map((b) => b['orderid']).toList(), ['NEW']);
// And the prune is written back, not recomputed on every read.
final prefs = await SharedPreferences.getInstance();
expect(
prefs.getString(await debugStoreKey('completed_bookings')),
isNot(contains('OLD')),
);
});
}