|
| 1 | +import { describe, it, expect } from 'vitest' |
| 2 | +import { mount } from '@vue/test-utils' |
| 3 | +import SettingField from '@/components/settings/SettingField.vue' |
| 4 | +import { ADVANCED_ACCORDIONS, validateField, type SettingField as Field } from '@/views/settings/fields' |
| 5 | + |
| 6 | +// MCP-2175 — editable `instructions` textarea in Advanced settings. |
| 7 | +// The built-in default (Go: defaultInstructions) is shown as the placeholder |
| 8 | +// and clearing the box must persist "" (Go maps "" -> default), never whitespace. |
| 9 | + |
| 10 | +const instrField: Field = { |
| 11 | + key: 'instructions', |
| 12 | + label: 'Server instructions', |
| 13 | + control: 'textarea', |
| 14 | + optional: true, |
| 15 | + placeholder: 'BUILT-IN DEFAULT', |
| 16 | +} |
| 17 | + |
| 18 | +describe('SettingField textarea control', () => { |
| 19 | + it('renders a <textarea> with the default bound as placeholder', () => { |
| 20 | + const w = mount(SettingField, { props: { field: instrField, modelValue: '' } }) |
| 21 | + const ta = w.find('[data-test="setting-textarea-instructions"]') |
| 22 | + expect(ta.exists()).toBe(true) |
| 23 | + expect(ta.element.tagName).toBe('TEXTAREA') |
| 24 | + expect(ta.attributes('placeholder')).toBe('BUILT-IN DEFAULT') |
| 25 | + }) |
| 26 | + |
| 27 | + it('emits "" when cleared to whitespace-only (empty-means-default)', async () => { |
| 28 | + const w = mount(SettingField, { props: { field: instrField, modelValue: 'old custom' } }) |
| 29 | + const ta = w.find('[data-test="setting-textarea-instructions"]') |
| 30 | + await ta.setValue(' \n ') |
| 31 | + const emits = w.emitted('update:modelValue') |
| 32 | + expect(emits).toBeTruthy() |
| 33 | + expect(emits![emits!.length - 1][0]).toBe('') |
| 34 | + }) |
| 35 | + |
| 36 | + it('preserves real multi-line content verbatim', async () => { |
| 37 | + const w = mount(SettingField, { props: { field: instrField, modelValue: '' } }) |
| 38 | + const ta = w.find('[data-test="setting-textarea-instructions"]') |
| 39 | + await ta.setValue('Use retrieve_tools first.\nThen call_tool_read.') |
| 40 | + const emits = w.emitted('update:modelValue') |
| 41 | + expect(emits![emits!.length - 1][0]).toBe('Use retrieve_tools first.\nThen call_tool_read.') |
| 42 | + }) |
| 43 | +}) |
| 44 | + |
| 45 | +describe('instructions field catalogue (MCP-2175)', () => { |
| 46 | + it('exposes an Advanced "mcp" accordion with an optional textarea instructions field', () => { |
| 47 | + const mcp = ADVANCED_ACCORDIONS.find((a) => a.id === 'mcp') |
| 48 | + expect(mcp, 'expected an Advanced accordion with id "mcp"').toBeTruthy() |
| 49 | + const f = mcp!.fields.find((x) => x.key === 'instructions') |
| 50 | + expect(f, 'expected an "instructions" field in the mcp accordion').toBeTruthy() |
| 51 | + expect(f!.control).toBe('textarea') |
| 52 | + expect(f!.optional).toBe(true) |
| 53 | + }) |
| 54 | + |
| 55 | + it('treats any blank/whitespace instructions value as valid', () => { |
| 56 | + const f: Field = { key: 'instructions', label: 'x', control: 'textarea', optional: true } |
| 57 | + expect(validateField(f, '')).toBeNull() |
| 58 | + expect(validateField(f, ' ')).toBeNull() |
| 59 | + expect(validateField(f, 'custom instructions text')).toBeNull() |
| 60 | + }) |
| 61 | +}) |
0 commit comments