40 lines
1.3 KiB
TypeScript
40 lines
1.3 KiB
TypeScript
import { describe, it, expect } from "vitest"
|
|
import { undatedChildren } from "../../app/utils/undatedChildren"
|
|
|
|
const node = (id: string, start: string | null) =>
|
|
({ id, event: { title: id, startDate: start }, children: [] }) as any
|
|
|
|
describe("undatedChildren", () => {
|
|
it("returns only children with no start", () => {
|
|
const children = [
|
|
node("a", "2026-06-13T10:00:00Z"),
|
|
node("b", null),
|
|
node("c", "2026-06-14T08:00:00Z"),
|
|
node("d", null),
|
|
]
|
|
const result = undatedChildren(children)
|
|
expect(result.map((c) => c.id)).toEqual(["b", "d"])
|
|
})
|
|
|
|
it("returns an empty array when all children are dated", () => {
|
|
const children = [
|
|
node("a", "2026-06-13T10:00:00Z"),
|
|
node("b", "2026-06-14T08:00:00Z"),
|
|
]
|
|
expect(undatedChildren(children)).toEqual([])
|
|
})
|
|
|
|
it("returns all children when none are dated", () => {
|
|
const children = [node("a", null), node("b", null)]
|
|
expect(undatedChildren(children).map((c) => c.id)).toEqual(["a", "b"])
|
|
})
|
|
|
|
it("treats empty string start as undated (falsy)", () => {
|
|
const children = [node("a", ""), node("b", "2026-06-13T10:00:00Z")]
|
|
expect(undatedChildren(children).map((c) => c.id)).toEqual(["a"])
|
|
})
|
|
|
|
it("returns an empty array for no children", () => {
|
|
expect(undatedChildren([])).toEqual([])
|
|
})
|
|
})
|