cmvr-wms/ruoyi-ui-vue3/tests/unit/purchase-name-options.test.mjs

47 lines
2.1 KiB
JavaScript
Raw Normal View History

import test from 'node:test'
import assert from 'node:assert/strict'
import { purchaseNameChoices } from '../../src/utils/purchase-sheet.js'
test('unmatched draft remains an option in open, empty-loading and closed remote menus',()=>{
const row={materialName:'新物品',materialBrand:'新品牌',materialParams:'型号A',unit:'个',finalUnitPrice:12}
const before={...row}
for(const results of [[],[{id:8,productName:'其他物品'}],[]]){
const choices=purchaseNameChoices(row,results)
assert.ok(choices.some(item=>!item.id&&item.productName===row.materialName))
assert.equal(choices[0].spec,'型号A')
assert.equal(choices[0].brand,'新品牌')
}
assert.deepEqual(row,before)
})
test('selected archive is retained when filtered out, without duplicate IDs or hiding same-name variants',()=>{
const row={productId:9,materialName:'电机',materialParams:'A',materialBrand:'品牌'}
const selected={id:9,productName:'电机',spec:'A'},other={id:10,productName:'电机',spec:'B'}
const results=[selected,other]
assert.equal(purchaseNameChoices(row,results),results)
assert.deepEqual(purchaseNameChoices(row,[other]).map(item=>item.id),[9,10])
assert.equal(purchaseNameChoices(row,[])[0].id,9)
})
test('draft and archive with the same name keep distinct selection values; empty drafts stay empty',()=>{
const archive={id:1,productName:'电机'}
const choices=purchaseNameChoices({materialName:'电机'},[archive])
assert.equal(choices.length,2)
assert.equal(choices[0].id,undefined)
assert.equal(choices[1],archive)
assert.deepEqual(purchaseNameChoices({materialName:''},[]),[])
})
test('opening and closing an empty remote result reaches stable visibility instead of a feedback loop',()=>{
const row={materialName:'档案不存在',materialBrand:'品牌',materialParams:'规格'}
// ElSelect remote empty-text=false suppresses visibility when options disappear.
let visible=true,transitions=0
for(let i=0;i<20;i++){
const next=purchaseNameChoices(row,visible?[]:[]).length>0
if(next!==visible)transitions++
visible=next
}
assert.equal(visible,true)
assert.equal(transitions,0)
})