Automerge backed Markdown editor for the Atmosphere
Something went wrong. Try again.
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102/** * Tests for renderMath and finishRenderMath stub functions. * * These are stubs for Obsidian API compatibility. MathJax is not bundled * in Reams, so: * - renderMath returns a placeholder element with the raw LaTeX source * - finishRenderMath is a no-op that immediately resolves * * Plugins that call these functions will not crash, but actual math * rendering is not supported. */
import { describe, it, expect, vi, beforeEach } from 'vitest'import { renderMath, finishRenderMath, _resetWarnedStubs } from '../obsidian-stubs'
beforeEach(() => { _resetWarnedStubs() vi.restoreAllMocks()})
describe('renderMath', () => { it('returns an HTMLElement with the source as text content', () => { vi.spyOn(console, 'warn').mockImplementation(() => {})
const el = renderMath('x^2 + y^2 = z^2', false)
expect(el).toBeInstanceOf(HTMLElement) expect(el.textContent).toBe('x^2 + y^2 = z^2') })
it('returns a <span> for inline math (display=false)', () => { vi.spyOn(console, 'warn').mockImplementation(() => {})
const el = renderMath('E = mc^2', false)
expect(el.tagName).toBe('SPAN') expect(el.classList.contains('math')).toBe(true) expect(el.classList.contains('math-inline')).toBe(true) })
it('returns a <div> for display math (display=true)', () => { vi.spyOn(console, 'warn').mockImplementation(() => {})
const el = renderMath('\\int_0^\\infty e^{-x^2} dx', true)
expect(el.tagName).toBe('DIV') expect(el.classList.contains('math')).toBe(true) expect(el.classList.contains('math-block')).toBe(true) })
it('emits a console.warn on first call', () => { const warnSpy = vi.spyOn(console, 'warn').mockImplementation(() => {})
renderMath('x', false)
expect(warnSpy).toHaveBeenCalledOnce() expect(warnSpy).toHaveBeenCalledWith( expect.stringContaining('[Reams] renderMath') ) })
it('emits console.warn only once per page-load (warn-once)', () => { const warnSpy = vi.spyOn(console, 'warn').mockImplementation(() => {})
renderMath('a', false) renderMath('b', true) renderMath('c', false)
expect(warnSpy).toHaveBeenCalledOnce() })
it('handles empty source string', () => { vi.spyOn(console, 'warn').mockImplementation(() => {})
const el = renderMath('', false)
expect(el.textContent).toBe('') })})
describe('finishRenderMath', () => { it('returns a resolved Promise<void>', async () => { const result = await finishRenderMath() expect(result).toBeUndefined() })
it('does not emit a warning (no-op)', async () => { const warnSpy = vi.spyOn(console, 'warn').mockImplementation(() => {})
await finishRenderMath()
// finishRenderMath should not warn - renderMath already warns expect(warnSpy).not.toHaveBeenCalled() })
it('can be called multiple times without error', async () => { expect(await finishRenderMath()).toBeUndefined() expect(await finishRenderMath()).toBeUndefined() expect(await finishRenderMath()).toBeUndefined() })})