Files
shanxia2.0/web-admin/src/utils/pl-plan-stop-product-arrange-required.test.ts
T

67 lines
1.9 KiB
TypeScript

import assert from 'node:assert/strict'
import { describe, it } from 'node:test'
import { findFirstStopProductArrangeGap } from './pl-plan-stop-product-arrange-required'
function row(partial: Record<string, unknown> = {}) {
return {
productId: 'p1',
unit: '吨',
planQty: 10,
packageSpec: '槽罐',
deliveryMethod: '送货上门',
...partial
}
}
describe('findFirstStopProductArrangeGap', () => {
it('returns null when load and deliveries are complete', () => {
assert.equal(
findFirstStopProductArrangeGap({
loadProducts: [row()],
deliveries: [{ products: [row()] }]
}),
null
)
})
it('flags load product missing fields including planQty 0', () => {
assert.equal(
findFirstStopProductArrangeGap({
loadProducts: [row({ unit: '', planQty: 0, packageSpec: ' ', deliveryMethod: null })],
deliveries: []
}),
'安排运输前请完善装货产品第1行:单位、计划数量、包装规格、送货方式'
)
})
it('flags delivery segment product and stops at first gap', () => {
assert.equal(
findFirstStopProductArrangeGap({
loadProducts: [row()],
deliveries: [
{ products: [row()] },
{ products: [row({ packageSpec: '' }), row({ deliveryMethod: '' })] }
]
}),
'安排运输前请完善送货段#2产品第1行:包装规格'
)
})
it('treats null/undefined/NaN planQty as missing', () => {
assert.equal(
findFirstStopProductArrangeGap({
loadProducts: [row({ planQty: undefined })],
deliveries: []
}),
'安排运输前请完善装货产品第1行:计划数量'
)
assert.equal(
findFirstStopProductArrangeGap({
loadProducts: [row({ planQty: Number.NaN })],
deliveries: []
}),
'安排运输前请完善装货产品第1行:计划数量'
)
})
})