This commit is contained in:
2026-09-15 18:17:17 +08:00
parent 55576a7c84
commit a7db793c95
12 changed files with 184 additions and 42 deletions
@@ -5,6 +5,7 @@ import { flushPromises, mount } from '@vue/test-utils'
import { beforeEach, describe, expect, it, vi } from 'vitest'
import { listOutbounds } from '../api/outbounds'
import OutboundsView from './OutboundsView.vue'
import StatusBadge from '@/shared/components/StatusBadge.vue'
const canPermission = vi.hoisted(() => vi.fn((_code: string) => true))
const routerPush = vi.hoisted(() => vi.fn())
@@ -16,6 +17,24 @@ vi.mock('../api/inventory', () => ({ listInventoryBalances: vi.fn(), listInvento
class ResizeObserverStub { observe() {} unobserve() {} disconnect() {} }
describe('OutboundsView permissions and navigation', () => {
it('distinguishes outbound stages and does not present unknown states as picking', async () => {
const statuses = [
['WAIT_OUTBOUND', '待出库', 'warning'], ['PICKING', '拣货中', 'info'],
['PICKED', '已拣货', 'warning'], ['OUTBOUNDED', '已出库', 'success'],
['CANCELLED', '已取消', 'danger'], ['FUTURE_STATE', '未知状态', 'neutral'],
]
vi.mocked(listOutbounds).mockResolvedValueOnce({ records: statuses.map(([status], index) => ({ id: String(index), outboundNo: `OUT-${index}`, status })), page: 1, size: 20, total: statuses.length, pages: 1 })
const wrapper = mount(OutboundsView, { global: { plugins: [ElementPlus] } })
await flushPromises()
const badges = wrapper.findAllComponents(StatusBadge).filter(badge => badge.element.closest('tbody'))
expect(badges).toHaveLength(statuses.length)
statuses.forEach(([, label, tone], index) => {
expect(badges[index].text()).toBe(label)
expect(badges[index].classes()).toContain(`is-${tone}`)
})
wrapper.unmount()
})
beforeEach(() => {
vi.stubGlobal('ResizeObserver', ResizeObserverStub)
vi.stubGlobal('localStorage', { getItem: () => null, setItem: () => undefined, removeItem: () => undefined })