test: cover phase 5 overseas admin flows

This commit is contained in:
2026-09-01 19:57:36 +08:00
parent 440cae9c6d
commit a5d4b7d54a
8 changed files with 392 additions and 3 deletions
@@ -0,0 +1,59 @@
import ElementPlus from 'element-plus'
import { flushPromises, mount } from '@vue/test-utils'
import { beforeEach, describe, expect, it, vi } from 'vitest'
import { createExceptionOrder, listExceptionOrders, resolveExceptionRelation } from '../api/exceptionOrders'
import ExceptionOrdersView from './ExceptionOrdersView.vue'
import { commonPhase5Stubs } from './phase5TestStubs'
const canPermission = vi.hoisted(() => vi.fn((_code: string) => false))
vi.mock('@/core/access/accessPreview', () => ({ useAccessPreviewStore: () => ({ can: canPermission }) }))
vi.mock('../api/exceptionOrders', () => ({ listExceptionOrders: vi.fn(), resolveExceptionRelation: vi.fn(), createExceptionOrder: vi.fn() }))
function mountView() { return mount(ExceptionOrdersView, { global: { plugins: [ElementPlus], stubs: commonPhase5Stubs } }) }
describe('ExceptionOrdersView permissions and creation', () => {
beforeEach(() => {
canPermission.mockReset().mockReturnValue(false)
vi.mocked(listExceptionOrders).mockReset().mockResolvedValue({ records: [], page: 1, size: 10, total: 0, pages: 0 })
vi.mocked(resolveExceptionRelation).mockReset().mockResolvedValue({ inboundOrderId: '9', inboundCode: 'IN-1', lastMileOrderId: '8', lastMileOrderNo: 'LM-1', customerId: '100' })
vi.mocked(createExceptionOrder).mockReset().mockResolvedValue({ id: '19', exceptionNo: 'EXC-1', status: 'PENDING' })
})
it('hides creation without the independent permission', async () => {
const wrapper = mountView()
await flushPromises()
expect(wrapper.find('[data-testid="data-table"]').text()).not.toContain('新增异常订单')
wrapper.unmount()
})
it('validates the required relation before submitting', async () => {
canPermission.mockImplementation(code => code.endsWith(':create'))
const wrapper = mountView()
await flushPromises()
await wrapper.findAll('button').find(button => button.text().includes('新增异常订单'))!.trigger('click')
await wrapper.find('[data-dialog="新增异常订单"] .dialog-confirm').trigger('click')
await flushPromises()
expect(resolveExceptionRelation).not.toHaveBeenCalled()
expect(createExceptionOrder).not.toHaveBeenCalled()
wrapper.unmount()
})
it('resolves and submits trimmed business fields', async () => {
canPermission.mockImplementation(code => code.endsWith(':create'))
const wrapper = mountView()
await flushPromises()
await wrapper.findAll('button').find(button => button.text().includes('新增异常订单'))!.trigger('click')
const dialog = wrapper.find('[data-dialog="新增异常订单"]')
await dialog.find('input[placeholder="请输入入仓码"]').setValue(' IN-1 ')
await dialog.find('select').setValue('RETURN')
await dialog.find('textarea').setValue(' 包裹破损 ')
await dialog.find('.dialog-confirm').trigger('click')
await flushPromises()
expect(resolveExceptionRelation).toHaveBeenCalledWith({ customerId: undefined, inboundCode: 'IN-1', lastMileOrderNo: undefined })
expect(createExceptionOrder).toHaveBeenCalledWith({
customerId: undefined, inboundCode: 'IN-1', lastMileOrderNo: 'LM-1',
exceptionType: 'RETURN', reason: '包裹破损', packageCount: undefined, skuCode: undefined,
})
wrapper.unmount()
})
})