cmvr-wms/ruoyi-ui-vue3/tests/unit/purchase-sheet-view.test.mjs

28 lines
2.3 KiB
JavaScript
Raw Normal View History

import test from 'node:test'
import assert from 'node:assert/strict'
import {queueMatches,sortSheetRows,batchProgress} from '../../src/utils/purchase-sheet-view.js'
test('mixed batch progress preserves confirmed work rather than reporting wholly unquoted',()=>{
assert.equal(batchProgress({requestCount:43,openCount:43,unlockedCount:7,unpricedCount:7,arrivableCount:36}).label,'部分采购')
assert.equal(batchProgress({requestCount:43,openCount:7,unlockedCount:7,unpricedCount:7,arrivableCount:0}).label,'部分完成')
assert.equal(batchProgress({requestCount:43,openCount:43,unlockedCount:43,unpricedCount:7,arrivableCount:0}).label,'待报价')
assert.equal(batchProgress({requestCount:43,openCount:43,unlockedCount:7,pendingCount:2,arrivableCount:34}).label,'待验收')
assert.equal(batchProgress({requestCount:9,openCount:9,unlockedCount:0,arrivableCount:9}).label,'采购中')
})
test('queues handle zero quotation, terminal records and partial deliveries',()=>{
const row={quantity:10,finalUnitPrice:0,priceLocked:false}
assert.ok(queueMatches(row,'confirm'));assert.ok(!queueMatches(row,'quote'))
const partial={...row,priceLocked:true,remainingQuantity:3,pendingArrivalQuantity:2,acceptedQuantity:5,receivedQuantity:4}
for(const q of ['arrival','acceptance','receipt'])assert.ok(queueMatches(partial,q))
assert.ok(!queueMatches(partial,'completed'));assert.ok(queueMatches({...partial,historical:true},'completed'))
assert.ok(!queueMatches({...partial,historical:true},'arrival'));assert.ok(queueMatches({...partial,purchaseStatus:5},'cancelled'))
assert.ok(!queueMatches({...partial,purchaseStatus:5},'acceptance'))
assert.ok(queueMatches({...partial,remainingQuantity:0,pendingArrivalQuantity:0,receivedQuantity:5},'completed'))
})
test('sort is stable and immutable; missing prices follow real prices including zero',()=>{
const rows=[{id:1,finalUnitPrice:null},{id:2,finalUnitPrice:0},{id:3,finalUnitPrice:10},{id:4,finalUnitPrice:2},{id:5,finalUnitPrice:2}]
assert.deepEqual(sortSheetRows(rows,'priceAsc').map(r=>r.id),[2,4,5,3,1]);assert.deepEqual(sortSheetRows(rows,'priceDesc').map(r=>r.id),[3,4,5,2,1])
assert.deepEqual(rows.map(r=>r.id),[1,2,3,4,5]);const snapshots=new Map(rows.map(r=>[r.id,{...r}]))
rows[3].finalUnitPrice=200;assert.deepEqual(sortSheetRows(rows,'priceAsc',row=>snapshots.get(row.id)).map(r=>r.id),[2,4,5,3,1])
})