Skip to content

Commit

Permalink
✅(frontend) adapt tests
Browse files Browse the repository at this point in the history
We adapt the tests. Remove the check if you are the last owner and use the new
props inside the relevant tests
  • Loading branch information
PanchoutNathan committed Oct 8, 2024
1 parent 5dd164b commit 9d7e113
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 21 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@ and this project adheres to

## [Unreleased]

### Fixed

- 🐛(frontend) fix update accesses form #448

## [1.2.1] - 2024-10-03

### Fixed
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ describe('ChooseRole', () => {
) => {
const defaultProps = {
availableRoles: [Role.VIEWER, Role.ADMIN],
roleAccess: Role.ADMIN,
currentRole: Role.ADMIN,
disabled: false,
setRole: mockSetRole,
Expand All @@ -28,11 +29,20 @@ describe('ChooseRole', () => {
jest.clearAllMocks();
});

it('renders available roles correctly', () => {
it('renders available roles correctly when we are Administrator', () => {
renderChooseRole();
expect(screen.getByLabelText('Viewer')).toBeInTheDocument();
expect(screen.getByLabelText('Administrator')).toBeInTheDocument();
});

it('renders available roles correctly when we are owner', () => {
renderChooseRole({
currentRole: Role.OWNER,
roleAccess: Role.OWNER,
});
expect(screen.getByLabelText('Viewer')).toBeInTheDocument();
expect(screen.getByLabelText('Administrator')).toBeInTheDocument();
expect(screen.getByLabelText('Owner')).toBeInTheDocument();
});

it('sets default role checked correctly', () => {
Expand Down Expand Up @@ -91,6 +101,7 @@ describe('ChooseRole', () => {
it('renders and checks owner role correctly when currentRole is owner', () => {
renderChooseRole({
currentRole: Role.OWNER,
roleAccess: Role.OWNER,
availableRoles: [Role.OWNER, Role.VIEWER, Role.ADMIN],
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -115,26 +115,6 @@ describe('ModalRole', () => {
);
});

it('disables the Validate button if the user is the last owner', () => {
renderModalRole(true, false); // isLastOwner = true, isOtherOwner = false

const validateButton = screen.getByRole('button', { name: /Validate/i });
expect(validateButton).toBeDisabled();
expect(
screen.getByText(/You are the sole owner of this domain/i),
).toBeInTheDocument();
});

it('disables the Validate button if the user is another owner', () => {
renderModalRole(false, true); // isLastOwner = false, isOtherOwner = true

const validateButton = screen.getByRole('button', { name: /Validate/i });
expect(validateButton).toBeDisabled();
expect(
screen.getByText(/You cannot update the role of other owner/i),
).toBeInTheDocument();
});

it('shows error message when update fails', async () => {
fetchMock.patch(`end:mail-domains/domain-slug/accesses/1-1-1-1-1-1/`, {
status: 400,
Expand Down

0 comments on commit 9d7e113

Please sign in to comment.