- Notifications
You must be signed in to change notification settings - Fork928
fix: disable AccountForm when user is not allowed edit users#3649
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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
Merged
Uh oh!
There was an error while loading.Please reload this page.
Merged
Changes fromall commits
Commits
Show all changes
7 commits Select commitHold shift + click to select a range
15f7d35
RED: add unit tests for AccountForm username field
johnstcn8772cf0
hopefully make the test green
johnstcnbbce1af
remove unnecesary tests
johnstcn1800982
move things to the right place
johnstcn8e8b4ec
PR comment
johnstcna8ad515
ensure button is also not enabled
johnstcn73fc790
🤯
johnstcnFile filter
Filter by extension
Conversations
Failed to load comments.
Loading
Uh oh!
There was an error while loading.Please reload this page.
Jump to
Jump to file
Failed to load files.
Loading
Uh oh!
There was an error while loading.Please reload this page.
Diff view
Diff view
There are no files selected for viewing
65 changes: 65 additions & 0 deletionssite/src/components/SettingsAccountForm/SettingsAccountForm.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,65 @@ | ||
import { screen } from "@testing-library/react" | ||
import { MockUser2 } from "../../testHelpers/entities" | ||
import { render } from "../../testHelpers/renderHelpers" | ||
import { AccountForm, AccountFormValues } from "./SettingsAccountForm" | ||
// NOTE: it does not matter what the role props of MockUser are set to, | ||
// only that editable is set to true or false. This is passed from | ||
// the call to /authorization done by authXService | ||
describe("AccountForm", () => { | ||
describe("when editable is set to true", () => { | ||
it("allows updating username", async () => { | ||
// Given | ||
const mockInitialValues: AccountFormValues = { | ||
username: MockUser2.username, | ||
} | ||
// When | ||
render( | ||
<AccountForm | ||
editable | ||
email={MockUser2.email} | ||
initialValues={mockInitialValues} | ||
isLoading={false} | ||
onSubmit={() => { | ||
return | ||
}} | ||
/>, | ||
) | ||
// Then | ||
const el = await screen.findByLabelText("Username") | ||
expect(el).toBeEnabled() | ||
const btn = await screen.findByRole("button", { name: /Update settings/i }) | ||
expect(btn).toBeEnabled() | ||
}) | ||
}) | ||
describe("when editable is set to false", () => { | ||
it("does not allow updating username", async () => { | ||
// Given | ||
const mockInitialValues: AccountFormValues = { | ||
username: MockUser2.username, | ||
} | ||
// When | ||
render( | ||
<AccountForm | ||
editable={false} | ||
email={MockUser2.email} | ||
initialValues={mockInitialValues} | ||
isLoading={false} | ||
onSubmit={() => { | ||
return | ||
}} | ||
/>, | ||
) | ||
// Then | ||
const el = await screen.findByLabelText("Username") | ||
expect(el).toBeDisabled() | ||
const btn = await screen.findByRole("button", { name: /Update settings/i }) | ||
expect(btn).toBeDisabled() | ||
}) | ||
}) | ||
}) |
14 changes: 12 additions & 2 deletionssite/src/components/SettingsAccountForm/SettingsAccountForm.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
8 changes: 6 additions & 2 deletionssite/src/pages/UserSettingsPage/AccountPage/AccountPage.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
10 changes: 10 additions & 0 deletionssite/src/testHelpers/entities.ts
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
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.