import { formatHTML } from 'diffable-html-snapshot'
import { describe, expect, it } from 'vitest'
import {
katexRenderer,
mathjaxRenderer,
renderers,
setupTest,
temmlRenderer,
} from './testing.ts'
describe.each(Object.keys(renderers))('createMathInlineView (%s)', (name) => {
const renderer = renderers[name as keyof typeof renderers]
it('renders the math inline DOM structure', () => {
const { editor, n } = setupTest(renderer)
editor.set(n.doc(n.paragraph(n.mathInline('x^2'))))
const dom = editor.view.dom
const mathInline = dom.querySelector('.prosemirror-math-inline')
expect(mathInline).toBeTruthy()
expect(mathInline?.querySelector('.prosemirror-math-source')).toBeTruthy()
expect(mathInline?.querySelector('.prosemirror-math-display')).toBeTruthy()
})
it('uses span elements for inline math', () => {
const { editor, n } = setupTest(renderer)
editor.set(n.doc(n.paragraph(n.mathInline('x'))))
const mathInline = editor.view.dom.querySelector('.prosemirror-math-inline')
expect(mathInline?.tagName).toBe('SPAN')
})
})
describe('createMathInlineView (temml snapshot)', () => {
it('renders Temml output in the display element', () => {
const { editor, n } = setupTest(temmlRenderer)
editor.set(n.doc(n.paragraph(n.mathInline('x^2'))))
const display = editor.view.dom.querySelector('.prosemirror-math-display')
const html = formatHTML(display?.innerHTML || '')
expect(html).toMatchInlineSnapshot(`
"
"
`)
})
})
describe('createMathInlineView (katex snapshot)', () => {
it('renders KaTeX output in the display element', () => {
const { editor, n } = setupTest(katexRenderer)
editor.set(n.doc(n.paragraph(n.mathInline('x^2'))))
const display = editor.view.dom.querySelector('.prosemirror-math-display')
const html = formatHTML(display?.innerHTML || '')
expect(html).toMatchInlineSnapshot(`
"
x
2
"
`)
})
})
describe('createMathInlineView (mathjax snapshot)', () => {
it('renders MathJax output in the display element', () => {
const { editor, n } = setupTest(mathjaxRenderer)
editor.set(n.doc(n.paragraph(n.mathInline('x^2'))))
const display = editor.view.dom.querySelector('.prosemirror-math-display')
const html = formatHTML(display?.innerHTML || '')
expect(html).toMatchInlineSnapshot(`
"
"
`)
})
})