/* Copyright 2026 Marimo. All rights reserved. */ import type { ExtractAtomValue } from "jotai"; import { afterEach, beforeEach, describe, expect, test } from "vitest"; import { hasRunAnyCellAtom } from "@/components/editor/cell/useRunCells"; import { userConfigAtom } from "@/core/config/config"; import { parseUserConfig } from "@/core/config/config-schema"; import { initialModeAtom } from "@/core/mode"; import { store } from "@/core/state/jotai"; import { visibleForTesting } from "../RenderHTML"; const { parseHtml } = visibleForTesting; describe("parseHtml", () => { test("renders HTML", () => { const html = "

Hello

"; expect(parseHtml({ html })).toMatchInlineSnapshot(`

Hello

`); }); test("no closing HTML", () => { const html = "

Hello"; expect(parseHtml({ html })).toMatchInlineSnapshot(`

Hello

`); }); test("script", () => { const html = "

Hello

"; expect(parseHtml({ html })).toMatchInlineSnapshot(` [

Hello

, ', }); expect( document.head.querySelector( 'script[src="https://cdn.example.com/unrun.js"]', ), ).toBeNull(); }); test("loads ', }); expect( document.head.querySelector( 'script[src="https://cdn.example.com/ok.js"]', ), ).not.toBeNull(); }); test("loads ', }); expect( document.head.querySelector( 'script[src="https://cdn.example.com/export.js"]', ), ).not.toBeNull(); }); }); describe("wrapTooltipTargets", () => { test("data-tooltip wraps element in Tooltip component", () => { const html = 'Hover me'; expect(parseHtml({ html })).toMatchInlineSnapshot(` Hover me `); }); test("element without data-tooltip is not wrapped", () => { const html = "No tooltip"; expect(parseHtml({ html })).toMatchInlineSnapshot(` No tooltip `); }); test("data-tooltip on nested element wraps only that element", () => { const html = '

Outer inner text

'; expect(parseHtml({ html })).toMatchInlineSnapshot(`

Outer inner text

`); }); test("data-tooltip on marimo custom elements is not wrapped", () => { const html = 'click'; expect(parseHtml({ html })).toMatchInlineSnapshot(` click `); }); test("data-tooltip on non-marimo custom elements is still wrapped", () => { const html = 'content'; expect(parseHtml({ html })).toMatchInlineSnapshot(` content `); }); }); describe("parseHtml with < nad >", () => { const html = 'thread panicked at "assertion failed: `(left == right)`"'; test("", () => { expect(parseHtml({ html })).toMatchInlineSnapshot(` [ "thread ", panicked at "assertion failed: \`(left == right)\`" , ] `); }); test(" sanitized", () => { const sanitized = html.replaceAll("<", "<").replaceAll(">", ">"); expect(parseHtml({ html: sanitized })).toMatchInlineSnapshot( `"thread panicked at "assertion failed: \`(left == right)\`""`, ); }); });