mirror of
https://github.com/shadcn-ui/ui.git
synced 2026-06-26 14:16:08 +00:00
38 lines
1.1 KiB
TypeScript
38 lines
1.1 KiB
TypeScript
import { describe, expect, it } from "vitest"
|
|
|
|
import { createFileTreeForRegistryItemFiles } from "@/lib/registry"
|
|
|
|
describe("createFileTreeForRegistryItemFiles", () => {
|
|
it("should create a nested file tree structure", async () => {
|
|
const files = [
|
|
{ path: "page.tsx" },
|
|
{ path: "components/foo.tsx" },
|
|
{ path: "components/baz.tsx" },
|
|
{ path: "components/boo/quip.tsx" },
|
|
]
|
|
|
|
const expectedOutput = [
|
|
{ name: "page.tsx", path: "page.tsx" },
|
|
{
|
|
name: "components",
|
|
children: [
|
|
{ name: "foo.tsx", path: "components/foo.tsx" },
|
|
{ name: "baz.tsx", path: "components/baz.tsx" },
|
|
{
|
|
name: "boo",
|
|
children: [{ name: "quip.tsx", path: "components/boo/quip.tsx" }],
|
|
},
|
|
],
|
|
},
|
|
]
|
|
|
|
const result = await createFileTreeForRegistryItemFiles(files)
|
|
expect(result).toEqual(expectedOutput)
|
|
})
|
|
|
|
it("should return an empty array for empty input", async () => {
|
|
const result = await createFileTreeForRegistryItemFiles([])
|
|
expect(result).toEqual([])
|
|
})
|
|
})
|