Files
shadcn-ui/apps/www/lib/registry.test.ts
shadcn 8f0c26f22a feat(www): code for blocks (#5756)
* feat: update blocks

* fix: scrollbars

* fix: code viewer

* test(shadcn): fix
2024-11-07 17:09:41 +04:00

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([])
})
})