优化
This commit is contained in:
@@ -4,13 +4,13 @@ import { afterAll, afterEach, beforeEach, describe, expect, it, vi } from 'vites
|
||||
import { listAllPlatformWarehouses } from '@/modules/warehouses'
|
||||
import AppDialog from '@/shared/components/AppDialog.vue'
|
||||
import QueryToolbar from '@/shared/components/QueryToolbar.vue'
|
||||
import { createPallet, getPallet, getPalletSummary, listPallets, listReceivingOverseasWarehouses, updatePallet } from '../api/pallets'
|
||||
import { createPallet, getPallet, getPalletLabelPdf, getPalletSummary, listPallets, listReceivingOverseasWarehouses, updatePallet } from '../api/pallets'
|
||||
import PalletsView from './PalletsView.vue'
|
||||
|
||||
vi.mock('vue-router', () => ({ useRouter: () => ({ push: vi.fn() }) }))
|
||||
vi.mock('@/core/access/accessPreview', () => ({ useAccessPreviewStore: () => ({ can: () => true }) }))
|
||||
vi.mock('@/modules/warehouses', () => ({ listAllPlatformWarehouses: vi.fn() }))
|
||||
vi.mock('../api/pallets', () => ({ createPallet: vi.fn(), getPallet: vi.fn(), getPalletSummary: vi.fn(), listPallets: vi.fn(), listReceivingOverseasWarehouses: vi.fn(), updatePallet: vi.fn() }))
|
||||
vi.mock('../api/pallets', () => ({ createPallet: vi.fn(), getPallet: vi.fn(), getPalletLabelPdf: vi.fn(), getPalletSummary: vi.fn(), listPallets: vi.fn(), listReceivingOverseasWarehouses: vi.fn(), updatePallet: 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) } }
|
||||
@@ -28,6 +28,7 @@ describe('PalletsView', () => {
|
||||
vi.mocked(getPalletSummary).mockReset().mockResolvedValue({ totalCount: 1, idleCount: 1, occupiedCount: 0, scrappedCount: 0 })
|
||||
vi.mocked(getPallet).mockReset().mockResolvedValue(pallet)
|
||||
vi.mocked(createPallet).mockReset()
|
||||
vi.mocked(getPalletLabelPdf).mockReset()
|
||||
vi.mocked(updatePallet).mockReset().mockResolvedValue(null)
|
||||
})
|
||||
|
||||
@@ -47,6 +48,31 @@ describe('PalletsView', () => {
|
||||
expect(wrapper.get('[aria-label="海外托盘数量概览"]').text()).toContain('已报废52')
|
||||
})
|
||||
|
||||
it('prints one pallet from the all-warehouse list and allows retry after failure', async () => {
|
||||
const pdf = new Blob(['%PDF-label'], { type: 'application/pdf' })
|
||||
vi.mocked(getPalletLabelPdf).mockRejectedValueOnce(new Error('打印服务暂不可用')).mockResolvedValueOnce(pdf)
|
||||
const createUrl = vi.fn(() => 'blob:pallet-label')
|
||||
vi.stubGlobal('URL', Object.assign(URL, { createObjectURL: createUrl, revokeObjectURL: vi.fn() }))
|
||||
const downloads: string[] = []
|
||||
const click = vi.spyOn(HTMLAnchorElement.prototype, 'click').mockImplementation(function (this: HTMLAnchorElement) { downloads.push(this.download) })
|
||||
try {
|
||||
const wrapper = mount(PalletsView, { attachTo: document.body, global: { plugins: [ElementPlus] } })
|
||||
await flushPromises()
|
||||
const button = wrapper.findAll('button').filter((item) => item.text() === '打印').at(-1)!
|
||||
await button.trigger('click')
|
||||
await flushPromises()
|
||||
expect(createUrl).not.toHaveBeenCalled()
|
||||
expect(button.attributes('disabled')).toBeUndefined()
|
||||
await button.trigger('click')
|
||||
await flushPromises()
|
||||
expect(getPalletLabelPdf).toHaveBeenNthCalledWith(2, '200', '9007199254740993')
|
||||
expect(createUrl).toHaveBeenCalledWith(pdf)
|
||||
expect(downloads).toEqual(['PLT-1-托盘码.pdf'])
|
||||
expect(createPallet).not.toHaveBeenCalled()
|
||||
expect(updatePallet).not.toHaveBeenCalled()
|
||||
} finally { click.mockRestore() }
|
||||
})
|
||||
|
||||
it('reloads all warehouses when the filters are reset', async () => {
|
||||
const wrapper = mount(PalletsView, { attachTo: document.body, global: { plugins: [ElementPlus] } })
|
||||
await flushPromises()
|
||||
|
||||
Reference in New Issue
Block a user