import {test, expect} from '../../fixtures/test' // Repeated setContent calls simulate real-world usage: autosave loading a draft, // a user switching between content templates, or a test harness resetting state. // Each call must fully replace prior content with no bleed-through or corruption. test.describe('rapid and repeated setContent calls', () => { test.beforeEach(async ({page, rcePage}) => { await page.goto('/scenarios/basic') await rcePage.waitForEditor() }) test('second setContent fully replaces first content', async ({page}) => { const result = await page.evaluate(() => { // @ts-expect-error -- TinyMCE global const ed = window.tinymce.activeEditor ed.setContent('
Original content
') ed.setContent('Replacement content
') return ed.getContent() }) expect(result).toContain('Replacement content') expect(result).not.toContain('Original content') }) test('ten sequential setContent calls leave only the last content', async ({page}) => { const result = await page.evaluate(() => { // @ts-expect-error -- TinyMCE global const ed = window.tinymce.activeEditor for (let i = 1; i <= 10; i++) { ed.setContent(`Content version ${i}
`) } return ed.getContent() }) expect(result).toContain('Content version 10') expect(result).not.toContain('Content version 9') expect(result).not.toContain('Content version 5') }) test('setContent with empty string followed by real content works', async ({page}) => { const result = await page.evaluate(() => { // @ts-expect-error -- TinyMCE global const ed = window.tinymce.activeEditor ed.setContent('') ed.setContent('Content after empty reset
') return ed.getContent() }) expect(result).toContain('Content after empty reset') }) test('setContent alternating between rich and plain content is stable', async ({page}) => { const result = await page.evaluate(() => { // @ts-expect-error -- TinyMCE global const ed = window.tinymce.activeEditor ed.setContent('Plain paragraph
') ed.setContent('Body text
') return ed.getContent() }) expect(result).toContain('Heading') expect(result).toContain('Body text') expect(result).not.toContain('List item') expect(result).not.toContain('Plain paragraph') }) test('setContent with table followed by setContent with paragraph is clean', async ({page}) => { const result = await page.evaluate(() => { // @ts-expect-error -- TinyMCE global const ed = window.tinymce.activeEditor ed.setContent('| Table cell |
Just a paragraph now
') return ed.getContent() }) expect(result).toContain('Just a paragraph now') expect(result).not.toContain('Table cell') expect(result).not.toContain('