Why: Plugin descriptors without an explicit scope remain personal-compatible in the backend, but the editor hid them. Evidence: Frontend tests (290), production build, and check-knip pass; focused regression was red before the fix and green after. Impact: Legacy plugin settings remain visible in user and project-personal editors while shared project and system editors stay scoped. Refs: Dev feature/rdm-settings-completion P1-P2
46 lines
2.5 KiB
TypeScript
46 lines
2.5 KiB
TypeScript
import { describe, expect, it, vi } from 'vitest'
|
|
import { renderToStaticMarkup } from 'react-dom/server'
|
|
import { SettingInput } from '../src/components/SettingsModal'
|
|
import { scopedSchema } from '../src/components/SettingsFields'
|
|
import { BorrowPanels } from '../src/components/BorrowPanels'
|
|
import type { SettingDesc } from '../src/contracts'
|
|
|
|
vi.mock('../src/store', () => ({ useStore: (select: (state: unknown) => unknown) => select({ ui: {} }) }))
|
|
const field = (type: SettingDesc['type'], options?: string[]): SettingDesc => ({
|
|
key: 'deliverables.style', group: 'deliverables', label: '交付风格', type, options, effect: 'new-run',
|
|
})
|
|
|
|
describe('setting editors preserve types and readable values', () => {
|
|
it('keeps legacy personal plugin settings visible only in personal scopes', () => {
|
|
const schema: SettingDesc[] = [
|
|
{ ...field('string'), key: 'plugin.legacy', scope: undefined },
|
|
{ ...field('string'), key: 'plugin.user', scope: 'user' },
|
|
{ ...field('string'), key: 'plugin.project-personal', scope: 'project-personal' },
|
|
{ ...field('string'), key: 'plugin.project', scope: 'project' },
|
|
{ ...field('string'), key: 'plugin.system', scope: 'system' },
|
|
]
|
|
const keys = (scope: string) => scopedSchema(schema, scope).map(desc => desc.key)
|
|
expect(keys('user')).toEqual(['plugin.legacy', 'plugin.user'])
|
|
expect(keys('project-personal')).toEqual(['plugin.legacy', 'plugin.user', 'plugin.project-personal'])
|
|
expect(keys('project')).toEqual(['plugin.project'])
|
|
expect(keys('system')).toEqual(['plugin.system'])
|
|
})
|
|
it('uses a number input for numeric values rather than submitting arbitrary strings', () => {
|
|
expect(renderToStaticMarkup(<SettingInput desc={field('number')} value={12} onChange={() => {}} />)).toContain('type="number"')
|
|
})
|
|
it('shows readable enum names and a distinct inherited choice', () => {
|
|
const html = renderToStaticMarkup(<SettingInput desc={field('enum', ['modern', 'formal', 'minimal'])} value="" onChange={() => {}} />)
|
|
expect(html).toContain('沿用默认')
|
|
expect(html).toContain('>现代</option>')
|
|
expect(html).toContain('>正式</option>')
|
|
expect(html).toContain('>简洁</option>')
|
|
})
|
|
it('personal supplementary panels no longer offer system credentials', () => {
|
|
const html = renderToStaticMarkup(<BorrowPanels />)
|
|
expect(html).not.toContain('新增密钥')
|
|
expect(html).not.toContain('主模型')
|
|
expect(html).toContain('条件注入')
|
|
expect(html).toContain('用户命令')
|
|
})
|
|
})
|