mirror of
https://seed.radicle.dev/rad:z4V1sjrXqjvFdnCUbxPFqd5p4DtH5.git
synced 2026-11-09 13:40:28 +08:00
Add tests for projectRouteToPath
Signed-off-by: Thomas Scholtes <geigerzaehler@axiom.fm>
This commit is contained in:
+235
-2
@@ -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);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user