import { mount, flushPromises, type VueWrapper } from '@vue/test-utils' import { NInput } from 'naive-ui' import { afterEach, describe, expect, it, vi } from 'vitest' import ContinuityReviewDrawer from '@/features/production/components/ContinuityReviewDrawer.vue' import GeometryObservationEditor from '@/features/production/components/GeometryObservationEditor.vue' import { createContinuityMock, continuityShots, fingerprint } from '../../fixtures/continuity' import type { GeometryFrameObservation } from '@/features/production/continuity.types' /** 挂载实际表单逻辑,布局和 Teleport 在本地 Chrome 独立验证。 */ let wrapper: VueWrapper /** * 从当前隔离页面点击真实按钮。 * @param label 完整按钮名称 */ async function click(label: string) { const button = wrapper.findAll('button').find(item => item.text() === label) expect(button, `应存在按钮 ${label}`).toBeDefined() await button!.trigger('click') await flushPromises() } afterEach(() => { wrapper?.unmount() localStorage.clear() sessionStorage.clear() vi.unstubAllGlobals() }) describe('连续性审核真实组件流程', () => { it('完成观察才能保存本次指纹,编辑后需重新诊断,历史失效保留原结论', async () => { const mock = createContinuityMock() vi.stubGlobal('fetch', mock.fetcher) wrapper = mount(ContinuityReviewDrawer, { props: { open: true, projectId: 'mock-project', shots: continuityShots, disabled: false }, global: { stubs: { teleport: true, AppDrawer: { template: '
' }, AssetImage: true, LayoutSupplementPanel: true } } }) await flushPromises() expect(mock.calls.every(item => item.method === 'GET')).toBe(true) await click('免费读取当前证据') expect(wrapper.text()).toContain('证据不足') expect(wrapper.text()).not.toContain('开门、关门属于即时状态') await wrapper.get('button[aria-label="人工观察说明"]').trigger('click') await flushPromises() expect(wrapper.text()).toContain('开门、关门属于即时状态') const inputs = wrapper.findAllComponents(NInput) inputs.find(item => item.props('placeholder') === '固定地标一')!.vm.$emit('update:value', '窗') inputs.find(item => item.props('placeholder') === '固定地标二')!.vm.$emit('update:value', '门') for (const [i, editor] of wrapper.findAllComponents(GeometryObservationEditor).entries()) { const frame: GeometryFrameObservation = { shotId: 's' + (i + 1), view: 'same_side', landmarkOrder: 'as_layout', evidence: '画面同侧地标可辨', features: [{ key: '铰链', side: 'left', evidence: '铰链连接可辨' }] } editor.vm.$emit('update:modelValue', frame) } await flushPromises() await click('免费诊断人工观察') expect(wrapper.text()).toContain('诊断结果:通过') wrapper .findAllComponents(NInput) .find(item => item.props('placeholder') === '填写真实审核人')! .vm.$emit('update:value', '测试审核人') await flushPromises() await click('保存本次连续性审核') const writes = mock.calls.filter(item => item.url.endsWith('/continuity/reviews')) expect(writes).toHaveLength(1) expect((writes[0]!.body.observation as { expectedFingerprint: string }).expectedFingerprint).toBe(fingerprint) expect(wrapper.text()).toContain('原审核结论:通过') mock.state.stale = true await click('读取') expect(wrapper.text()).toContain('当前状态:已失效') expect(wrapper.text()).toContain('原审核结论:通过') wrapper.findAllComponents(GeometryObservationEditor)[0]!.vm.$emit('update:modelValue', { shotId: 's1', view: 'unknown', landmarkOrder: 'unknown', evidence: '编辑了观察', features: [] }) await flushPromises() const save = wrapper.findAll('button').find(item => item.text() === '保存本次连续性审核')! expect(save.attributes('disabled')).toBeDefined() expect(mock.calls.filter(item => item.method === 'PUT')).toHaveLength(0) }) it('三镜相同来源问题合并范围,仍保留逐镜来源状态', async () => { const mock = createContinuityMock() mock.state.stale = true vi.stubGlobal('fetch', mock.fetcher) wrapper = mount(ContinuityReviewDrawer, { props: { open: true, projectId: 'mock-project', shots: continuityShots, disabled: false }, global: { stubs: { AppDrawer: { template: '
' }, AssetImage: true, LayoutSupplementPanel: true } } }) await flushPromises() await click('免费读取当前证据') expect(wrapper.text()).toContain('镜头 1.1、1.2、1.3:布局来源已变化') expect(wrapper.text().match(/镜头 1.1、1.2、1.3:布局来源已变化/g)).toHaveLength(1) }) it('预览参数变化废弃待审结果,版本冲突不重发正式确认', async () => { const mock = createContinuityMock() vi.stubGlobal('fetch', mock.fetcher) wrapper = mount(ContinuityReviewDrawer, { props: { open: true, projectId: 'mock-project', shots: continuityShots, disabled: false }, global: { stubs: { AppDrawer: { template: '
' }, AssetImage: true } } }) await flushPromises() const inputs = wrapper.findAllComponents(NInput) inputs .find(item => item.props('placeholder') === '待审结构约束,例如固定连接位置与活动方向')! .vm.$emit('update:value', '固定门轴') inputs .find(item => item.props('placeholder') === '填写人工观察或设计依据')! .vm.$emit('update:value', '人工依据') await flushPromises() await click('免费预览结构约束') expect(wrapper.text()).toContain('需要确认布局并重新确认母版') await wrapper .findAll('.n-collapse-item__header-main') .find(item => item.text() === '本次完整布局约束')! .trigger('click') await flushPromises() expect(wrapper.text()).toContain('固定连接位置') expect(wrapper.text()).not.toContain(fingerprint) expect(wrapper.text()).not.toContain('"layoutConfirmation"') inputs .find(item => item.props('placeholder') === '待审结构约束,例如固定连接位置与活动方向')! .vm.$emit('update:value', '修改后的门轴') await flushPromises() expect(wrapper.text()).not.toContain('确认正式布局') await click('免费预览结构约束') wrapper .findAllComponents(NInput) .find(item => item.props('placeholder') === '填写真实确认人')! .vm.$emit('update:value', 'goujun') await flushPromises() await wrapper.find('[role="checkbox"]').trigger('click') mock.state.conflict = true await click('确认正式布局') const writes = mock.calls.filter(item => item.method === 'PUT') expect(writes).toHaveLength(1) expect(writes[0]!.body.confirmedBy).toBe('goujun') expect(writes[0]!.body.expectedVersion).toBe(fingerprint) expect(wrapper.text()).not.toContain('确认正式布局') expect(wrapper.emitted('changed')).toHaveLength(1) }) })