import { type Component } from 'vue' import { flushPromises, mount } from '@vue/test-utils' import { describe, expect, it } from 'vitest' import AppDialog from '@/components/ui/AppDialog.vue' import AppDrawer from '@/components/ui/AppDrawer.vue' import WorkspaceSectionHeading from '@/components/ui/WorkspaceSectionHeading.vue' import FieldLabel from '@/components/ui/FieldLabel.vue' import ImageGenerationPreview from '@/features/subject-images/components/ImageGenerationPreview.vue' import { imagePreviewFixture } from '../../fixtures/image-preview' /** 各种公共标题保持相同的说明入口,动态状态不被隐藏。 */ const cases: Array<{ /** 当前公共布局。 */ component: Component /** 可访问说明名称。 */ label: string /** 原布局需要的显隐参数。 */ extra: Record }> = [ { component: AppDialog, label: '操作说明', extra: { open: true } }, { component: AppDrawer, label: '操作说明', extra: { open: true } }, { component: WorkspaceSectionHeading, label: '审核范围说明', extra: {} } ] describe('分镜界面按需显示说明', () => { it.each(cases)('$label 首屏保留标题,完整说明由用户主动展开', async ({ component, label, extra }) => { const wrapper = mount(component, { props: { ...extra, title: '审核范围', description: '完整操作说明应能保留并随时核对', descriptionAsInfo: true }, global: { stubs: { teleport: true } } }) try { await flushPromises() expect(wrapper.text()).toContain('审核范围') expect(wrapper.text()).not.toContain('完整操作说明应能保留') await wrapper.get(`button[aria-label="${label}"]`).trigger('click') await flushPromises() expect(wrapper.text()).toContain('完整操作说明应能保留并随时核对') } finally { wrapper.unmount() } }) it('动态状态插槽直接显示,不能被静态说明收起选项隐藏', async () => { const wrapper = mount(AppDialog, { props: { open: true, title: '原任务', description: '流程说明', descriptionAsInfo: true }, slots: { description: '

当前费用未知,请核查原请求

' }, global: { stubs: { teleport: true } } }) try { await flushPromises() expect(wrapper.text()).toContain('当前费用未知,请核查原请求') expect(wrapper.find('button[aria-label="操作说明"]').exists()).toBe(false) } finally { wrapper.unmount() } }) it('视觉重点等创作内容原样展示,不被系统术语转换改写', async () => { const original = 'Prompt 是角色在画面中写下的原始台词' const wrapper = mount(FieldLabel, { props: { label: '视觉重点', description: original, iconOnly: true, icon: 'info', verbatim: true }, global: { stubs: { teleport: true } } }) try { expect(wrapper.text()).not.toContain(original) await wrapper.get('button').trigger('click') await flushPromises() expect(wrapper.text()).toContain(original) } finally { wrapper.unmount() } }) it('图片预览先显示参考与主要操作,完整提示词仍可主动核对', async () => { const original = '必须完整保留的画面描述,'.repeat(30) const wrapper = mount(ImageGenerationPreview, { props: { preview: { ...imagePreviewFixture(), providerPrompt: original }, loading: false, error: '', staleNotice: '' } }) try { expect(wrapper.text()).toContain('预览实际生成输入') expect(wrapper.text()).not.toContain(original) await wrapper .findAll('.n-collapse-item__header-main') .find(row => row.text() === '本次实际使用的画面描述')! .trigger('click') await flushPromises() expect(wrapper.text()).toContain(original) } finally { wrapper.unmount() } }) })