one
Version:
One is a new React Framework that makes Vite serve both native and web.
22 lines • 1.47 kB
JavaScript
var import_vitest = require("vitest");
var import_router = require("./router.cjs");
const contextKey = "/account";
(0, import_vitest.afterEach)(() => {
(0, import_router.unregisterProtectedRoutes)(contextKey);
});
(0, import_vitest.describe)("protected route redirects", () => {
(0, import_vitest.it)("resolves a protected href to its redirect target", () => {
(0, import_router.registerProtectedRoutes)(contextKey, /* @__PURE__ */new Map([["settings", "/login"]]));
(0, import_vitest.expect)((0, import_router.isRouteProtected)("/account/settings?tab=billing")).toBe(true);
(0, import_vitest.expect)((0, import_router.resolveProtectedHref)("/account/settings?tab=billing")).toBe("/login");
});
(0, import_vitest.it)("blocks a protected href without an explicit target", () => {
(0, import_router.registerProtectedRoutes)(contextKey, /* @__PURE__ */new Map([["settings", void 0]]));
(0, import_vitest.expect)((0, import_router.resolveProtectedHref)("/account/settings")).toBeUndefined();
});
(0, import_vitest.it)("leaves allowed and similarly prefixed routes unchanged", () => {
(0, import_router.registerProtectedRoutes)(contextKey, /* @__PURE__ */new Map([["settings", "/login"]]));
(0, import_vitest.expect)((0, import_router.resolveProtectedHref)("/account/profile")).toBe("/account/profile");
(0, import_vitest.expect)((0, import_router.resolveProtectedHref)("/accounting/settings")).toBe("/accounting/settings");
});
});