import { describe, expect, it } from "vitest"; import { getToastConfig, showToast, type ToastType } from "./toast"; // getToastConfig drives every toast's styling; a missing entry for a // ToastType member crashes showToast at runtime (that bug shipped once — // the 'warning' variant — which is why this suite exists). const ALL_TYPES: ToastType[] = ["error", "success", "info", "warning"]; describe("getToastConfig", () => { it("has a complete config for every ToastType", () => { for (const type of ALL_TYPES) { const config = getToastConfig(type); expect(config, `missing config for "${type}"`).toBeDefined(); expect(config.bgClass, `missing bgClass for "${type}"`).toBeTruthy(); expect(config.icon, `missing icon for "${type}"`).toBeTruthy(); } }); it("styles the warning variant with the /90 opacity used by siblings", () => { expect(getToastConfig("warning").bgClass).toBe("bg-yellow-500/90"); }); it("keeps distinct visuals per type", () => { const classes = ALL_TYPES.map((type) => getToastConfig(type).bgClass); expect(new Set(classes).size).toBe(ALL_TYPES.length); }); }); describe("showToast", () => { it("creates the container and a styled toast", () => { showToast("Saved", "success"); const container = document.getElementById("toast-container"); expect(container).not.toBeNull(); expect(container?.innerHTML).toContain("Saved"); expect(container?.innerHTML).toContain("bg-green-500/90"); }); it("renders the warning variant without throwing", () => { // Regression: 'warning' had no config entry and crashed on render. expect(() => showToast("Careful", "warning")).not.toThrow(); expect(document.getElementById("toast-container")?.innerHTML).toContain("bg-yellow-500/90"); }); });