- 添加生产环境服务器地址配置支持内外网切换 - 实现采购列表只看我创建的功能开关 - 更新构建脚本中的默认生产环境API地址 - 优化采购单表格单元格编辑体验改用自动补全组件 - 调整应用更新检查逻辑增强生产环境兼容性 - 修复开发服务器切换时的一些验证问题 - 增强应用启动时的服务地址配置灵活性
77 lines
6.0 KiB
JavaScript
77 lines
6.0 KiB
JavaScript
import {expect,it,vi} from 'vitest'
|
|
import {readFileSync} from 'node:fs'
|
|
import {parse} from '@vue/compiler-sfc'
|
|
import {baseParse} from '@vue/compiler-dom'
|
|
import {defineComponent} from 'vue'
|
|
import {mount} from '@vue/test-utils'
|
|
import Sheet from '../../src/components/PurchaseSheet/index.vue'
|
|
|
|
vi.mock('@/utils/request',()=>({default:vi.fn()}))
|
|
vi.mock('@/store/modules/user',()=>({default:()=>({permissions:['*:*:*']})}))
|
|
vi.mock('@/store/modules/app',()=>({default:()=>({size:'default'})}))
|
|
|
|
it('purchase keeps template export on the main list only and removes quote-entry shortcuts',()=>{
|
|
const template=parse(readFileSync('src/components/PurchaseSheet/index.vue','utf8')).descriptor.template.content
|
|
const labels=[],exports=[]
|
|
function collect(node,ancestors=[]){if(node.tag==='el-button'){const label=(node.children||[]).filter(child=>child.type===2).map(child=>child.content.trim()).join('');labels.push(label);if(label==='导出模板')exports.push({node,ancestors})}for(const child of node.children||[])collect(child,[...ancestors,node])}
|
|
collect(baseParse(template))
|
|
expect(exports).toHaveLength(1);expect(exports[0].ancestors.some(node=>node.tag==='template'&&node.props.some(p=>p.name==='if'&&p.exp?.content==='!sheet'))).toBe(true)
|
|
expect(exports[0].node.props.some(p=>p.name==='on'&&p.arg?.content==='click'&&p.exp?.content==='exportTemplate')).toBe(true)
|
|
expect(labels).not.toContain('录入报价');expect(labels).toContain('导入采购')
|
|
expect(template).toContain('exportInquiry');expect(template).toContain('startEditing')
|
|
})
|
|
|
|
it.each([true,false])('main-list template export respects existing permissions (%s)',async allowed=>{
|
|
const template=parse(readFileSync('src/components/PurchaseSheet/index.vue','utf8')).descriptor.template.content
|
|
let toolbar;function find(node){if(node.tag==='div'&&node.props.some(p=>p.name==='class'&&p.value?.content==='sheet-list-tabs'))toolbar=node;for(const child of node.children||[])find(child)}find(baseParse(template))
|
|
const exportTemplate=vi.fn(),host=defineComponent({template:template.slice(toolbar.loc.start.offset,toolbar.loc.end.offset),data:()=>({viewMode:'batches',drafts:[]}),methods:{exportTemplate,changeView:vi.fn(),restoreDraft:vi.fn()}})
|
|
const wrapper=mount(host,{global:{mocks:{$can:()=>allowed},stubs:{ElRadioGroup:{template:'<div><slot/></div>'},ElRadioButton:true,ElDropdown:true,ElDropdownMenu:true,ElDropdownItem:true,BusinessIcon:true,ElButton:{emits:['click'],template:'<button @click="$emit(\'click\')"><slot/></button>'}}}})
|
|
const button=wrapper.findAll('button').find(b=>b.text()==='导出模板');expect(!!button).toBe(allowed)
|
|
if(button){await button.trigger('click');expect(exportTemplate).toHaveBeenCalledOnce()}else expect(exportTemplate).not.toHaveBeenCalled()
|
|
wrapper.unmount()
|
|
})
|
|
|
|
it('purchase editing removes the entire fixed operations column and restores it after editing',async()=>{
|
|
const source=readFileSync('src/components/PurchaseSheet/index.vue','utf8')
|
|
const template=parse(source).descriptor.template.content
|
|
let column
|
|
function find(node){
|
|
if(node.tag==='el-table-column'&&node.props.some(p=>p.name==='key'&&p.value?.content==='operations'))column=node
|
|
for(const child of node.children||[])find(child)
|
|
}
|
|
find(baseParse(template));expect(column).toBeTruthy()
|
|
const actual=template.slice(column.loc.start.offset,column.loc.end.offset)
|
|
const records=vi.fn()
|
|
const host=defineComponent({template:`<div>${actual}</div>`,data:()=>({isEditing:false,saving:false,canEdit:true}),methods:{canArrive:()=>false,records,rowActions:Sheet.methods.rowActions,runRowCommand:Sheet.methods.runRowCommand}})
|
|
const tableColumn=defineComponent({props:['label','width'],template:'<section class="operations"><strong>{{label}}</strong><slot :row="row"/></section>',data:()=>({row:{id:1,purchaseStatus:0,pendingArrivalQuantity:0,acceptedQuantity:0}})})
|
|
const button=defineComponent({emits:['click'],template:'<button @click="$emit(\'click\')"><slot/></button>'})
|
|
const wrapper=mount(host,{global:{stubs:{ElTableColumn:tableColumn,ElButton:button},mocks:{$can:()=>false}}})
|
|
expect(wrapper.get('.operations').text()).toContain('操作')
|
|
expect(wrapper.findAll('button').map(button=>button.text())).toEqual(['到货记录','附件'])
|
|
await wrapper.get('button').trigger('click');expect(records).toHaveBeenCalledOnce()
|
|
await wrapper.setData({isEditing:true})
|
|
expect(wrapper.find('.operations').exists()).toBe(false)
|
|
expect(wrapper.find('button').exists()).toBe(false)
|
|
await wrapper.setData({isEditing:false})
|
|
expect(wrapper.get('.operations').text()).toContain('到货记录')
|
|
expect(wrapper.findComponent(tableColumn).props('width')).toBe('180')
|
|
wrapper.unmount()
|
|
})
|
|
|
|
it('row actions keep concurrent arrival and receipt flows and guard attachment access',()=>{
|
|
const vm={saving:false,canEdit:true,canArrive:()=>true,$can:()=>true,sheet:{batch:{id:482}},$refs:{documents:{open:vi.fn()},cancelPurchase:{open:vi.fn()}},arrival:vi.fn(),$router:{push:vi.fn()}}
|
|
vm.rowActions=row=>Sheet.methods.rowActions.call(vm,row)
|
|
const row={id:12,projectId:4,materialName:'电机',materialParams:'A1',pendingArrivalQuantity:2,acceptedQuantity:3,receivedQuantity:1}
|
|
expect(vm.rowActions(row).map(action=>action.command)).toEqual(['arrival','receipt','attachments','cancel'])
|
|
const run=command=>Sheet.methods.runRowCommand.call(vm,command,row)
|
|
run('attachments');expect(vm.$refs.documents.open).toHaveBeenCalledWith('detail',12,'电机 / A1')
|
|
run('arrival');expect(vm.arrival).toHaveBeenCalledWith([row])
|
|
run('receipt');expect(vm.$router.push).toHaveBeenCalledWith({path:'/warehouse/pending',query:{sourceGroup:'B:482',projectId:4}})
|
|
run('cancel');expect(vm.$refs.cancelPurchase.open).toHaveBeenCalledWith(row)
|
|
vm.$can=()=>false;vm.canEdit=false
|
|
expect(vm.rowActions(row).map(action=>action.command)).toEqual(['attachments'])
|
|
vm.arrival.mockClear();run('arrival');expect(vm.arrival).not.toHaveBeenCalled()
|
|
vm.$refs.documents.open.mockClear();vm.saving=true;run('attachments');expect(vm.$refs.documents.open).not.toHaveBeenCalled()
|
|
vm.saving=false;row.id=null;run('attachments');expect(vm.$refs.documents.open).not.toHaveBeenCalled()
|
|
})
|