59 lines
3.4 KiB
TypeScript
59 lines
3.4 KiB
TypeScript
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";
|
|
import { scumMapVehicleIconUrl } from "../examples/scum-server-plugin/features/map-vehicle-icons.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("includes the backpack and military helmet entries users expect", () => {
|
|
const byCode = new Map(scumCatalogEntries.map((entry) => [entry.code, entry]));
|
|
expect(byCode.get("Improvised_Backpack_Big")).toMatchObject({ kind: "item" });
|
|
expect(byCode.get("Military_Backpack_01_01")).toMatchObject({ kind: "item" });
|
|
expect(byCode.get("Military_Helmet_01_01")).toMatchObject({ kind: "item" });
|
|
expect(byCode.get("Improvised_Backpack_Big")?.icon).toContain("backpacks/");
|
|
expect(byCode.get("Military_Helmet_01_01")?.icon).toContain("head armor/");
|
|
});
|
|
|
|
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 <name>_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("<svg");
|
|
});
|
|
|
|
it("uses the small map asset for known classes while keeping catalog originals separate", () => {
|
|
for (const code of ["Rager_ES", "Laika_ES", "BPC_Laika_C", "Dinghy_ES", "Tractor_ES"]) {
|
|
const icon = scumMapVehicleIconUrl(code);
|
|
expect(icon).toContain("/map/vehicles/");
|
|
expect(existsSync(fileURLToPath(icon))).toBe(true);
|
|
expect(readFileSync(fileURLToPath(icon)).length).toBeLessThan(4000);
|
|
}
|
|
expect(scumVehicleIconUrl("Laika_ES")).toContain("scum-catalog");
|
|
});
|
|
});
|