From d7442d23ae558ff1c0b51996d8cf9f39f31fbcc1 Mon Sep 17 00:00:00 2001 From: Thomas Scholtes Date: Thu, 6 Jul 2023 13:53:48 +0200 Subject: [PATCH] Add tests for projectRouteToPath Signed-off-by: Thomas Scholtes --- tests/unit/router.test.ts | 237 +++++++++++++++++++++++++++++++++++++- 1 file changed, 235 insertions(+), 2 deletions(-) diff --git a/tests/unit/router.test.ts b/tests/unit/router.test.ts index e0f0ced78..7e8969372 100644 --- a/tests/unit/router.test.ts +++ b/tests/unit/router.test.ts @@ -5,6 +5,7 @@ import { testExports, type Route } from "@app/lib/router"; window.origin = "http://localhost:3000"; describe("route invariant when parsed", () => { + const origin = "http://localhost:3000"; const baseUrl = { hostname: "willow.radicle.garden", port: 8000, @@ -26,7 +27,7 @@ describe("route invariant when parsed", () => { }); }); test("projects.tree", () => { - return expectParsingInvariant({ + expectParsingInvariant({ resource: "projects", params: { view: { resource: "tree" }, @@ -36,8 +37,240 @@ describe("route invariant when parsed", () => { }); }); + test("projects.tree with peer", () => { + expectParsingInvariant({ + resource: "projects", + params: { + view: { resource: "tree" }, + baseUrl, + id: "PROJECT", + peer: "PEER", + route: "", + }, + }); + }); + + test("projects.tree with peer and revision", () => { + const route: Route = { + resource: "projects", + params: { + view: { resource: "tree" }, + baseUrl, + id: "PROJECT", + peer: "PEER", + revision: "REVISION", + route: "", + }, + }; + const path = testExports.routeToPath(route); + route.params.revision = undefined; + route.params.route = "REVISION"; + expect(testExports.pathToRoute(new URL(path, origin))).toEqual(route); + }); + + test("projects.tree with peer and revision and path", () => { + const route: Route = { + resource: "projects", + params: { + view: { resource: "tree" }, + baseUrl, + id: "PROJECT", + peer: "PEER", + path: "PATH", + revision: "REVISION", + route: "", + }, + }; + const path = testExports.routeToPath(route); + route.params.revision = undefined; + route.params.path = undefined; + route.params.route = "REVISION/PATH"; + expect(testExports.pathToRoute(new URL(path, origin))).toEqual(route); + }); + + test("projects.history", () => { + expectParsingInvariant({ + resource: "projects", + params: { + view: { resource: "history" }, + baseUrl, + id: "PROJECT", + route: "", + }, + }); + }); + + test("projects.history with revision", () => { + const route: Route = { + resource: "projects", + params: { + view: { resource: "history" }, + baseUrl, + id: "PROJECT", + peer: "PEER", + revision: "REVISION", + }, + }; + const path = testExports.routeToPath(route); + route.params.revision = undefined; + route.params.route = "REVISION"; + expect(testExports.pathToRoute(new URL(path, origin))).toEqual(route); + }); + + test("projects.commits", () => { + expectParsingInvariant({ + resource: "projects", + params: { + view: { resource: "commits", commitId: "COMMIT" }, + baseUrl, + id: "PROJECT", + peer: "PEER", + }, + }); + }); + + test("projects.issues", () => { + expectParsingInvariant({ + resource: "projects", + params: { + view: { + resource: "issues", + params: { view: { resource: "list" }, search: "" }, + }, + baseUrl, + id: "PROJECT", + }, + }); + }); + + test("projects.issues with search", () => { + expectParsingInvariant({ + resource: "projects", + params: { + view: { + resource: "issues", + params: { view: { resource: "list" }, search: "SEARCH" }, + }, + baseUrl, + id: "PROJECT", + }, + }); + }); + + test("projects.issues.new", () => { + expectParsingInvariant({ + resource: "projects", + params: { + view: { + resource: "issues", + params: { view: { resource: "new" }, search: "" }, + }, + baseUrl, + id: "PROJECT", + }, + }); + }); + + test("projects.issue", () => { + expectParsingInvariant({ + resource: "projects", + params: { + view: { + resource: "issue", + params: { issue: "ISSUE" }, + }, + baseUrl, + id: "PROJECT", + }, + }); + }); + + test("projects.patches"), + () => { + expectParsingInvariant({ + resource: "projects", + params: { + view: { + resource: "patches", + params: { view: { resource: "list" }, search: "" }, + }, + baseUrl, + id: "PROJECT", + }, + }); + }; + + test("projects.patches with search", () => { + expectParsingInvariant({ + resource: "projects", + params: { + view: { + resource: "patches", + params: { view: { resource: "list" }, search: "SEARCH" }, + }, + baseUrl, + id: "PROJECT", + }, + }); + }); + + test("projects.patch", () => { + expectParsingInvariant({ + resource: "projects", + params: { + view: { + resource: "patch", + params: { patch: "PATCH", search: "" }, + }, + baseUrl, + id: "PROJECT", + }, + }); + }); + + test("projects.patch with revision", () => { + expectParsingInvariant({ + resource: "projects", + params: { + view: { + resource: "patch", + params: { patch: "PATCH", search: "", revision: "REVISION" }, + }, + baseUrl, + id: "PROJECT", + }, + }); + }); + + test("projects.patch with search", () => { + expectParsingInvariant({ + resource: "projects", + params: { + view: { + resource: "patch", + params: { patch: "PATCH", search: "SEARCH" }, + }, + baseUrl, + id: "PROJECT", + }, + }); + }); + + test("projects.patch with revision and search", () => { + expectParsingInvariant({ + resource: "projects", + params: { + view: { + resource: "patch", + params: { patch: "PATCH", search: "SEARCH", revision: "REVISION" }, + }, + baseUrl, + id: "PROJECT", + }, + }); + }); + function expectParsingInvariant(route: Route) { - const origin = "http://localhost:3000"; const path = testExports.routeToPath(route); expect(testExports.pathToRoute(new URL(path, origin))).toEqual(route); }