UNPKG

one

Version:

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

101 lines (99 loc) 4.56 kB
"use strict"; var __create = Object.create; var __defProp = Object.defineProperty; var __getOwnPropDesc = Object.getOwnPropertyDescriptor; var __getOwnPropNames = Object.getOwnPropertyNames; var __getProtoOf = Object.getPrototypeOf; var __hasOwnProp = Object.prototype.hasOwnProperty; var __copyProps = (to, from, except, desc) => { if (from && typeof from === "object" || typeof from === "function") { for (let key of __getOwnPropNames(from)) if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable }); } return to; }; var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps( // If the importer is in node compatibility mode or this is not an ESM // file that has been converted to a CommonJS file using a Babel- // compatible transform (i.e. "__esModule" has not been set), then set // "default" to the CommonJS "module.exports" for node compatibility. isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target, mod)); var import_jsx_runtime = require("react/jsx-runtime"); var import_react = __toESM(require("react"), 1); var import_react_test_renderer = __toESM(require("react-test-renderer"), 1); var import_vitest = require("vitest"); var import_Protected = require("../views/Protected.native.js"); var import_Screen = require("../views/Screen.native.js"); var import_withLayoutContext = require("./withLayoutContext.native.js"); function readGuardedRedirects(children) { var result; function Capture() { result = (0, import_withLayoutContext.useFilterScreenChildren)(children); return null; } (0, import_react_test_renderer.act)(function () { import_react_test_renderer.default.create(/* @__PURE__ */(0, import_jsx_runtime.jsx)(Capture, {})); }); return result.guardedRedirects; } (0, import_vitest.describe)("Protected redirectTo", function () { (0, import_vitest.it)("associates a failed guard redirect with each protected screen", function () { var redirects = readGuardedRedirects(/* @__PURE__ */(0, import_jsx_runtime.jsxs)(import_Protected.Protected, { guard: false, redirectTo: "/login", children: [/* @__PURE__ */(0, import_jsx_runtime.jsx)(import_Screen.Screen, { name: "dashboard" }), /* @__PURE__ */(0, import_jsx_runtime.jsx)(import_Screen.Screen, { name: "settings" })] })); (0, import_vitest.expect)(Array.from(redirects)).toEqual([["dashboard", "/login"], ["settings", "/login"]]); }); (0, import_vitest.it)("uses the innermost failing guard redirect", function () { var redirects = readGuardedRedirects(/* @__PURE__ */(0, import_jsx_runtime.jsx)(import_Protected.Protected, { guard: false, redirectTo: "/login", children: /* @__PURE__ */(0, import_jsx_runtime.jsx)(import_Protected.Protected, { guard: false, redirectTo: "/subscribe", children: /* @__PURE__ */(0, import_jsx_runtime.jsx)(import_Screen.Screen, { name: "premium" }) }) })); (0, import_vitest.expect)(redirects.get("premium")).toBe("/subscribe"); }); (0, import_vitest.it)("inherits a failed parent redirect through a passing child guard", function () { var redirects = readGuardedRedirects(/* @__PURE__ */(0, import_jsx_runtime.jsx)(import_Protected.Protected, { guard: false, redirectTo: "/login", children: /* @__PURE__ */(0, import_jsx_runtime.jsx)(import_Protected.Protected, { guard: true, children: /* @__PURE__ */(0, import_jsx_runtime.jsx)(import_Screen.Screen, { name: "account" }) }) })); (0, import_vitest.expect)(redirects.get("account")).toBe("/login"); }); (0, import_vitest.it)("ignores redirectTo on a passing parent guard", function () { var redirects = readGuardedRedirects(/* @__PURE__ */(0, import_jsx_runtime.jsx)(import_Protected.Protected, { guard: true, redirectTo: "/login", children: /* @__PURE__ */(0, import_jsx_runtime.jsx)(import_Protected.Protected, { guard: false, children: /* @__PURE__ */(0, import_jsx_runtime.jsx)(import_Screen.Screen, { name: "account" }) }) })); (0, import_vitest.expect)(redirects.has("account")).toBe(true); (0, import_vitest.expect)(redirects.get("account")).toBeUndefined(); }); }); //# sourceMappingURL=withLayoutContext.test.native.js.map