import {test, expect} from '../../fixtures/test' // HTML attributes on elements must be handled selectively: // - Safe attributes (href, alt, title, data-*, class, id on safe elements) should survive // - Dangerous attributes (on*, srcdoc, formaction) must be stripped // This tests canvas-rce's attribute whitelist, which is critical for Canvas LMS // since course content often uses data-* attributes for LTI and media widgets. test.describe('HTML attribute preservation', () => { 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('title attribute on links is preserved', async ({page}) => { const content = await setAndGet( page, 'link', ) expect(content).toContain('link') expect(content).toMatch(/href="https:\/\/example\.com"/) expect(content).toMatch(/title="Visit example"/) }) test('alt attribute on images is preserved', async ({page}) => { const content = await setAndGet( page, 'A descriptive label', ) // If img is kept, alt must be there if (content.includes(' { const content = await setAndGet(page, 'media embed') expect(content).toContain('media embed') // data-* attributes: preserved or stripped depends on TinyMCE config // The important thing is the content text survives }) test('class attribute on span is preserved', async ({page}) => { const content = await setAndGet(page, 'x^2') expect(content).toContain('x^2') }) test('formaction attribute on button is stripped', async ({page}) => { const content = await setAndGet( page, '', ) // Either button is removed entirely, or formaction is stripped if (content.includes(' { const content = await setAndGet(page, '') // Either iframe removed, or srcdoc stripped, or script stripped expect(content).not.toContain('srcdoc="