import { describe, expect, it } from "vitest"; import { existsSync, readFileSync } from "node:fs"; import { dirname, join, resolve } from "node:path"; import { fileURLToPath } from "node:url"; import { scumCatalogEntries, scumCatalogIconUrl, scumVehicleEntry, scumVehicleFallbackIconUrl, scumVehicleIconUrl } from "../examples/scum-server-plugin/features/scum-catalog.js"; const pluginRoot = resolve(dirname(fileURLToPath(import.meta.url)), "../examples/scum-server-plugin"); const catalogSource = readFileSync(join(pluginRoot, "features/scum-catalog.ts"), "utf8"); describe("scum catalog icons", () => { it("resolves icons on demand instead of importing each icon as its own module", () => { expect(catalogSource).not.toContain("import.meta.glob"); expect(scumCatalogIconUrl("npcs/zombie11.webp")).toContain("zombie11.webp"); expect(scumCatalogIconUrl("npcs/does-not-exist.webp")).toBe(""); }); it("ships an icon file for every entry that declares one", () => { const missing = scumCatalogEntries.filter((entry) => entry.icon && !existsSync(join(pluginRoot, "assets/scum-catalog", entry.icon))); expect(missing.map((entry) => entry.icon)).toEqual([]); }); it("matches the live server's _ES vehicle classes to bundled icons", () => { const liveClasses = ["Rager_ES", "Laika_ES", "RIS_ES", "WolfsWagen_ES", "WheelBarrow_Metal_ES", "Barba_ES", "Tractor_ES", "Dinghy_ES", "Cruiser_ES", "SidecarBike_ES", "Dirtbike_ES", "CityBike_ES", "SUP_ES", "MountainBike_ES", "Kinglet_Duster_ES", "WheelBarrow_Improvised_ES"]; for (const code of liveClasses) expect(scumVehicleIconUrl(code)).toContain("scum-catalog"); expect(scumVehicleEntry("Rager_ES")?.name).toBe("Rager"); expect(scumVehicleEntry("BPC_Rager_C")?.name).toBe("Rager"); expect(scumVehicleEntry("Laika_ES")?.name).toBe("Laika"); expect(scumVehicleEntry("WheelBarrow_Metal_ES")?.name).toBe("Metal Wheelbarrow"); }); it("draws an inline glyph for models whose class ships no icon", () => { expect(scumVehicleIconUrl("Pickup_01_A_ES")).toBe(""); expect(scumVehicleFallbackIconUrl("Pickup_01_A_ES")).toContain("data:image/svg+xml"); expect(scumVehicleFallbackIconUrl("Quad_01_D_ES")).toContain("data:image/svg+xml"); expect(decodeURIComponent(scumVehicleFallbackIconUrl("Dinghy_ES"))).toContain("