one
Version:
One is a new React Framework that makes Vite serve both native and web.
1,727 lines (1,726 loc) • 46.7 kB
JavaScript
"use strict";
var import_vitest = require("vitest"), import_getPathFromState = require("../getPathFromState"), import_getStateFromPath = require("../getStateFromPath");
(0, import_vitest.test)("converts state to path string", function() {
var 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", function() {
var 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: function(author) {
return author.replace(/^\w/, function(c) {
return c.toUpperCase();
});
},
id: function(id) {
return Number(id.replace(/^x/, ""));
},
valid: Boolean
},
stringify: {
author: function(author) {
return author.toLowerCase();
},
id: function(id) {
return `x${id}`;
}
}
}
}
}
}
}
}
}, state = {
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
}
}
]
}
}
]
}
}
]
};
(0, import_vitest.expect)((0, import_getPathFromState.getPathFromState)(state, 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", function() {
(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", function() {
var path = "/foo/bar", state = {
routes: [
{
name: "foo",
state: {
routes: [
{
name: "bar"
}
]
}
}
]
};
(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)("doesn't add query param for empty params", function() {
var path = "/foo", state = {
routes: [
{
name: "foo",
params: {}
}
]
};
(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)("handles state with config with nested screens", function() {
var 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: function(author) {
return author.replace(/^\w/, function(c) {
return c.toUpperCase();
});
},
count: Number,
valid: Boolean
},
stringify: {
author: function(author) {
return author.toLowerCase();
},
id: function(id) {
return `x${id}`;
},
unknown: function(_) {
return "x";
}
}
}
}
}
}
}
}
}
}
}, state = {
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
}
}
]
}
}
]
}
}
]
}
}
]
};
(0, import_vitest.expect)((0, import_getPathFromState.getPathFromState)(state, 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", function() {
var 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: function(author) {
return author.replace(/^\w/, function(c) {
return c.toUpperCase();
});
},
count: Number,
valid: Boolean
},
stringify: {
author: function(author) {
return author.toLowerCase();
},
id: function(id) {
return `x${id}`;
},
unknown: function(_) {
return "x";
}
}
}
}
}
}
}
}
}
}
}, state = {
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
}
}
]
}
}
]
}
}
]
}
}
]
};
(0, import_vitest.expect)((0, import_getPathFromState.getPathFromState)(state, 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", function() {
var 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: function(author) {
return author.replace(/^\w/, function(c) {
return c.toUpperCase();
});
},
count: Number,
valid: Boolean
},
stringify: {
author: function(author) {
return author.replace(/^\w/, function(c) {
return c.toLowerCase();
});
},
unknown: function(_) {
return "x";
}
}
}
}
}
}
}
}
}, state = {
routes: [
{
name: "Foo",
state: {
routes: [
{
name: "Foe",
state: {
routes: [
{
name: "Baz",
params: {
answer: "42",
author: "Jane",
count: 10,
valid: !0
}
}
]
}
}
]
}
}
]
};
(0, import_vitest.expect)((0, import_getPathFromState.getPathFromState)(state, 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", function() {
var 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: function(author) {
return author.replace(/^\w/, function(c) {
return c.toUpperCase();
});
},
count: Number,
valid: Boolean
},
stringify: {
author: function(author) {
return author.replace(/^\w/, function(c) {
return c.toLowerCase();
});
},
unknown: function(_) {
return "x";
}
}
}
}
}
}
}
}
}, state = {
routes: [
{
name: "Foo",
state: {
routes: [
{
name: "Foe",
state: {
routes: [
{
name: "Baz",
params: {
answer: "42",
author: "Jane",
count: 10,
valid: !0
}
}
]
}
}
]
}
}
]
};
(0, import_vitest.expect)((0, import_getPathFromState.getPathFromState)(state, 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", function() {
var 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: function(author) {
return author.replace(/^\w/, function(c) {
return c.toLowerCase();
});
}
},
parse: {
author: function(author) {
return author.replace(/^\w/, function(c) {
return c.toUpperCase();
});
},
count: Number,
valid: Boolean
}
}
}
}
}
}
}
}
}
}, state = {
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
}
}
]
}
}
]
}
}
]
}
}
]
};
(0, import_vitest.expect)((0, import_getPathFromState.getPathFromState)(state, 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", function() {
var 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: function(author) {
return author.replace(/^\w/, function(c) {
return c.toLowerCase();
});
}
},
parse: {
author: function(author) {
return author.replace(/^\w/, function(c) {
return c.toUpperCase();
});
},
count: Number,
valid: Boolean
}
}
}
}
}
}
}
}
}
}, state = {
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
}
}
]
}
}
]
}
}
]
}
}
]
};
(0, import_vitest.expect)((0, import_getPathFromState.getPathFromState)(state, 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", function() {
var path = "/foo/bar/baz", config = {
screens: {
Foo: {
path: "foo",
screens: {
Foe: "foe",
Bar: {
path: "bar",
screens: {
Baz: "baz"
}
}
}
}
}
}, state = {
routes: [
{
name: "Foo",
state: {
routes: [
{
name: "Bar",
state: {
routes: [
{
name: "Baz"
}
]
}
}
]
}
}
]
};
(0, import_vitest.expect)((0, import_getPathFromState.getPathFromState)(state, 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", function() {
var path = "/baz", config = {
screens: {
Foo: {
path: "foo",
screens: {
Foe: "foe",
Bar: {
path: "bar",
screens: {
Baz: {
path: "baz",
exact: !0
}
}
}
}
}
}
}, state = {
routes: [
{
name: "Foo",
state: {
routes: [
{
name: "Bar",
state: {
routes: [
{
name: "Baz"
}
]
}
}
]
}
}
]
};
(0, import_vitest.expect)((0, import_getPathFromState.getPathFromState)(state, 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", function() {
var path = "/foo/dathomir/bar/42/baz", config = {
screens: {
Foo: {
path: "foo/:planet",
stringify: {
id: function(id) {
return `planet=${id}`;
}
},
screens: {
Foe: "foe",
Bar: {
path: "bar/:id",
parse: {
id: Number
},
screens: {
Baz: "baz"
}
}
}
}
}
}, state = {
routes: [
{
name: "Foo",
params: {
planet: "dathomir"
},
state: {
routes: [
{
name: "Bar",
state: {
routes: [
{
name: "Baz",
params: {
id: 42
}
}
]
}
}
]
}
}
]
};
(0, import_vitest.expect)((0, import_getPathFromState.getPathFromState)(state, 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", function() {
var path = "/baz", config = {
screens: {
Foo: {
path: "foo/:id",
stringify: {
id: function(id) {
return `id=${id}`;
}
},
screens: {
Foe: "foe",
Bar: {
path: "bar/:id",
stringify: {
id: function(id) {
return `id=${id}`;
}
},
parse: {
id: Number
},
screens: {
Baz: {
path: "baz",
exact: !0
}
}
}
}
}
}
}, state = {
routes: [
{
name: "Foo",
state: {
routes: [
{
name: "Bar",
state: {
routes: [
{
name: "Baz"
}
]
}
}
]
}
}
]
};
(0, import_vitest.expect)((0, import_getPathFromState.getPathFromState)(state, 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", function() {
var path = "/bar", config = {
screens: {
Foo: {
path: "",
screens: {
Foe: "foe"
}
},
Bar: "bar"
}
}, state = {
routes: [
{
name: "Foo",
state: {
routes: [
{
name: "Bar"
}
]
}
}
]
};
(0, import_vitest.expect)((0, import_getPathFromState.getPathFromState)(state, 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", function() {
var path = "/?foo=42", config = {
screens: {
Foo: {
screens: {
Foe: "foe",
Bar: {
screens: {
Qux: {
path: "",
parse: {
foo: Number
}
},
Baz: "baz"
}
}
}
}
}
}, state = {
routes: [
{
name: "Foo",
state: {
routes: [
{
name: "Bar",
state: {
routes: [
{
name: "Qux",
params: {
foo: 42
}
}
]
}
}
]
}
}
]
};
(0, import_vitest.expect)((0, import_getPathFromState.getPathFromState)(state, 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", function() {
var path = "/?toString=42", config = {
screens: {
Foo: {
screens: {
Foe: "foe",
Bar: {
screens: {
Qux: {
path: "",
parse: {}
},
Baz: "baz"
}
}
}
}
}
}, state = {
routes: [
{
name: "Foo",
state: {
routes: [
{
name: "Bar",
state: {
routes: [
{
name: "Qux",
params: {
toString: 42
}
}
]
}
}
]
}
}
]
};
(0, import_vitest.expect)((0, import_getPathFromState.getPathFromState)(state, 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", function() {
var path = "/foo/baz", config = {
screens: {
Foo: {
path: "foo",
screens: {
Bar: {
path: "",
screens: {
Baz: {
path: "baz"
}
}
}
}
}
}
}, state = {
routes: [
{
name: "Foo",
state: {
routes: [
{
name: "Bar",
state: {
routes: [
{
name: "Baz"
}
]
}
}
]
}
}
]
};
(0, import_vitest.expect)((0, import_getPathFromState.getPathFromState)(state, 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", function() {
var path = "/baz", config = {
screens: {
Foo: {
path: "foo",
screens: {
Bar: {
path: "",
exact: !0,
screens: {
Baz: {
path: "baz"
}
}
}
}
}
}
}, state = {
routes: [
{
name: "Foo",
state: {
routes: [
{
name: "Bar",
state: {
routes: [
{
name: "Baz"
}
]
}
}
]
}
}
]
};
(0, import_vitest.expect)((0, import_getPathFromState.getPathFromState)(state, 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", function() {
var path = "/foo/bar", config = {
screens: {
Foo: {
path: "foo",
screens: {
Bar: "bar"
}
},
Baz: {
path: ""
}
}
}, state = {
routes: [
{
name: "Foo",
state: {
routes: [
{
name: "Bar",
state: {
routes: [
{
name: "Baz"
}
]
}
}
]
}
}
]
};
(0, import_vitest.expect)((0, import_getPathFromState.getPathFromState)(state, 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', function() {
var path = "/", config = {
screens: {
Foo: {
path: "",
screens: {
Bar: ""
}
}
}
}, state = {
routes: [
{
name: "Foo",
state: {
routes: [
{
name: "Bar"
}
]
}
}
]
};
(0, import_vitest.expect)((0, import_getPathFromState.getPathFromState)(state, config)).toBe(path), (0, import_vitest.expect)((0, import_getPathFromState.getPathFromState)((0, import_getStateFromPath.getStateFromPath)(path, config), config)).toBe(path);
});
(0, import_vitest.test)("parses no path specified", function() {
var path = "/bar", config = {
screens: {
Foo: {
screens: {
Foe: {},
Bar: "bar"
}
}
}
}, state = {
routes: [
{
name: "Foo",
state: {
routes: [
{
name: "Bar"
}
]
}
}
]
};
(0, import_vitest.expect)((0, import_getPathFromState.getPathFromState)(state, 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", function() {
var 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: function(author) {
return author.replace(/^\w/, function(c) {
return c.toLowerCase();
});
}
},
parse: {
author: function(author) {
return author.replace(/^\w/, function(c) {
return c.toUpperCase();
});
},
count: Number,
valid: Boolean
}
}
}
}
}
}
}
}
}
}, state = {
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
}
}
]
}
}
]
}
}
]
}
}
]
};
(0, import_vitest.expect)((0, import_getPathFromState.getPathFromState)(state, 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", function() {
var 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: function(author) {
return author.replace(/^\w/, function(c) {
return c.toLowerCase();
});
}
},
parse: {
author: function(author) {
return author.replace(/^\w/, function(c) {
return c.toUpperCase();
});
},
count: Number,
valid: Boolean
}
}
}
}
}
}
}
}
}
}, state = {
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
}
}
]
}
}
]
}
}
]
}
}
]
};
(0, import_vitest.expect)((0, import_getPathFromState.getPathFromState)(state, 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", function() {
var 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: function(author) {
return author.replace(/^\w/, function(c) {
return c.toLowerCase();
});
}
},
parse: {
author: function(author) {
return author.replace(/^\w/, function(c) {
return c.toUpperCase();
});
},
count: Number,
valid: Boolean
}
}
}
}
}
}
}
}
}
}, state = {
routes: [
{
name: "Bar",
params: {
fruit: "apple",
type: "sweet"
},
state: {
routes: [
{
name: "Foo",
state: {
routes: [
{
name: "Baz",
state: {
routes: [
{
name: "Bis",
params: {
author: "Jane"
}
}
]
}
}
]
}
}
]
}
}
]
};
(0, import_vitest.expect)((0, import_getPathFromState.getPathFromState)(state, 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", function() {
var 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: function(author) {
return author.replace(/^\w/, function(c) {
return c.toLowerCase();
});
}
},
parse: {
author: function(author) {
return author.replace(/^\w/, function(c) {
return c.toUpperCase();
});
},
count: Number,
valid: Boolean
}
}
}
}
}
}
}
}
}
}, state = {
routes: [
{
name: "Bar",
params: {
fruit: "apple",
type: "sweet"
},
state: {
routes: [
{
name: "Foo",
state: {
routes: [
{
name: "Baz",
state: {
routes: [
{
name: "Bis",
params: {
author: "Jane"
}
}
]
}
}
]
}
}
]
}
}
]
};
(0, import_vitest.expect)((0, import_getPathFromState.getPathFromState)(state, 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", function() {
var path = "/bar/undefined/apple", config = {
screens: {
Bar: "bar/:type/:fruit"
}
}, state = {
routes: [
{
name: "Bar",
params: {
fruit: "apple"
}
}
]
};
(0, import_vitest.expect)((0, import_getPathFromState.getPathFromState)(state, 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", function() {
var path = "/test/bar/42/whatever", config = {
screens: {
404: "*",
Foo: {
screens: {
Bar: {
path: "/bar/:id/"
}
}
}
}
}, state = {
routes: [
{
name: "404"
}
]
};
(0, import_vitest.expect)((0, import_getPathFromState.getPathFromState)(state, 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", function() {
var path = "/bar/42/whatever/baz/initt", config = {
screens: {
Foo: {
screens: {
Bar: {
path: "/bar/:id/",
screens: {
404: "*"
}
}
}
}
}
}, state = {
routes: [
{
name: "Foo",
state: {
routes: [
{
name: "Bar",
params: {
id: "42"
},
state: {
routes: [
{
name: "404"
}
]
}
}
]
}
}
]
};
(0, import_vitest.expect)((0, import_getPathFromState.getPathFromState)(state, 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", function() {
var path = "/whatever", config = {
screens: {
Foo: {
screens: {
Bar: {
path: "/bar/:id/",
screens: {
404: {
path: "*",
exact: !0
}
}
},
Baz: {}
}
}
}
}, state = {
routes: [
{
name: "Foo",
state: {
routes: [
{
name: "Bar",
state: {
routes: [
{
name: "404"
}
]
}
}
]
}
}
]
};
(0, import_vitest.expect)((0, import_getPathFromState.getPathFromState)(state, 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", function() {
var path = "/bar/42/test", config = {
screens: {
Foo: {
screens: {
Bar: {
path: "/bar/:id/",
screens: {
404: "*",
Test: "test"
}
}
}
}
}
}, state = {
routes: [
{
name: "Foo",
state: {
routes: [
{
name: "Bar",
params: {
id: "42"
},
state: {
routes: [
{
name: "Test"
}
]
}
}
]
}
}
]
};
(0, import_vitest.expect)((0, import_getPathFromState.getPathFromState)(state, 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", function() {
var path = "/bar/42/baz/test", config = {
screens: {
Foo: {
screens: {
Bar: {
path: "/bar/:id/",
screens: {
Baz: "baz"
}
},
404: "*"
}
}
}
}, state = {
routes: [
{
name: "Foo",
state: {
routes: [
{
name: "404"
}
]
}
}
]
};
(0, import_vitest.expect)((0, import_getPathFromState.getPathFromState)(state, 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", function() {
var path = "foo/fruits/apple", config = {
path: "foo",
screens: {
Foo: {
screens: {
Fruits: "fruits/:fruit"
}
}
}
}, state = {
routes: [
{
name: "Foo",
state: {
routes: [
{
name: "Fruits",
params: {
fruit: "apple"
}
}
]
}
}
]
};
(0, import_vitest.expect)((0, import_getPathFromState.getPathFromState)(state, 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", function() {
var 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: function(id) {
return `@${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", function() {
var config = {
screens: {
Foo: {
path: "foo/:id([a-z]+\\/)"
}
}
};
(0, import_vitest.expect)((0, import_getPathFromState.getPathFromState)({
routes: [
{
name: "Foo",
params: {
id: "bar"
}
}
]
}, config)).toBe("/foo/bar");
});
//# sourceMappingURL=getPathFromState.test.js.map