From 2c3eccf9d6f7937b8ff8908c651d68b5cd691f3c Mon Sep 17 00:00:00 2001 From: Hongming Wang Date: Thu, 23 Apr 2026 10:29:53 -0700 Subject: [PATCH] test(auth): provide window.location.pathname in redirectToLogin mocks The pathname.startsWith() loop-break added to redirectToLogin needs pathname on the mock Location object; tests were supplying only href. Co-Authored-By: Claude Opus 4.7 (1M context) --- canvas/src/lib/__tests__/auth.test.ts | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/canvas/src/lib/__tests__/auth.test.ts b/canvas/src/lib/__tests__/auth.test.ts index f1cd3b52..8188ddf2 100644 --- a/canvas/src/lib/__tests__/auth.test.ts +++ b/canvas/src/lib/__tests__/auth.test.ts @@ -47,7 +47,12 @@ describe("redirectToLogin", () => { const href = "https://acme.moleculesai.app/dashboard"; Object.defineProperty(window, "location", { writable: true, - value: { href }, + value: { + href, + pathname: "/dashboard", + hostname: "acme.moleculesai.app", + protocol: "https:", + }, }); redirectToLogin("sign-in"); // href now holds the redirect target. encodeURIComponent(href) must @@ -61,7 +66,12 @@ describe("redirectToLogin", () => { it("uses signup path for sign-up screenHint", () => { Object.defineProperty(window, "location", { writable: true, - value: { href: "https://acme.moleculesai.app/" }, + value: { + href: "https://acme.moleculesai.app/", + pathname: "/", + hostname: "acme.moleculesai.app", + protocol: "https:", + }, }); redirectToLogin("sign-up"); expect((window.location as unknown as { href: string }).href).toContain("/cp/auth/signup");