one
Version:
One is a new React Framework that makes Vite serve both native and web.
296 lines (295 loc) • 7.88 kB
JavaScript
var import_vitest = require("vitest"), import_getNavigateAction = require("./getNavigateAction");
(0, import_vitest.describe)("getNavigateAction", () => {
(0, import_vitest.describe)("NAVIGATE", () => {
(0, import_vitest.it)("works", () => {
const action = (0, import_getNavigateAction.getNavigateAction)({
routes: [
{
name: "page-2"
}
]
}, {
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: []
});
(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", () => {
const action = (0, import_getNavigateAction.getNavigateAction)({
routes: [
{
name: "page-1",
params: {
foo: "foo",
bar: "bar"
}
}
]
}, {
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: []
});
(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", () => {
const action = (0, import_getNavigateAction.getNavigateAction)({
routes: [
{
name: "foo",
state: {
routes: [
{
name: "bar",
state: {
routes: [
{
name: "baz"
}
]
}
}
]
}
}
]
}, {
stale: !1,
type: "stack",
key: "stack-5qQ9ln4FB9",
index: 0,
routeNames: ["index", "foo"],
routes: [
{
name: "index",
key: "index-Kyz4PdQ7ZAvE0XFhBWydM"
}
],
preloadedRoutes: []
});
(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", () => {
const action = (0, import_getNavigateAction.getNavigateAction)({
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"
}
}
]
}
}
]
}
}
]
}, {
stale: !1,
type: "stack",
key: "stack-5qQ9ln4FB9",
index: 0,
routeNames: ["index", "[level1]"],
routes: [
{
name: "index",
key: "index-Kyz4PdQ7ZAvE0XFhBWydM"
}
],
preloadedRoutes: []
});
(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", () => {
const action = (0, import_getNavigateAction.getNavigateAction)({
routes: [
{
name: "foo",
state: {
routes: [
{
name: "bar",
state: {
routes: [
{
name: "baz-2"
}
]
}
}
]
}
}
]
}, {
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: []
});
(0, import_vitest.expect)(action).toStrictEqual({
type: "NAVIGATE",
target: "stack-s3o7RyPD",
payload: {
key: void 0,
name: "baz-2",
params: {}
}
});
});
}), (0, import_vitest.describe)("PUSH", () => {
(0, import_vitest.it)("returns a NAVIGATE action with a unique key", () => {
const action = (0, import_getNavigateAction.getNavigateAction)({
routes: [
{
name: "page-2"
}
]
}, {
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: []
}, "PUSH");
(0, import_vitest.expect)(action).toStrictEqual({
type: "NAVIGATE",
target: "stack-pWRo04",
payload: {
key: action.payload.key,
name: "page-2",
params: {}
}
});
});
});
});
//# sourceMappingURL=getNavigateAction.test.js.map