repositories / pi-ext

pi-ext

bugabingas pi extensions

owned by bugabinga

extensions/ui/__tests__/visual-block.test.ts

Raw
File outline
import { describe, expect, it } from "vitest";
import {
	renderVisualBlockShell,
	visualBlockSummary,
} from "../web/components/visual-block.js";

describe("ui visual block rendering", () => {
	it("renders widget fallback and ids", () => {
		expect(
			visualBlockSummary({
				type: "widget_mount",
				widgetId: "widget-1",
				title: "Demo",
				fallback: "Fallback text",
				status: "mounted",
			}),
		).toBe("Demo · widget-1 · mounted · Fallback text");
	});

	it("renders widget errors with a fix hint", () => {
		expect(
			visualBlockSummary({
				type: "widget_error",
				widgetId: "widget-1",
				message: "boom",
				status: "error",
			}),
		).toBe("widget-1 · error · boom · agent: fix widget HTML/JS");
	});

	it("renders bounded iframe shell", () => {
		const html = renderVisualBlockShell({
			widgetId: "widget-1",
			title: "Demo",
			fallback: "Fallback",
			srcdoc: "<p>Hi</p>",
		});
		expect(html).toContain("ui-visual-block");
		expect(html).toContain("widget-1");
		expect(html).toContain("iframe");
		expect(html).toContain("Fallback");
	});
});