-
Notifications
You must be signed in to change notification settings - Fork 0
/
colorUtils.test.ts
50 lines (43 loc) · 1.51 KB
/
colorUtils.test.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
import { hexToRgb, generatePalette } from "./index"; // adjust the import path based on your project structure
describe("hexToRgb", () => {
test("converts hex to RGB correctly", () => {
expect(hexToRgb("#ffffff")).toBe("rgb(255,255,255)");
expect(hexToRgb("#000000")).toBe("rgb(0,0,0)");
expect(hexToRgb("#ff0000")).toBe("rgb(255,0,0)");
});
});
describe("generateColorPalette", () => {
const params = {
colors: { primary: "#ff0000" },
lightTextColor: "#ffffff",
darkTextColor: "#000000",
};
test("generates correct color palette", () => {
const palette = generatePalette(params);
console.log(palette);
expect(palette.primary).toHaveProperty("DEFAULT");
expect(palette.primary).toHaveProperty("text");
expect(palette.primary).toHaveProperty("light");
expect(palette.primary).toHaveProperty("dark");
});
test("fails with invalid color format", () => {
expect(() =>
generatePalette({ ...params, colors: { primary: "not-a-color" } })
).toThrow();
});
test("fails with invalid color format for light text", () => {
expect(() =>
generatePalette({ ...params, lightTextColor: "not-a-color"})
).toThrow();
});
test("fails with invalid color format for dark text", () => {
expect(() =>
generatePalette({ ...params, darkTextColor: "not-a-color"})
).toThrow();
});
test("fails with invalid color with less 6 characters", () => {
expect(() =>
generatePalette({ ...params, colors: { primary: "#fff" } })
).toThrow();
});
});