优化
This commit is contained in:
@@ -6,10 +6,12 @@ import DispatchDocumentsDialog from './DispatchDocumentsDialog.vue'
|
||||
import DeliveryDocumentsDialog from './DeliveryDocumentsDialog.vue'
|
||||
import { destination, detail } from '../dispatchTestFixtures'
|
||||
import { getDispatch } from '../api/dispatches'
|
||||
import { getLooseboardExecution, completeLooseboardPickup } from '../api/dispatchLooseboardExecution'
|
||||
import { deliveryDocumentCategories, getDeliveryDocuments, saveDeliveryDocuments, type DeliveryDocuments } from '../api/deliveryDocuments'
|
||||
const can = vi.hoisted(() => vi.fn(() => true))
|
||||
vi.mock('@/core/access/accessPreview', () => ({ useAccessPreviewStore: () => ({ can }) }))
|
||||
vi.mock('../api/dispatches', () => ({ getDispatch: vi.fn() }))
|
||||
vi.mock('../api/dispatchLooseboardExecution', () => ({ getLooseboardExecution: vi.fn(), completeLooseboardPickup: vi.fn(), readLooseboardPhoto: vi.fn() }))
|
||||
vi.mock('../api/deliveryDocuments', async original => ({ ...await original<typeof import('../api/deliveryDocuments')>(), getDeliveryDocuments: vi.fn(), saveDeliveryDocuments: vi.fn() }))
|
||||
const dialogStub = defineComponent({ props: ['modelValue', 'showConfirm'], emits: ['confirm'], setup(props, { slots, emit }) { return () => props.modelValue ? h('section', [slots.default?.(), props.showConfirm ? h('button', { class: 'save', onClick: () => emit('confirm') }, '保存资料') : null]) : null } })
|
||||
function documents(no = 'DL-1', customerId = '101'): DeliveryDocuments {
|
||||
@@ -96,3 +98,24 @@ it('does not request delivery documents without delivery list permission', async
|
||||
expect(wrapper.text()).toContain('当前账号无派送资料查看权限')
|
||||
wrapper.unmount()
|
||||
})
|
||||
it.each([true, false])('closes pickup dialog only after successful confirmation (success=%s)', async success => {
|
||||
const value = detail({ stage: 'DELIVERING' })
|
||||
value.orderDetails[0]!.sourceBusinessType = 'LOCAL_LOOSEBOARD'
|
||||
vi.mocked(getDispatch).mockResolvedValue(value)
|
||||
const snapshot = { dispatchNo: 'PC/1', recordVersion: '3', stage: 'DELIVERING', direct: false, items: [], canCompletePickup: true, pickupCompleted: false }
|
||||
vi.mocked(getLooseboardExecution).mockResolvedValue(snapshot)
|
||||
if (success) vi.mocked(completeLooseboardPickup).mockResolvedValue({ ...snapshot, canCompletePickup: false, pickupCompleted: true })
|
||||
else vi.mocked(completeLooseboardPickup).mockRejectedValue(new Error('取货确认失败'))
|
||||
const wrapper = setup(); await flushPromises()
|
||||
await wrapper.get('.save').trigger('click'); await flushPromises()
|
||||
expect(completeLooseboardPickup).toHaveBeenCalledTimes(1)
|
||||
if (success) {
|
||||
expect(wrapper.emitted('update:modelValue')).toEqual([[false]])
|
||||
expect(wrapper.emitted('saved')).toHaveLength(1)
|
||||
} else {
|
||||
expect(wrapper.emitted('update:modelValue')).toBeUndefined()
|
||||
expect(wrapper.emitted('saved')).toBeUndefined()
|
||||
expect(wrapper.text()).toContain('取货确认失败')
|
||||
}
|
||||
wrapper.unmount()
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user