feat(admin): edit domestic order declarations
This commit is contained in:
@@ -0,0 +1,75 @@
|
||||
import ElementPlus, { ElMessageBox } from 'element-plus'
|
||||
import { flushPromises, mount } from '@vue/test-utils'
|
||||
import { beforeEach, describe, expect, it, vi } from 'vitest'
|
||||
import { updatePlatformUnifiedOrderDeclaration } from '@/modules/unified-orders/api/unifiedOrders'
|
||||
import OrderDeclarationEditorDialog from './OrderDeclarationEditorDialog.vue'
|
||||
|
||||
vi.mock('@/modules/unified-orders/api/unifiedOrders', () => ({ updatePlatformUnifiedOrderDeclaration: vi.fn() }))
|
||||
|
||||
const detail = {
|
||||
summary: {
|
||||
orderId: '90001', tenantId: '208', inboundCode: 'RK-001', mainStatus: 'WAIT_MEASURE',
|
||||
receivingWarehouseName: '深圳仓', destinationWarehouseName: '洛杉矶中转仓',
|
||||
channelCode: 'OLD', channelName: '原渠道', channelChanged: false,
|
||||
expectedArrivalAt: '2026-09-06T10:00:00', customerRemark: '原备注',
|
||||
},
|
||||
order: {
|
||||
order: { version: 7, channelCode: 'OLD', channelName: '原渠道', customerRemark: '原备注' },
|
||||
cargoes: [{ itemNo: 1, cargoName: '台灯', packageCount: 2, totalQuantity: 20, lengthCm: 40, widthCm: 30, heightCm: 20, grossWeightKg: 18, volumeCbm: 0.048 }],
|
||||
parties: [], internalNotes: [], statusHistory: [],
|
||||
},
|
||||
timeline: [],
|
||||
} as never
|
||||
|
||||
function createWrapper() {
|
||||
return mount(OrderDeclarationEditorDialog, {
|
||||
props: { modelValue: true, detail },
|
||||
global: {
|
||||
plugins: [ElementPlus],
|
||||
stubs: {
|
||||
AppDialog: {
|
||||
props: ['modelValue', 'confirmLoading'], emits: ['confirm', 'update:modelValue'],
|
||||
template: '<section v-if="modelValue"><slot /><button data-testid="save" @click="$emit(\'confirm\')">保存</button></section>',
|
||||
},
|
||||
LoadErrorState: { props: ['title', 'message'], template: '<div class="load-error">{{ title }} {{ message }}<slot name="details" /></div>' },
|
||||
ApiErrorMeta: true,
|
||||
},
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
describe('OrderDeclarationEditorDialog', () => {
|
||||
beforeEach(() => {
|
||||
vi.mocked(updatePlatformUnifiedOrderDeclaration).mockReset()
|
||||
vi.spyOn(ElMessageBox, 'confirm').mockResolvedValue('confirm' as never)
|
||||
})
|
||||
|
||||
it('requires a second confirmation when the channel changes and keeps inbound/warehouse facts read-only', async () => {
|
||||
vi.mocked(updatePlatformUnifiedOrderDeclaration).mockResolvedValue({ version: 8 } as never)
|
||||
const wrapper = createWrapper()
|
||||
expect(wrapper.text()).toContain('国内收货仓和中转仓不可修改,如需变更请重新下单')
|
||||
expect(wrapper.text()).toContain('RK-001')
|
||||
const inputs = wrapper.findAll('input')
|
||||
await inputs[0]!.setValue('NEW')
|
||||
await wrapper.get('[data-testid="save"]').trigger('click')
|
||||
await flushPromises()
|
||||
|
||||
expect(ElMessageBox.confirm).toHaveBeenCalledWith(expect.stringContaining('现有入仓码和箱唛不会改变'), '确认变更渠道', expect.any(Object))
|
||||
expect(updatePlatformUnifiedOrderDeclaration).toHaveBeenCalledWith('208', '90001', expect.objectContaining({ expectedVersion: 7, channelCode: 'NEW' }))
|
||||
expect(wrapper.emitted('updated')).toHaveLength(1)
|
||||
expect(wrapper.emitted('update:modelValue')).toContainEqual([false])
|
||||
})
|
||||
|
||||
it('preserves the editor and entered values when the versioned update fails', async () => {
|
||||
vi.mocked(updatePlatformUnifiedOrderDeclaration).mockRejectedValue(new Error('订单版本已变化,请刷新详情后重试'))
|
||||
const wrapper = createWrapper()
|
||||
const inputs = wrapper.findAll('input')
|
||||
await inputs[1]!.setValue('保留填写的渠道名')
|
||||
await wrapper.get('[data-testid="save"]').trigger('click')
|
||||
await flushPromises()
|
||||
|
||||
expect(wrapper.find('.load-error').exists()).toBe(true)
|
||||
expect((inputs[1]!.element as HTMLInputElement).value).toBe('保留填写的渠道名')
|
||||
expect(wrapper.emitted('update:modelValue')).toBeUndefined()
|
||||
})
|
||||
})
|
||||
Reference in New Issue
Block a user