one
Version:
One is a new React Framework that makes Vite serve both native and web.
297 lines (296 loc) • 7.42 kB
JavaScript
import { describe, expect, it } from "vitest";
import { getNavigateAction } from "./getNavigateAction";
describe("getNavigateAction", () => {
describe("NAVIGATE", () => {
it("works", () => {
const action = 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: []
});
expect(action).toStrictEqual({
type: "NAVIGATE",
target: "stack-pWRo04",
payload: { key: void 0, name: "page-2", params: {} }
});
}), it("handles params", () => {
const action = 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: []
});
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", () => {
const action = 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: []
});
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", () => {
const action = 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: []
});
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", () => {
const action = 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: []
});
expect(action).toStrictEqual({
type: "NAVIGATE",
target: "stack-s3o7RyPD",
payload: {
key: void 0,
name: "baz-2",
params: {}
}
});
});
}), describe("PUSH", () => {
it("returns a NAVIGATE action with a unique key", () => {
const action = 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");
expect(action).toStrictEqual({
type: "NAVIGATE",
target: "stack-pWRo04",
payload: {
key: action.payload.key,
name: "page-2",
params: {}
}
});
});
});
});
//# sourceMappingURL=getNavigateAction.test.js.map