优化
This commit is contained in:
@@ -1,8 +1,9 @@
|
||||
import { flushPromises, shallowMount } from '@vue/test-utils'
|
||||
import { beforeEach, describe, expect, it, vi } from 'vitest'
|
||||
import { listPlatformUnifiedOrders } from '@/modules/unified-orders/api/unifiedOrders'
|
||||
import { listPlatformUnifiedOrders, updatePlatformUnifiedOrderPlanning } from '@/modules/unified-orders/api/unifiedOrders'
|
||||
import { createPlatformExportTask } from '@/modules/downloads'
|
||||
import { showExportTaskCreatedDialog } from '@/shared/components/exportTaskCreatedDialog'
|
||||
import { ApiResponseError } from '@/shared/api/http'
|
||||
import UnifiedOrdersView from './UnifiedOrdersView.vue'
|
||||
|
||||
vi.mock('vue-router', () => ({
|
||||
@@ -27,6 +28,7 @@ vi.mock('@/modules/unified-orders/api/unifiedOrders', () => ({
|
||||
getPlatformUnifiedOrder: vi.fn(),
|
||||
listPlatformUnifiedOrderFeeDetails: vi.fn(),
|
||||
listPlatformUnifiedOrders: vi.fn(),
|
||||
updatePlatformUnifiedOrderPlanning: vi.fn(),
|
||||
unifiedOrderStatusOptions: [
|
||||
{ value: 'PENDING_REVIEW', label: '待审核' },
|
||||
{ value: 'WAIT_MEASURE', label: '待测量数据' },
|
||||
@@ -49,8 +51,11 @@ function mountView() {
|
||||
AdminPage: { template: '<main><slot /></main>' },
|
||||
ListPageLayout: { template: '<section><slot name="toolbar" /><slot name="state" /><slot /></section>' },
|
||||
QueryToolbar: { name: 'QueryToolbar', props: ['modelValue'], emits: ['update:modelValue', 'search', 'reset'], template: '<div data-testid="query-toolbar" />' },
|
||||
DataTable: { name: 'DataTable', props: ['page', 'pageSize'], emits: ['update:page', 'update:pageSize', 'selection-change'], template: '<div data-testid="data-table"><slot name="toolbar-actions" /></div>' },
|
||||
DataTable: { name: 'DataTable', props: ['page', 'pageSize', 'data'], emits: ['update:page', 'update:pageSize', 'selection-change'], template: '<div data-testid="data-table"><slot name="toolbar-actions" /><div v-for="row in data" :key="row.orderId" class="test-row"><slot name="estimatedVolume" :row="row" /><slot name="expectedArrival" :row="row" /></div></div>' },
|
||||
'el-button': { template: '<button><slot /></button>' },
|
||||
'el-input-number': { name: 'ElInputNumber', props: ['modelValue', 'disabled'], emits: ['update:modelValue', 'change'], template: '<input class="number-input" :value="modelValue" :disabled="disabled" @change="$emit(\'change\')" />' },
|
||||
'el-date-picker': { name: 'ElDatePicker', props: ['modelValue', 'disabled'], emits: ['update:modelValue', 'change'], template: '<input class="date-input" :value="modelValue" :disabled="disabled" @change="$emit(\'change\')" />' },
|
||||
ApiErrorMeta: { props: ['details'], template: '<code class="api-meta">{{ details.code }} {{ details.requestId }} {{ details.traceId }}</code>' },
|
||||
},
|
||||
},
|
||||
})
|
||||
@@ -59,6 +64,7 @@ function mountView() {
|
||||
describe('UnifiedOrdersView list request coordination', () => {
|
||||
beforeEach(() => {
|
||||
vi.mocked(listPlatformUnifiedOrders).mockReset().mockResolvedValue(emptyPage())
|
||||
vi.mocked(updatePlatformUnifiedOrderPlanning).mockReset()
|
||||
vi.mocked(createPlatformExportTask).mockReset().mockResolvedValue({ taskName: '国内仓订单', taskNo: 'EXP-1' } as never)
|
||||
vi.mocked(showExportTaskCreatedDialog).mockReset().mockResolvedValue(false)
|
||||
})
|
||||
@@ -185,4 +191,41 @@ describe('UnifiedOrdersView list request coordination', () => {
|
||||
parameters: expect.objectContaining({ page: expect.anything(), size: expect.anything() }),
|
||||
}))
|
||||
})
|
||||
|
||||
it('edits arrival and estimated volume with the row version and preserves evidence on failure', async () => {
|
||||
vi.mocked(listPlatformUnifiedOrders).mockResolvedValue({
|
||||
records: [{
|
||||
orderId: '2089223263733518337', orderVersion: 7, tenantId: '2089176869176389634',
|
||||
inboundCode: 'NYEXX2609030001', expectedArrivalAt: '2026-09-10T08:30:00', estimatedVolumeCbm: 0.25,
|
||||
}], page: 1, size: 20, total: 1, pages: 1,
|
||||
} as never)
|
||||
vi.mocked(updatePlatformUnifiedOrderPlanning)
|
||||
.mockResolvedValueOnce({ version: 8 } as never)
|
||||
.mockRejectedValueOnce(new ApiResponseError('订单版本已变化', 'A0409', 200, undefined, 'req-planning', 'trace-planning'))
|
||||
|
||||
const wrapper = mountView()
|
||||
await flushPromises()
|
||||
const volume = wrapper.getComponent({ name: 'ElInputNumber' })
|
||||
volume.vm.$emit('update:modelValue', 0.5)
|
||||
volume.vm.$emit('change', 0.5)
|
||||
await flushPromises()
|
||||
|
||||
expect(updatePlatformUnifiedOrderPlanning).toHaveBeenNthCalledWith(1,
|
||||
'2089176869176389634', '2089223263733518337', {
|
||||
expectedVersion: 7, expectedArrivalAt: '2026-09-10T08:30:00', estimatedVolumeCbm: 0.5,
|
||||
})
|
||||
|
||||
const arrival = wrapper.getComponent({ name: 'ElDatePicker' })
|
||||
arrival.vm.$emit('update:modelValue', '2026-09-12T16:00:00')
|
||||
arrival.vm.$emit('change', '2026-09-12T16:00:00')
|
||||
await flushPromises()
|
||||
|
||||
expect(updatePlatformUnifiedOrderPlanning).toHaveBeenNthCalledWith(2,
|
||||
'2089176869176389634', '2089223263733518337', {
|
||||
expectedVersion: 8, expectedArrivalAt: '2026-09-12T16:00:00', estimatedVolumeCbm: 0.5,
|
||||
})
|
||||
expect(wrapper.getComponent({ name: 'ElDatePicker' }).props('modelValue')).toBe('2026-09-12T16:00:00')
|
||||
expect(wrapper.text()).toContain('订单版本已变化')
|
||||
expect(wrapper.text()).toContain('A0409 req-planning trace-planning')
|
||||
})
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user