1import { describe, expect, it } from "vite-plus/test";
2
3import { hexToHsv, hsvToHex } from "./color";
4
5describe("picker color conversion", () => {
6 it.each(["#000000", "#ffffff", "#808080", "#ff0000", "#00ff00", "#0000ff", "#2563eb"])(
7 "round trips %s through HSV without changing the persisted color",
8 (hex) => {
9 const { h, s, v } = hexToHsv(hex);
10 expect(hsvToHex(h, s, v)).toBe(hex);
11 },
12 );
13
14 it("wraps hue at the slider boundary and across keyboard steps", () => {
15 expect(hsvToHex(360, 1, 1)).toBe("#ff0000");
16 expect(hsvToHex(720, 1, 1)).toBe("#ff0000");
17 expect(hsvToHex(-60, 1, 1)).toBe("#ff00ff");
18 });
19
20 it("represents black and greys without undefined saturation", () => {
21 expect(hexToHsv("#000000")).toEqual({ h: 0, s: 0, v: 0 });
22 expect(hexToHsv("#ffffff")).toEqual({ h: 0, s: 0, v: 1 });
23 });
24});