pl-child-identity.test.mjs 1.9 KB

12345678910111213141516171819202122232425262728293031323334
  1. import assert from 'node:assert/strict'
  2. import { readFileSync } from 'node:fs'
  3. import test from 'node:test'
  4. test('native driver feedback submits the stored stop-product business identity', () => {
  5. const source = readFileSync(new URL('../pages/pl/driver-plan/detail.vue', import.meta.url), 'utf8')
  6. const save = source.slice(source.indexOf('async function handleSave()'))
  7. const start = save.indexOf('const products =')
  8. const end = save.indexOf('await driverPlanApi.saveDriverFeedback', start)
  9. assert.ok(start >= 0 && end > start)
  10. const build = new Function('stop', `${save.slice(start, end)}; return products`)
  11. const rows = build({ showProductQty: true, products: [{ stopProductId: 'stable-id', actualQtyText: '12.5' }] })
  12. assert.deepEqual(rows, [{ stopProductId: 'stable-id', actualQty: 12.5 }])
  13. assert.equal(build({ showProductQty: false, products: [] }), undefined)
  14. })
  15. test('native site feedback keeps stop identity across save and detail refresh', async () => {
  16. const source = readFileSync(new URL('../pages/pl/transport-plan/detail.vue', import.meta.url), 'utf8')
  17. const start = source.indexOf('async function handleSave()')
  18. const end = source.indexOf('\nfunction goList()', start)
  19. assert.ok(start >= 0 && end > start)
  20. const writes = []
  21. const stopStates = { value: [{ stopType: 'delivery', stopId: 'saved-stop', quantityText: '8', attachmentUrls: [], remark: '' }] }
  22. const save = new Function('readonly', 'saving', 'stopStates', 'sitePlanApi', 'planId', 'uni', 'loadDetail', `${source.slice(start, end)};return handleSave`)(
  23. { value: false }, { value: false }, stopStates,
  24. { saveFeedback: async (_id, payload) => writes.push(payload) }, { value: 'plan' },
  25. { showToast() {} }, async () => { stopStates.value = stopStates.value.map(row => ({ ...row })) }
  26. )
  27. await save()
  28. await save()
  29. assert.deepEqual(writes.map(row => [row.stopType, row.stopId, row.quantity]), [
  30. ['delivery', 'saved-stop', 8], ['delivery', 'saved-stop', 8]
  31. ])
  32. })