",
}
}
/>
`);
});
test("codehilite with copy button", () => {
const html =
'
';
const result = parseHtml({ html });
// Check that the result is wrapped in a CopyableCode component
expect(result).toMatchInlineSnapshot(`
`);
});
test("custom tags - valid", () => {
let html = "
";
expect(parseHtml({ html })).toMatchInlineSnapshot("
");
html = "
";
expect(parseHtml({ html })).toMatchInlineSnapshot("
");
html = "
";
expect(parseHtml({ html })).toMatchInlineSnapshot("
");
});
test("custom tags - invalid", () => {
let html = "
lorem";
expect(parseHtml({ html })).toMatchInlineSnapshot(`
[
,
" lorem",
]
`);
html = "
";
expect(parseHtml({ html })).toMatchInlineSnapshot(`
`);
html = "
<1>
";
expect(parseHtml({ html })).toMatchInlineSnapshot(`
<1>
`);
html = "
<1/>
";
expect(parseHtml({ html })).toMatchInlineSnapshot(`
<1/>
`);
html = "
";
expect(parseHtml({ html })).toMatchInlineSnapshot(`
`);
});
test("removes body tags but preserves children", () => {
const html = "
Hello
World
";
expect(parseHtml({ html })).toMatchInlineSnapshot(`
Hello
World
`);
});
test("removes nested body tags", () => {
const html = "
Content
";
expect(parseHtml({ html })).toMatchInlineSnapshot(`
Content
`);
});
test("removes html tags but preserves children", () => {
const html =
"
TestContent
";
expect(parseHtml({ html })).toMatchInlineSnapshot(`
Test
Content
`);
});
test("removes nested html tags", () => {
const html = "
Content
";
expect(parseHtml({ html })).toMatchInlineSnapshot(`
Content
`);
});
test("remove nested body in html", () => {
const html = "
Content";
expect(parseHtml({ html })).toMatchInlineSnapshot(`
Content
`);
});
});
describe("replaceSrcScripts trust gate", () => {
let previousHasRunAnyCell: ExtractAtomValue
;
let previousConfig: ExtractAtomValue;
let previousMode: ExtractAtomValue;
const windowWithExport = window as Window & {
__MARIMO_EXPORT_CONTEXT__?: unknown;
};
function clearTrustSignals() {
const cleared = parseUserConfig({});
store.set(hasRunAnyCellAtom, false);
store.set(userConfigAtom, {
...cleared,
runtime: { ...cleared.runtime, auto_instantiate: false },
});
store.set(initialModeAtom, "edit");
delete windowWithExport.__MARIMO_EXPORT_CONTEXT__;
}
beforeEach(() => {
previousHasRunAnyCell = store.get(hasRunAnyCellAtom);
previousConfig = store.get(userConfigAtom);
previousMode = store.get(initialModeAtom);
clearTrustSignals();
for (const s of document.head.querySelectorAll(
'script[src^="https://cdn.example.com/"]',
)) {
s.remove();
}
});
afterEach(() => {
store.set(hasRunAnyCellAtom, previousHasRunAnyCell);
store.set(userConfigAtom, previousConfig);
store.set(initialModeAtom, previousMode);
delete windowWithExport.__MARIMO_EXPORT_CONTEXT__;
for (const s of document.head.querySelectorAll(
'script[src^="https://cdn.example.com/"]',
)) {
s.remove();
}
});
test("drops ',
});
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)\`""`,
);
});
});