Skip to content

armgit / kaneo

Public Imported from GitHub
0

⚡ Project management that doesn't become the project. Boards, Gantt charts, and GitHub integration. Self-host it or use Kaneo Cloud.

test(web): cover browser-supported label colors

Tind7d0b6ff1096
diff --git a/apps/web/src/lib/label-color.test.ts b/apps/web/src/lib/label-color.test.ts
index 8cca75f65..b2242d2d0 100644
--- a/apps/web/src/lib/label-color.test.ts
+++ b/apps/web/src/lib/label-color.test.ts
@@ -1,6 +1,8 @@
-import { describe, expect, it } from "vitest";
+import { afterEach, describe, expect, it, vi } from "vitest";
import { FALLBACK_LABEL_COLOR, resolveLabelColor } from "./label-color";
+afterEach(() => vi.unstubAllGlobals());
+
describe("resolveLabelColor", () => {
it("maps Kaneo's named label colors to their CSS variables", () => {
expect(resolveLabelColor("red")).toBe("var(--color-red-600)");
@@ -14,4 +16,23 @@ describe("resolveLabelColor", () => {
it("uses the neutral fallback for invalid colors", () => {
expect(resolveLabelColor("not a color")).toBe(FALLBACK_LABEL_COLOR);
});
+
+ it("preserves non-hex colors supported by the browser", () => {
+ const color = "rgb(232 56 85)";
+ const supports = vi.fn(() => true);
+ vi.stubGlobal("CSS", { supports });
+
+ const resolved = resolveLabelColor(color);
+
+ expect(resolved).toBe(color);
+ expect(supports).toHaveBeenCalledWith("color", color);
+ });
+
+ it("uses the fallback when the browser rejects a non-hex color", () => {
+ vi.stubGlobal("CSS", { supports: () => false });
+
+ const resolved = resolveLabelColor("not a color");
+
+ expect(resolved).toBe(FALLBACK_LABEL_COLOR);
+ });
});