import {test, expect} from '../../fixtures/test' //
elements must preserve internal whitespace — indentation, multiple
// spaces, and newlines. TinyMCE and canvas-rce must not collapse whitespace
// inside during serialization, which would corrupt code examples.
test.describe('preformatted text whitespace preservation', () => {
test.beforeEach(async ({page, rcePage}) => {
await page.goto('/scenarios/basic')
await rcePage.waitForEditor()
})
test(' with indentation preserves leading spaces', async ({page, rcePage}) => {
await page.evaluate(() => {
// @ts-expect-error -- TinyMCE global
window.tinymce.activeEditor.setContent(' indented code
')
})
const content = await rcePage.getContent()
expect(content).toMatch(/ with multiple lines preserves line structure', async ({page, rcePage}) => {
await page.evaluate(() => {
// @ts-expect-error -- TinyMCE global
window.tinymce.activeEditor.setContent('line one\nline two\nline three
')
})
const content = await rcePage.getContent()
expect(content).toMatch(/ content with code syntax is preserved', async ({page, rcePage}) => {
const codeSnippet = 'function hello() {\n return "world";\n}'
await page.evaluate((code: string) => {
// @ts-expect-error -- TinyMCE global
window.tinymce.activeEditor.setContent(`${code}`)
}, codeSnippet)
const content = await rcePage.getContent()
expect(content).toContain('function hello')
expect(content).toContain('return')
expect(content).toMatch(/ wrapper', async ({page, rcePage}) => {
await page.evaluate(() => {
// @ts-expect-error -- TinyMCE global
window.tinymce.activeEditor.setContent('some code
')
})
await rcePage.contentFrame().locator('body').click()
await rcePage.contentFrame().locator('body').press('Control+a')
// Switch to paragraph via Blocks menu
await page.locator('.tox-tbtn--bespoke[aria-label="Blocks"]').click()
await page.locator('.tox-collection__item:has-text("Paragraph")').click()
const content = await rcePage.getContent()
expect(content).not.toMatch(/ element is not stripped by the sanitization pipeline', async ({page, rcePage}) => {
await page.evaluate(() => {
// @ts-expect-error -- TinyMCE global
window.tinymce.activeEditor.insertContent('safe code block
')
})
const content = await rcePage.getContent()
expect(content).toMatch(/