优化
This commit is contained in:
@@ -29,8 +29,8 @@ function render(detail = fixture(), permissions = ['review', 'buy', 'cancel', 'r
|
||||
return mount(ProcurementNodeActions, { attachTo: document.body, props: { detail, customerId: '10001' }, global: { plugins: [pinia, ElementPlus] } })
|
||||
}
|
||||
async function open(wrapper: ReturnType<typeof render>) { await wrapper.find('.purchase-actions button').trigger('click'); await flushPromises(); return wrapper.findComponent(AppDialog) }
|
||||
async function explain(wrapper: ReturnType<typeof render>, value = '已核对客户资料') { await wrapper.findComponent(AppDialog).findAllComponents({ name: 'ElFormItem' }).find(row => row.props('label') === '操作说明')!.find('textarea').setValue(value) }
|
||||
async function confirm(wrapper: ReturnType<typeof render>) { wrapper.findComponent(AppDialog).vm.$emit('confirm'); await flushPromises() }
|
||||
async function explain(wrapper: ReturnType<typeof render>, value = '已核对客户资料') { await wrapper.findComponent(AppDialog).findAllComponents({ name: 'ElFormItem' }).find(row => ['操作说明', '审核说明', '拒绝原因'].includes(row.props('label')))!.find('textarea').setValue(value) }
|
||||
async function confirm(wrapper: ReturnType<typeof render>) { const dialog = wrapper.findComponent(AppDialog); const approve = dialog.findAll('button').find(button => button.text() === '通过'); if (approve) await approve.trigger('click'); else dialog.vm.$emit('confirm'); await flushPromises() }
|
||||
enableAutoUnmount(afterEach)
|
||||
afterEach(() => vi.unstubAllGlobals())
|
||||
beforeEach(() => {
|
||||
@@ -40,40 +40,43 @@ beforeEach(() => {
|
||||
vi.mocked(uploadProcurementFile).mockReset().mockResolvedValue({ id: '11', fileId: '101', category: 'PURCHASE', fileName: 'purchase.pdf', contentType: 'application/pdf', sizeBytes: 3, createdAt: '' })
|
||||
})
|
||||
describe('procurement purchase node operations', () => {
|
||||
it('switches to domestic warehouses, clears old selection and preserves editable direction after failure', async () => {
|
||||
vi.mocked(listOverseasPurchaseWarehouseOptions).mockImplementation(async direction => direction === 'DOMESTIC_TO_OVERSEAS'
|
||||
? [{ warehouseId: '30001', warehouseCode: 'SZX', warehouseName: '国内采购仓', countryCode: 'CN' }]
|
||||
: [{ warehouseId: '20001', warehouseCode: 'LAX', warehouseName: '海外采购仓', countryCode: 'US' }])
|
||||
const wrapper = render(); const dialog = await open(wrapper); await explain(wrapper)
|
||||
const field = (label: string) => dialog.findAllComponents({ name: 'ElFormItem' }).find(item => item.props('label') === label)!
|
||||
field('采购仓').findComponent({ name: 'ElSelect' }).vm.$emit('update:modelValue', '20001')
|
||||
field('采购方向').findComponent({ name: 'ElSelect' }).vm.$emit('update:modelValue', 'DOMESTIC_TO_OVERSEAS'); await flushPromises()
|
||||
expect(listOverseasPurchaseWarehouseOptions).toHaveBeenLastCalledWith('DOMESTIC_TO_OVERSEAS')
|
||||
expect(field('采购仓').findComponent({ name: 'ElSelect' }).props('modelValue')).toBe('')
|
||||
await confirm(wrapper); expect(submitProcurementCommand).not.toHaveBeenCalled()
|
||||
field('采购仓').findComponent({ name: 'ElSelect' }).vm.$emit('update:modelValue', '30001')
|
||||
vi.mocked(submitProcurementCommand).mockRejectedValueOnce(new Error('connection lost'))
|
||||
await confirm(wrapper)
|
||||
expect(submitProcurementCommand).toHaveBeenCalledWith('OP-100', '10001', 'review', expect.objectContaining({ procurementDirection: 'DOMESTIC_TO_OVERSEAS', purchaseWarehouseId: '30001' }))
|
||||
const original = vi.mocked(submitProcurementCommand).mock.calls[0]![3]
|
||||
expect(sessionStorage.getItem(storageKey)).toBeNull()
|
||||
expect(field('采购方向').findComponent({ name: 'ElSelect' }).props('modelValue')).toBe('DOMESTIC_TO_OVERSEAS')
|
||||
await confirm(wrapper)
|
||||
const next = vi.mocked(submitProcurementCommand).mock.calls[1]![3]
|
||||
expect(next.procurementDirection).toBe('DOMESTIC_TO_OVERSEAS')
|
||||
expect(next.purchaseWarehouseId).toBe('30001')
|
||||
expect(next.idempotencyKey).not.toBe(original.idempotencyKey)
|
||||
it.each(['OVERSEAS_TO_DOMESTIC', 'DOMESTIC_TO_OVERSEAS'] as const)('locks review direction and requests the matching warehouse catalog: %s', async direction => {
|
||||
const value = fixture(); value.customerView.order.procurementDirection = direction
|
||||
const wrapper = render(value); const dialog = await open(wrapper)
|
||||
const fields = dialog.findAllComponents({ name: 'ElFormItem' })
|
||||
const directionField = fields.find(item => item.props('label') === '采购方向')!
|
||||
expect(directionField.findComponent({ name: 'ElSelect' }).exists()).toBe(false)
|
||||
expect(directionField.text()).toContain(direction === 'DOMESTIC_TO_OVERSEAS' ? '国内采购,发往海外' : '海外采购,发往国内')
|
||||
expect(listOverseasPurchaseWarehouseOptions).toHaveBeenLastCalledWith(direction)
|
||||
expect(fields.some(item => item.props('label') === (direction === 'DOMESTIC_TO_OVERSEAS' ? '国内采购仓' : '海外采购仓'))).toBe(true)
|
||||
expect(fields.some(item => item.props('label') === '审核决定')).toBe(false)
|
||||
expect(dialog.findAll('button').map(button => button.text())).toEqual(expect.arrayContaining(['取消', '拒绝', '通过']))
|
||||
expect(dialog.text()).not.toContain('确认提交')
|
||||
})
|
||||
it('ignores late warehouse responses from a previous direction', async () => {
|
||||
let finishImport!: (rows: Awaited<ReturnType<typeof listOverseasPurchaseWarehouseOptions>>) => void
|
||||
vi.mocked(listOverseasPurchaseWarehouseOptions).mockImplementation(direction => direction === 'DOMESTIC_TO_OVERSEAS'
|
||||
? Promise.resolve([{ warehouseId: '30001', warehouseCode: 'SZX', warehouseName: '国内采购仓', countryCode: 'CN' }])
|
||||
: new Promise(resolve => { finishImport = resolve }))
|
||||
it('allows approval without a remark after a blank rejection attempt once a warehouse is selected', async () => {
|
||||
const wrapper = render(); const dialog = await open(wrapper)
|
||||
dialog.findAllComponents({ name: 'ElFormItem' }).find(item => item.props('label') === '采购方向')!.findComponent({ name: 'ElSelect' }).vm.$emit('update:modelValue', 'DOMESTIC_TO_OVERSEAS'); await flushPromises()
|
||||
finishImport([{ warehouseId: '20001', warehouseCode: 'LAX', warehouseName: '过期海外候选', countryCode: 'US' }]); await flushPromises()
|
||||
const warehouse = dialog.findAllComponents({ name: 'ElFormItem' }).find(item => item.props('label') === '采购仓')!.findComponent({ name: 'ElSelect' })
|
||||
expect(warehouse.findAllComponents({ name: 'ElOption' }).map(item => item.props('value'))).toEqual(['30001'])
|
||||
await dialog.findAll('button').find(button => button.text() === '拒绝')!.trigger('click'); await flushPromises()
|
||||
expect(submitProcurementCommand).not.toHaveBeenCalled()
|
||||
dialog.findAllComponents({ name: 'ElFormItem' }).find(item => item.props('label') === '海外采购仓')!.findComponent({ name: 'ElSelect' }).vm.$emit('update:modelValue', '20001')
|
||||
await confirm(wrapper)
|
||||
expect(submitProcurementCommand).toHaveBeenCalledWith('OP-100', '10001', 'review', expect.objectContaining({ decision: 'APPROVE', remark: '', purchaseWarehouseId: '20001' }))
|
||||
})
|
||||
it('requires a nonblank rejection reason and lets cancel close without changing the order', async () => {
|
||||
const wrapper = render(); const dialog = await open(wrapper)
|
||||
const reject = () => dialog.findAll('button').find(button => button.text() === '拒绝')!
|
||||
await reject().trigger('click'); await flushPromises()
|
||||
expect(submitProcurementCommand).not.toHaveBeenCalled()
|
||||
expect(dialog.text()).toContain('请填写拒绝原因')
|
||||
await explain(wrapper, ' '); await reject().trigger('click'); await flushPromises()
|
||||
expect(submitProcurementCommand).not.toHaveBeenCalled()
|
||||
await explain(wrapper, '供应商无法提供该商品'); await reject().trigger('click'); await flushPromises()
|
||||
expect(submitProcurementCommand).toHaveBeenCalledWith('OP-100', '10001', 'review', expect.objectContaining({ decision: 'REJECT', remark: '供应商无法提供该商品' }))
|
||||
expect(vi.mocked(submitProcurementCommand).mock.calls[0]![3]).not.toHaveProperty('purchaseWarehouseId')
|
||||
wrapper.unmount()
|
||||
const next = render(); const nextDialog = await open(next)
|
||||
await nextDialog.findAll('button').find(button => button.text() === '取消')!.trigger('click'); await flushPromises()
|
||||
expect(submitProcurementCommand).toHaveBeenCalledTimes(1)
|
||||
expect(nextDialog.props('modelValue')).toBe(false)
|
||||
})
|
||||
|
||||
it('disables terminal physical changes and keeps the management evidence form open', async () => {
|
||||
@@ -264,14 +267,14 @@ describe('procurement purchase node operations', () => {
|
||||
it('requires an authoritative warehouse on approval and sends the current order version', async () => {
|
||||
const wrapper = render(); const dialog = await open(wrapper); await explain(wrapper)
|
||||
await confirm(wrapper); expect(submitProcurementCommand).not.toHaveBeenCalled(); expect(document.body.textContent).toContain('请选择有效采购仓')
|
||||
dialog.findAllComponents({ name: 'ElFormItem' }).find(item => item.props('label') === '采购仓')!.findComponent({ name: 'ElSelect' }).vm.$emit('update:modelValue', '20001'); await confirm(wrapper)
|
||||
dialog.findAllComponents({ name: 'ElFormItem' }).find(item => item.props('label') === '海外采购仓')!.findComponent({ name: 'ElSelect' }).vm.$emit('update:modelValue', '20001'); await confirm(wrapper)
|
||||
expect(submitProcurementCommand).toHaveBeenCalledWith('OP-100', '10001', 'review', { version: 3, idempotencyKey: expect.any(String), decision: 'APPROVE', procurementDirection: 'OVERSEAS_TO_DOMESTIC', remark: '已核对客户资料', purchaseWarehouseId: '20001' })
|
||||
expect(wrapper.emitted('changed')).toHaveLength(1); expect(sessionStorage.getItem(storageKey)).toBeNull()
|
||||
})
|
||||
it('rejects without a warehouse and never substitutes an invented candidate', async () => {
|
||||
vi.mocked(listOverseasPurchaseWarehouseOptions).mockRejectedValue(new Error('unavailable'))
|
||||
const wrapper = render(); const dialog = await open(wrapper); await explain(wrapper, '购买对象不符合要求')
|
||||
dialog.findComponent({ name: 'ElRadioGroup' }).vm.$emit('update:modelValue', 'REJECT'); await confirm(wrapper)
|
||||
await dialog.findAll('button').find(button => button.text() === '拒绝')!.trigger('click'); await flushPromises()
|
||||
expect(submitProcurementCommand).toHaveBeenCalledWith('OP-100', '10001', 'review', expect.objectContaining({ decision: 'REJECT' }))
|
||||
expect(vi.mocked(submitProcurementCommand).mock.calls[0][3]).not.toHaveProperty('purchaseWarehouseId')
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user