| 1 | import { describe, expect, it } from "@effect/vitest"; |
| 2 | |
| 3 | import { |
| 4 | changedThemePaintKinds, |
| 5 | themeRoleFromUtilityClass, |
| 6 | type ThemePaintSnapshot, |
| 7 | } from "./themeInspector"; |
| 8 | |
| 9 | const WHITE_PAINT: ThemePaintSnapshot = { |
| 10 | background: "rgb(255, 255, 255)\nnone", |
| 11 | border: "rgb(255, 255, 255)\nnone", |
| 12 | foreground: "rgb(255, 255, 255)\nnone", |
| 13 | }; |
| 14 | |
| 15 | describe("changedThemePaintKinds", () => { |
| 16 | it("does not match an identical hardcoded color", () => { |
| 17 | expect(changedThemePaintKinds(WHITE_PAINT, { ...WHITE_PAINT })).toEqual([]); |
| 18 | }); |
| 19 | |
| 20 | it("reports only paint that changed with the probed token", () => { |
| 21 | expect( |
| 22 | changedThemePaintKinds(WHITE_PAINT, { |
| 23 | ...WHITE_PAINT, |
| 24 | background: "rgb(1, 254, 167)\nnone", |
| 25 | foreground: "rgb(1, 254, 167)\nnone", |
| 26 | }), |
| 27 | ).toEqual(["background", "foreground"]); |
| 28 | }); |
| 29 | }); |
| 30 | |
| 31 | describe("themeRoleFromUtilityClass", () => { |
| 32 | it("maps semantic utilities to their actual palette role", () => { |
| 33 | expect(themeRoleFromUtilityClass("text-foreground", "foreground")).toBe("text"); |
| 34 | expect(themeRoleFromUtilityClass("text-muted-foreground", "foreground")).toBe( |
| 35 | "mutedForeground", |
| 36 | ); |
| 37 | expect(themeRoleFromUtilityClass("bg-primary/90", "background")).toBe("messageAction"); |
| 38 | expect(themeRoleFromUtilityClass("ring-ring", "border")).toBe("focus"); |
| 39 | }); |
| 40 | |
| 41 | it("does not infer hardcoded or potentially inactive colors", () => { |
| 42 | expect(themeRoleFromUtilityClass("bg-white", "background")).toBeNull(); |
| 43 | expect(themeRoleFromUtilityClass("hover:bg-accent", "background")).toBeNull(); |
| 44 | }); |
| 45 | }); |