import {test, expect} from '../../fixtures/test' // rce_allowlist.json does not allow rel on , so the editor strips it on every // round-trip. What survives is whatever TinyMCE's link plugin re-adds, which is // noopener and only when target="_blank". These tests pin that, not preservation. test.describe('link rel attribute 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('rel is reduced to noopener on target="_blank" links', async ({page}) => { const content = await setAndGet( page, 'external', ) expect(content).toContain('external') expect(content).toMatch(/href="https:\/\/example\.com"/) expect(content).toMatch(/target="_blank"/) // The allowlist has no rel, so it is stripped; TinyMCE's link plugin then // re-adds noopener because target is _blank. noreferrer does not come back. expect(content).toMatch(/rel="noopener"/) }) test('rel="nofollow" on link is preserved', async ({page}) => { const content = await setAndGet( page, 'sponsored link', ) expect(content).toContain('sponsored link') expect(content).toMatch(/href="https:\/\/example\.com"/) }) test('link without rel attribute is preserved as-is', async ({page}) => { const content = await setAndGet(page, 'plain link') expect(content).toContain('plain link') expect(content).toMatch(/href="https:\/\/example\.com"/) }) test('link with rel and title together are both preserved', async ({page}) => { const content = await setAndGet( page, 'link text', ) expect(content).toContain('link text') expect(content).toMatch(/href="https:\/\/example\.com"/) }) test('internal anchor link has no rel requirement', async ({page}) => { const content = await setAndGet(page, 'Jump to section 2') expect(content).toContain('Jump to section 2') expect(content).toMatch(/href="#section-2"/) }) test('mailto link with rel attribute is preserved', async ({page}) => { const content = await setAndGet( page, 'Email support', ) expect(content).toContain('Email support') expect(content).toContain('mailto:help@example.com') }) test('target="_blank" without rel still preserves both', async ({page}) => { const content = await setAndGet( page, 'Canvas', ) expect(content).toContain('Canvas') expect(content).toMatch(/target="_blank"/) }) })