From 3e29e6042ea98ce167a664c1420b79613376d050 Mon Sep 17 00:00:00 2001 From: Jakub Zych Date: Fri, 13 Nov 2026 13:29:09 +0100 Subject: [PATCH] test(35-03): add failing tests for insertImage and colorpicker - insertImage C4 table expects escaped markdown/html/css/text snippets - ColorPickerField sync cases; stubs return empty until GREEN Co-authored-by: Cursor --- .../form/fields/ColorPickerField.vue | 11 +++++ admin/src/components/mail/insertImage.ts | 7 +++ admin/tests/form/mail-smoke.test.ts | 48 +++++++++++++++++++ 3 files changed, 66 insertions(+) create mode 100644 admin/src/components/form/fields/ColorPickerField.vue create mode 100644 admin/src/components/mail/insertImage.ts diff --git a/admin/src/components/form/fields/ColorPickerField.vue b/admin/src/components/form/fields/ColorPickerField.vue new file mode 100644 index 00000000..4ddf3043 --- /dev/null +++ b/admin/src/components/form/fields/ColorPickerField.vue @@ -0,0 +1,11 @@ + + + diff --git a/admin/src/components/mail/insertImage.ts b/admin/src/components/mail/insertImage.ts new file mode 100644 index 00000000..0f8f1a71 --- /dev/null +++ b/admin/src/components/mail/insertImage.ts @@ -0,0 +1,7 @@ +// Stub for TDD RED (35-03 Task 5): real escaping lands in GREEN. +export type InsertImageLanguage = 'markdown' | 'html' | 'css' | 'text' + +/** Builds the snippet inserted into a mail body or code editor. */ +export function insertImage(_language: InsertImageLanguage, _url: string, _alt: string): string { + return '' +} diff --git a/admin/tests/form/mail-smoke.test.ts b/admin/tests/form/mail-smoke.test.ts index 38420022..69d4dac4 100644 --- a/admin/tests/form/mail-smoke.test.ts +++ b/admin/tests/form/mail-smoke.test.ts @@ -280,6 +280,54 @@ describe('CodeEditorField loading and fallback', () => { }) }) +describe('insertImage', () => { + it('escapes markdown, html, css and text snippets per UI-SPEC C4', async () => { + const { insertImage } = await import('../../src/components/mail/insertImage') + expect(insertImage('markdown', 'https://cdn.example.com/a b.png', 'Logo [x]')).toBe( + '![Logo \\[x\\]](https://cdn.example.com/a%20b.png)', + ) + expect(insertImage('html', 'https://cdn.example.com/a"b.png', 'a "b" ')).toBe( + 'a "b" <c>', + ) + expect(insertImage('css', 'https://cdn.example.com/a.png', 'ignored')).toBe( + 'url("https://cdn.example.com/a.png")', + ) + expect(insertImage('text', 'https://cdn.example.com/a.png', 'ignored')).toBe( + 'https://cdn.example.com/a.png', + ) + }) +}) + +describe('ColorPickerField', () => { + it('syncs a typed #rrggbb into the swatch and keeps the last valid on partial', async () => { + const Field = (await import('../../src/components/form/fields/ColorPickerField.vue')).default + setBundle( + { + ...mailPreviewBundle, + 'backend::lang.colorpicker.pick': { other: 'Pick a colour for “:field”' }, + 'backend::lang.colorpicker.not_set': { other: 'Not set' }, + }, + 'en', + ) + const wrapper = mount(Field, { + props: { + field: { name: 'body_bg', label: 'Body background', type: 'colorpicker' } as FormField, + modelValue: '', + controlId: 'f-color', + }, + attachTo: document.body, + }) + const text = wrapper.find('input[type="text"]') + const swatch = wrapper.find('input[type="color"]') + expect(swatch.element.value).toBe('#ffffff') + await text.setValue('#D66829') + expect(wrapper.emitted('update:modelValue')?.at(-1)).toEqual(['#D66829']) + expect(swatch.element.value.toLowerCase()).toBe('#d66829') + await text.setValue('#D66') + expect(swatch.element.value.toLowerCase()).toBe('#d66829') + }) +}) + // Last in the file: it replaces the editor chunk for the rest of the run. describe('CodeEditorField chunk failure', () => { afterEach(() => {