UNPKG

one

Version:

One is a new React Framework that makes Vite serve both native and web.

24 lines (23 loc) 1.3 kB
import { afterEach, describe, expect, it } from "vitest"; import { isRouteProtected, registerProtectedRoutes, resolveProtectedHref, unregisterProtectedRoutes } from "./router.native.js"; var contextKey = "/account"; afterEach(function () { unregisterProtectedRoutes(contextKey); }); describe("protected route redirects", function () { it("resolves a protected href to its redirect target", function () { registerProtectedRoutes(contextKey, /* @__PURE__ */new Map([["settings", "/login"]])); expect(isRouteProtected("/account/settings?tab=billing")).toBe(true); expect(resolveProtectedHref("/account/settings?tab=billing")).toBe("/login"); }); it("blocks a protected href without an explicit target", function () { registerProtectedRoutes(contextKey, /* @__PURE__ */new Map([["settings", void 0]])); expect(resolveProtectedHref("/account/settings")).toBeUndefined(); }); it("leaves allowed and similarly prefixed routes unchanged", function () { registerProtectedRoutes(contextKey, /* @__PURE__ */new Map([["settings", "/login"]])); expect(resolveProtectedHref("/account/profile")).toBe("/account/profile"); expect(resolveProtectedHref("/accounting/settings")).toBe("/accounting/settings"); }); }); //# sourceMappingURL=protectedRoutes.test.native.js.map