From cb151003417f9a1fae221f4c182b418043bf1d21 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marc-Andr=C3=A9=20Bombeck?= Date: Thu, 6 Aug 2026 04:13:54 +0200 Subject: [PATCH] test: cover scoped record navigation --- .../shared-record-navigation.test.tsx | 58 +++++++++++++++++++ 1 file changed, 58 insertions(+) create mode 100644 src/__tests__/shared-record-navigation.test.tsx diff --git a/src/__tests__/shared-record-navigation.test.tsx b/src/__tests__/shared-record-navigation.test.tsx new file mode 100644 index 000000000..df014f4f5 --- /dev/null +++ b/src/__tests__/shared-record-navigation.test.tsx @@ -0,0 +1,58 @@ +import { describe, expect, it } from "vitest"; + +import { + SHARED_RECORD_DOMAIN_ROUTE_FAMILIES, + resolveSharedRecordNavigation, +} from "@/lib/navigation/shared-record"; +import { SHARE_DOMAINS } from "@/lib/sharing/scope"; +import { + isDestinationInSharedRecord, + visibleNavDestinations, +} from "@/components/layout/nav-model"; + +describe("shared-record navigation", () => { + it("keeps every granted route family in one closed eight-domain inventory", () => { + expect(Object.keys(SHARED_RECORD_DOMAIN_ROUTE_FAMILIES)).toEqual( + SHARE_DOMAINS, + ); + + for (const domain of SHARE_DOMAINS) { + expect( + SHARED_RECORD_DOMAIN_ROUTE_FAMILIES[domain].length, + `${domain} needs at least one route family`, + ).toBeGreaterThan(0); + } + }); + + it("offers a scoped grant only its matching doorway", () => { + const navigation = resolveSharedRecordNavigation(["labs"]); + + expect(navigation.destinationHrefs).toEqual(["/labs"]); + expect(navigation.allowsPath("/labs/panel/7")).toBe(true); + expect(navigation.allowsPath("/medications")).toBe(false); + + expect( + visibleNavDestinations(undefined, true, true, ["labs"]).map( + (destination) => destination.href, + ), + ).toEqual(["/labs"]); + expect(isDestinationInSharedRecord("/labs/panel/7", ["labs"])).toBe(true); + expect(isDestinationInSharedRecord("/medications", ["labs"])).toBe(false); + }); + + it("keeps whole-record navigation distinct from an all-sections scope", () => { + const wholeRecord = resolveSharedRecordNavigation(null); + const allSections = resolveSharedRecordNavigation([...SHARE_DOMAINS]); + + expect(wholeRecord.allowsPath("/")).toBe(true); + expect(allSections.allowsPath("/")).toBe(false); + }); + + it("refuses unclassified direct URLs in presentation before pages start reads", () => { + const navigation = resolveSharedRecordNavigation(["documents"]); + + expect(navigation.allowsPath("/documents/record-1")).toBe(true); + expect(navigation.allowsPath("/settings/account")).toBe(false); + expect(navigation.allowsPath("/new-unclassified-route")).toBe(false); + }); +});