48 lines
2.4 KiB
TypeScript
48 lines
2.4 KiB
TypeScript
import ElementPlus from 'element-plus'
|
|
import { createPinia } from 'pinia'
|
|
import { enableAutoUnmount, flushPromises, mount } from '@vue/test-utils'
|
|
import { afterAll, afterEach, beforeEach, describe, expect, it, vi } from 'vitest'
|
|
import { convertLastMileContainerToInboundPlans, convertLastMileOrderToInboundPlan, listLastMileOrders } from '../api/lastMileOrders'
|
|
import LastMileOrdersView from './LastMileOrdersView.vue'
|
|
|
|
vi.mock('@/core/access/accessPreview', () => ({ useAccessPreviewStore: () => ({ can: () => true }) }))
|
|
vi.mock('vue-router', () => ({ useRouter: () => ({ push: vi.fn() }) }))
|
|
vi.mock('../api/lastMileOrders', () => ({
|
|
listLastMileOrders: vi.fn(), convertLastMileContainerToInboundPlans: vi.fn(),
|
|
convertLastMileOrderToInboundPlan: vi.fn(), transferLastMileOrders: vi.fn(),
|
|
}))
|
|
|
|
class ResizeObserverStub implements ResizeObserver { observe() {} unobserve() {} disconnect() {} }
|
|
function memoryStorage(): Storage {
|
|
const values = new Map<string, string>()
|
|
return {
|
|
get length() { return values.size }, clear: () => values.clear(), getItem: (key) => values.get(key) ?? null,
|
|
key: (index) => [...values.keys()][index] ?? null, removeItem: (key) => values.delete(key), setItem: (key, value) => values.set(key, value),
|
|
}
|
|
}
|
|
|
|
enableAutoUnmount(afterEach)
|
|
afterAll(() => vi.unstubAllGlobals())
|
|
|
|
describe('LastMileOrdersView container boundary', () => {
|
|
beforeEach(() => {
|
|
vi.stubGlobal('ResizeObserver', ResizeObserverStub)
|
|
vi.stubGlobal('localStorage', memoryStorage())
|
|
vi.mocked(listLastMileOrders).mockReset().mockResolvedValue({ records: [], page: 1, size: 10, total: 0, pages: 0 })
|
|
vi.mocked(convertLastMileContainerToInboundPlans).mockReset()
|
|
vi.mocked(convertLastMileOrderToInboundPlan).mockReset()
|
|
})
|
|
|
|
it('fails closed instead of grouping the current order page as a whole container', async () => {
|
|
const wrapper = mount(LastMileOrdersView, { attachTo: document.body, global: { plugins: [createPinia(), ElementPlus] } })
|
|
await flushPromises()
|
|
const pendingTab = wrapper.findAll('.el-radio-button').find((item) => item.text().includes('待分配'))
|
|
await pendingTab!.trigger('click')
|
|
await flushPromises()
|
|
expect(wrapper.text()).toContain('已停止从订单分页本地聚合整柜')
|
|
expect(listLastMileOrders).toHaveBeenCalledTimes(1)
|
|
expect(convertLastMileContainerToInboundPlans).not.toHaveBeenCalled()
|
|
expect(convertLastMileOrderToInboundPlan).not.toHaveBeenCalled()
|
|
})
|
|
})
|