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'; import 'package:miler/data/milk_run.dart'; import 'package:miler/data/service_profile.dart'; import 'package:miler/data/work_domain.dart'; /// ───────────────────────────────────────────────────────────────────────── /// PICKED IS NOT OUT FOR DELIVERY /// /// ── The regression ── /// /// The release used to ride along with `pickup-complete`: the rider slid to /// confirm five bags at a counter and the same gesture posted all five /// consignments `Out_for_Delivery`. The hub's board then showed five **active** /// deliveries for food still on the shelf in front of him, and the day had no /// moment left in it meaning "I have set off" — picked and out-for-delivery had /// been collapsed into one claim. /// /// They are two claims about where the load is, made an hour apart, and only /// the rider can make the second one. The ladder the hub sees is now: /// /// ``` /// pickup-complete ──▶ Converted_To_Consignment admin: picked /// START DELIVERY ──▶ Out_for_Delivery admin: active /// deliver ──▶ Delivered admin: delivered /// ``` /// /// These are the pure halves of that — the rung ladder and the stores it reads. /// The press itself lives in `MyPickups.startRound`. /// ───────────────────────────────────────────────────────────────────────── void main() { TestWidgetsFlutterBinding.ensureInitialized(); setUp(() { SharedPreferences.setMockInitialValues({}); ServiceProfile.setActive(ServiceProfile.milkMan); }); tearDown(() => ServiceProfile.setActive(ServiceProfile.parcel)); Map order(String id, {String status = 'picked'}) => { 'orderid': id, 'pickupid': int.parse(id), 'sourceid': 'K1', 'sourcename': 'Vidhya Kitchen', 'orderstatus': status, 'pickuplat': 11.01, 'pickuplon': 76.95, 'droplat': 11.05, 'droplon': 76.99, }; group('after the counter, before the road', () { test('a collected order is PICKED, not the delivery-active rung', () async { await addCollectedOrderIds(['1001']); expect( MilkRun.stageOf( order('1001'), acceptedIds: {'1001'}, collectedIds: await getCollectedOrderIds(), outForDeliveryIds: await getOutForDeliveryOrderIds(), ), StopStatus.picked, ); }); test('collecting does not release the round', () async { // The whole regression in one line: nothing on the pickup path may write // the released set. Only `startRound` does, and only after the server has // agreed. await addCollectedOrderIds(['1001', '1002']); expect(await getOutForDeliveryOrderIds(), isEmpty); }); test('an unreleased order is still on the deliveries tab', () async { // The gate for the tab is the *collected* set, never the released one. // Withholding uncollected-but-unreleased orders put them on no tab at // all: dropped from Home as collected, hidden here as unstarted. await addCollectedOrderIds(['1001']); final queue = WorkBoundary.deliveryQueue( [order('1001')], collectedIds: await getCollectedOrderIds(), acceptedIds: {'1001'}, ); expect(queue.map((s) => s['orderid']), ['1001']); }); }); group('the press', () { test('releasing the load moves it to the delivery-active rung', () async { await addCollectedOrderIds(['1001', '1002']); // What `startRound` writes once the server has accepted the batch. await addOutForDeliveryOrderIds(['1001', '1002']); for (final id in ['1001', '1002']) { expect( MilkRun.stageOf( order(id), acceptedIds: {id}, collectedIds: await getCollectedOrderIds(), outForDeliveryIds: await getOutForDeliveryOrderIds(), ), StopStatus.outForDelivery, reason: '$id should be active once the round has started', ); } }); test('it survives a restart, because it is on the device', () async { await addOutForDeliveryOrderIds(['1001']); // A fresh read of the store is what the screen does on every fetch. expect(await getOutForDeliveryOrderIds(), contains('1001')); }); test('completing a stop clears it, so tomorrow starts closed', () async { await addOutForDeliveryOrderIds(['1001', '1002']); await removeOutForDeliveryOrderIds(['1001']); expect(await getOutForDeliveryOrderIds(), {'1002'}); }); }); group('the other line', () { test('a logistics parcel never has a round to start', () { ServiceProfile.setActive(ServiceProfile.parcel); // Its collected parcel goes to a hub and somebody else delivers it, so // the rider must never be shown a control claiming he has set off. expect(ServiceProfile.active.deliversToCustomer, isFalse); expect( MilkRun.navigatesToCustomer(order('1001'), collectedIds: {'1001'}), isFalse, ); }); }); }