UNPKG

one

Version:

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

124 lines (123 loc) 2.88 kB
import { describe, expect, it } from "vitest"; import { getPathFromState } from "./getPathFromState.native.js"; describe("hash support", function () { it("appends hash to the path", function () { var state = { index: 0, key: "key", routes: [{ name: "index", path: "/", params: { "#": "hash1" } }], stale: true, type: "stack" }; var config = { screens: { index: "", _sitemap: "_sitemap" } }; expect(getPathFromState(state, config)).toBe("/#hash1"); }); it("works with nested state, existing router and path params", function () { var state = { index: 1, key: "key", routeNames: ["index", "[test]", "_sitemap", "+not-found"], routes: [{ key: "key", name: "index", params: void 0, path: "/" }, { key: "key", name: "[test]", params: { test: "hello-world", query: "true", "#": "a" }, path: void 0 }], stale: false, type: "stack" }; var config = { screens: { "[test]": ":test", index: "", _sitemap: "_sitemap" } }; expect(getPathFromState(state, config)).toBe("/hello-world?query=true#a"); }); }); it.skip(`handles url search params params`, function () { var state = { routes: [{ name: "index", params: { test: "true", hello: "world", array: ["1", "2"] }, path: "/?test=true&hello=world&array=1&array=2" }] }; var config = { screens: { index: "", _sitemap: "_sitemap" } }; expect(getPathFromState(state, config)).toBe("/?test=true&hello=world&array=1&array=2"); }); it(`handles uninitialized state on nested navigation with route params`, function () { var config = { screens: { index: "", "[folderSlugL1]": { path: ":folderSlugL1", screens: { "[folderSlugL2]": { path: ":folderSlugL2", screens: { "[folderSlugL3]": { path: ":folderSlugL3", screens: { page: "page" } } } } } } } }; var state = { routes: [{ name: "[folderSlugL1]", params: { folderSlugL1: "foo", screen: "[folderSlugL2]", params: { folderSlugL1: "foo", folderSlugL2: "bar", screen: "[folderSlugL3]", params: { folderSlugL1: "foo", folderSlugL2: "bar", folderSlugL3: "baz", screen: "page" } } } }] }; expect(getPathFromState(state, config)).toBe("/foo/bar/baz/page"); }); //# sourceMappingURL=getPathFromState.test.native.js.map