import {test, expect} from '../../fixtures/test' // Headings with id attributes create named anchors for in-page navigation. // Instructors use these with #hash links to build course page tables of contents. // canvas-rce must preserve id attributes on heading elements — stripping them // breaks every internal anchor link in the document. test.describe('heading anchor IDs', () => { 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('id attribute on h2 is preserved', async ({page}) => { const content = await setAndGet(page, '

Overview

') expect(content).toContain('Overview') expect(content).toMatch(/

{ const content = await setAndGet(page, '

Learning Objectives

') expect(content).toContain('Learning Objectives') expect(content).toMatch(/id="learning-objectives"/) }) test('multiple headings with different ids are all preserved', async ({page}) => { const content = await setAndGet( page, `

Part One

Introduction text.

Part Two

Body text.

Part Three

`, ) expect(content).toContain('Part One') expect(content).toContain('Part Two') expect(content).toContain('Part Three') expect(content).toMatch(/id="part-one"/) expect(content).toMatch(/id="part-two"/) expect(content).toMatch(/id="part-three"/) }) test('anchor link pointing to heading id works end-to-end', async ({page}) => { const content = await setAndGet( page, '

References

See References section above.

', ) expect(content).toContain('References') expect(content).toMatch(/id="references"/) expect(content).toMatch(/href="#references"/) expect(content).toContain('References section') }) test('heading with id and class together are both preserved', async ({page}) => { const content = await setAndGet(page, '

Introduction

') expect(content).toContain('Introduction') expect(content).toMatch(/id="intro"/) }) test('h1 through h4 all preserve id attribute', async ({page}) => { const content = await setAndGet( page, `

Title

Section

Subsection

Detail

`, ) expect(content).toMatch(/id="h1-anchor"/) expect(content).toMatch(/id="h2-anchor"/) expect(content).toMatch(/id="h3-anchor"/) expect(content).toMatch(/id="h4-anchor"/) }) test('kebab-case and underscore ids are preserved as-is', async ({page}) => { const content = await setAndGet(page, '

Module 3 — Week 2

') expect(content).toMatch(/id="module_3-week_2"/) expect(content).toContain('Module 3') }) })