diff --git a/tests/audit-navigation-auth-regressions.test.ts b/tests/audit-navigation-auth-regressions.test.ts index c9c79904..d6f9fe48 100644 --- a/tests/audit-navigation-auth-regressions.test.ts +++ b/tests/audit-navigation-auth-regressions.test.ts @@ -177,8 +177,20 @@ describe("audit navigation and auth regressions", () => { // The viewport-driven region/tabpanel role is wired through the extracted hook, whose // media-query subscription carries the guard with it. expect(clinicalDashboardSource).toContain("useUploadDesktopLayout()"); - expect(source("src/components/clinical-dashboard/use-upload-desktop-layout.ts")).toContain( - "subscribeToUploadDesktopLayout", + // Assert the EXPORTED hook's return wires the media-query subscription through + // useSyncExternalStore with the () => false server snapshot, and that the call closes + // right after that snapshot. Scoping to the exported function body (not the whole file) + // plus the `return` anchor and trailing `)` means a stale/disconnected call elsewhere, a + // comment or string, a present-but-unused helper, a dropped SSR fallback, or a mutated + // snapshot such as `() => false || getUploadDesktopLayoutSnapshot()` all fail the guard. + const uploadDesktopHookSource = source("src/components/clinical-dashboard/use-upload-desktop-layout.ts"); + const useUploadDesktopLayoutBody = sourceSegment( + uploadDesktopHookSource, + "export function useUploadDesktopLayout(", + "}", + ); + expect(useUploadDesktopLayoutBody).toMatch( + /return\s+useSyncExternalStore\(\s*subscribeToUploadDesktopLayout,\s*getUploadDesktopLayoutSnapshot,\s*\(\)\s*=>\s*false\s*\)/, ); expect(clinicalDashboardSource).toContain('event.key === "ArrowRight"'); expect(clinicalDashboardSource).toContain('event.key === "ArrowLeft"');