import { flushPromises, mount, type VueWrapper } from '@vue/test-utils' import { NTabs } from 'naive-ui' import { afterEach, describe, expect, it, vi } from 'vitest' import ProjectSettingsDialog from '@/features/generation-config/components/ProjectSettingsDialog.vue' import { projectsApi } from '@/features/projects/api' import { policyReceipt } from '../../fixtures/quality-policy' /** 当前全屏配置抽屉。 */ let wrapper: VueWrapper | undefined afterEach(() => { wrapper?.unmount() wrapper = undefined document.body.innerHTML = '' }) describe('配置入口定位到指定分类', () => { it('规则入口直接显示质量规则,关闭后从普通入口重开回到生成配置', async () => { const save = vi.spyOn(projectsApi, 'saveQualityPolicy') const confirm = vi.spyOn(projectsApi, 'confirmQualityPolicy') vi.spyOn(projectsApi, 'qualityPolicy').mockResolvedValue( policyReceipt('settings-quality', { version: 1, physicsMode: 'realistic', allowExaggeratedMotion: false, allowNonPhysicalActions: false, allowSupernaturalAbilities: false, customRules: [] }) ) wrapper = mount(ProjectSettingsDialog, { attachTo: document.body, props: { projectId: 'settings-quality', disabled: false, open: true, initialTab: 'quality' }, global: { stubs: { CreativeProfileSettings: true } } }) await flushPromises() expect(wrapper.getComponent(NTabs).props('value')).toBe('quality') expect(wrapper.findComponent({ name: 'QualityPolicySettings' }).exists()).toBe(true) expect(save).not.toHaveBeenCalled() expect(confirm).not.toHaveBeenCalled() await wrapper.setProps({ open: false }) await wrapper.setProps({ open: true, initialTab: 'generation' }) await flushPromises() expect(wrapper.getComponent(NTabs).props('value')).toBe('generation') }) })