import {test, expect} from '../../fixtures/test' // getContent({format: 'text'}) strips all HTML tags and returns plain text. // Canvas uses this for word count, character limits, and content previews. // It must return actual readable text — not tag noise, not empty string. test.describe('getContent with text format', () => { test.beforeEach(async ({page, rcePage}) => { await page.goto('/scenarios/basic') await rcePage.waitForEditor() }) test('getContent text strips HTML tags from bold text', async ({page}) => { const result = await page.evaluate(() => { // @ts-expect-error -- TinyMCE global const ed = window.tinymce.activeEditor ed.setContent('
bold text
') return ed.getContent({format: 'text'}) }) expect(result).toContain('bold text') expect(result).not.toContain('') expect(result).not.toContain('') }) test('getContent text preserves words from a list', async ({page}) => { const result = await page.evaluate(() => { // @ts-expect-error -- TinyMCE global const ed = window.tinymce.activeEditor ed.setContent('
| Cell A | Cell B |
Welcome to the course.
') return ed.getContent({format: 'text'}) }) expect(result).toContain('Course Introduction') expect(result).toContain('Welcome to the course') expect(result).not.toContain('Visit our website for more.
') return ed.getContent({format: 'text'}) }) expect(result).toContain('our website') expect(result).toContain('for more') // href should not appear in plain text output expect(result).not.toContain('https://example.com') expect(result).not.toContain(' { const results = await page.evaluate(() => { // @ts-expect-error -- TinyMCE global const ed = window.tinymce.activeEditor ed.setContent('italic word
') return { html: ed.getContent({format: 'html'}), text: ed.getContent({format: 'text'}), } }) expect(results.html).toMatch(/italic<\/em>/) expect(results.text).toContain('italic') expect(results.text).not.toContain('') expect(results.html).not.toBe(results.text) }) test('getContent text word count matches visible words', async ({page}) => { const result = await page.evaluate(() => { // @ts-expect-error -- TinyMCE global const ed = window.tinymce.activeEditor ed.setContent('one two three four five
') return ed.getContent({format: 'text'}) }) const words = result.trim().split(/\s+/).filter(Boolean) expect(words.length).toBe(5) }) })