mirror of
https://github.com/shadcn-ui/ui.git
synced 2026-06-27 22:54:18 +00:00
165 lines
3.0 KiB
TypeScript
165 lines
3.0 KiB
TypeScript
import { describe, expect, test } from "vitest"
|
|
|
|
import { transformTailwindCss } from "../../../src/utils/updaters/update-tailwind-css"
|
|
|
|
describe("transformTailwindCss", () => {
|
|
test("should add light and dark css vars if not present", async () => {
|
|
expect(
|
|
await transformTailwindCss(
|
|
`@tailwind base;
|
|
@tailwind components;
|
|
@tailwind utilities;
|
|
`,
|
|
{
|
|
light: {
|
|
background: "white",
|
|
foreground: "black",
|
|
},
|
|
dark: {
|
|
background: "black",
|
|
foreground: "white",
|
|
},
|
|
}
|
|
)
|
|
).toMatchInlineSnapshot(`
|
|
"@tailwind base;
|
|
@tailwind components;
|
|
@tailwind utilities;
|
|
@layer base{
|
|
:root{
|
|
--background: white;
|
|
--foreground: black
|
|
}
|
|
.dark{
|
|
--background: black;
|
|
--foreground: white
|
|
}
|
|
}
|
|
@layer base {
|
|
* {
|
|
@apply border-border;
|
|
}
|
|
body {
|
|
@apply bg-background text-foreground;
|
|
}
|
|
}
|
|
"
|
|
`)
|
|
})
|
|
|
|
test("should update light and dark css vars if present", async () => {
|
|
expect(
|
|
await transformTailwindCss(
|
|
`@tailwind base;
|
|
@tailwind components;
|
|
@tailwind utilities;
|
|
|
|
@layer base{
|
|
:root{
|
|
--background: 210 40% 98%;
|
|
}
|
|
|
|
.dark{
|
|
--background: 222.2 84% 4.9%;
|
|
}
|
|
}
|
|
`,
|
|
{
|
|
light: {
|
|
background: "215 20.2% 65.1%",
|
|
foreground: "222.2 84% 4.9%",
|
|
},
|
|
dark: {
|
|
foreground: "60 9.1% 97.8%",
|
|
},
|
|
}
|
|
)
|
|
).toMatchInlineSnapshot(`
|
|
"@tailwind base;
|
|
@tailwind components;
|
|
@tailwind utilities;
|
|
|
|
@layer base{
|
|
:root{
|
|
--background: 215 20.2% 65.1%;
|
|
--foreground: 222.2 84% 4.9%;
|
|
}
|
|
|
|
.dark{
|
|
--background: 222.2 84% 4.9%;
|
|
--foreground: 60 9.1% 97.8%;
|
|
}
|
|
}
|
|
|
|
@layer base {
|
|
|
|
* {
|
|
|
|
@apply border-border;
|
|
}
|
|
|
|
body {
|
|
|
|
@apply bg-background text-foreground;
|
|
}
|
|
}
|
|
"
|
|
`)
|
|
})
|
|
|
|
test("should not add the base layer if it is already present", async () => {
|
|
expect(
|
|
await transformTailwindCss(
|
|
`@tailwind base;
|
|
@tailwind components;
|
|
@tailwind utilities;
|
|
|
|
@layer base{
|
|
:root{
|
|
--background: 210 40% 98%;
|
|
}
|
|
|
|
.dark{
|
|
--background: 222.2 84% 4.9%;
|
|
}
|
|
}
|
|
|
|
@layer base {
|
|
* {
|
|
@apply border-border;
|
|
}
|
|
body {
|
|
@apply bg-background text-foreground;
|
|
}
|
|
}
|
|
`,
|
|
{}
|
|
)
|
|
).toMatchInlineSnapshot(`
|
|
"@tailwind base;
|
|
@tailwind components;
|
|
@tailwind utilities;
|
|
|
|
@layer base{
|
|
:root{
|
|
--background: 210 40% 98%;
|
|
}
|
|
|
|
.dark{
|
|
--background: 222.2 84% 4.9%;
|
|
}
|
|
}
|
|
|
|
@layer base {
|
|
* {
|
|
@apply border-border;
|
|
}
|
|
body {
|
|
@apply bg-background text-foreground;
|
|
}
|
|
}
|
|
"
|
|
`)
|
|
})
|
|
})
|