import 'package:flutter_test/flutter_test.dart'; import 'package:miler/views/Dashboard/home/trip.dart'; /// Bookings shows one flat list — no trip tabs, deliberately — so the only /// thing telling the rider which of the day's runs he is on is the label above /// it. The number has to mean what the hub means by it, and that is the part /// worth pinning down: the numbering is against the WHOLE day, not against the /// subset of it the rider happened to accept. /// /// This exercises the same `groupIntoTrips` + positional numbering the screen /// uses, which is the piece that can silently go wrong. void main() { Map stop(String id, String slotFrom, String slotTo) => { 'orderid': id, 'pickupcustomer': 'Shop $id', 'slotstarttime': slotFrom, 'slotendtime': slotTo, }; /// Order id → 1-based trip number, the way `_numberTrips` builds it. Map numberTrips(List> allToday) { final byId = >{}; for (final s in allToday) { final id = (s['orderid'] ?? '').toString(); if (id.isEmpty) continue; byId.putIfAbsent(id, () => s); } final trips = Trip.groupIntoTrips(byId.values.toList()); return { for (var i = 0; i < trips.length; i++) for (final id in trips[i].orderIds) id: i + 1, }; } final morning = [ stop('A', '2026-08-06T09:00:00', '2026-08-06T12:00:00'), stop('B', '2026-08-06T09:00:00', '2026-08-06T12:00:00'), ]; final afternoon = [ stop('C', '2026-08-06T14:00:00', '2026-08-06T17:00:00'), ]; test('trips are numbered by their slot, earliest first', () { final numbers = numberTrips([...afternoon, ...morning]); expect(numbers['A'], 1); expect(numbers['B'], 1); expect(numbers['C'], 2); }); test('a rider who took only the afternoon is still on Trip 2', () { // ── The reason this is computed from the day and not from the queue ── // // Numbering only the accepted stops would call this run "Trip 1", while the // hub, Home and the rider's own supervisor all call it Trip 2. The label is // a shared name or it is worse than nothing. final dayNumbers = numberTrips([...morning, ...afternoon]); expect(dayNumbers['C'], 2); final queueOnly = numberTrips(afternoon); expect( queueOnly['C'], 1, reason: 'this is exactly the wrong answer the screen must not give', ); }); test('a stop appearing twice in one fetch does not split its trip', () { // The same stop arrives from up to three sources per fetch — v1, v3 and the // local accepted store — and each copy carries the same slot. final numbers = numberTrips([...morning, ...morning, ...afternoon]); expect(numbers['A'], 1); expect(numbers['C'], 2); }); test('a day with one slot is Trip 1, not "your route"', () { expect(numberTrips(morning)['A'], 1); }); }