Files
shadcn-ui/apps/v4/registry/config.test.ts
shadcn 687f09817b feat: chartColor and fontHeading (#10115)
* feat: chart color

* fix

* fix

* fix: chart color

* chore: changeset

* chore: restore directory registry formatting

* feat: add fontHeading

* feat: rebuild registry

* fix: v0

* refactor

* fix

* fix

* fix

* fix

* fix

* fix: refactor preset handling

* fix

* fix

* fix
2026-03-19 23:35:01 +04:00

86 lines
2.5 KiB
TypeScript

import { describe, expect, it } from "vitest"
import {
buildRegistryBase,
DEFAULT_CONFIG,
designSystemConfigSchema,
} from "./config"
describe("buildRegistryBase", () => {
it("seeds a font-heading fallback when heading inherits the body font", () => {
const result = buildRegistryBase(DEFAULT_CONFIG)
expect(result.registryDependencies).toContain("font-inter")
expect(result.registryDependencies).not.toContain("font-heading-inter")
expect(result.cssVars?.theme?.["--font-heading"]).toBe("var(--font-sans)")
})
it("adds a heading font dependency when a distinct heading font is selected", () => {
const result = buildRegistryBase({
...DEFAULT_CONFIG,
fontHeading: "playfair-display",
})
expect(result.registryDependencies).toContain("font-inter")
expect(result.registryDependencies).toContain(
"font-heading-playfair-display"
)
expect(result.cssVars?.theme?.["--font-heading"]).toBeUndefined()
})
it("normalizes a matching heading font back to inherit", () => {
const result = buildRegistryBase({
...DEFAULT_CONFIG,
fontHeading: "inter",
})
expect(result.registryDependencies).not.toContain("font-heading-inter")
expect(result.cssVars?.theme?.["--font-heading"]).toBe("var(--font-sans)")
})
it("inherits the selected body font variable for non-sans body fonts", () => {
const result = buildRegistryBase({
...DEFAULT_CONFIG,
font: "jetbrains-mono",
fontHeading: "inherit",
})
expect(result.registryDependencies).toContain("font-jetbrains-mono")
expect(result.cssVars?.theme?.["--font-heading"]).toBe("var(--font-mono)")
})
it("defaults chartColor to neutral when omitted", () => {
const result = designSystemConfigSchema.parse({
base: "radix",
style: "nova",
iconLibrary: "lucide",
theme: "neutral",
font: "inter",
fontHeading: "inherit",
menuAccent: "subtle",
menuColor: "default",
radius: "default",
})
expect(result.chartColor).toBe("neutral")
})
it("rejects chartColor values that are unavailable for the selected base color", () => {
const result = designSystemConfigSchema.safeParse({
base: "radix",
style: "nova",
iconLibrary: "lucide",
baseColor: "neutral",
theme: "neutral",
chartColor: "stone",
font: "inter",
fontHeading: "inherit",
menuAccent: "subtle",
menuColor: "default",
radius: "default",
})
expect(result.success).toBe(false)
})
})