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: '
' } })) vi.mock('element-plus', () => ({ ElMessage: { warning: vi.fn(), success: vi.fn() } })) function render() { return mount(InboundOrdersView, { global: { directives: { loading: {} }, stubs: { AdminPage: { template: '
' }, ListPageLayout: { template: '
' }, DataTable: { template: '
' }, ElButton: { template: '' }, 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() } })