import {test, expect} from '../../fixtures/test' //
 is the standard HTML pattern for code blocks. The outer 
// preserves whitespace; the inner  marks it as code.
// language-* classes (from Prism, highlight.js) indicate the syntax language.
// Canvas CS courses and tutorials use this pattern extensively.
test.describe('
 code block patterns', () => {
  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('
 block preserves code text', async ({page}) => {
    const content = await setAndGet(
      page,
      '
function hello() {\n  return "world";\n}
', ) expect(content).toContain('function hello') expect(content).toContain('return') expect(content).toContain('world') }) test('language class on is preserved', async ({page}) => { const content = await setAndGet( page, '
def greet(name):\n    return f"Hello {name}"
', ) expect(content).toContain('def greet') expect(content).toContain('Hello') }) test('language class on
 is preserved', async ({page}) => {
    const content = await setAndGet(
      page,
      '
const x = 42;
', ) expect(content).toContain('const x = 42') }) test('
 with special characters preserved', async ({page}) => {
    const content = await setAndGet(
      page,
      '
if (a < b && c > 0) { doSomething(); }
', ) expect(content).toContain('doSomething') }) test('paragraph before and after code block all preserved', async ({page}) => { const content = await setAndGet( page, '

Example code:

print("Hello World")

End of example.

', ) expect(content).toContain('Example code') expect(content).toContain('Hello World') expect(content).toContain('End of example') }) test('
 with inline comments preserved', async ({page}) => {
    const content = await setAndGet(
      page,
      '
// Calculate sum\nlet sum = a + b; // result
', ) expect(content).toContain('Calculate sum') expect(content).toContain('let sum') }) test('multiple code blocks in sequence all preserved', async ({page}) => { const content = await setAndGet( page, '
Block one code
Block two code
', ) expect(content).toContain('Block one code') expect(content).toContain('Block two code') }) })