import { describe, expect, it } from "vitest";
import { clamp, adjust, adjustHexColor, generateColorPalette } from "./colors";
describe("clamp", () => {
    it("should clamp a value between min and max", () => {
        expect(clamp(5, 0, 10)).toBe(5);
        expect(clamp(-1, 0, 10)).toBe(0);
        expect(clamp(15, 0, 10)).toBe(10);
        expect(clamp(0, 0, 10)).toBe(0);
        expect(clamp(10, 0, 10)).toBe(10);
    });
    it("should return the same value if it's within the range", () => {
        expect(clamp(5, 5, 10)).toBe(5);
        expect(clamp(7, 5, 10)).toBe(7);
        expect(clamp(10, 5, 10)).toBe(10);
    });
    it("should return the min value if the value is less than min", () => {
        expect(clamp(0, 5, 10)).toBe(5);
        expect(clamp(-1, 5, 10)).toBe(5);
        expect(clamp(-10, 5, 10)).toBe(5);
    });
    it("should return the max value if the value is greater than max", () => {
        expect(clamp(11, 5, 10)).toBe(10);
        expect(clamp(15, 5, 10)).toBe(10);
        expect(clamp(20, 5, 10)).toBe(10);
    });
    it("should return the min value if min and max are the same", () => {
        expect(clamp(5, 5, 5)).toBe(5);
        expect(clamp(0, 5, 5)).toBe(5);
        expect(clamp(10, 5, 5)).toBe(5);
    });
    it("should return the max value if min and max are the same", () => {
        expect(clamp(5, 10, 10)).toBe(10);
        expect(clamp(0, 10, 10)).toBe(10);
        expect(clamp(15, 10, 10)).toBe(10);
    });
    it("should return the min value if min and max are the same and value is less than min", () => {
        expect(clamp(5, 5, 5)).toBe(5);
        expect(clamp(0, 5, 5)).toBe(5);
        expect(clamp(-10, 5, 5)).toBe(5);
    });
    it("should return the max value if min and max are the same and value is greater than max", () => {
        expect(clamp(5, 10, 10)).toBe(10);
        expect(clamp(15, 10, 10)).toBe(10);
        expect(clamp(20, 10, 10)).toBe(10);
    });
});
describe("adjust", () => {
    it("should adjust a value by a given amount", () => {
        expect(adjust(5, 0.5)).toBe(133);
        expect(adjust(5, -0.5)).toBe(5);
        expect(adjust(255, 0.5)).toBe(250);
        expect(adjust(255, -0.5)).toBe(128);
    });
    it("should return the same value if the amount is 0", () => {
        expect(adjust(5, 0)).toBe(5);
        expect(adjust(255, 0)).toBe(255);
    });
});
describe("adjustHexColor", () => {
    // Colors are taken from our design system
    it("should adjust a hex color by a given amount", () => {
        // Primary color. Base is #008491
        expect(adjustHexColor("#008491", 0.9)).toBe("#E6FAFA");
        expect(adjustHexColor("#008491", 0.85)).toBe("#D9FAFA");
        expect(adjustHexColor("#008491", 0.22)).toBe("#38BCC9");
        expect(adjustHexColor("#008491", 0)).toBe("#008491");
        expect(adjustHexColor("#008491", -0.18)).toBe("#055663");
        expect(adjustHexColor("#008491", -0.3)).toBe("#053845");
        // Secondary color. Base is #0F766E
        expect(adjustHexColor("#0F766E", 0.25)).toBe("#4FB6AE");
        expect(adjustHexColor("#0F766E", 0.23)).toBe("#4AB1A9");
        expect(adjustHexColor("#0F766E", 0.11)).toBe("#2B928A");
        expect(adjustHexColor("#0F766E", 0)).toBe("#0F766E");
        expect(adjustHexColor("#0F766E", -0.1)).toBe("#055D55");
    });
    it("should return the same color if the amount is 0", () => {
        expect(adjustHexColor("#000000", 0)).toBe("#000000");
        expect(adjustHexColor("#ffffff", 0)).toBe("#FFFFFF");
    });
    it("should return the same color if the input is not a valid hex color", () => {
        expect(adjustHexColor("invalid-color", 0.5)).toBe("invalid-color");
        expect(adjustHexColor("123456", -0.5)).toBe("123456");
    });
});
describe("generateColorPalette", () => {
    it("should generate a color palette from a base color", () => {
        const baseColor = "#008491";
        const shades = {
            50: 0.9,
            100: 0.85,
            200: 0.22,
            300: 0,
            400: -0.18,
            500: -0.3,
        };
        const expectedPalette = {
            "50": "#E6FAFA",
            "100": "#D9FAFA",
            "200": "#38BCC9",
            "300": "#008491",
            "400": "#055663",
            "500": "#053845",
        };
        expect(generateColorPalette(baseColor, shades)).toEqual(expectedPalette);
    });
    it("should return an empty object if the base color is not a valid color", () => {
        const baseColor = "invalid-color";
        const shades = {
            50: 0.9,
            100: 0.85,
        };
        expect(generateColorPalette(baseColor, shades)).toEqual({
            50: "invalid-color",
            100: "invalid-color",
        });
    });
    it("should return an empty object if the shades object is empty", () => {
        const baseColor = "#008491";
        const shades = {};
        expect(generateColorPalette(baseColor, shades)).toEqual({});
    });
});
//# sourceMappingURL=colors.test.js.map