From f9b1fb7e76480bdbcb070cdd8e6fcd6cbac9a6c0 Mon Sep 17 00:00:00 2001 From: Jonathan Amponsah <82057176+mgalore@users.noreply.github.com> Date: Fri, 14 Aug 2026 22:05:10 +0000 Subject: [PATCH] test: cover path coverage utilities --- tests/utils/path-coverage.test.ts | 55 +++++++++++++++++++++++++++++++ 1 file changed, 55 insertions(+) create mode 100644 tests/utils/path-coverage.test.ts diff --git a/tests/utils/path-coverage.test.ts b/tests/utils/path-coverage.test.ts new file mode 100644 index 00000000..62c804ba --- /dev/null +++ b/tests/utils/path-coverage.test.ts @@ -0,0 +1,55 @@ +import { calculatePathCoverage, formatDependencyPath } from "../../src/utils/path-coverage.js"; + +describe("calculatePathCoverage", () => { + it("moves a matching path to coveredPaths and leaves other paths remaining", () => { + expect(calculatePathCoverage([["root", "left"], ["root", "right"]], ["root", "left"])).toEqual({ + coverage: "partial", + coveredPaths: [["root", "left"]], + remainingPaths: [["root", "right"]], + }); + }); + + it("reports complete coverage when the only known path is covered", () => { + expect(calculatePathCoverage([["root", "only"]], ["root", "only"])).toEqual({ + coverage: "complete", + coveredPaths: [["root", "only"]], + remainingPaths: [], + }); + }); + + it.each([null, undefined, []] as const)("leaves every known path uncovered for %p", coveredPath => { + expect(calculatePathCoverage([["a"], ["b"]], coveredPath)).toEqual({ + coverage: "partial", + coveredPaths: [], + remainingPaths: [["a"], ["b"]], + }); + }); + + it("reports complete coverage for an empty known-path set", () => { + expect(calculatePathCoverage([], undefined)).toEqual({ + coverage: "complete", + coveredPaths: [], + remainingPaths: [], + }); + }); + + it("compares paths by ordered elements and length", () => { + const knownPaths = [["a", "b"], ["b", "a"], ["a"]]; + + expect(calculatePathCoverage(knownPaths, ["a", "b"])).toEqual({ + coverage: "partial", + coveredPaths: [["a", "b"]], + remainingPaths: [["b", "a"], ["a"]], + }); + }); +}); + +describe("formatDependencyPath", () => { + it.each([ + [["a", "b", "c"], "a -> b -> c"], + [["only"], "only"], + [[], ""], + ])("formats %p as %p", (path, formattedPath) => { + expect(formatDependencyPath(path)).toBe(formattedPath); + }); +});