UNPKG

one

Version:

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

331 lines (330 loc) 8.74 kB
"use strict"; var import_vitest = require("vitest"), import_getNavigateAction = require("./getNavigateAction"); (0, import_vitest.describe)("getNavigateAction", function() { (0, import_vitest.describe)("NAVIGATE", function() { (0, import_vitest.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 = (0, import_getNavigateAction.getNavigateAction)(actionState, navigationState); (0, import_vitest.expect)(action).toStrictEqual({ type: "NAVIGATE", target: "stack-pWRo04", payload: { key: void 0, name: "page-2", params: {} } }); }), (0, import_vitest.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 = (0, import_getNavigateAction.getNavigateAction)(actionState, navigationState); (0, import_vitest.expect)(action).toStrictEqual({ type: "NAVIGATE", target: "stack-pWRo04", payload: { key: void 0, name: "page-1", params: { foo: "foo", bar: "bar" } } }); }), (0, import_vitest.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 = (0, import_getNavigateAction.getNavigateAction)(actionState, navigationState); (0, import_vitest.expect)(action).toStrictEqual({ type: "NAVIGATE", target: "stack-5qQ9ln4FB9", payload: { key: void 0, name: "foo", params: { screen: "bar", params: { screen: "baz", params: {} } } } }); }), (0, import_vitest.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 = (0, import_getNavigateAction.getNavigateAction)(actionState, navigationState); (0, import_vitest.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" } } } } }); }), (0, import_vitest.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 = (0, import_getNavigateAction.getNavigateAction)(actionState, navigationState); (0, import_vitest.expect)(action).toStrictEqual({ type: "NAVIGATE", target: "stack-s3o7RyPD", payload: { key: void 0, name: "baz-2", params: {} } }); }); }), (0, import_vitest.describe)("PUSH", function() { (0, import_vitest.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 = (0, import_getNavigateAction.getNavigateAction)(actionState, navigationState, "PUSH"); (0, import_vitest.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.js.map