UNPKG

one

Version:

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

75 lines (74 loc) 2.59 kB
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime"; import React from "react"; import TestRenderer, { act } from "react-test-renderer"; import { describe, expect, it } from "vitest"; import { Protected } from "../views/Protected.native.js"; import { Screen } from "../views/Screen.native.js"; import { useFilterScreenChildren } from "./withLayoutContext.native.js"; function readGuardedRedirects(children) { var result; function Capture() { result = useFilterScreenChildren(children); return null; } act(function () { TestRenderer.create(/* @__PURE__ */_jsx(Capture, {})); }); return result.guardedRedirects; } describe("Protected redirectTo", function () { it("associates a failed guard redirect with each protected screen", function () { var redirects = readGuardedRedirects(/* @__PURE__ */_jsxs(Protected, { guard: false, redirectTo: "/login", children: [/* @__PURE__ */_jsx(Screen, { name: "dashboard" }), /* @__PURE__ */_jsx(Screen, { name: "settings" })] })); expect(Array.from(redirects)).toEqual([["dashboard", "/login"], ["settings", "/login"]]); }); it("uses the innermost failing guard redirect", function () { var redirects = readGuardedRedirects(/* @__PURE__ */_jsx(Protected, { guard: false, redirectTo: "/login", children: /* @__PURE__ */_jsx(Protected, { guard: false, redirectTo: "/subscribe", children: /* @__PURE__ */_jsx(Screen, { name: "premium" }) }) })); expect(redirects.get("premium")).toBe("/subscribe"); }); it("inherits a failed parent redirect through a passing child guard", function () { var redirects = readGuardedRedirects(/* @__PURE__ */_jsx(Protected, { guard: false, redirectTo: "/login", children: /* @__PURE__ */_jsx(Protected, { guard: true, children: /* @__PURE__ */_jsx(Screen, { name: "account" }) }) })); expect(redirects.get("account")).toBe("/login"); }); it("ignores redirectTo on a passing parent guard", function () { var redirects = readGuardedRedirects(/* @__PURE__ */_jsx(Protected, { guard: true, redirectTo: "/login", children: /* @__PURE__ */_jsx(Protected, { guard: false, children: /* @__PURE__ */_jsx(Screen, { name: "account" }) }) })); expect(redirects.has("account")).toBe(true); expect(redirects.get("account")).toBeUndefined(); }); }); //# sourceMappingURL=withLayoutContext.test.native.js.map