import { afterEach, describe, expect, it, vi } from 'vitest' import { flushPromises, mount, DOMWrapper, type VueWrapper } from '@vue/test-utils' import StoryboardDiagnosis from '@/features/breakdown/components/StoryboardDiagnosis.vue' import WorkflowExecutionPanel from '@/features/workflows/WorkflowExecutionPanel.vue' import { breakdownApi } from '@/features/breakdown/api' import type { LegacyActionDiagnosisResults } from '@/features/breakdown/types' import type { WorkflowExecution } from '@/features/workflows/execution.types' /** 页面回执同时包含修订完成、局部证据不足和 AI 待复查。 */ const shot: LegacyActionDiagnosisResults['shots'][number] = { shotId: 'shot-1', episodeNo: 1, beatNo: 1, shotNo: 1, title: '捂耳取铃', diagnosisId: 'diag-1', status: 'stale' as const, issues: [], createdAt: null, policyStatus: 'stale', shotStale: true, repairStatus: 'repaired', requiresPostRepairDiagnosis: true, handAudit: { status: 'partial_evidence', evidenceCount: 1, expectedActionCount: 2, coveredActionCount: 1, issueCount: 0, coverage: 0.5 }, bodyMotionFindings: [{ dimension: 'balance', status: 'needs_review', description: '重心需要核对', quote: '单脚站立' }] } let wrapper: VueWrapper | undefined afterEach(() => { wrapper?.unmount(); wrapper = undefined; vi.restoreAllMocks(); vi.unstubAllGlobals(); document.body.innerHTML = '' }) describe('诊断版本及复查展示', () => { it('修订完成不显示全部通过,展示规则和镜头过期、手部覆盖及全身疑点', async () => { vi.spyOn(breakdownApi, 'legacyActionDiagnosisResults').mockResolvedValue({ projectId: 'diag-update', episodeNo: 1, counts: { total: 1, conflict: 0, clear: 0, insufficient: 0, invalid: 0, stale: 1, pending: 0 }, shots: [shot] }) vi.spyOn(breakdownApi, 'handOccupancyDiagnostics').mockResolvedValue({ projectId: 'diag-update', shotCount: 1, evidenceShotCount: 0, diagnostics: [] } as never) wrapper = mount(StoryboardDiagnosis, { attachTo: document.body, props: { projectId: 'diag-update', episodeNo: 1, episodeNos: [1] } }) await flushPromises(); await wrapper.get('button').trigger('click'); await flushPromises() const dialog = new DOMWrapper(document.querySelector('[aria-label="动作诊断"]')!) expect(dialog.text()).toContain('镜头已修订,AI 待复查') expect(dialog.text()).toContain('镜头内容已变化') expect(dialog.text()).toContain('质量规则已变化') expect(dialog.text()).toContain('手部动作证据 1 / 2') expect(dialog.text()).toContain('重心需要核对') expect(dialog.text()).not.toContain('全部通过') }) it('中断诊断显示人工核查与可复用数量,不把未匹配镜头描述为未计费', () => { const execution = { id: 'task', projectId: 'p', workflowName: 'storyboard-legacy-action-diagnosis', status: 'failed', current: 1, total: 3, result: { recoveryRequired: true, retryAutomatically: false, requiresManualReview: true, resumeMode: 'manual', reusableShotCount: 1, manualReviewShotCount: 2, scopedShotCount: 3, qualityPolicyVerified: true }, metadata: null, stage: 'interrupted', currentResourceId: null, error: '诊断中断', startedAt: null, completedAt: null, createdAt: '', updatedAt: '' } satisfies WorkflowExecution wrapper = mount(WorkflowExecutionPanel, { props: { execution, loading: false, error: '' } }) expect(wrapper.text()).toContain('需要人工核查') expect(wrapper.text()).toContain('可复用 1 镜') expect(wrapper.text()).toContain('待核查 2 镜') expect(wrapper.text()).toContain('可能已产生费用') expect(wrapper.text()).not.toContain('未计费') }) })