import {test, expect} from '../../fixtures/test' // Images in canvas-rce course content require accurate src and alt attribute // preservation. Alt text is a legal accessibility requirement (WCAG 2.1 AA). // canvas-rce must not strip src, alt, or other safe img attributes. test.describe('image element handling', () => { test.beforeEach(async ({page, rcePage}) => { await page.goto('/scenarios/basic') await rcePage.waitForEditor() }) async function setAndGet(page: any, html: string): Promise { return page.evaluate((content: string) => { // @ts-expect-error -- TinyMCE global window.tinymce.activeEditor.setContent(content) // @ts-expect-error -- TinyMCE global return window.tinymce.activeEditor.getContent() }, html) } test(' with alt text preserves alt attribute', async ({page}) => { const content = await setAndGet( page, 'A mountain landscape at sunset', ) if (content.includes(' with empty alt (decorative) preserves alt=""', async ({page}) => { const content = await setAndGet(page, '') if (content.includes(' src attribute is preserved', async ({page}) => { const src = 'https://example.com/image.png' const content = await setAndGet(page, `test image`) if (content.includes(' width and height attributes are preserved', async ({page}) => { const content = await setAndGet( page, 'sized', ) if (content.includes(' with data-canvas-id attribute for media tracking', async ({page}) => { const content = await setAndGet( page, 'media', ) if (content.includes(' inside a
with
', async ({page}) => { const content = await setAndGet( page, '
Bar chart showing quarterly sales
Q1-Q4 Sales Data
', ) expect(content).toContain('Q1-Q4 Sales Data') }) test(' with long alt text is preserved in full', async ({page}) => { const longAlt = 'Detailed diagram showing the water cycle including evaporation from the ocean surface, cloud formation through condensation, precipitation as rain or snow, and runoff back to the ocean' const content = await setAndGet( page, `${longAlt}`, ) if (content.includes(' inline with text paragraph is preserved', async ({page}) => { const content = await setAndGet( page, '

See the diagram: inline diagram above for reference.

', ) expect(content).toContain('See the diagram') expect(content).toContain('above for reference') }) test('javascript: in img src is stripped', async ({page}) => { const content = await setAndGet( page, 'xss', ) expect(content).not.toContain('javascript:alert') }) test(' with title attribute is preserved', async ({page}) => { const content = await setAndGet( page, 'campus', ) if (content.includes('