gantt-board/scripts/tests/sprintSelection.test.ts

64 lines
2.1 KiB
TypeScript

import assert from "node:assert/strict"
import test from "node:test"
import { findCurrentSprint, isSprintInProgress } from "../../src/lib/server/sprintSelection"
const NOW = new Date("2026-02-24T15:30:00")
test("isSprintInProgress uses inclusive boundaries", () => {
assert.equal(isSprintInProgress("2026-02-24", "2026-02-24", NOW), true)
assert.equal(isSprintInProgress("2026-02-25", "2026-02-26", NOW), false)
})
test("findCurrentSprint prefers active sprint in range", () => {
const sprint = findCurrentSprint(
[
{ id: "planning", status: "planning", startDate: "2026-02-20", endDate: "2026-02-28" },
{ id: "active", status: "active", startDate: "2026-02-22", endDate: "2026-02-26" },
],
{ now: NOW }
)
assert.equal(sprint?.id, "active")
})
test("findCurrentSprint falls back to non-completed in range", () => {
const sprint = findCurrentSprint(
[{ id: "planning", status: "planning", startDate: "2026-02-20", endDate: "2026-02-28" }],
{ now: NOW }
)
assert.equal(sprint?.id, "planning")
})
test("findCurrentSprint returns null for completed-only unless fallback enabled", () => {
const sprints = [{ id: "done", status: "completed", startDate: "2026-02-20", endDate: "2026-02-28" }] as const
const withoutFallback = findCurrentSprint(sprints, { now: NOW })
const withFallback = findCurrentSprint(sprints, { now: NOW, includeCompletedFallback: true })
assert.equal(withoutFallback, null)
assert.equal(withFallback?.id, "done")
})
test("findCurrentSprint is global across all sprints", () => {
const sprint = findCurrentSprint(
[
{ id: "planning", status: "planning", startDate: "2026-02-20", endDate: "2026-02-28" },
{ id: "active", status: "active", startDate: "2026-02-20", endDate: "2026-02-28" },
],
{ now: NOW }
)
assert.equal(sprint?.id, "active")
})
test("findCurrentSprint returns null when no sprint is in range", () => {
const sprint = findCurrentSprint(
[{ id: "future", status: "active", startDate: "2026-03-01", endDate: "2026-03-07" }],
{ now: NOW }
)
assert.equal(sprint, null)
})