import { describe, expect, it } from "vitest";
import { render } from "@testing-library/react";
import { Icon } from "@/ui/icons";
import { pluginIconName } from "../pluginIcon";
const svg = (shape: string, root = "") => ``;
const rendered = (name: string) => render().container;
const markup = (name: string) => rendered(name).innerHTML;
describe("pluginIconName", () => {
it("gives plugins without an icon the generic one", () => {
expect(pluginIconName("a.b", null)).toBe("plugin");
expect(pluginIconName("a.b", undefined)).toBe("plugin");
});
it("renders a plugin's icon under a name of its own", () => {
const name = pluginIconName("a.b", { light: svg(''), dark: null });
expect(name).toMatch(/^ext:pluginIcon\/a\.b\//);
expect(markup(name)).toContain(" {
const published = pluginIconName("a.b", { light: svg(''), dark: null });
const local = pluginIconName("a.b", { light: svg(''), dark: null });
expect(local).not.toBe(published);
expect(markup(published)).toContain(" {
const name = pluginIconName("c.d", {
light: svg(''),
dark: svg(''),
});
expect(markup(name)).toContain(" {
const plain = pluginIconName("g", { light: svg(''), dark: null });
const other = pluginIconName("g_dark", { light: svg(''), dark: null });
expect(markup(plain)).not.toContain(" {
pluginIconName("e.f", { light: svg(''), dark: svg('') });
const name = pluginIconName("e.f", { light: svg(''), dark: null });
expect(markup(name)).not.toContain(" {
const filled = rendered(
pluginIconName("h.i", {
light: svg('', ' fill="#E5A50A" stroke="#FFFFFF"'),
dark: null,
}),
);
const group = filled.querySelector("circle")?.closest("g");
expect(group?.getAttribute("fill")).toBe("#E5A50A");
expect(group?.getAttribute("stroke")).toBe("#FFFFFF");
const plain = rendered(pluginIconName("j.k", { light: svg(''), dark: null }));
expect(plain.querySelector("circle")?.closest("g")?.getAttribute("fill")).toBe("#000");
});
});