one
Version:
One is a new React Framework that makes Vite serve both native and web.
1,558 lines (1,557 loc) • 41.2 kB
JavaScript
var import_vitest = require("vitest"), import_getPathFromState = require("../getPathFromState"), import_getStateFromPath = require("../getStateFromPath");
(0, import_vitest.test)("converts state to path string", () => {
const state = {
routes: [
{
name: "foo",
state: {
index: 1,
routes: [
{ name: "boo" },
{
name: "bar",
params: { fruit: "apple" },
state: {
routes: [
{
name: "baz qux",
params: { author: "jane", valid: !0 }
}
]
}
}
]
}
}
]
}, path = "/foo/bar/baz%20qux?author=jane&valid=true";
(0, import_vitest.expect)((0, import_getPathFromState.getPathFromState)(state)).toBe(path), (0, import_vitest.expect)((0, import_getPathFromState.getPathFromState)((0, import_getStateFromPath.getStateFromPath)(path))).toBe(path);
});
(0, import_vitest.test)("converts state to path string with config", () => {
const path = "/few/bar/sweet/apple/baz/jane?id=x10&valid=true", config = {
screens: {
Foo: {
path: "few",
screens: {
Bar: {
path: "bar/:type/:fruit",
screens: {
Baz: {
path: "baz/:author",
parse: {
author: (author) => author.replace(/^\w/, (c) => c.toUpperCase()),
id: (id) => Number(id.replace(/^x/, "")),
valid: Boolean
},
stringify: {
author: (author) => author.toLowerCase(),
id: (id) => `x${id}`
}
}
}
}
}
}
}
};
(0, import_vitest.expect)((0, import_getPathFromState.getPathFromState)({
routes: [
{
name: "Foo",
state: {
index: 1,
routes: [
{ name: "boo" },
{
name: "Bar",
params: { fruit: "apple", type: "sweet", avaliable: !1 },
state: {
routes: [
{
name: "Baz",
params: {
author: "Jane",
id: 10,
valid: !0
}
}
]
}
}
]
}
}
]
}, config)).toBe(path), (0, import_vitest.expect)((0, import_getPathFromState.getPathFromState)((0, import_getStateFromPath.getStateFromPath)(path, config), config)).toBe(
path
);
});
(0, import_vitest.test)("prepends trailing slash to path", () => {
(0, import_vitest.expect)(
(0, import_getPathFromState.getPathFromState)({
routes: [
{
name: "foo",
state: {
routes: [{ name: "bar" }]
}
}
]
})
).toBe("/foo/bar"), (0, import_vitest.expect)(
(0, import_getPathFromState.getPathFromState)({
routes: [
{
name: "foo",
state: {
routes: [{ name: "bar", path: "foo/bar" }]
}
}
]
})
).toBe("/foo/bar");
});
(0, import_vitest.test)("handles route without param", () => {
const path = "/foo/bar";
(0, import_vitest.expect)((0, import_getPathFromState.getPathFromState)({
routes: [
{
name: "foo",
state: {
routes: [{ name: "bar" }]
}
}
]
})).toBe(path), (0, import_vitest.expect)((0, import_getPathFromState.getPathFromState)((0, import_getStateFromPath.getStateFromPath)(path))).toBe(path);
});
(0, import_vitest.test)("doesn't add query param for empty params", () => {
const path = "/foo";
(0, import_vitest.expect)((0, import_getPathFromState.getPathFromState)({
routes: [
{
name: "foo",
params: {}
}
]
})).toBe(path), (0, import_vitest.expect)((0, import_getPathFromState.getPathFromState)((0, import_getStateFromPath.getStateFromPath)(path))).toBe(path);
});
(0, import_vitest.test)("handles state with config with nested screens", () => {
const path = "/foo/foe/bar/sweet/apple/baz/jane?answer=42&count=10&valid=true", config = {
screens: {
Foo: {
path: "foo",
screens: {
Foe: {
path: "foe",
screens: {
Bar: {
path: "bar/:type/:fruit",
screens: {
Baz: {
path: "baz/:author",
parse: {
author: (author) => author.replace(/^\w/, (c) => c.toUpperCase()),
count: Number,
valid: Boolean
},
stringify: {
author: (author) => author.toLowerCase(),
id: (id) => `x${id}`,
unknown: (_) => "x"
}
}
}
}
}
}
}
}
}
};
(0, import_vitest.expect)((0, import_getPathFromState.getPathFromState)({
routes: [
{
name: "Foo",
state: {
routes: [
{
name: "Foe",
state: {
routes: [
{
name: "Bar",
params: { fruit: "apple", type: "sweet" },
state: {
routes: [
{
name: "Baz",
params: {
answer: "42",
author: "Jane",
count: "10",
valid: !0
}
}
]
}
}
]
}
}
]
}
}
]
}, config)).toBe(path), (0, import_vitest.expect)((0, import_getPathFromState.getPathFromState)((0, import_getStateFromPath.getStateFromPath)(path, config), config)).toBe(
path
);
});
(0, import_vitest.test)("handles state with config with nested screens and exact", () => {
const path = "/foe/bar/sweet/apple/baz/jane?answer=42&count=10&valid=true", config = {
screens: {
Foo: {
path: "foo",
screens: {
Foe: {
path: "foe",
exact: !0,
screens: {
Bar: {
path: "bar/:type/:fruit",
screens: {
Baz: {
path: "baz/:author",
parse: {
author: (author) => author.replace(/^\w/, (c) => c.toUpperCase()),
count: Number,
valid: Boolean
},
stringify: {
author: (author) => author.toLowerCase(),
id: (id) => `x${id}`,
unknown: (_) => "x"
}
}
}
}
}
}
}
}
}
};
(0, import_vitest.expect)((0, import_getPathFromState.getPathFromState)({
routes: [
{
name: "Foo",
state: {
routes: [
{
name: "Foe",
state: {
routes: [
{
name: "Bar",
params: { fruit: "apple", type: "sweet" },
state: {
routes: [
{
name: "Baz",
params: {
answer: "42",
author: "Jane",
count: "10",
valid: !0
}
}
]
}
}
]
}
}
]
}
}
]
}, config)).toBe(path), (0, import_vitest.expect)((0, import_getPathFromState.getPathFromState)((0, import_getStateFromPath.getStateFromPath)(path, config), config)).toBe(
path
);
});
(0, import_vitest.test)("handles state with config with nested screens and unused configs", () => {
const path = "/foo/foe/baz/jane?answer=42&count=10&valid=true", config = {
screens: {
Foo: {
path: "foo",
screens: {
Foe: {
path: "foe",
screens: {
Baz: {
path: "baz/:author",
parse: {
author: (author) => author.replace(/^\w/, (c) => c.toUpperCase()),
count: Number,
valid: Boolean
},
stringify: {
author: (author) => author.replace(/^\w/, (c) => c.toLowerCase()),
unknown: (_) => "x"
}
}
}
}
}
}
}
};
(0, import_vitest.expect)((0, import_getPathFromState.getPathFromState)({
routes: [
{
name: "Foo",
state: {
routes: [
{
name: "Foe",
state: {
routes: [
{
name: "Baz",
params: {
answer: "42",
author: "Jane",
count: 10,
valid: !0
}
}
]
}
}
]
}
}
]
}, config)).toBe(path), (0, import_vitest.expect)((0, import_getPathFromState.getPathFromState)((0, import_getStateFromPath.getStateFromPath)(path, config), config)).toBe(
path
);
});
(0, import_vitest.test)("handles state with config with nested screens and unused configs with exact", () => {
const path = "/foe/baz/jane?answer=42&count=10&valid=true", config = {
screens: {
Foo: {
path: "foo",
screens: {
Foe: {
path: "foe",
exact: !0,
screens: {
Baz: {
path: "baz/:author",
parse: {
author: (author) => author.replace(/^\w/, (c) => c.toUpperCase()),
count: Number,
valid: Boolean
},
stringify: {
author: (author) => author.replace(/^\w/, (c) => c.toLowerCase()),
unknown: (_) => "x"
}
}
}
}
}
}
}
};
(0, import_vitest.expect)((0, import_getPathFromState.getPathFromState)({
routes: [
{
name: "Foo",
state: {
routes: [
{
name: "Foe",
state: {
routes: [
{
name: "Baz",
params: {
answer: "42",
author: "Jane",
count: 10,
valid: !0
}
}
]
}
}
]
}
}
]
}, config)).toBe(path), (0, import_vitest.expect)((0, import_getPathFromState.getPathFromState)((0, import_getStateFromPath.getStateFromPath)(path, config), config)).toBe(
path
);
});
(0, import_vitest.test)("handles nested object with stringify in it", () => {
const path = "/bar/sweet/apple/foo/bis/jane?answer=42&count=10&valid=true", config = {
screens: {
Bar: {
path: "bar/:type/:fruit",
screens: {
Foo: {
path: "foo",
screens: {
Foe: {
path: "foe"
},
Baz: {
screens: {
Bos: "bos",
Bis: {
path: "bis/:author",
stringify: {
author: (author) => author.replace(/^\w/, (c) => c.toLowerCase())
},
parse: {
author: (author) => author.replace(/^\w/, (c) => c.toUpperCase()),
count: Number,
valid: Boolean
}
}
}
}
}
}
}
}
}
};
(0, import_vitest.expect)((0, import_getPathFromState.getPathFromState)({
routes: [
{
name: "Bar",
params: { fruit: "apple", type: "sweet" },
state: {
routes: [
{
name: "Foo",
state: {
routes: [
{
name: "Baz",
state: {
routes: [
{
name: "Bis",
params: {
answer: "42",
author: "Jane",
count: 10,
valid: !0
}
}
]
}
}
]
}
}
]
}
}
]
}, config)).toBe(path), (0, import_vitest.expect)((0, import_getPathFromState.getPathFromState)((0, import_getStateFromPath.getStateFromPath)(path, config), config)).toBe(
path
);
});
(0, import_vitest.test)("handles nested object with stringify in it with exact", () => {
const path = "/bis/jane?answer=42&count=10&valid=true", config = {
screens: {
Bar: {
path: "bar/:type/:fruit",
screens: {
Foo: {
path: "foo",
screens: {
Foe: {
path: "foe"
},
Baz: {
path: "baz",
screens: {
Bos: "bos",
Bis: {
path: "bis/:author",
exact: !0,
stringify: {
author: (author) => author.replace(/^\w/, (c) => c.toLowerCase())
},
parse: {
author: (author) => author.replace(/^\w/, (c) => c.toUpperCase()),
count: Number,
valid: Boolean
}
}
}
}
}
}
}
}
}
};
(0, import_vitest.expect)((0, import_getPathFromState.getPathFromState)({
routes: [
{
name: "Bar",
params: { fruit: "apple", type: "sweet" },
state: {
routes: [
{
name: "Foo",
state: {
routes: [
{
name: "Baz",
state: {
routes: [
{
name: "Bis",
params: {
answer: "42",
author: "Jane",
count: 10,
valid: !0
}
}
]
}
}
]
}
}
]
}
}
]
}, config)).toBe(path), (0, import_vitest.expect)((0, import_getPathFromState.getPathFromState)((0, import_getStateFromPath.getStateFromPath)(path, config), config)).toBe(
path
);
});
(0, import_vitest.test)("handles nested object for second route depth", () => {
const path = "/foo/bar/baz", config = {
screens: {
Foo: {
path: "foo",
screens: {
Foe: "foe",
Bar: {
path: "bar",
screens: {
Baz: "baz"
}
}
}
}
}
};
(0, import_vitest.expect)((0, import_getPathFromState.getPathFromState)({
routes: [
{
name: "Foo",
state: {
routes: [
{
name: "Bar",
state: {
routes: [{ name: "Baz" }]
}
}
]
}
}
]
}, config)).toBe(path), (0, import_vitest.expect)((0, import_getPathFromState.getPathFromState)((0, import_getStateFromPath.getStateFromPath)(path, config), config)).toBe(
path
);
});
(0, import_vitest.test)("handles nested object for second route depth with exact", () => {
const path = "/baz", config = {
screens: {
Foo: {
path: "foo",
screens: {
Foe: "foe",
Bar: {
path: "bar",
screens: {
Baz: {
path: "baz",
exact: !0
}
}
}
}
}
}
};
(0, import_vitest.expect)((0, import_getPathFromState.getPathFromState)({
routes: [
{
name: "Foo",
state: {
routes: [
{
name: "Bar",
state: {
routes: [{ name: "Baz" }]
}
}
]
}
}
]
}, config)).toBe(path), (0, import_vitest.expect)((0, import_getPathFromState.getPathFromState)((0, import_getStateFromPath.getStateFromPath)(path, config), config)).toBe(
path
);
});
(0, import_vitest.test)("handles nested object for second route depth and path and stringify in roots", () => {
const path = "/foo/dathomir/bar/42/baz", config = {
screens: {
Foo: {
path: "foo/:planet",
stringify: {
id: (id) => `planet=${id}`
},
screens: {
Foe: "foe",
Bar: {
path: "bar/:id",
parse: {
id: Number
},
screens: {
Baz: "baz"
}
}
}
}
}
};
(0, import_vitest.expect)((0, import_getPathFromState.getPathFromState)({
routes: [
{
name: "Foo",
params: { planet: "dathomir" },
state: {
routes: [
{
name: "Bar",
state: {
routes: [{ name: "Baz", params: { id: 42 } }]
}
}
]
}
}
]
}, config)).toBe(path), (0, import_vitest.expect)((0, import_getPathFromState.getPathFromState)((0, import_getStateFromPath.getStateFromPath)(path, config), config)).toBe(
path
);
});
(0, import_vitest.test)("handles nested object for second route depth and path and stringify in roots with exact", () => {
const path = "/baz", config = {
screens: {
Foo: {
path: "foo/:id",
stringify: {
id: (id) => `id=${id}`
},
screens: {
Foe: "foe",
Bar: {
path: "bar/:id",
stringify: {
id: (id) => `id=${id}`
},
parse: {
id: Number
},
screens: {
Baz: {
path: "baz",
exact: !0
}
}
}
}
}
}
};
(0, import_vitest.expect)((0, import_getPathFromState.getPathFromState)({
routes: [
{
name: "Foo",
state: {
routes: [
{
name: "Bar",
state: {
routes: [{ name: "Baz" }]
}
}
]
}
}
]
}, config)).toBe(path), (0, import_vitest.expect)((0, import_getPathFromState.getPathFromState)((0, import_getStateFromPath.getStateFromPath)(path, config), config)).toBe(
path
);
});
(0, import_vitest.test)("ignores empty string paths", () => {
const path = "/bar", config = {
screens: {
Foo: {
path: "",
screens: {
Foe: "foe"
}
},
Bar: "bar"
}
};
(0, import_vitest.expect)((0, import_getPathFromState.getPathFromState)({
routes: [
{
name: "Foo",
state: {
routes: [{ name: "Bar" }]
}
}
]
}, config)).toBe(path), (0, import_vitest.expect)((0, import_getPathFromState.getPathFromState)((0, import_getStateFromPath.getStateFromPath)(path, config), config)).toBe(
path
);
});
(0, import_vitest.test)("keeps query params if path is empty", () => {
const path = "/?foo=42", config = {
screens: {
Foo: {
screens: {
Foe: "foe",
Bar: {
screens: {
Qux: {
path: "",
parse: { foo: Number }
},
Baz: "baz"
}
}
}
}
}
};
(0, import_vitest.expect)((0, import_getPathFromState.getPathFromState)({
routes: [
{
name: "Foo",
state: {
routes: [
{
name: "Bar",
state: {
routes: [{ name: "Qux", params: { foo: 42 } }]
}
}
]
}
}
]
}, config)).toBe(path), (0, import_vitest.expect)((0, import_getPathFromState.getPathFromState)((0, import_getStateFromPath.getStateFromPath)(path, config), config)).toEqual(
path
);
});
(0, import_vitest.test)("does not use Object.prototype properties as parsing functions", () => {
const path = "/?toString=42", config = {
screens: {
Foo: {
screens: {
Foe: "foe",
Bar: {
screens: {
Qux: {
path: "",
parse: {}
},
Baz: "baz"
}
}
}
}
}
};
(0, import_vitest.expect)((0, import_getPathFromState.getPathFromState)({
routes: [
{
name: "Foo",
state: {
routes: [
{
name: "Bar",
state: {
routes: [{ name: "Qux", params: { toString: 42 } }]
}
}
]
}
}
]
}, config)).toBe(path), (0, import_vitest.expect)((0, import_getPathFromState.getPathFromState)((0, import_getStateFromPath.getStateFromPath)(path, config), config)).toEqual(
path
);
});
(0, import_vitest.test)("cuts nested configs too", () => {
const path = "/foo/baz", config = {
screens: {
Foo: {
path: "foo",
screens: {
Bar: {
path: "",
screens: {
Baz: {
path: "baz"
}
}
}
}
}
}
};
(0, import_vitest.expect)((0, import_getPathFromState.getPathFromState)({
routes: [
{
name: "Foo",
state: {
routes: [
{
name: "Bar",
state: {
routes: [{ name: "Baz" }]
}
}
]
}
}
]
}, config)).toBe(path), (0, import_vitest.expect)((0, import_getPathFromState.getPathFromState)((0, import_getStateFromPath.getStateFromPath)(path, config), config)).toBe(
path
);
});
(0, import_vitest.test)("cuts nested configs too with exact", () => {
const path = "/baz", config = {
screens: {
Foo: {
path: "foo",
screens: {
Bar: {
path: "",
exact: !0,
screens: {
Baz: {
path: "baz"
}
}
}
}
}
}
};
(0, import_vitest.expect)((0, import_getPathFromState.getPathFromState)({
routes: [
{
name: "Foo",
state: {
routes: [
{
name: "Bar",
state: {
routes: [{ name: "Baz" }]
}
}
]
}
}
]
}, config)).toBe(path), (0, import_vitest.expect)((0, import_getPathFromState.getPathFromState)((0, import_getStateFromPath.getStateFromPath)(path, config), config)).toBe(
path
);
});
(0, import_vitest.test)("handles empty path at the end", () => {
const path = "/foo/bar", config = {
screens: {
Foo: {
path: "foo",
screens: {
Bar: "bar"
}
},
Baz: { path: "" }
}
};
(0, import_vitest.expect)((0, import_getPathFromState.getPathFromState)({
routes: [
{
name: "Foo",
state: {
routes: [
{
name: "Bar",
state: {
routes: [{ name: "Baz" }]
}
}
]
}
}
]
}, config)).toBe(path), (0, import_vitest.expect)((0, import_getPathFromState.getPathFromState)((0, import_getStateFromPath.getStateFromPath)(path, config), config)).toBe(
path
);
});
(0, import_vitest.test)('returns "/" for empty path', () => {
const config = {
screens: {
Foo: {
path: "",
screens: {
Bar: ""
}
}
}
};
(0, import_vitest.expect)((0, import_getPathFromState.getPathFromState)({
routes: [
{
name: "Foo",
state: {
routes: [
{
name: "Bar"
}
]
}
}
]
}, config)).toBe("/"), (0, import_vitest.expect)((0, import_getPathFromState.getPathFromState)((0, import_getStateFromPath.getStateFromPath)("/", config), config)).toBe(
"/"
);
});
(0, import_vitest.test)("parses no path specified", () => {
const path = "/bar", config = {
screens: {
Foo: {
screens: {
Foe: {},
Bar: "bar"
}
}
}
};
(0, import_vitest.expect)((0, import_getPathFromState.getPathFromState)({
routes: [
{
name: "Foo",
state: {
routes: [{ name: "Bar" }]
}
}
]
}, config)).toBe(path), (0, import_vitest.expect)((0, import_getPathFromState.getPathFromState)((0, import_getStateFromPath.getStateFromPath)(path, config), config)).toBe(
path
);
});
(0, import_vitest.test)("strips undefined query params", () => {
const path = "/bar/sweet/apple/foo/bis/jane?count=10&valid=true", config = {
screens: {
Bar: {
path: "bar/:type/:fruit",
screens: {
Foo: {
path: "foo",
screens: {
Foe: {
path: "foe"
},
Baz: {
screens: {
Bos: "bos",
Bis: {
path: "bis/:author",
stringify: {
author: (author) => author.replace(/^\w/, (c) => c.toLowerCase())
},
parse: {
author: (author) => author.replace(/^\w/, (c) => c.toUpperCase()),
count: Number,
valid: Boolean
}
}
}
}
}
}
}
}
}
};
(0, import_vitest.expect)((0, import_getPathFromState.getPathFromState)({
routes: [
{
name: "Bar",
params: { fruit: "apple", type: "sweet" },
state: {
routes: [
{
name: "Foo",
state: {
routes: [
{
name: "Baz",
state: {
routes: [
{
name: "Bis",
params: {
author: "Jane",
count: 10,
valid: !0
}
}
]
}
}
]
}
}
]
}
}
]
}, config)).toBe(path), (0, import_vitest.expect)((0, import_getPathFromState.getPathFromState)((0, import_getStateFromPath.getStateFromPath)(path, config), config)).toBe(
path
);
});
(0, import_vitest.test)("strips undefined query params with exact", () => {
const path = "/bis/jane?count=10&valid=true", config = {
screens: {
Bar: {
path: "bar/:type/:fruit",
screens: {
Foo: {
path: "foo",
screens: {
Foe: {
path: "foe"
},
Baz: {
screens: {
Bos: "bos",
Bis: {
path: "bis/:author",
exact: !0,
stringify: {
author: (author) => author.replace(/^\w/, (c) => c.toLowerCase())
},
parse: {
author: (author) => author.replace(/^\w/, (c) => c.toUpperCase()),
count: Number,
valid: Boolean
}
}
}
}
}
}
}
}
}
};
(0, import_vitest.expect)((0, import_getPathFromState.getPathFromState)({
routes: [
{
name: "Bar",
params: { fruit: "apple", type: "sweet" },
state: {
routes: [
{
name: "Foo",
state: {
routes: [
{
name: "Baz",
state: {
routes: [
{
name: "Bis",
params: {
author: "Jane",
count: 10,
valid: !0
}
}
]
}
}
]
}
}
]
}
}
]
}, config)).toBe(path), (0, import_vitest.expect)((0, import_getPathFromState.getPathFromState)((0, import_getStateFromPath.getStateFromPath)(path, config), config)).toBe(
path
);
});
(0, import_vitest.test)("handles stripping all query params", () => {
const path = "/bar/sweet/apple/foo/bis/jane", config = {
screens: {
Bar: {
path: "bar/:type/:fruit",
screens: {
Foo: {
path: "foo",
screens: {
Foe: {
path: "foe"
},
Baz: {
screens: {
Bos: "bos",
Bis: {
path: "bis/:author",
stringify: {
author: (author) => author.replace(/^\w/, (c) => c.toLowerCase())
},
parse: {
author: (author) => author.replace(/^\w/, (c) => c.toUpperCase()),
count: Number,
valid: Boolean
}
}
}
}
}
}
}
}
}
};
(0, import_vitest.expect)((0, import_getPathFromState.getPathFromState)({
routes: [
{
name: "Bar",
params: { fruit: "apple", type: "sweet" },
state: {
routes: [
{
name: "Foo",
state: {
routes: [
{
name: "Baz",
state: {
routes: [
{
name: "Bis",
params: {
author: "Jane"
}
}
]
}
}
]
}
}
]
}
}
]
}, config)).toBe(path), (0, import_vitest.expect)((0, import_getPathFromState.getPathFromState)((0, import_getStateFromPath.getStateFromPath)(path, config), config)).toBe(
path
);
});
(0, import_vitest.test)("handles stripping all query params with exact", () => {
const path = "/bis/jane", config = {
screens: {
Bar: {
path: "bar/:type/:fruit",
screens: {
Foo: {
path: "foo",
screens: {
Foe: {
path: "foe"
},
Baz: {
path: "baz",
screens: {
Bos: "bos",
Bis: {
path: "bis/:author",
exact: !0,
stringify: {
author: (author) => author.replace(/^\w/, (c) => c.toLowerCase())
},
parse: {
author: (author) => author.replace(/^\w/, (c) => c.toUpperCase()),
count: Number,
valid: Boolean
}
}
}
}
}
}
}
}
}
};
(0, import_vitest.expect)((0, import_getPathFromState.getPathFromState)({
routes: [
{
name: "Bar",
params: { fruit: "apple", type: "sweet" },
state: {
routes: [
{
name: "Foo",
state: {
routes: [
{
name: "Baz",
state: {
routes: [
{
name: "Bis",
params: {
author: "Jane"
}
}
]
}
}
]
}
}
]
}
}
]
}, config)).toBe(path), (0, import_vitest.expect)((0, import_getPathFromState.getPathFromState)((0, import_getStateFromPath.getStateFromPath)(path, config), config)).toBe(
path
);
});
(0, import_vitest.test)("replaces undefined query params", () => {
const path = "/bar/undefined/apple", config = {
screens: {
Bar: "bar/:type/:fruit"
}
};
(0, import_vitest.expect)((0, import_getPathFromState.getPathFromState)({
routes: [
{
name: "Bar",
params: { fruit: "apple" }
}
]
}, config)).toBe(path), (0, import_vitest.expect)((0, import_getPathFromState.getPathFromState)((0, import_getStateFromPath.getStateFromPath)(path, config), config)).toBe(
path
);
});
import_vitest.test.skip("matches wildcard patterns at root", () => {
const path = "/test/bar/42/whatever", config = {
screens: {
404: "*",
Foo: {
screens: {
Bar: {
path: "/bar/:id/"
}
}
}
}
};
(0, import_vitest.expect)((0, import_getPathFromState.getPathFromState)({
routes: [{ name: "404" }]
}, config)).toBe("/404"), (0, import_vitest.expect)((0, import_getPathFromState.getPathFromState)((0, import_getStateFromPath.getStateFromPath)(path, config), config)).toBe(
"/404"
);
});
import_vitest.test.skip("matches wildcard patterns at nested level", () => {
const path = "/bar/42/whatever/baz/initt", config = {
screens: {
Foo: {
screens: {
Bar: {
path: "/bar/:id/",
screens: {
404: "*"
}
}
}
}
}
};
(0, import_vitest.expect)((0, import_getPathFromState.getPathFromState)({
routes: [
{
name: "Foo",
state: {
routes: [
{
name: "Bar",
params: { id: "42" },
state: {
routes: [{ name: "404" }]
}
}
]
}
}
]
}, config)).toBe("/bar/42/404"), (0, import_vitest.expect)((0, import_getPathFromState.getPathFromState)((0, import_getStateFromPath.getStateFromPath)(path, config), config)).toBe(
"/bar/42/404"
);
});
import_vitest.test.skip("matches wildcard patterns at nested level with exact", () => {
const path = "/whatever", config = {
screens: {
Foo: {
screens: {
Bar: {
path: "/bar/:id/",
screens: {
404: {
path: "*",
exact: !0
}
}
},
Baz: {}
}
}
}
};
(0, import_vitest.expect)((0, import_getPathFromState.getPathFromState)({
routes: [
{
name: "Foo",
state: {
routes: [
{
name: "Bar",
state: {
routes: [{ name: "404" }]
}
}
]
}
}
]
}, config)).toBe("/404"), (0, import_vitest.expect)((0, import_getPathFromState.getPathFromState)((0, import_getStateFromPath.getStateFromPath)(path, config), config)).toBe(
"/404"
);
});
(0, import_vitest.test)("tries to match wildcard patterns at the end", () => {
const path = "/bar/42/test", config = {
screens: {
Foo: {
screens: {
Bar: {
path: "/bar/:id/",
screens: {
404: "*",
Test: "test"
}
}
}
}
}
};
(0, import_vitest.expect)((0, import_getPathFromState.getPathFromState)({
routes: [
{
name: "Foo",
state: {
routes: [
{
name: "Bar",
params: { id: "42" },
state: {
routes: [{ name: "Test" }]
}
}
]
}
}
]
}, config)).toBe(path), (0, import_vitest.expect)((0, import_getPathFromState.getPathFromState)((0, import_getStateFromPath.getStateFromPath)(path, config), config)).toBe(
path
);
});
import_vitest.test.skip("uses nearest parent wildcard match for unmatched paths", () => {
const path = "/bar/42/baz/test", config = {
screens: {
Foo: {
screens: {
Bar: {
path: "/bar/:id/",
screens: {
Baz: "baz"
}
},
404: "*"
}
}
}
};
(0, import_vitest.expect)((0, import_getPathFromState.getPathFromState)({
routes: [
{
name: "Foo",
state: {
routes: [{ name: "404" }]
}
}
]
}, config)).toBe("/404"), (0, import_vitest.expect)((0, import_getPathFromState.getPathFromState)((0, import_getStateFromPath.getStateFromPath)(path, config), config)).toBe(
"/404"
);
});
import_vitest.test.skip("handles path at top level", () => {
const path = "foo/fruits/apple", config = {
path: "foo",
screens: {
Foo: {
screens: {
Fruits: "fruits/:fruit"
}
}
}
};
(0, import_vitest.expect)((0, import_getPathFromState.getPathFromState)({
routes: [
{
name: "Foo",
state: {
routes: [
{
name: "Fruits",
params: { fruit: "apple" }
}
]
}
}
]
}, config)).toBe(`/${path}`), (0, import_vitest.expect)((0, import_getPathFromState.getPathFromState)((0, import_getStateFromPath.getStateFromPath)(path, config), config)).toBe(`/${path}`);
});
import_vitest.test.skip("ignores regexp patterns when provided", () => {
const config = {
screens: {
Foo: {
path: "foo/:id(\\d+)",
parse: {
id: Number
}
},
Bar: {
path: "foo/:id([a-z]+)"
},
Baz: {
path: "foo/:id(\\d+)/:name([a-z]+)"
},
Qux: {
path: "foo/:id(@[a-z]+)",
stringify: {
id: (id) => `@${id}`
}
}
}
};
(0, import_vitest.expect)(
(0, import_getPathFromState.getPathFromState)(
{
routes: [
{
name: "Foo",
params: { id: 42 }
}
]
},
config
)
).toBe("/foo/42"), (0, import_vitest.expect)(
(0, import_getPathFromState.getPathFromState)(
{
routes: [
{
name: "Bar",
params: { id: "bar" }
}
]
},
config
)
).toBe("/foo/bar"), (0, import_vitest.expect)(
(0, import_getPathFromState.getPathFromState)(
{
routes: [
{
name: "Baz",
params: { id: 42, name: "bar" }
}
]
},
config
)
).toBe("/foo/42/bar"), (0, import_vitest.expect)(
(0, import_getPathFromState.getPathFromState)(
{
routes: [
{
name: "Qux",
params: { id: "bar" }
}
]
},
config
)
).toBe("/foo/@bar");
});
import_vitest.test.skip("correctly handles regex pattern with slash", () => {
(0, import_vitest.expect)(
(0, import_getPathFromState.getPathFromState)(
{
routes: [
{
name: "Foo",
params: { id: "bar" }
}
]
},
{
screens: {
Foo: {
path: "foo/:id([a-z]+\\/)"
}
}
}
)
).toBe("/foo/bar");
});
//# sourceMappingURL=getPathFromState.test.js.map