-
Notifications
You must be signed in to change notification settings - Fork 581
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore(site): Add unit tests, mocks (#514)
* Extract and unit test redirect functions * Move router to make app more testable * Make mock entities more consistent * Use labels instead of placeholders * Fill out handlers * Lint * Reorganize App * Make mock entities reference each other * Add describes in tests * Clean up api and mocks
- Loading branch information
Showing
10 changed files
with
161 additions
and
118 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
import React from "react" | ||
import { Routes, Route } from "react-router-dom" | ||
import { RequireAuth, AuthAndNav } from "./components" | ||
import { IndexPage } from "./pages" | ||
import { NotFoundPage } from "./pages/404" | ||
import { CliAuthenticationPage } from "./pages/cli-auth" | ||
import { HealthzPage } from "./pages/healthz" | ||
import { SignInPage } from "./pages/login" | ||
import { ProjectsPage } from "./pages/projects" | ||
import { ProjectPage } from "./pages/projects/[organization]/[project]" | ||
import { CreateWorkspacePage } from "./pages/projects/[organization]/[project]/create" | ||
import { WorkspacePage } from "./pages/workspaces/[workspace]" | ||
|
||
export const AppRouter: React.FC = () => ( | ||
<Routes> | ||
<Route path="/"> | ||
<Route | ||
index | ||
element={ | ||
<RequireAuth> | ||
<IndexPage /> | ||
</RequireAuth> | ||
} | ||
/> | ||
|
||
<Route path="login" element={<SignInPage />} /> | ||
<Route path="healthz" element={<HealthzPage />} /> | ||
<Route path="cli-auth" element={<CliAuthenticationPage />} /> | ||
|
||
<Route path="projects"> | ||
<Route | ||
index | ||
element={ | ||
<AuthAndNav> | ||
<ProjectsPage /> | ||
</AuthAndNav> | ||
} | ||
/> | ||
<Route path=":organization/:project"> | ||
<Route | ||
index | ||
element={ | ||
<AuthAndNav> | ||
<ProjectPage /> | ||
</AuthAndNav> | ||
} | ||
/> | ||
<Route | ||
path="create" | ||
element={ | ||
<RequireAuth> | ||
<CreateWorkspacePage /> | ||
</RequireAuth> | ||
} | ||
/> | ||
</Route> | ||
</Route> | ||
|
||
<Route path="workspaces"> | ||
<Route | ||
path=":workspace" | ||
element={ | ||
<AuthAndNav> | ||
<WorkspacePage /> | ||
</AuthAndNav> | ||
} | ||
/> | ||
</Route> | ||
|
||
{/* Using path="*"" means "match anything", so this route | ||
acts like a catch-all for URLs that we don't have explicit | ||
routes for. */} | ||
<Route path="*" element={<NotFoundPage />} /> | ||
</Route> | ||
</Routes> | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import { embedRedirect, retrieveRedirect } from "./redirect" | ||
|
||
describe("redirect helper functions", () => { | ||
describe("embedRedirect", () => { | ||
it("embeds the page to return to in the URL", () => { | ||
const result = embedRedirect("/workspaces", "/page") | ||
expect(result).toEqual("/page?redirect=%2Fworkspaces") | ||
}) | ||
it("defaults to navigating to the login page", () => { | ||
const result = embedRedirect("/workspaces") | ||
expect(result).toEqual("/login?redirect=%2Fworkspaces") | ||
}) | ||
}) | ||
describe("retrieveRedirect", () => { | ||
it("retrieves the page to return to from the URL", () => { | ||
const result = retrieveRedirect("?redirect=%2Fworkspaces") | ||
expect(result).toEqual("/workspaces") | ||
}) | ||
}) | ||
}) |
Oops, something went wrong.