import {test, expect} from '../../fixtures/test'
// List items in course content commonly contain inline formatting — bold terms,
// italic emphasis, links, and code. canvas-rce must preserve formatting inside
//
elements; stripping it flattens semantically rich content.
test.describe('inline formatting inside list items', () => {
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('bold text inside list item is preserved', async ({page}) => {
const content = await setAndGet(
page,
'- Key term: definition follows
- Normal item
',
)
expect(content).toMatch(/Key term<\/strong>/)
expect(content).toContain('definition follows')
expect(content).toContain('Normal item')
})
test('italic text inside list item is preserved', async ({page}) => {
const content = await setAndGet(page, '- Read Chapter 3 before class
')
expect(content).toMatch(/Chapter 3<\/em>/)
expect(content).toContain('before class')
})
test('link inside list item is preserved', async ({page}) => {
const content = await setAndGet(
page,
'',
)
expect(content).toContain('Canvas')
expect(content).toMatch(/href="https:\/\/canvas\.instructure\.com"/)
expect(content).toContain('to submit')
})
test('code inline inside list item is preserved', async ({page}) => {
const content = await setAndGet(
page,
'- Run
npm install first - Then run
npm test
',
)
expect(content).toContain('npm install')
expect(content).toContain('npm test')
expect(content).toContain('first')
})
test('multiple formatting types in the same list item', async ({page}) => {
const content = await setAndGet(
page,
'- Important: review the highlighted sections and section 3
',
)
expect(content).toMatch(/Important:<\/strong>/)
expect(content).toMatch(/highlighted<\/em>/)
expect(content).toContain('section 3')
})
test('ordered list items with numbered content preserve formatting', async ({page}) => {
const content = await setAndGet(
page,
'- Step 1: Open the editor
- Step 2: Type content
- Step 3: Save
',
)
expect(content).toMatch(/Step 1:<\/strong>/)
expect(content).toMatch(/Step 2:<\/strong>/)
expect(content).toMatch(/Step 3:<\/strong>/)
expect(content).toMatch(/ {
const content = await setAndGet(
page,
'',
)
expect(content).toContain('Resource 1')
expect(content).toContain('Resource 2')
expect(content).toMatch(/href="https:\/\/example\.com\/resource-1"/)
expect(content).toMatch(/href="https:\/\/example\.com\/resource-2"/)
})
test('superscript inside list item is preserved', async ({page}) => {
const content = await setAndGet(
page,
'- Formula: E = mc2
- Area = πr2
',
)
expect(content).toContain('E = mc')
expect(content).toContain('Area')
expect(content).toMatch(/2<\/sup>/)
})
})