2026-08-04 21:01:39 +08:00
|
|
|
|
import ElementPlus, { ElMessageBox } from 'element-plus'
|
|
|
|
|
|
import { createPinia, setActivePinia } from 'pinia'
|
|
|
|
|
|
import { enableAutoUnmount, flushPromises, mount } from '@vue/test-utils'
|
|
|
|
|
|
import { afterAll, afterEach, beforeEach, describe, expect, it, vi } from 'vitest'
|
|
|
|
|
|
import { ApiResponseError } from '@/shared/api/http'
|
|
|
|
|
|
import { useAuthStore } from '@/core/auth/auth'
|
|
|
|
|
|
import { useAccessPreviewStore } from '@/core/access/accessPreview'
|
|
|
|
|
|
import {
|
2026-08-07 17:14:42 +08:00
|
|
|
|
downloadInboundMeasurementImage,
|
2026-08-04 21:01:39 +08:00
|
|
|
|
getInboundMeasurement,
|
|
|
|
|
|
submitInboundMeasurement,
|
2026-08-07 17:14:42 +08:00
|
|
|
|
updateConfirmedPackageCount,
|
2026-08-04 21:01:39 +08:00
|
|
|
|
} from './api'
|
|
|
|
|
|
import type { InboundMeasurementDetail } from './types'
|
|
|
|
|
|
import InboundMeasurementPanel from './InboundMeasurementPanel.vue'
|
|
|
|
|
|
|
|
|
|
|
|
vi.mock('./api', () => ({
|
2026-08-07 17:14:42 +08:00
|
|
|
|
downloadInboundMeasurementImage: vi.fn(),
|
2026-08-04 21:01:39 +08:00
|
|
|
|
getInboundMeasurement: vi.fn(),
|
|
|
|
|
|
saveInboundMeasurementDraft: vi.fn(),
|
|
|
|
|
|
submitInboundMeasurement: vi.fn(),
|
2026-08-07 17:14:42 +08:00
|
|
|
|
updateConfirmedPackageCount: vi.fn(),
|
2026-08-04 21:01:39 +08:00
|
|
|
|
}))
|
|
|
|
|
|
|
|
|
|
|
|
class ResizeObserverStub implements ResizeObserver {
|
|
|
|
|
|
observe() {}
|
|
|
|
|
|
unobserve() {}
|
|
|
|
|
|
disconnect() {}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
function createMemoryStorage(): 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),
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
function measurement(overrides: Partial<InboundMeasurementDetail> = {}): InboundMeasurementDetail {
|
|
|
|
|
|
return {
|
|
|
|
|
|
inboundId: '7001',
|
|
|
|
|
|
inboundCode: 'RK202608040001',
|
|
|
|
|
|
companyName: '测试企业',
|
|
|
|
|
|
channelCode: 'SEA-FBA',
|
|
|
|
|
|
channelName: '美西海运',
|
|
|
|
|
|
processStatus: 'MEASURING',
|
|
|
|
|
|
measureReviewStatus: null,
|
|
|
|
|
|
recommendedPalletType: 'STANDARD',
|
|
|
|
|
|
reviewReason: null,
|
|
|
|
|
|
reviewerId: null,
|
|
|
|
|
|
reviewerName: null,
|
|
|
|
|
|
measurementId: '9001',
|
|
|
|
|
|
sourceType: 'THIRD_PARTY',
|
|
|
|
|
|
measurementStatus: 'RECEIVED',
|
|
|
|
|
|
version: 2,
|
|
|
|
|
|
originalDocumentNo: 'DOC-001',
|
|
|
|
|
|
originalGrossWeightKg: 118.5,
|
|
|
|
|
|
originalVolumeCbm: 0.8,
|
2026-08-07 16:17:45 +08:00
|
|
|
|
originalPackageCount: 10,
|
2026-08-04 21:01:39 +08:00
|
|
|
|
actualPackageCount: 10,
|
|
|
|
|
|
actualGrossWeightKg: 120,
|
|
|
|
|
|
actualVolumeCbm: 0.6,
|
|
|
|
|
|
volumeWeightKg: 100.2,
|
|
|
|
|
|
actualGoodsName: '蓝牙音箱',
|
|
|
|
|
|
items: [{
|
|
|
|
|
|
id: '9101',
|
2026-08-07 16:17:45 +08:00
|
|
|
|
boxCode: 'RK202608040001#10-1',
|
2026-08-04 21:01:39 +08:00
|
|
|
|
itemNo: '001',
|
|
|
|
|
|
boxSpecification: '50×40×30cm',
|
|
|
|
|
|
packageCount: 10,
|
|
|
|
|
|
lengthCm: 50,
|
|
|
|
|
|
widthCm: 40,
|
|
|
|
|
|
heightCm: 30,
|
|
|
|
|
|
girthCm: 190,
|
|
|
|
|
|
unitWeightKg: 12,
|
|
|
|
|
|
unitVolumeCbm: 0.06,
|
|
|
|
|
|
totalWeightKg: 120,
|
|
|
|
|
|
totalVolumeCbm: 0.6,
|
|
|
|
|
|
volumeWeightKg: 100.2,
|
|
|
|
|
|
intelligentImageFileId: '88001',
|
2026-08-07 16:17:45 +08:00
|
|
|
|
machineNo: 'MJ20210327',
|
|
|
|
|
|
measuredAt: '2026-08-04T10:30:00+08:00',
|
2026-08-04 21:01:39 +08:00
|
|
|
|
overLimitWarning: null,
|
|
|
|
|
|
outerLengthCm: null,
|
|
|
|
|
|
outerWidthCm: null,
|
|
|
|
|
|
outerHeightCm: null,
|
|
|
|
|
|
remark: '设备自动回传',
|
|
|
|
|
|
}],
|
|
|
|
|
|
weightResults: [],
|
|
|
|
|
|
...overrides,
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
async function mountPanel(permissions = [
|
|
|
|
|
|
'platform:firstleg:inbound:measure:view',
|
|
|
|
|
|
'platform:firstleg:inbound:measure:edit',
|
|
|
|
|
|
'platform:firstleg:inbound:measure:submit',
|
|
|
|
|
|
]) {
|
|
|
|
|
|
const pinia = createPinia()
|
|
|
|
|
|
setActivePinia(pinia)
|
|
|
|
|
|
const auth = useAuthStore()
|
|
|
|
|
|
auth.token = 'token'
|
|
|
|
|
|
auth.permissions = permissions
|
|
|
|
|
|
useAccessPreviewStore().initializeAfterLogin()
|
|
|
|
|
|
const wrapper = mount(InboundMeasurementPanel, {
|
|
|
|
|
|
props: { customerId: '10001', inboundId: '7001' },
|
|
|
|
|
|
attachTo: document.body,
|
|
|
|
|
|
global: { plugins: [pinia, ElementPlus] },
|
|
|
|
|
|
})
|
|
|
|
|
|
await flushPromises()
|
|
|
|
|
|
return wrapper
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
enableAutoUnmount(afterEach)
|
|
|
|
|
|
afterAll(() => vi.unstubAllGlobals())
|
|
|
|
|
|
|
|
|
|
|
|
describe('InboundMeasurementPanel', () => {
|
|
|
|
|
|
beforeEach(() => {
|
|
|
|
|
|
vi.stubGlobal('ResizeObserver', ResizeObserverStub)
|
|
|
|
|
|
vi.stubGlobal('localStorage', createMemoryStorage())
|
|
|
|
|
|
vi.stubGlobal('sessionStorage', createMemoryStorage())
|
|
|
|
|
|
document.body.innerHTML = ''
|
|
|
|
|
|
vi.mocked(getInboundMeasurement).mockReset().mockResolvedValue(measurement())
|
2026-08-07 17:14:42 +08:00
|
|
|
|
vi.mocked(updateConfirmedPackageCount).mockReset().mockResolvedValue({
|
|
|
|
|
|
measurementId: '9001', measurementVersion: 3, itemId: '9101',
|
|
|
|
|
|
boxCode: 'RK202608040001#10-1', confirmedPackageCount: 10,
|
|
|
|
|
|
})
|
2026-08-04 21:01:39 +08:00
|
|
|
|
vi.mocked(submitInboundMeasurement).mockReset().mockResolvedValue({
|
|
|
|
|
|
measurementId: '9001', version: 2, processStatus: 'MEASURE_PENDING', measureReviewStatus: 'PENDING',
|
|
|
|
|
|
recommendedPalletType: 'STANDARD', feeId: null, feeNo: null, feeStatus: null,
|
|
|
|
|
|
})
|
|
|
|
|
|
vi.spyOn(ElMessageBox, 'confirm').mockResolvedValue(undefined as never)
|
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
|
|
it('loads third-party facts and renders server-calculated values separately', async () => {
|
|
|
|
|
|
const wrapper = await mountPanel()
|
|
|
|
|
|
|
|
|
|
|
|
expect(getInboundMeasurement).toHaveBeenCalledWith('10001', '7001')
|
|
|
|
|
|
expect(wrapper.text()).toContain('第三方设备')
|
|
|
|
|
|
expect(wrapper.text()).toContain('RK202608040001')
|
|
|
|
|
|
expect(wrapper.text()).toContain('箱规周长')
|
|
|
|
|
|
expect(wrapper.text()).toContain('190 cm')
|
|
|
|
|
|
expect(wrapper.text()).toContain('0.6 CBM')
|
2026-08-07 17:14:42 +08:00
|
|
|
|
expect(wrapper.text()).toContain('MJ20210327')
|
|
|
|
|
|
const measuredAtInput = wrapper.findAll('label').find((label) => label.text().includes('测量时间'))?.find('input')
|
|
|
|
|
|
expect((measuredAtInput?.element as HTMLInputElement).value).toBe('2026-08-04 10:30:00+08:00')
|
|
|
|
|
|
expect(wrapper.text()).toContain('预览图片')
|
2026-08-04 21:01:39 +08:00
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
|
|
it('follows the prototype grouping, labels, and editable field order', async () => {
|
|
|
|
|
|
const wrapper = await mountPanel()
|
|
|
|
|
|
const text = wrapper.text()
|
|
|
|
|
|
|
|
|
|
|
|
expect(text).toContain('原单数据')
|
2026-08-07 16:17:45 +08:00
|
|
|
|
expect(text).toContain('扫描箱测量数据明细')
|
2026-08-07 16:25:56 +08:00
|
|
|
|
expect(text).toContain('订单总箱数')
|
|
|
|
|
|
expect(text).toContain('确认箱数合计')
|
2026-08-04 21:01:39 +08:00
|
|
|
|
expect(text).toContain('实测总毛重')
|
|
|
|
|
|
expect(text).toContain('实测总体积')
|
|
|
|
|
|
expect(text).toContain('实测总材积重')
|
|
|
|
|
|
expect(text).not.toContain('租户')
|
|
|
|
|
|
|
|
|
|
|
|
const labels = wrapper.findAll('.measurement-item__grid label > span').map((label) => label.text())
|
|
|
|
|
|
expect(labels.slice(0, 8)).toEqual([
|
2026-08-07 16:17:45 +08:00
|
|
|
|
'箱号',
|
2026-08-07 17:14:42 +08:00
|
|
|
|
'测量长(cm)',
|
|
|
|
|
|
'测量宽(cm)',
|
|
|
|
|
|
'测量高(cm)',
|
2026-08-07 16:17:45 +08:00
|
|
|
|
'确认箱数 *',
|
2026-08-07 17:14:42 +08:00
|
|
|
|
'每箱毛重(kg)',
|
2026-08-07 16:17:45 +08:00
|
|
|
|
'机器编号',
|
|
|
|
|
|
'测量时间',
|
2026-08-04 21:01:39 +08:00
|
|
|
|
])
|
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
|
|
it('reuses the established first-leg detail surface and status patterns', async () => {
|
|
|
|
|
|
const wrapper = await mountPanel()
|
|
|
|
|
|
|
|
|
|
|
|
expect(wrapper.classes()).toContain('surface-panel')
|
|
|
|
|
|
expect(wrapper.find('.measurement-panel__heading').classes()).toContain('panel-heading')
|
|
|
|
|
|
expect(wrapper.find('.status-badge').text()).toBe('测量中')
|
|
|
|
|
|
})
|
|
|
|
|
|
|
2026-08-07 17:14:42 +08:00
|
|
|
|
it('saves only the changed confirmed package count with the current measurement version', async () => {
|
|
|
|
|
|
vi.mocked(updateConfirmedPackageCount).mockResolvedValueOnce({
|
|
|
|
|
|
measurementId: '9001', measurementVersion: 3, itemId: '9101',
|
|
|
|
|
|
boxCode: 'RK202608040001#10-1', confirmedPackageCount: 9,
|
|
|
|
|
|
})
|
2026-08-04 21:01:39 +08:00
|
|
|
|
const wrapper = await mountPanel()
|
2026-08-07 17:14:42 +08:00
|
|
|
|
const countInput = wrapper.findAll('label').find((label) => label.text().includes('确认箱数'))?.find('input')
|
|
|
|
|
|
await countInput?.setValue('9')
|
|
|
|
|
|
const save = wrapper.findAll('button').find((button) => button.text().includes('保存确认箱数'))
|
2026-08-04 21:01:39 +08:00
|
|
|
|
await save?.trigger('click')
|
|
|
|
|
|
await flushPromises()
|
|
|
|
|
|
|
2026-08-07 17:14:42 +08:00
|
|
|
|
expect(updateConfirmedPackageCount).toHaveBeenCalledWith('10001', '7001', '9101', {
|
|
|
|
|
|
measurementVersion: 2,
|
|
|
|
|
|
confirmedPackageCount: 9,
|
|
|
|
|
|
})
|
2026-08-04 21:01:39 +08:00
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
|
|
it('preserves the edited form when the backend reports a version conflict', async () => {
|
2026-08-07 17:14:42 +08:00
|
|
|
|
vi.mocked(updateConfirmedPackageCount).mockRejectedValueOnce(
|
2026-08-04 21:01:39 +08:00
|
|
|
|
new ApiResponseError('数据版本已变化,请刷新后重试', 'A0409', 200, null, 'req-conflict', 'trace-conflict'),
|
|
|
|
|
|
)
|
|
|
|
|
|
const wrapper = await mountPanel()
|
2026-08-07 17:14:42 +08:00
|
|
|
|
const countInput = wrapper.findAll('label').find((label) => label.text().includes('确认箱数'))?.find('input')
|
|
|
|
|
|
await countInput?.setValue('9')
|
|
|
|
|
|
const save = wrapper.findAll('button').find((button) => button.text().includes('保存确认箱数'))
|
2026-08-04 21:01:39 +08:00
|
|
|
|
await save?.trigger('click')
|
|
|
|
|
|
await flushPromises()
|
|
|
|
|
|
|
|
|
|
|
|
expect(wrapper.text()).toContain('数据版本已变化,当前修改尚未丢失')
|
|
|
|
|
|
expect(wrapper.text()).toContain('req-conflict')
|
2026-08-07 17:14:42 +08:00
|
|
|
|
expect((countInput?.element as HTMLInputElement).value).toBe('9')
|
2026-08-04 21:01:39 +08:00
|
|
|
|
expect(getInboundMeasurement).toHaveBeenCalledTimes(1)
|
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
|
|
it('requires the dirty draft to be saved before submitting for review', async () => {
|
|
|
|
|
|
const wrapper = await mountPanel()
|
2026-08-07 17:14:42 +08:00
|
|
|
|
const countInput = wrapper.findAll('label').find((label) => label.text().includes('确认箱数'))?.find('input')
|
|
|
|
|
|
await countInput?.setValue('9')
|
2026-08-04 21:01:39 +08:00
|
|
|
|
const submit = wrapper.findAll('button').find((button) => button.text().includes('提交审核'))
|
|
|
|
|
|
await submit?.trigger('click')
|
|
|
|
|
|
await flushPromises()
|
|
|
|
|
|
|
|
|
|
|
|
expect(submitInboundMeasurement).not.toHaveBeenCalled()
|
|
|
|
|
|
expect(ElMessageBox.confirm).not.toHaveBeenCalled()
|
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
|
|
it('submits the saved version and emits changed after confirmation', async () => {
|
|
|
|
|
|
const wrapper = await mountPanel()
|
|
|
|
|
|
const submit = wrapper.findAll('button').find((button) => button.text().includes('提交审核'))
|
|
|
|
|
|
await submit?.trigger('click')
|
|
|
|
|
|
await flushPromises()
|
|
|
|
|
|
|
|
|
|
|
|
expect(ElMessageBox.confirm).toHaveBeenCalledWith(
|
|
|
|
|
|
expect.stringContaining('准备托盘与库位占用'),
|
|
|
|
|
|
'提交测量审核',
|
|
|
|
|
|
expect.objectContaining({ confirmButtonText: '确认提交' }),
|
|
|
|
|
|
)
|
|
|
|
|
|
expect(submitInboundMeasurement).toHaveBeenCalledWith('10001', '7001', { measurementId: '9001', version: 2 })
|
|
|
|
|
|
expect(wrapper.emitted('changed')).toHaveLength(1)
|
|
|
|
|
|
})
|
|
|
|
|
|
|
2026-08-07 16:25:56 +08:00
|
|
|
|
it('blocks normal submission when confirmed box counts do not match the order total', async () => {
|
|
|
|
|
|
vi.mocked(getInboundMeasurement).mockResolvedValueOnce(measurement({ originalPackageCount: 12 }))
|
|
|
|
|
|
const wrapper = await mountPanel()
|
|
|
|
|
|
|
|
|
|
|
|
expect(wrapper.text()).toContain('确认箱数尚未与订单总箱数匹配')
|
|
|
|
|
|
expect(wrapper.text()).toContain('还差 2 箱')
|
|
|
|
|
|
const submit = wrapper.findAll('button').find((button) => button.text().includes('提交审核'))
|
|
|
|
|
|
expect(submit?.attributes('disabled')).toBeDefined()
|
|
|
|
|
|
expect(submitInboundMeasurement).not.toHaveBeenCalled()
|
|
|
|
|
|
})
|
|
|
|
|
|
|
2026-08-07 17:14:42 +08:00
|
|
|
|
it('keeps device facts read-only but allows manual count correction after submission', async () => {
|
|
|
|
|
|
vi.mocked(getInboundMeasurement).mockResolvedValueOnce(measurement({ processStatus: 'MEASURE_PENDING' }))
|
|
|
|
|
|
const wrapper = await mountPanel()
|
|
|
|
|
|
const countInput = wrapper.findAll('label').find((label) => label.text().includes('确认箱数'))?.find('input')
|
|
|
|
|
|
|
|
|
|
|
|
expect((countInput?.element as HTMLInputElement).matches(':disabled')).toBe(false)
|
|
|
|
|
|
expect(wrapper.findAll('button').find((button) => button.text().includes('保存确认箱数'))?.attributes('disabled')).toBeUndefined()
|
|
|
|
|
|
expect(wrapper.findAll('button').find((button) => button.text().includes('提交审核'))?.attributes('disabled')).toBeDefined()
|
|
|
|
|
|
expect(vi.mocked(downloadInboundMeasurementImage)).not.toHaveBeenCalled()
|
|
|
|
|
|
})
|
|
|
|
|
|
|
2026-08-04 21:01:39 +08:00
|
|
|
|
it('clears the previous customer context before loading the next one', async () => {
|
|
|
|
|
|
const wrapper = await mountPanel()
|
|
|
|
|
|
vi.mocked(getInboundMeasurement).mockResolvedValueOnce(measurement({ inboundId: '7002', inboundCode: 'RK202608040002', companyName: '第二企业' }))
|
|
|
|
|
|
|
|
|
|
|
|
await wrapper.setProps({ customerId: '10002', inboundId: '7002' })
|
|
|
|
|
|
await flushPromises()
|
|
|
|
|
|
|
|
|
|
|
|
expect(getInboundMeasurement).toHaveBeenLastCalledWith('10002', '7002')
|
|
|
|
|
|
expect(wrapper.text()).toContain('RK202608040002')
|
|
|
|
|
|
expect(wrapper.text()).not.toContain('测试企业')
|
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
|
|
it('renders a permission-specific read-only state without requesting data', async () => {
|
|
|
|
|
|
const wrapper = await mountPanel([])
|
|
|
|
|
|
|
|
|
|
|
|
expect(wrapper.text()).toContain('无测量查看权限')
|
|
|
|
|
|
expect(getInboundMeasurement).not.toHaveBeenCalled()
|
|
|
|
|
|
})
|
|
|
|
|
|
})
|