import {test, expect} from '../../fixtures/test' // TinyMCE's getContent({format: 'text'}) strips all HTML tags and returns plain // text. This is used for character counting and accessibility announcements. // canvas-rce refactors must not break this format option. test.describe('getContent — text format', () => { test.beforeEach(async ({page, rcePage}) => { await page.goto('/scenarios/basic') await rcePage.waitForEditor() }) async function getTextContent(page: any): Promise { return page.evaluate(() => { // @ts-expect-error -- TinyMCE global return window.tinymce.activeEditor.getContent({format: 'text'}) }) } test('plain text content returns without HTML tags', async ({page, rcePage}) => { await page.evaluate(() => { // @ts-expect-error -- TinyMCE global window.tinymce.activeEditor.setContent('

hello world

') }) const text = await getTextContent(page) expect(text).toContain('hello world') expect(text).not.toContain('

') expect(text).not.toContain('

') }) test('bold text content strips tags', async ({page, rcePage}) => { await page.evaluate(() => { // @ts-expect-error -- TinyMCE global window.tinymce.activeEditor.setContent('

bold text

') }) const text = await getTextContent(page) expect(text).toContain('bold text') expect(text).not.toContain('') }) test('table content returns cell text in text format', async ({page, rcePage}) => { await page.evaluate(() => { // @ts-expect-error -- TinyMCE global window.tinymce.activeEditor.setContent( '
cell onecell two
', ) }) const text = await getTextContent(page) expect(text).toContain('cell one') expect(text).toContain('cell two') expect(text).not.toContain('') expect(text).not.toContain('
') }) test('heading text is returned without heading tags', async ({page, rcePage}) => { await page.evaluate(() => { // @ts-expect-error -- TinyMCE global window.tinymce.activeEditor.setContent('

Chapter Title

body text

') }) const text = await getTextContent(page) expect(text).toContain('Chapter Title') expect(text).toContain('body text') expect(text).not.toContain('

') }) test('list items are returned as text without list markup', async ({page, rcePage}) => { await page.evaluate(() => { // @ts-expect-error -- TinyMCE global window.tinymce.activeEditor.setContent('
  • item one
  • item two
') }) const text = await getTextContent(page) expect(text).toContain('item one') expect(text).toContain('item two') expect(text).not.toContain('
    ') expect(text).not.toContain('
  • ') }) test('text format word count matches visual word count', async ({page, rcePage}) => { await page.evaluate(() => { // @ts-expect-error -- TinyMCE global window.tinymce.activeEditor.setContent('

    one two three

    ') }) await page.waitForTimeout(500) const text = await getTextContent(page) const words = text.trim().split(/\s+/).filter(Boolean) expect(words.length).toBe(3) }) })