feat(admin): synchronize fleet photos and multi-image loading documents

This commit is contained in:
2026-10-26 17:12:38 +08:00
parent e399f3f76f
commit acb90007de
29 changed files with 556 additions and 95 deletions
@@ -6,13 +6,13 @@ import ApiErrorMeta from '@/shared/components/ApiErrorMeta.vue'
import DispatchEvidenceFiles from './DispatchEvidenceFiles.vue'
import * as api from '../api/dispatches'
import type { DispatchEvidenceFile } from '../dispatchContracts'
import { downloadDriverLicense } from '@/modules/overseas-master-data'
vi.mock('@/modules/overseas-master-data', () => ({ downloadDriverLicense: vi.fn() }))
import { downloadDriverLicense, getResourcePhoto, downloadResourcePhoto } from '@/modules/overseas-master-data'
vi.mock('@/modules/overseas-master-data', () => ({ downloadDriverLicense: vi.fn(), getResourcePhoto: vi.fn(), downloadResourcePhoto: vi.fn() }))
vi.mock('../api/dispatches', () => ({ getDispatchEvidence: vi.fn(), getDispatchEvidenceContent: vi.fn(), uploadDispatchEvidence: vi.fn() }))
const metadata = (fileId = '301', contentType = 'image/png'): DispatchEvidenceFile => ({ fileId, fileName: contentType === 'application/pdf' ? '本车证照.pdf' : '本车证据.png', contentType, sizeBytes: 3 })
const options = { props: { modelValue: ['301'], dispatchNo: 'PC/1', kind: 'VEHICLE' as const }, global: { stubs: { ElButton: { props: ['disabled'], template: '<button :disabled="disabled"><slot /></button>' }, AppDialog: { name: 'AppDialog', props: ['modelValue', 'title'], template: '<section v-if="modelValue" role="dialog"><slot /><button @click="$emit(\'update:modelValue\', false)">关闭预览</button></section>' } } } }
const button = (wrapper: ReturnType<typeof mount>, label: string) => wrapper.findAll('button').find(value => value.text() === label)!
it.each(['VEHICLE', 'DRIVER_PHOTO', 'DRIVER'] as const)('does not count a PDF or failed upload as a %s photo', async kind => {
it.each(['VEHICLE', 'DRIVER_PHOTO'] as const)('does not count a PDF or failed upload as a %s photo', async kind => {
const wrapper = mount(DispatchEvidenceFiles, { ...options, props: { ...options.props, kind, photoCard: true, modelValue: [] } }); await flushPromises()
await selectFile(wrapper, new File(['pdf'], 'document.pdf', { type: 'application/pdf' }))
expect(api.uploadDispatchEvidence).not.toHaveBeenCalled()
@@ -154,3 +154,36 @@ it('rejects mismatched file identity and a blocked PDF popup without fetching co
vi.mocked(api.getDispatchEvidence).mockResolvedValueOnce(metadata('301', 'application/pdf')); const open = vi.spyOn(window, 'open').mockReturnValueOnce(null)
const blocked = mount(DispatchEvidenceFiles, options); await flushPromises(); await button(blocked, '预览').trigger('click'); await flushPromises(); expect(blocked.text()).toContain('请允许本站打开PDF预览窗口'); expect(api.getDispatchEvidenceContent).not.toHaveBeenCalled(); blocked.unmount(); open.mockRestore()
})
it('accepts a PDF driver license in the photo card without requiring another image', async () => {
vi.mocked(api.uploadDispatchEvidence).mockResolvedValue(metadata('302', 'application/pdf'))
const wrapper = mount(DispatchEvidenceFiles, { ...options, props: { ...options.props, kind: 'DRIVER', photoCard: true, modelValue: [] } })
await flushPromises(); await selectFile(wrapper, new File(['pdf'], 'license.pdf', { type: 'application/pdf' }))
expect(api.uploadDispatchEvidence).toHaveBeenCalledOnce()
expect(wrapper.emitted('update:modelValue')?.at(-1)).toEqual([['302']]); wrapper.unmount()
})
it('previews a master photo without submitting its foreign file ID as dispatch evidence', async () => {
vi.mocked(getResourcePhoto).mockResolvedValue({ recordVersion: '1', photo: metadata('81') })
vi.mocked(downloadResourcePhoto).mockResolvedValue(new Blob(['png'], { type: 'image/png' }))
const wrapper = mount(DispatchEvidenceFiles, { ...options, props: { ...options.props, photoCard: true, modelValue: [], masterResource: { kind: 'VEHICLE', id: '7' } } })
await flushPromises()
expect(wrapper.text()).toContain('已带入档案照片')
expect(api.getDispatchEvidence).not.toHaveBeenCalled()
expect(wrapper.emitted('update:modelValue')).toBeUndefined()
expect(wrapper.emitted('available')?.at(-1)).toEqual([true])
await wrapper.setProps({ modelValue: ['301'] }); await flushPromises()
expect(wrapper.text()).not.toContain('已带入档案照片')
expect(api.getDispatchEvidence).toHaveBeenCalledWith('PC/1', 'VEHICLE', '301')
expect(getResourcePhoto).toHaveBeenCalledOnce(); wrapper.unmount()
})
it('ignores late profile photo responses after changing the selected resource', async () => {
let finish!: (value: Awaited<ReturnType<typeof getResourcePhoto>>) => void
vi.mocked(getResourcePhoto).mockImplementationOnce(() => new Promise(resolve => { finish = resolve }))
.mockResolvedValueOnce({ recordVersion: '0', photo: null })
const wrapper = mount(DispatchEvidenceFiles, { ...options, props: { ...options.props, photoCard: true, modelValue: [], masterResource: { kind: 'VEHICLE', id: '7' } } })
await wrapper.setProps({ masterResource: { kind: 'VEHICLE', id: '8' } }); await flushPromises()
finish({ recordVersion: '1', photo: metadata('81') }); await flushPromises()
expect(downloadResourcePhoto).not.toHaveBeenCalled()
expect(wrapper.text()).not.toContain('已带入档案照片')
expect(wrapper.emitted('available')?.at(-1)).toEqual([false]); wrapper.unmount()
})