UNPKG

one

Version:

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

274 lines (273 loc) 7.51 kB
import { describe, expect, it } from "vitest"; import { getNavigateAction } from "./getNavigateAction.native.js"; describe("getNavigateAction", function () { describe("NAVIGATE", function () { it("works", function () { var actionState = { routes: [{ name: "page-2" }] }, navigationState = { stale: !1, type: "stack", key: "stack-pWRo04", index: 0, routeNames: ["_sitemap", "index", "page-1", "page-2"], routes: [{ name: "page-1", key: "page-1-Gc-TeIdZmx_jAcRD-SGcs" }], preloadedRoutes: [] }, action = getNavigateAction(actionState, navigationState); expect(action).toStrictEqual({ type: "NAVIGATE", target: "stack-pWRo04", payload: { key: void 0, name: "page-2", params: {} } }); }), it("handles params", function () { var actionState = { routes: [{ name: "page-1", params: { foo: "foo", bar: "bar" } }] }, navigationState = { stale: !1, type: "stack", key: "stack-pWRo04", index: 0, routeNames: ["_sitemap", "index", "page-1", "page-2"], routes: [{ name: "page-1", key: "page-1-Gc-TeIdZmx_jAcRD-SGcs" }], preloadedRoutes: [] }, action = getNavigateAction(actionState, navigationState); expect(action).toStrictEqual({ type: "NAVIGATE", target: "stack-pWRo04", payload: { key: void 0, name: "page-1", params: { foo: "foo", bar: "bar" } } }); }), it("handles navigating into nested navigator", function () { var actionState = { routes: [{ name: "foo", state: { routes: [{ name: "bar", state: { routes: [{ name: "baz" }] } }] } }] }, navigationState = { stale: !1, type: "stack", key: "stack-5qQ9ln4FB9", index: 0, routeNames: ["index", "foo"], routes: [{ name: "index", key: "index-Kyz4PdQ7ZAvE0XFhBWydM" }], preloadedRoutes: [] }, action = getNavigateAction(actionState, navigationState); expect(action).toStrictEqual({ type: "NAVIGATE", target: "stack-5qQ9ln4FB9", payload: { key: void 0, name: "foo", params: { screen: "bar", params: { screen: "baz", params: {} } } } }); }), it("handles navigating into nested navigator with route params", function () { var actionState = { routes: [{ name: "[level1]", params: { level1: "foo" }, state: { routes: [{ name: "[level2]", params: { level1: "foo", level2: "bar" }, state: { routes: [{ name: "[level3]", params: { level1: "foo", level2: "bar", level3: "baz" } }] } }] } }] }, navigationState = { stale: !1, type: "stack", key: "stack-5qQ9ln4FB9", index: 0, routeNames: ["index", "[level1]"], routes: [{ name: "index", key: "index-Kyz4PdQ7ZAvE0XFhBWydM" }], preloadedRoutes: [] }, action = getNavigateAction(actionState, navigationState); expect(action).toStrictEqual({ type: "NAVIGATE", target: "stack-5qQ9ln4FB9", payload: { key: void 0, name: "[level1]", params: { level1: "foo", level2: "bar", // not actually necessary, but it's how the current implementation works screen: "[level2]", params: { level1: "foo", level2: "bar", level3: "baz", // not actually necessary, but it's how the current implementation works screen: "[level3]", params: { level1: "foo", level2: "bar", level3: "baz" } } } } }); }), it("correctly finds out where the states diverge and return an action valid payload", function () { var actionState = { routes: [{ name: "foo", state: { routes: [{ name: "bar", state: { routes: [{ name: "baz-2" }] } }] } }] }, navigationState = { stale: !1, type: "stack", key: "stack-aCzOliK0", routeNames: ["index", "foo"], index: 0, routes: [{ name: "foo", key: "foo-teuUBQHk", state: { stale: !1, type: "stack", key: "stack-XZ3RJRBg", routeNames: ["bar"], index: 0, routes: [{ name: "bar", key: "bar-FDtH59Dj", state: { stale: !1, type: "stack", key: "stack-s3o7RyPD", routeNames: ["baz-1", "baz-2"], index: 0, routes: [{ name: "baz-1", key: "baz-1-K2zLhRSZ" }] } }] } }], preloadedRoutes: [] }, action = getNavigateAction(actionState, navigationState); expect(action).toStrictEqual({ type: "NAVIGATE", target: "stack-s3o7RyPD", payload: { key: void 0, name: "baz-2", params: {} } }); }); }), describe("PUSH", function () { it("returns a NAVIGATE action with a unique key", function () { var actionState = { routes: [{ name: "page-2" }] }, navigationState = { stale: !1, type: "stack", key: "stack-pWRo04", index: 0, routeNames: ["_sitemap", "index", "page-1", "page-2"], routes: [{ name: "page-1", key: "page-1-Gc-TeIdZmx_jAcRD-SGcs" }], preloadedRoutes: [] }, action = getNavigateAction(actionState, navigationState, "PUSH"); expect(action).toStrictEqual({ type: "NAVIGATE", target: "stack-pWRo04", payload: { key: action.payload.key, /* since this contains a randomly generated nanoid */ name: "page-2", params: {} } }); }); }); }); //# sourceMappingURL=getNavigateAction.test.native.js.map