-
Notifications
You must be signed in to change notification settings - Fork 894
fix: only show editable orgs on deployment page #14193
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 9 commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
713b954
fix: only show editable orgs on deployment page
code-asher 9f39257
canEditOrganization was lying
code-asher 475f6e2
Limit the number of org permission checks
code-asher 83bf388
fixup! fix: only show editable orgs on deployment page
code-asher e4f5bf7
Pass in ids instead of entire orgs
code-asher 9e76ebc
Assign permission value in one spot
code-asher bfa0000
Improved sort
code-asher b86684d
Tuples-b-gone
code-asher 6b42506
Destruct props
code-asher 02e7e47
No need for extra routes with a bit of ?
code-asher ddd2ea5
Add org IDs to permissions query
code-asher 64631e1
Two is now one
code-asher 9aca231
Merge remote-tracking branch 'github/main' into asher/show-editable-orgs
code-asher ba22bc9
fixup! Merge remote-tracking branch 'github/main' into asher/show-edi…
code-asher 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
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
125 changes: 125 additions & 0 deletions
125
site/src/pages/ManagementSettingsPage/OrganizationSettingsPage.test.tsx
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,125 @@ | ||
import { screen, within } from "@testing-library/react"; | ||
import { HttpResponse, http } from "msw"; | ||
import { | ||
MockDefaultOrganization, | ||
MockOrganization2, | ||
} from "testHelpers/entities"; | ||
import { | ||
renderWithManagementSettingsLayout, | ||
waitForLoaderToBeRemoved, | ||
} from "testHelpers/renderHelpers"; | ||
import { server } from "testHelpers/server"; | ||
import OrganizationSettingsPage from "./OrganizationSettingsPage"; | ||
|
||
jest.spyOn(console, "error").mockImplementation(() => {}); | ||
|
||
const renderRootPage = async () => { | ||
renderWithManagementSettingsLayout(<OrganizationSettingsPage />, { | ||
route: "/organizations", | ||
path: "/organizations", | ||
code-asher marked this conversation as resolved.
Show resolved
Hide resolved
|
||
extraRoutes: [ | ||
{ | ||
path: "/organizations/:organization", | ||
element: <OrganizationSettingsPage />, | ||
}, | ||
], | ||
}); | ||
await waitForLoaderToBeRemoved(); | ||
}; | ||
|
||
const renderPage = async (orgName: string) => { | ||
renderWithManagementSettingsLayout(<OrganizationSettingsPage />, { | ||
route: `/organizations/${orgName}`, | ||
path: "/organizations/:organization", | ||
}); | ||
await waitForLoaderToBeRemoved(); | ||
}; | ||
|
||
describe("OrganizationSettingsPage", () => { | ||
it("has no organizations", async () => { | ||
server.use( | ||
http.get("/api/v2/organizations", () => { | ||
return HttpResponse.json([]); | ||
}), | ||
http.post("/api/v2/authcheck", async () => { | ||
return HttpResponse.json({ | ||
[`${MockDefaultOrganization.id}.editOrganization`]: true, | ||
viewDeploymentValues: true, | ||
}); | ||
}), | ||
); | ||
await renderRootPage(); | ||
await screen.findByText("No organizations found"); | ||
}); | ||
|
||
it("has no editable organizations", async () => { | ||
server.use( | ||
http.get("/api/v2/organizations", () => { | ||
return HttpResponse.json([MockDefaultOrganization, MockOrganization2]); | ||
}), | ||
http.post("/api/v2/authcheck", async () => { | ||
return HttpResponse.json({ | ||
viewDeploymentValues: true, | ||
}); | ||
}), | ||
); | ||
await renderRootPage(); | ||
await screen.findByText("No organizations found"); | ||
}); | ||
|
||
it("redirects to default organization", async () => { | ||
server.use( | ||
http.get("/api/v2/organizations", () => { | ||
// Default always preferred regardless of order. | ||
return HttpResponse.json([MockOrganization2, MockDefaultOrganization]); | ||
}), | ||
http.post("/api/v2/authcheck", async () => { | ||
return HttpResponse.json({ | ||
[`${MockDefaultOrganization.id}.editOrganization`]: true, | ||
[`${MockOrganization2.id}.editOrganization`]: true, | ||
viewDeploymentValues: true, | ||
}); | ||
}), | ||
); | ||
await renderRootPage(); | ||
const form = screen.getByTestId("org-settings-form"); | ||
expect(within(form).getByRole("textbox", { name: "Name" })).toHaveValue( | ||
MockDefaultOrganization.name, | ||
); | ||
}); | ||
|
||
it("redirects to non-default organization", async () => { | ||
server.use( | ||
http.get("/api/v2/organizations", () => { | ||
return HttpResponse.json([MockDefaultOrganization, MockOrganization2]); | ||
}), | ||
http.post("/api/v2/authcheck", async () => { | ||
return HttpResponse.json({ | ||
[`${MockOrganization2.id}.editOrganization`]: true, | ||
viewDeploymentValues: true, | ||
}); | ||
}), | ||
); | ||
await renderRootPage(); | ||
const form = screen.getByTestId("org-settings-form"); | ||
expect(within(form).getByRole("textbox", { name: "Name" })).toHaveValue( | ||
MockOrganization2.name, | ||
); | ||
}); | ||
|
||
it("cannot find organization", async () => { | ||
server.use( | ||
http.get("/api/v2/organizations", () => { | ||
return HttpResponse.json([MockDefaultOrganization, MockOrganization2]); | ||
}), | ||
http.post("/api/v2/authcheck", async () => { | ||
return HttpResponse.json({ | ||
[`${MockOrganization2.id}.editOrganization`]: true, | ||
viewDeploymentValues: true, | ||
}); | ||
}), | ||
); | ||
await renderPage("the-endless-void"); | ||
await screen.findByText("Organization not found"); | ||
}); | ||
}); |
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
Oops, something went wrong.
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.