-
Notifications
You must be signed in to change notification settings - Fork 928
chore(site): Add unit tests, mocks #514
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
d612209
Extract and unit test redirect functions
presleyp 194c787
Move router to make app more testable
presleyp 5198d39
Make mock entities more consistent
presleyp e79e3de
Use labels instead of placeholders
presleyp 2c74904
Fill out handlers
presleyp 3e6b156
Lint
presleyp 42cc2fb
Merge branch 'main' into 465/presleyp/routing
presleyp fd0407f
Reorganize App
presleyp 3633dfc
Make mock entities reference each other
presleyp 507b54a
Add describes in tests
presleyp 0e2315c
Clean up api and mocks
presleyp a0eca97
Merge branch 'main' into 465/presleyp/routing
presleyp File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 |
---|---|---|
|
@@ -5,39 +5,39 @@ export const MockSessionToken = { session_token: "my-session-token" } | |
export const MockAPIKey = { key: "my-api-key" } | ||
|
||
export const MockUser: UserResponse = { | ||
id: "test-user-id", | ||
id: "test-user", | ||
username: "TestUser", | ||
email: "[email protected]", | ||
created_at: "", | ||
} | ||
|
||
export const MockProject: Project = { | ||
id: "project-id", | ||
export const MockOrganization: Organization = { | ||
id: "test-org", | ||
name: "Test Organization", | ||
created_at: "", | ||
updated_at: "", | ||
organization_id: "test-org", | ||
name: "Test Project", | ||
provisioner: "test-provisioner", | ||
active_version_id: "", | ||
} | ||
|
||
export const MockProvisioner: Provisioner = { | ||
id: "test-provisioner", | ||
name: "Test Provisioner", | ||
} | ||
|
||
export const MockOrganization: Organization = { | ||
id: "test-org", | ||
name: "Test Organization", | ||
export const MockProject: Project = { | ||
id: "test-project", | ||
created_at: "", | ||
updated_at: "", | ||
organization_id: MockOrganization.id, | ||
name: "Test Project", | ||
provisioner: MockProvisioner.id, | ||
active_version_id: "", | ||
} | ||
|
||
export const MockWorkspace: Workspace = { | ||
id: "test-workspace", | ||
name: "Test-Workspace", | ||
created_at: "", | ||
updated_at: "", | ||
project_id: "project-id", | ||
owner_id: "test-user-id", | ||
project_id: MockProject.id, | ||
owner_id: MockUser.id, | ||
} |
This file contains hidden or 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 hidden or 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.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.