Radish alpha
r
Radicle web interface
Radicle
Git (anonymous pull)
Log in to clone via SSH
Add tests for projectRouteToPath
Thomas Scholtes committed 2 years ago
commit d7442d23ae558ff1c0b51996d8cf9f39f31fbcc1
parent 2386b7c1543f9767496b072abf6b99c805a26d4b
1 file changed +235 -2
modified 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);
  }