import assert from 'node:assert/strict' import { readFileSync } from 'node:fs' import test from 'node:test' test('native driver feedback submits the stored stop-product business identity', () => { const source = readFileSync(new URL('../pages/pl/driver-plan/detail.vue', import.meta.url), 'utf8') const save = source.slice(source.indexOf('async function handleSave()')) const start = save.indexOf('const products =') const end = save.indexOf('await driverPlanApi.saveDriverFeedback', start) assert.ok(start >= 0 && end > start) const build = new Function('stop', `${save.slice(start, end)}; return products`) const rows = build({ showProductQty: true, products: [{ stopProductId: 'stable-id', actualQtyText: '12.5' }] }) assert.deepEqual(rows, [{ stopProductId: 'stable-id', actualQty: 12.5 }]) assert.equal(build({ showProductQty: false, products: [] }), undefined) }) test('native site feedback keeps stop identity across save and detail refresh', async () => { const source = readFileSync(new URL('../pages/pl/transport-plan/detail.vue', import.meta.url), 'utf8') const start = source.indexOf('async function handleSave()') const end = source.indexOf('\nfunction goList()', start) assert.ok(start >= 0 && end > start) const writes = [] const stopStates = { value: [{ stopType: 'delivery', stopId: 'saved-stop', quantityText: '8', attachmentUrls: [], remark: '' }] } const save = new Function('readonly', 'saving', 'stopStates', 'sitePlanApi', 'planId', 'uni', 'loadDetail', `${source.slice(start, end)};return handleSave`)( { value: false }, { value: false }, stopStates, { saveFeedback: async (_id, payload) => writes.push(payload) }, { value: 'plan' }, { showToast() {} }, async () => { stopStates.value = stopStates.value.map(row => ({ ...row })) } ) await save() await save() assert.deepEqual(writes.map(row => [row.stopType, row.stopId, row.quantity]), [ ['delivery', 'saved-stop', 8], ['delivery', 'saved-stop', 8] ]) })