import {test, expect} from '../../fixtures/test'
//
is the WCAG-recommended way to label a table for screen readers.
// Course content with data tables should use captions for accessibility.
// canvas-rce must preserve during serialization — stripping it
// removes the accessible table name and breaks screen reader navigation.
test.describe('table caption element', () => {
test.beforeEach(async ({page, rcePage}) => {
await page.goto('/scenarios/basic')
await rcePage.waitForEditor()
})
async function setAndGet(page: any, html: string): Promise {
return page.evaluate((content: string) => {
// @ts-expect-error -- TinyMCE global
window.tinymce.activeEditor.setContent(content)
// @ts-expect-error -- TinyMCE global
return window.tinymce.activeEditor.getContent()
}, html)
}
test(' text is preserved in output', async ({page}) => {
const content = await setAndGet(
page,
'',
)
expect(content).toContain('Student Grades')
expect(content).toContain('Alice')
})
test(' element tag is preserved (not demoted to p)', async ({page}) => {
const content = await setAndGet(
page,
'',
)
expect(content).toContain('Quarterly Revenue')
// Caption should appear as , not just a floating
if (content.includes('
]*>Quarterly Revenue<\/caption>/)
}
})
test('table with caption and thead/tbody structure is fully preserved', async ({page}) => {
const content = await setAndGet(
page,
`
Exam Schedule
| Subject | Date | Room |
| Math | June 10 | 101 |
| English | June 12 | 202 |
`,
)
expect(content).toContain('Exam Schedule')
expect(content).toContain('Subject')
expect(content).toContain('Math')
expect(content).toContain('English')
})
test(' with formatted text inside is preserved', async ({page}) => {
const content = await setAndGet(
page,
'Important: Grade Distribution| A | 90-100 |
',
)
expect(content).toContain('Grade Distribution')
expect(content).toContain('A')
expect(content).toContain('90-100')
})
test('multiple tables each with their own caption are independent', async ({page}) => {
const content = await setAndGet(
page,
`
`,
)
expect(content).toContain('Table One')
expect(content).toContain('Table Two')
expect(content).toContain('data 1')
expect(content).toContain('data 2')
})
})