38 lines
916 B
TypeScript
38 lines
916 B
TypeScript
import { describe, it, expect } from "vitest"
|
|
import { resolvePath } from "../../app/utils/resolvePath"
|
|
|
|
const grandchild = {
|
|
id: "gc",
|
|
title: "Grandchild",
|
|
children: [],
|
|
} as any
|
|
|
|
const child = {
|
|
id: "c",
|
|
title: "Child",
|
|
children: [grandchild],
|
|
} as any
|
|
|
|
const root = {
|
|
id: "__voyage",
|
|
title: "Root",
|
|
children: [child],
|
|
} as any
|
|
|
|
describe("resolvePath", () => {
|
|
it("returns [root] for an empty path", () => {
|
|
expect(resolvePath(root, [])).toEqual([root])
|
|
})
|
|
|
|
it("returns the full chain for a valid path", () => {
|
|
expect(resolvePath(root, ["c", "gc"])).toEqual([root, child, grandchild])
|
|
})
|
|
|
|
it("stops at the last valid node when an id is not found mid-path", () => {
|
|
expect(resolvePath(root, ["c", "nope", "gc"])).toEqual([root, child])
|
|
})
|
|
|
|
it("stops at the root when the first id is not found", () => {
|
|
expect(resolvePath(root, ["missing"])).toEqual([root])
|
|
})
|
|
})
|