import { describe, expect, it } from "vitest"; import { accentGradient, detectThemeColorsFromPixels, elementGlowColor, elementGradientColors, elementOrder, normalizeHex, overviewFileName, overviewBlendModes, weaponTypeIconPath, } from "@/lib/overview-image"; describe("overview image generator", () => { it("normalizes valid colors and rejects invalid colors", () => { expect(normalizeHex(" #e9a51a ")).toBe("#E9A51A"); expect(normalizeHex("#fff")).toBeNull(); expect(normalizeHex("orange")).toBeNull(); }); it("creates a deterministic accent gradient", () => { expect(accentGradient("#E9A51A")).toBe( "linear-gradient(90deg, #CD9117 0%, #E9A51A 25%, #F1C56A 50%, #E9A51A 75%, #CD9117 100%)", ); expect(accentGradient("#FF0000", "#0000FF")).toBe( "linear-gradient(90deg, #E00000 0%, #FF0000 25%, #AC59AC 50%, #0000FF 75%, #0000E0 100%)", ); }); it("maps every catalog weapon type to a PNG", () => { expect(weaponTypeIconPath("WEAPON_SWORD_ONE_HAND")).toBe( "/icon/weapon-types/sword.png", ); expect(weaponTypeIconPath("WEAPON_CLAYMORE")).toBe( "/icon/weapon-types/claymore.png", ); expect(weaponTypeIconPath("WEAPON_POLE")).toBe( "/icon/weapon-types/polearm.png", ); expect(weaponTypeIconPath("WEAPON_BOW")).toBe( "/icon/weapon-types/bow.png", ); expect(weaponTypeIconPath("WEAPON_CATALYST")).toBe( "/icon/weapon-types/catalyst.png", ); expect(weaponTypeIconPath(null)).toBeNull(); }); it("maps every element to gradient and fixed glow colors", () => { for (const element of elementOrder) { const [start, end] = elementGradientColors(element); expect(normalizeHex(start)).toBe(start); expect(normalizeHex(end)).toBe(end); expect(normalizeHex(elementGlowColor(element))).toBe( elementGlowColor(element), ); } expect(elementGradientColors("Unknown")).toEqual(["#FFFFFF", "#FFFFFF"]); expect(elementGlowColor(null)).toBe("#FFFFFF"); }); it("creates a safe PNG filename", () => { expect(overviewFileName("Traveler / Pyro", "Main DPS")).toBe( "overview-Traveler-Pyro-main-dps.png", ); }); it("supports every Tailwind blend mode and detects top and bottom themes", () => { expect(overviewBlendModes.map((mode) => mode.value)).toHaveLength(18); const pixels = new Uint8ClampedArray([ 255, 0, 0, 255, 255, 0, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 0, 0, 255, 255, 0, 0, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, ]); expect(detectThemeColorsFromPixels(pixels, 2, 4)).toEqual({ top: ["#FF0000", "#FFFF00"], bottom: ["#0000FF", "#00FFFF"], }); }); });