cmvr-wms/ruoyi-ui-vue3/tests/unit/purchase-paste-issues.test.mjs

20 lines
2.6 KiB
JavaScript
Raw Normal View History

import test from 'node:test'
import assert from 'node:assert/strict'
import {pasteRectangle,resolveRow} from '../../src/utils/purchase-sheet.js'
test('large pastes report every invalid unit with copied-source and target lines and leave all originals intact',()=>{
const rows=Array.from({length:25},(_,i)=>({_key:'old'+i,materialName:'原物品'+i,unit:'台',quantity:1})),before=JSON.stringify(rows),items=Array.from({length:70},(_,i)=>({id:i+1,productName:'设备'+(i+1),spec:'S'+i,brand:'B',unit:'台',category:'设备'}))
const text=items.map((item,i)=>[item.productName,item.spec,item.brand,i===2||i===62?'件':'台',1].join('\t')).join('\n');let key=0
assert.throws(()=>pasteRectangle(rows,text,25,0,['materialName','materialParams','materialBrand','unit','quantity'],{emptyRow:()=>({_key:'new'+key++}),readonly:()=>false,items,units:['台','件'],sourceStartLine:2}),error=>{
assert.equal(error.pasteIssues.length,2);assert.deepEqual(error.pasteIssues.map(issue=>[issue.sourceLine,issue.line,issue.materialName,issue.currentValue,issue.expectedValue]),[[4,28,'设备3','件','台'],[64,88,'设备63','件','台']]);assert.match(error.message,/共 2 行/);return true
});assert.equal(JSON.stringify(rows),before)
})
test('visible sorted targets keep correct original line numbers and aggregate non-unit errors too',()=>{
const rows=Array.from({length:5},(_,i)=>({_key:'r'+i,materialName:'设备'+i,quantity:1,unit:'台'}));assert.throws(()=>pasteRectangle(rows,'0\n错误\n2',4,0,['quantity'],{readonly:()=>false,items:[],units:['台'],rowIndices:[4,1,3]}),error=>{assert.deepEqual(error.pasteIssues.map(issue=>[issue.sourceLine,issue.line,issue.field]),[[1,5,'quantity'],[2,2,'quantity']]);return true});assert.equal(rows[3].quantity,1)
})
test('a selected duplicate archive still rejects conflicting units without rewriting the source',()=>{
const items=[{id:1,productName:'电机',unit:'台'},{id:2,productName:'电机',unit:'个'}],row={productId:2,materialName:'电机',unit:'台'};assert.throws(()=>resolveRow(row,items),error=>error.field==='unit'&&error.currentValue==='台'&&error.expectedValue==='个');assert.equal(row.unit,'台')
})
test('pasting an unchanged fixed archive unit is a no-op, while mismatches retain precise values',()=>{
const row={_key:'old',productId:1,materialName:'电机',unit:'台',quantity:1},context={readonly:()=>false,canEditField:()=>false,items:[{id:1,productName:'电机',unit:'台'}],units:['台','件']};assert.equal(pasteRectangle([row],'台',0,0,['unit'],context)[0].unit,'台');assert.throws(()=>pasteRectangle([row],'件',0,0,['unit'],context),error=>error.pasteIssues[0].expectedValue==='台');assert.equal(row.unit,'台')
})