优化
This commit is contained in:
@@ -2,13 +2,39 @@ import ElementPlus from 'element-plus'
|
||||
import { flushPromises, mount } from '@vue/test-utils'
|
||||
import { beforeEach, expect, it, vi } from 'vitest'
|
||||
import DispatchLooseboardExecution from './DispatchLooseboardExecution.vue'
|
||||
import { getLooseboardExecution, uploadLooseboardPhoto, saveLooseboardPhotos } from '../api/dispatchLooseboardExecution'
|
||||
import { getLooseboardExecution, completeLooseboardPickup, uploadLooseboardPhoto, saveLooseboardPhotos } from '../api/dispatchLooseboardExecution'
|
||||
import type { LooseboardExecution } from '../api/dispatchLooseboardExecution'
|
||||
|
||||
vi.mock('@/core/access/accessPreview', () => ({ useAccessPreviewStore: () => ({ can: () => true }) }))
|
||||
vi.mock('../api/dispatchLooseboardExecution', () => ({ getLooseboardExecution: vi.fn(), uploadLooseboardPhoto: vi.fn(), saveLooseboardPhotos: vi.fn(), readLooseboardPhoto: vi.fn() }))
|
||||
const value = (direct = true): LooseboardExecution => ({ dispatchNo: 'PC1', recordVersion: '3', stage: direct ? 'LOADING' : 'DELIVERING', direct, items: [{ itemId: '101', customerId: '1', orderNo: 'LB1', destination: 'TEST', packages: 2, pickupPhotos: [], arrivalPhotos: [], canPickup: true, canArrive: false }] })
|
||||
vi.mock('../api/dispatchLooseboardExecution', () => ({ getLooseboardExecution: vi.fn(), completeLooseboardPickup: vi.fn(), uploadLooseboardPhoto: vi.fn(), saveLooseboardPhotos: vi.fn(), readLooseboardPhoto: vi.fn() }))
|
||||
const value = (direct = true): LooseboardExecution => ({ dispatchNo: 'PC1', recordVersion: '3', stage: direct ? 'LOADING' : 'DELIVERING', direct, items: [{ itemId: '101', customerId: '1', orderNo: 'LB1', destination: 'TEST', packages: 2, pickupPhotos: [], arrivalPhotos: [], canPickup: true, canArrive: false, pickupRequired: true }] })
|
||||
beforeEach(() => { vi.clearAllMocks(); vi.mocked(getLooseboardExecution).mockResolvedValue(value()) })
|
||||
it('requires the explicit pickup completion command after photos are ready', async () => {
|
||||
const snapshot = { ...value(false), canCompletePickup: true }
|
||||
vi.mocked(getLooseboardExecution).mockResolvedValue(snapshot)
|
||||
vi.mocked(completeLooseboardPickup).mockResolvedValue({ ...snapshot, canCompletePickup: false, pickupCompleted: true })
|
||||
const wrapper = mount(DispatchLooseboardExecution, { props: { dispatchNo: 'PC1' }, global: { plugins: [ElementPlus] } }); await flushPromises()
|
||||
expect(completeLooseboardPickup).not.toHaveBeenCalled()
|
||||
const editor = wrapper.vm as unknown as { canCompletePickup: boolean; confirmPickup: () => Promise<void> }
|
||||
expect(editor.canCompletePickup).toBe(true)
|
||||
await editor.confirmPickup(); await flushPromises()
|
||||
expect(completeLooseboardPickup).toHaveBeenCalledWith('PC1', { recordVersion: '3', idempotencyKey: expect.any(String) })
|
||||
expect(editor.canCompletePickup).toBe(false)
|
||||
expect(wrapper.emitted('pickupCompleted')).toHaveLength(1)
|
||||
expect(wrapper.emitted('saved')).toBeUndefined()
|
||||
wrapper.unmount()
|
||||
})
|
||||
it('hides loaded warehouse cargo and keeps remote pickup and pending inbound notice', async () => {
|
||||
const snapshot = value(false)
|
||||
snapshot.items.push({ ...snapshot.items[0]!, itemId: '102', orderNo: 'WAREHOUSE-LOADED', pickupRequired: false })
|
||||
snapshot.items.push({ ...snapshot.items[0]!, itemId: '103', orderNo: 'WAIT-INBOUND', pickupRequired: false, warehouseNotice: 'WAIT-INBOUND:还没拣货入库' })
|
||||
vi.mocked(getLooseboardExecution).mockResolvedValue(snapshot)
|
||||
const wrapper = mount(DispatchLooseboardExecution, { props: { dispatchNo: 'PC1' }, global: { plugins: [ElementPlus] } }); await flushPromises()
|
||||
expect(wrapper.text()).toContain('LB1')
|
||||
expect(wrapper.text()).not.toContain('WAREHOUSE-LOADED')
|
||||
expect(wrapper.text()).toContain('WAIT-INBOUND:还没拣货入库')
|
||||
wrapper.unmount()
|
||||
})
|
||||
it('shows pure looseboard photo flow and uploads to its authoritative item and node', async () => {
|
||||
vi.mocked(uploadLooseboardPhoto).mockResolvedValue({ fileId: '77', fileName: 'pickup.png', contentType: 'image/png', sizeBytes: 10 })
|
||||
vi.mocked(saveLooseboardPhotos).mockResolvedValue({ ...value(), stage: 'DELIVERING' })
|
||||
@@ -31,7 +57,8 @@ it('keeps pickup upload visible but disabled until mixed warehouse cargo departs
|
||||
const wrapper = mount(DispatchLooseboardExecution, { props: { dispatchNo: 'PC1' }, global: { plugins: [ElementPlus] } }); await flushPromises()
|
||||
expect(wrapper.text()).not.toContain('混排货物按原流程')
|
||||
expect(wrapper.text()).toContain('上传取货照片')
|
||||
expect(wrapper.text()).toContain('完成仓内拣货并确认装车后可上传')
|
||||
expect(wrapper.text()).not.toContain('完成仓内拣货并确认装车后可上传')
|
||||
expect(wrapper.text()).not.toContain('尚未上传')
|
||||
const input = wrapper.get('input[aria-label="LB1上传取货照片"]')
|
||||
expect(input.attributes('disabled')).toBeDefined()
|
||||
Object.defineProperty(input.element, 'files', { value: [new File(['test'], 'pickup.png', { type: 'image/png' })], configurable: true })
|
||||
|
||||
Reference in New Issue
Block a user