|
| 1 | +import { screen } from "@testing-library/react" |
| 2 | +import { MockUser2 } from "../../testHelpers/entities" |
| 3 | +import { render } from "../../testHelpers/renderHelpers" |
| 4 | +import { AccountForm, AccountFormValues } from "./SettingsAccountForm" |
| 5 | + |
| 6 | +// NOTE: it does not matter what the role props of MockUser are set to, |
| 7 | +// only that editable is set to true or false. This is passed from |
| 8 | +// the call to /authorization done by authXService |
| 9 | +describe("AccountForm", () => { |
| 10 | + describe("for owners", () => { |
| 11 | + it("allows updating username", async () => { |
| 12 | + // Given |
| 13 | + const mockInitialValues: AccountFormValues = { |
| 14 | + username: MockUser2.username, |
| 15 | + editable: true, |
| 16 | + } |
| 17 | + |
| 18 | + // When |
| 19 | + render( |
| 20 | + <AccountForm |
| 21 | + email={MockUser2.email} |
| 22 | + initialValues={mockInitialValues} |
| 23 | + isLoading={false} |
| 24 | + onSubmit={() => { |
| 25 | + return |
| 26 | + }} |
| 27 | + />, |
| 28 | + ) |
| 29 | + |
| 30 | + // Then |
| 31 | + const el = await screen.findByLabelText("Username") |
| 32 | + expect(el).toBeEnabled() |
| 33 | + }) |
| 34 | + }) |
| 35 | + |
| 36 | + describe("for user admins", () => { |
| 37 | + it("allows updating username", async () => { |
| 38 | + // Given |
| 39 | + const mockInitialValues: AccountFormValues = { |
| 40 | + username: MockUser2.username, |
| 41 | + editable: true, |
| 42 | + } |
| 43 | + |
| 44 | + // When |
| 45 | + render( |
| 46 | + <AccountForm |
| 47 | + email={MockUser2.email} |
| 48 | + initialValues={mockInitialValues} |
| 49 | + isLoading={false} |
| 50 | + onSubmit={() => { |
| 51 | + return |
| 52 | + }} |
| 53 | + />, |
| 54 | + ) |
| 55 | + |
| 56 | + // Then |
| 57 | + const el = await screen.findByLabelText("Username") |
| 58 | + expect(el).toBeEnabled() |
| 59 | + }) |
| 60 | + }) |
| 61 | + |
| 62 | + describe("for members", () => { |
| 63 | + it("allows updating username", async () => { |
| 64 | + // Given |
| 65 | + const mockInitialValues: AccountFormValues = { |
| 66 | + username: MockUser2.username, |
| 67 | + editable: false, |
| 68 | + } |
| 69 | + |
| 70 | + // When |
| 71 | + render( |
| 72 | + <AccountForm |
| 73 | + email={MockUser2.email} |
| 74 | + initialValues={mockInitialValues} |
| 75 | + isLoading={false} |
| 76 | + onSubmit={() => { |
| 77 | + return |
| 78 | + }} |
| 79 | + />, |
| 80 | + ) |
| 81 | + |
| 82 | + // Then |
| 83 | + const el = await screen.findByLabelText("Username") |
| 84 | + expect(el).toBeDisabled() |
| 85 | + }) |
| 86 | + }) |
| 87 | +}) |
0 commit comments