- 新增 PDF 文档支持,包括格式校验和完整性检查 - 扩展 Word、TXT 和 ZIP 格式附件处理能力 - 添加 Excel 附件可选择仅作为业务文件不解析行数据 - 实现业务助手表格布局配置新增库存和预算字段 - 集成通知、反馈通知等新的业务助手动作类型 - 完善部门管理包含父级部门和排序字段支持 - 增强业务规则校验涵盖更多系统管理场景 - 优化附件上传限制提示信息更准确 - 添加生成文件下载的安全性校验机制 - 扩展测试覆盖确保各业务动作规则正确性
36 lines
2.4 KiB
JavaScript
36 lines
2.4 KiB
JavaScript
import test from 'node:test'
|
|
import assert from 'node:assert/strict'
|
|
import { readFileSync } from 'node:fs'
|
|
|
|
const source=readFileSync(new URL('../../src/components/PurchaseSheet/index.vue',import.meta.url),'utf8')
|
|
const method=source.slice(source.indexOf('async cancelEditing()'),source.indexOf('async back()')).trim().replace(/,$/,'')
|
|
const cancelEditing=Function(`return ({${method}}).cancelEditing`)()
|
|
function context({existing=false,confirm=true,saving=false}={}) {
|
|
const calls=[]
|
|
return {calls,saving,dirty:true,sheet:{batch:{id:existing?12:null},version:existing?'v1':null,unbatched:false},baseline:JSON.stringify({batch:{id:12},version:'v1',rows:[{materialName:'原始物品'}]}),
|
|
validationEnabled:true,onlyInvalid:true,editing:true,rowFilter:'filter',history:[1],selected:[1],commonProject:1,commonCategory:1,_activeCell:{},
|
|
$confirm:async(...args)=>{calls.push(['confirm',...args]);if(!confirm)throw 'cancel'},
|
|
draftId:()=>existing?'12':'new',clearDraft:id=>calls.push(['clear',id]),
|
|
loadBatches:async()=>calls.push(['load']),layout:()=>calls.push(['layout']),
|
|
back:()=>{throw Error('Cancel must not preserve and return through back()')}
|
|
}
|
|
}
|
|
test('cancelling a new purchase explicitly discards only its draft and returns without saving',async()=>{
|
|
const state=context();await cancelEditing.call(state)
|
|
assert.equal(state.sheet,null);assert.equal(state.editing,false);assert.deepEqual(state.selected,[])
|
|
assert.deepEqual(state.calls.filter(c=>c[0]==='clear'),[['clear','new']])
|
|
assert.equal(state.calls.filter(c=>c[0]==='load').length,1)
|
|
})
|
|
test('declining discard preserves the new purchase and never clears its draft',async()=>{
|
|
const state=context({confirm:false}),original=state.sheet;await cancelEditing.call(state)
|
|
assert.equal(state.sheet,original);assert.equal(state.editing,true)
|
|
assert.equal(state.calls.some(c=>c[0]==='clear'||c[0]==='load'),false)
|
|
})
|
|
test('existing purchase cancellation restores baseline; saving and absent sheets are no-ops',async()=>{
|
|
const state=context({existing:true});await cancelEditing.call(state)
|
|
assert.deepEqual(state.sheet,JSON.parse(state.baseline));assert.equal(state.editing,false)
|
|
assert.equal(state.calls.some(c=>c[0]==='load'),false)
|
|
const busy=context({saving:true});await cancelEditing.call(busy);assert.equal(busy.calls.length,0)
|
|
const empty=context();empty.sheet=null;await cancelEditing.call(empty);assert.equal(empty.calls.length,0)
|
|
})
|