import { describe, expect, it } from "vitest"; import { buildDualColorStyle, DEFAULT_DUAL_COLOR_SETTINGS } from "./dualColor"; describe("buildDualColorStyle", () => { it("returns null when there is no primary color", () => { expect( buildDualColorStyle("", "#000000", { ...DEFAULT_DUAL_COLOR_SETTINGS, dualColorEnabled: true, }), ).toBeNull(); expect( buildDualColorStyle(undefined, "#000000", { ...DEFAULT_DUAL_COLOR_SETTINGS, dualColorEnabled: true, }), ).toBeNull(); }); it("renders the primary color only when the gradient is disabled", () => { expect( buildDualColorStyle("#ffffff", "#000000", { ...DEFAULT_DUAL_COLOR_SETTINGS, dualColorEnabled: false, }), ).toEqual({ backgroundColor: "#ffffff" }); }); it("renders the primary color only when there is no secondary color", () => { expect( buildDualColorStyle("#ffffff", "", { ...DEFAULT_DUAL_COLOR_SETTINGS, dualColorEnabled: true, }), ).toEqual({ backgroundColor: "#ffffff" }); }); it("builds a 135deg split fill for the diagonal/none default", () => { const style = buildDualColorStyle("#ffffff", "#000000", { ...DEFAULT_DUAL_COLOR_SETTINGS, dualColorEnabled: true, }); expect(style?.backgroundImage).toContain("135deg"); expect(style?.backgroundImage).toContain("#ffffff 0%"); expect(style?.backgroundImage).toContain("#000000 100%"); expect(style?.backgroundColor).toBe("#ffffff"); }); it("maps each cut to its gradient angle", () => { const angle = ( cut: "vertical" | "horizontal" | "diagonal" | "diagonal_reverse", ): string | undefined => buildDualColorStyle("#ffffff", "#000000", { ...DEFAULT_DUAL_COLOR_SETTINGS, dualColorEnabled: true, dualColorCut: cut, })?.backgroundImage as string | undefined; expect(angle("vertical")).toContain("90deg"); expect(angle("horizontal")).toContain("180deg"); expect(angle("diagonal")).toContain("135deg"); expect(angle("diagonal_reverse")).toContain("45deg"); }); it("adjusts the stops for gentle and aggressive gradients", () => { expect( buildDualColorStyle("#ffffff", "#000000", { ...DEFAULT_DUAL_COLOR_SETTINGS, dualColorEnabled: true, dualColorGradient: "gentle", })?.backgroundImage, ).toContain("25%"); expect( buildDualColorStyle("#ffffff", "#000000", { ...DEFAULT_DUAL_COLOR_SETTINGS, dualColorEnabled: true, dualColorGradient: "aggressive", })?.backgroundImage, ).toContain("55%"); }); });