import {test, expect} from '../../fixtures/test' // Linked images () are common in course content — clicking // a diagram opens a full-size version, or an image links to an external resource. // Both the img attributes (src, alt) and the link href must survive serialization. test.describe('linked images (anchor wrapping img)', () => { 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('image wrapped in link preserves href and src', async ({page}) => { const content = await setAndGet( page, 'diagram thumbnail', ) if (content.includes(' { const content = await setAndGet( page, 'preview image', ) expect(content).toContain('example.com/detail.png') if (content.includes('target')) { expect(content).toMatch(/target="_blank"/) } }) test('linked image with title on both anchor and img', async ({page}) => { const content = await setAndGet( page, 'campus photo', ) expect(content).toContain('example.com/photo.jpg') }) test('linked image inside a paragraph with surrounding text', async ({page}) => { const content = await setAndGet( page, '

See the diagram: architecture diagram for reference.

', ) expect(content).toContain('See the diagram') expect(content).toContain('for reference') expect(content).toContain('example.com/diagram.png') }) test('linked image inside a figure with caption', async ({page}) => { const content = await setAndGet( page, '
lab equipment
Lab equipment overview
', ) expect(content).toContain('Lab equipment overview') expect(content).toContain('example.com/full.jpg') }) test('linked image with javascript: href is sanitized', async ({page}) => { const content = await setAndGet( page, 'click me', ) expect(content).not.toContain('javascript:') }) test('multiple linked images in sequence all preserve their hrefs', async ({page}) => { const content = await setAndGet( page, `image A image B`, ) expect(content).toContain('example.com/a.jpg') expect(content).toContain('example.com/b.jpg') }) })