Files
summercms/admin/tests/form/insertImage.test.ts

33 lines
1.2 KiB
TypeScript

import { describe, expect, it } from 'vitest'
import { insertImage } from '../../src/components/mail/insertImage'
describe('insertImage (UI-SPEC C4)', () => {
it.each([
[
'markdown',
'https://cdn.example.com/a b(c).png',
'Logo [x]',
'![Logo \\[x\\]](https://cdn.example.com/a%20b%28c%29.png)',
],
[
'html',
'https://cdn.example.com/a"b.png',
'a "b" <c>',
'<img src="https://cdn.example.com/a&quot;b.png" alt="a &quot;b&quot; &lt;c&gt;">',
],
['css', 'https://cdn.example.com/a.png', 'ignored', 'url("https://cdn.example.com/a.png")'],
['text', 'https://cdn.example.com/a.png', 'ignored', 'https://cdn.example.com/a.png'],
] as const)('builds %s snippets with escaping', (language, url, alt, want) => {
expect(insertImage(language, url, alt)).toBe(want)
})
it('handles empty alt and parentheses in markdown URLs', () => {
expect(insertImage('markdown', 'https://cdn.example.com/x(y).png', '')).toBe(
'![](https://cdn.example.com/x%28y%29.png)',
)
expect(insertImage('html', 'https://cdn.example.com/x.png', '')).toBe(
'<img src="https://cdn.example.com/x.png" alt="">',
)
})
})