33 lines
1.2 KiB
TypeScript
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"b.png" alt="a "b" <c>">',
|
|
],
|
|
['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(
|
|
'',
|
|
)
|
|
expect(insertImage('html', 'https://cdn.example.com/x.png', '')).toBe(
|
|
'<img src="https://cdn.example.com/x.png" alt="">',
|
|
)
|
|
})
|
|
})
|