2026-10-18 08:49:30 +08:00
|
|
|
import { beforeEach, expect, test, vi } from 'vitest'
|
|
|
|
|
import { defineComponent, nextTick, ref } from 'vue'
|
|
|
|
|
import { shallowMount } from '@vue/test-utils'
|
|
|
|
|
import ProjectWorkspace from '@/components/ProjectWorkspace/index.vue'
|
|
|
|
|
|
|
|
|
|
const measurement=vi.hoisted(()=>({width:null}))
|
|
|
|
|
const api=vi.hoisted(()=>({getProject:vi.fn(),projectOptions:vi.fn(),projectOverview:vi.fn()}))
|
|
|
|
|
vi.mock('@vueuse/core',()=>({useElementSize:()=>({width:measurement.width})}))
|
|
|
|
|
vi.mock('@/api/project/project',()=>({getProject:api.getProject,projectOptions:api.projectOptions}))
|
|
|
|
|
vi.mock('@/api/production/tasks',()=>({projectOverview:api.projectOverview}))
|
2026-10-21 15:13:39 +08:00
|
|
|
vi.mock('@/api/project/workspace',()=>({workspaceCapabilities:vi.fn(),workspaceSummary:vi.fn(),memberProjects:vi.fn()}))
|
2026-10-18 08:49:30 +08:00
|
|
|
|
|
|
|
|
beforeEach(()=>{measurement.width=ref(1126);vi.clearAllMocks()})
|
|
|
|
|
|
|
|
|
|
test('the real project workspace reacts to embedded width without reloading business data',async()=>{
|
|
|
|
|
const descriptions=defineComponent({name:'DescriptionLayout',props:['column'],template:'<section><slot/></section>'})
|
|
|
|
|
const wrapper=shallowMount(ProjectWorkspace,{props:{embedded:true},global:{renderStubDefaultSlot:true,
|
|
|
|
|
stubs:{ElDescriptions:descriptions,ElDescriptionsItem:defineComponent({props:['label'],template:'<div>{{label}}<slot/></div>'}),
|
|
|
|
|
ElSelect:true,ElOption:true,ElTag:true,ElButton:true,ElAlert:true,ElTabs:true,ElTabPane:true},
|
|
|
|
|
directives:{loading:()=>{}},mocks:{$auth:{hasPermiOr:()=>false}}}})
|
|
|
|
|
await wrapper.setData({project:{id:1501,projectName:'很长的项目名称用于布局回归',projectCode:'TEST',projectType:'RESEARCH',projectStatus:1,totalAmount:100}})
|
|
|
|
|
for(const [width,columns] of [[1126,3],[632,2],[335,1],[980,3]]) {
|
|
|
|
|
measurement.width.value=width;await nextTick()
|
|
|
|
|
expect(wrapper.findComponent(descriptions).props('column')).toBe(columns)
|
|
|
|
|
expect(wrapper.text()).toContain('很长的项目名称用于布局回归')
|
|
|
|
|
expect(wrapper.text()).toContain('项目类型')
|
|
|
|
|
}
|
|
|
|
|
expect(api.getProject).not.toHaveBeenCalled();expect(api.projectOverview).not.toHaveBeenCalled()
|
|
|
|
|
wrapper.unmount()
|
|
|
|
|
})
|