The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
test(desktop): prove file-preview math renders to KaTeX
Topher Ross0fa1212c97f5
diff --git a/apps/desktop/src/lib/file-preview-math.render.test.tsx b/apps/desktop/src/lib/file-preview-math.render.test.tsxnew file mode 100644index 00000000000..4d444551bbb--- /dev/null+++ b/apps/desktop/src/lib/file-preview-math.render.test.tsx@@ -0,0 +1,64 @@+import { render, waitFor } from '@testing-library/react'+import { describe, expect, it } from 'vitest'+import { Streamdown } from 'streamdown'++import { createMemoizedMathPlugin } from '@/lib/katex-memo'+import { normalizeFilePreviewMath } from '@/lib/markdown-preprocess'++// This is the exact pipeline the file preview runs: normalizeFilePreviewMath+// → Streamdown with the memoized math plugin. Rendering here (jsdom) proves the+// wiring produces KaTeX output, not raw `$..$` source text.+describe('file-preview math rendering', () => {+ const mathPlugin = createMemoizedMathPlugin({ singleDollarTextMath: true })++ it('renders inline $..$ math as KaTeX', async () => {+ const { container } = render(+ <Streamdown mode="static" plugins={{ math: mathPlugin }}>+ {normalizeFilePreviewMath('The formula $x^2 + y^2$ here.')}+ </Streamdown>+ )++ await waitFor(() => {+ expect(container.querySelector('.katex')).not.toBeNull()+ })+ expect(container.textContent).not.toContain('$x^2')+ })++ it('renders $$..$$ display math as KaTeX', async () => {+ const { container } = render(+ <Streamdown mode="static" plugins={{ math: mathPlugin }}>+ {normalizeFilePreviewMath('Block:\n\n$$E = mc^2$$')}+ </Streamdown>+ )++ await waitFor(() => {+ expect(container.querySelector('.katex-display') || container.querySelector('.katex')).not.toBeNull()+ })+ })++ it('renders \(..\) delimiter math as KaTeX', async () => {+ const { container } = render(+ <Streamdown mode="static" plugins={{ math: mathPlugin }}>+ {normalizeFilePreviewMath('A fraction \\(\\frac{a}{b}\\) inline.')}+ </Streamdown>+ )++ await waitFor(() => {+ expect(container.querySelector('.katex')).not.toBeNull()+ })+ expect(container.querySelector('.katex-mathml, .katex-html')).not.toBeNull()+ })++ it('leaves a literal code-fence \$ alone as code, not math', async () => {+ const { container } = render(+ <Streamdown mode="static" plugins={{ math: mathPlugin }}>+ {normalizeFilePreviewMath('```bash\necho $HOME\n```')}+ </Streamdown>+ )++ await waitFor(() => {+ expect(container.querySelector('.katex')).toBeNull()+ })+ expect(container.querySelector('code')?.textContent).toContain('$HOME')+ })+})\ No newline at end of file