- 将 Account 组件中的 Text 导入移动到顶部 - 移除 App.tsx 中的 expo-updates 相关代码 - 添加 PackageUpdates 相关组件和 hooks - 更新应用名称从 "CMVR 物资管理" 为 "车研物资" - 添加应用图标和自适应图标配置 - 更新 Android 权限配置,添加 REQUEST_INSTALL_PACKAGES 权限 - 修改堆栈导航数据结构,支持路由参数传递 - 添加阅读尺寸偏好设置功能 - 重构登录界面为独立组件 LoginView - 添加文件库界面组件 FileLibrary - 更新状态栏样式逻辑 - 调整 Tab 栏样式和尺寸 - 集成包更新和应用更新对话框 - 修复导入语句顺序和类型引用 - 优化业务列表组件的路由参数处理 - 添加作用域参数用于 API 请求区分
34 lines
4.1 KiB
JavaScript
34 lines
4.1 KiB
JavaScript
import {beforeEach,afterEach,expect,it,vi} from 'vitest'
|
|
import {mount,flushPromises} from '@vue/test-utils'
|
|
import ElementPlus from 'element-plus'
|
|
import Photos from '@/components/ArrivalPhotos/index.vue'
|
|
const request=vi.hoisted(()=>vi.fn())
|
|
vi.mock('@/utils/request',()=>({default:request}))
|
|
let wrapper,created,revoke
|
|
beforeEach(()=>{request.mockReset();created=URL.createObjectURL;revoke=URL.revokeObjectURL;URL.createObjectURL=vi.fn(()=>`blob:photo-${Math.random()}`);URL.revokeObjectURL=vi.fn()})
|
|
afterEach(()=>{wrapper?.unmount();document.body.innerHTML='';URL.createObjectURL=created;URL.revokeObjectURL=revoke})
|
|
function page(props={}){wrapper=mount(Photos,{attachTo:document.body,props:{requestId:10,modelValue:[],...props,'onUpdate:modelValue':value=>wrapper.setProps({modelValue:value})},global:{plugins:[ElementPlus]}});return wrapper}
|
|
async function choose(files){const input=wrapper.find('input[type=file]');Object.defineProperty(input.element,'files',{value:files,configurable:true});await input.trigger('change');await flushPromises()}
|
|
const picture=()=>new File(['image'],'到货.png',{type:'image/png'})
|
|
it('photos are optional and successful uploads are included in the model before submission',async()=>{
|
|
request.mockImplementation(async c=>c.method==='post'?{data:{id:c.data.get('uploadId'),name:'到货.png'}}:{});page();expect(wrapper.vm.pending).toBe(false)
|
|
await choose([picture()]);expect(wrapper.props('modelValue')).toHaveLength(1);expect(wrapper.props('modelValue')[0].id).toMatch(/^[0-9a-f-]{36}$/);expect(wrapper.vm.pending).toBe(false)
|
|
await wrapper.findAll('button').find(b=>b.text()==='移除').trigger('click');await flushPromises();expect(wrapper.props('modelValue')).toEqual([]);expect(request.mock.calls[1][0].method).toBe('delete')
|
|
})
|
|
it('failed photos can be retried using the same upload identifier or removed without blocking optional registration',async()=>{
|
|
request.mockRejectedValueOnce(Error('模拟上传失败')).mockImplementation(async c=>({data:{id:c.data.get('uploadId'),name:'到货.png'}}));page();await choose([picture()]);expect(wrapper.vm.pending).toBe(true);expect(wrapper.text()).toContain('模拟上传失败')
|
|
await wrapper.findAll('button').find(b=>b.text()==='重试').trigger('click');await flushPromises();expect(wrapper.vm.pending).toBe(false);expect(request.mock.calls[0][0].data.get('uploadId')).toBe(request.mock.calls[1][0].data.get('uploadId'))
|
|
})
|
|
it('read-only saved photos load privately on demand and never expose upload or remove controls',async()=>{
|
|
request.mockResolvedValue(new Blob(['private'],{type:'image/png'}));page({compact:true,readonly:true,disabled:true,modelValue:[{id:'11111111-1111-4111-8111-111111111111',name:'到货.png'}]});expect(request).not.toHaveBeenCalled()
|
|
await wrapper.find('button').trigger('click');await flushPromises();expect(request).toHaveBeenCalledOnce();expect(request.mock.calls[0][0].url).toContain('/content');expect(document.body.textContent).not.toContain('上传照片');expect(document.body.textContent).not.toContain('移除')
|
|
})
|
|
it('non-images and oversized files do not upload; each arrival is limited to nine photos',async()=>{
|
|
request.mockImplementation(async c=>({data:{id:c.data.get('uploadId'),name:'到货.png'}}));page();await choose([new File(['not image'],'file.txt',{type:'text/plain'}),new File([new Uint8Array(20*1024*1024+1)],'large.png',{type:'image/png'})]);expect(request).not.toHaveBeenCalled()
|
|
await choose(Array.from({length:10},picture));expect(wrapper.props('modelValue')).toHaveLength(9);expect(request).toHaveBeenCalledTimes(9)
|
|
})
|
|
it('saved photo loading errors can retry without editing the arrival or its photo metadata',async()=>{
|
|
request.mockRejectedValueOnce(Error('模拟读取失败')).mockResolvedValue(new Blob(['private'],{type:'image/png'}));page({readonly:true,modelValue:[{id:'11111111-1111-4111-8111-111111111111',name:'到货.png'}]});await flushPromises();expect(wrapper.text()).toContain('加载失败,点击重试');expect(wrapper.props('modelValue')[0].error).toBeUndefined()
|
|
await wrapper.find('.arrival-photo-placeholder').trigger('click');await flushPromises();expect(request).toHaveBeenCalledTimes(2);expect(wrapper.text()).not.toContain('模拟读取失败')
|
|
})
|