import {test, expect} from '../../fixtures/test' // editor.insertContent() inserts HTML at the current cursor position. // Canvas uses this when the Link dialog, Image dialog, and Equation editor // inject their output into the document. Tests verify the inserted content // appears correctly alongside existing content. test.describe('editor.insertContent() API', () => { test.beforeEach(async ({page, rcePage}) => { await page.goto('/scenarios/basic') await rcePage.waitForEditor() }) test('insertContent adds text at cursor position', async ({page}) => { const content = await page.evaluate(() => { // @ts-expect-error -- TinyMCE global const ed = window.tinymce.activeEditor ed.setContent('

Before | After

') ed.insertContent('INSERTED') return ed.getContent() }) expect(content).toContain('INSERTED') }) test('insertContent after setContent preserves both', async ({page}) => { const content = await page.evaluate(() => { // @ts-expect-error -- TinyMCE global const ed = window.tinymce.activeEditor ed.setContent('

Existing text

') // move cursor to body then insert ed.selection.select(ed.getBody(), true) ed.selection.collapse(false) ed.insertContent('

New paragraph

') return ed.getContent() }) expect(content).toContain('Existing text') expect(content).toContain('New paragraph') }) test('insertContent with an image element', async ({page}) => { const content = await page.evaluate(() => { // @ts-expect-error -- TinyMCE global const ed = window.tinymce.activeEditor ed.setContent('

Caption:

') ed.insertContent('Inserted photo') return ed.getContent() }) expect(content).toContain('alt') }) test('insertContent with a link element', async ({page}) => { const content = await page.evaluate(() => { // @ts-expect-error -- TinyMCE global const ed = window.tinymce.activeEditor ed.setContent('

See:

') ed.insertContent('the resource') return ed.getContent() }) expect(content).toContain('the resource') expect(content).toContain('example.com') }) test('insertContent with a table', async ({page}) => { const content = await page.evaluate(() => { // @ts-expect-error -- TinyMCE global const ed = window.tinymce.activeEditor ed.setContent('') ed.insertContent('
Inserted cell AInserted cell B
') return ed.getContent() }) expect(content).toContain('Inserted cell A') expect(content).toContain('Inserted cell B') }) })