Files
admin-web/src/modules/overseas-warehouse/pages/InboundOrdersView.dispatch.test.ts
T
2026-10-19 17:56:31 +08:00

54 lines
3.0 KiB
TypeScript

import { flushPromises, mount } from '@vue/test-utils'
import { beforeEach, expect, it, vi } from 'vitest'
import InboundOrdersView from './InboundOrdersView.vue'
import { overseasWarehousePermissions as permission } from '../permissions'
const access = vi.hoisted(() => ({ codes: [] as string[] }))
vi.mock('@/core/access/accessPreview', () => ({ useAccessPreviewStore: () => ({ can: (code: string) => access.codes.includes(code) }) }))
vi.mock('vue-router', () => ({ useRouter: () => ({ push: vi.fn() }), onBeforeRouteLeave: vi.fn(), onBeforeRouteUpdate: vi.fn() }))
vi.mock('../api/inboundOrders', () => ({ listInboundOrders: vi.fn().mockResolvedValue({ records: [], total: 0 }), createFbaAppointment: vi.fn(), getFbaAppointment: vi.fn(), updateFbaAppointment: vi.fn(), updateInboundPlan: vi.fn() }))
vi.mock('../components/SmartDispatchDialog.vue', () => ({ default: { name: 'SmartDispatchDialog', props: ['modelValue', 'orders'], template: '<section v-if="modelValue" data-dispatch-dialog />' } }))
vi.mock('element-plus', () => ({ ElMessage: { warning: vi.fn(), success: vi.fn() } }))
function render() {
return mount(InboundOrdersView, { global: { directives: { loading: {} }, stubs: {
AdminPage: { template: '<main><slot /></main>' }, ListPageLayout: { template: '<div><slot /></div>' },
DataTable: { template: '<div><slot name="toolbar-actions" /></div>' },
ElButton: { template: '<button><slot /></button>' },
AppDialog: true, FbaAppointmentFields: true, QueryToolbar: true, OperationErrorToast: true,
} } })
}
beforeEach(() => { vi.clearAllMocks(); access.codes = [permission.inboundOrderList] })
it('opens the existing smart-dispatch flow with dispatch list/create and no legacy smart permission or selected rows', async () => {
access.codes.push(permission.dispatchList, permission.dispatchCreate)
const wrapper = render()
try {
await flushPromises()
const button = wrapper.findAll('button').find(button => button.text() === '智能排车')!
expect(button.exists()).toBe(true)
await button.trigger('click')
expect(wrapper.find('[data-dispatch-dialog]').exists()).toBe(true)
expect(wrapper.getComponent({ name: 'SmartDispatchDialog' }).props('orders')).toEqual([])
} finally { wrapper.unmount() }
})
it.each([
['list only', [permission.dispatchList]],
['create only', [permission.dispatchCreate]],
['legacy smart only', ['platform:overseas-warehouse:inbound-order:smart-dispatch']],
['list plus legacy smart', [permission.dispatchList, 'platform:overseas-warehouse:inbound-order:smart-dispatch']],
])('blocks the button and direct handler for %s', async (_, codes) => {
access.codes.push(...codes)
const wrapper = render()
try {
await flushPromises()
expect(wrapper.findAll('button').some(button => button.text() === '智能排车')).toBe(false)
const state = wrapper.vm as unknown as { openSmartDispatch(): void }
state.openSmartDispatch()
await flushPromises()
expect(wrapper.find('[data-dispatch-dialog]').exists()).toBe(false)
} finally { wrapper.unmount() }
})