import { mount } from '@vue/test-utils' import { describe, expect, it } from 'vitest' import IdentityEditor from '@/features/subject-identity/components/IdentityEditor.vue' import { identityFixture } from '@/features/subject-identity/testing/fixtures' describe('主体身份保存状态', () => { it.each([ { name: '未创建身份', identity: null }, { name: '空身份记录', identity: identityFixture({ description: null, generationPrompt: '' }) }, { name: '仅空白字符', identity: identityFixture({ description: ' ', generationPrompt: '\n' }) } ])('$name 不显示已保存,输入后可保存,撤销输入后禁止空提交', async ({ identity }) => { const wrapper = mount(IdentityEditor, { props: { identity, disabled: false, module: 'prop' } }) try { const actions = wrapper.get('.page-form-actions') expect(actions.text()).toBe('保存主体身份') expect(actions.text()).not.toContain('已保存') expect(actions.get('button').attributes('disabled')).toBeDefined() await wrapper.get('#identity-description').setValue('竹编鱼篓,固定圆筒结构') expect(actions.text()).toBe('保存主体身份') expect(actions.get('button').attributes('disabled')).toBeUndefined() await wrapper.get('#identity-description').setValue(identity?.description ?? '') expect(actions.text()).toBe('保存主体身份') expect(actions.text()).not.toContain('已保存') } finally { wrapper.unmount() } }) it('后端已有身份文本才显示已保存,修改后的草稿显示保存操作', async () => { const wrapper = mount(IdentityEditor, { props: { identity: identityFixture(), disabled: false, module: 'character' } }) try { expect(wrapper.get('.page-form-actions').text()).toBe('已保存') expect(wrapper.get('.page-form-actions button').text()).toBe('已保存') await wrapper.get('#identity-prompt').setValue('修改中的核心提示词') expect(wrapper.get('.page-form-actions').text()).toBe('保存主体身份') expect(wrapper.get('.page-form-actions button').text()).toBe('保存主体身份') } finally { wrapper.unmount() } }) })