import {test, expect} from '../../fixtures/test' // Word count must work correctly across structured content. A naive implementation // that only counts plain text would miss words in tables, lists, or formatted elements. test.describe('word count — edge cases', () => { test.beforeEach(async ({page, rcePage}) => { await page.goto('/scenarios/basic') await rcePage.waitForEditor() }) async function getWordCount(page: any): Promise { const text = await page.locator('[data-testid="status-bar-word-count"]').textContent() const match = text?.match(/(\d+)/) return match ? parseInt(match[1], 10) : 0 } test('words inside a table are counted', async ({page, rcePage}) => { await page.evaluate(() => { // @ts-expect-error -- TinyMCE global window.tinymce.activeEditor.setContent( '
alpha betagamma delta
', ) }) await page.waitForTimeout(500) const count = await getWordCount(page) // 4 words: alpha, beta, gamma, delta expect(count).toBeGreaterThanOrEqual(4) }) test('words inside a list are counted', async ({page, rcePage}) => { await page.evaluate(() => { // @ts-expect-error -- TinyMCE global window.tinymce.activeEditor.setContent( '', ) }) await page.waitForTimeout(500) const count = await getWordCount(page) // 5 words: first, item, second, item, third expect(count).toBeGreaterThanOrEqual(5) }) test('words inside a heading are counted', async ({page, rcePage}) => { await page.evaluate(() => { // @ts-expect-error -- TinyMCE global window.tinymce.activeEditor.setContent('

Main Title Here

body

') }) await page.waitForTimeout(500) const count = await getWordCount(page) // 4 words: Main, Title, Here, body expect(count).toBeGreaterThanOrEqual(4) }) test('words in bold/italic formatting are counted', async ({page, rcePage}) => { await page.evaluate(() => { // @ts-expect-error -- TinyMCE global window.tinymce.activeEditor.setContent( '

bold word and italic word

', ) }) await page.waitForTimeout(500) const count = await getWordCount(page) // 4 words: bold, word, and, italic, word = 5 (or 4 if "and" not counted — be lenient) expect(count).toBeGreaterThanOrEqual(4) }) test('word count decreases after deleting words', async ({page, rcePage}) => { await page.evaluate(() => { // @ts-expect-error -- TinyMCE global window.tinymce.activeEditor.setContent('

one two three four five

') }) await page.waitForTimeout(500) const before = await getWordCount(page) // Select all and replace with fewer words await page.evaluate(() => { // @ts-expect-error -- TinyMCE global window.tinymce.activeEditor.setContent('

one two

') }) await page.waitForTimeout(500) const after = await getWordCount(page) expect(after).toBeLessThan(before) expect(after).toBe(2) }) test('hyphenated words are counted consistently', async ({page, rcePage}) => { await page.evaluate(() => { // @ts-expect-error -- TinyMCE global window.tinymce.activeEditor.setContent('

well-known fact

') }) await page.waitForTimeout(500) const count = await getWordCount(page) // Either 2 (hyphen = compound word) or 3 (hyphen splits), both are acceptable expect(count).toBeGreaterThanOrEqual(2) expect(count).toBeLessThanOrEqual(3) }) })