Skip to content

Commit

Permalink
fixup! ✨(frontend) add mail domain access management
Browse files Browse the repository at this point in the history
  • Loading branch information
daproclaima committed Sep 27, 2024
1 parent b10c183 commit d1ef239
Show file tree
Hide file tree
Showing 2 changed files with 83 additions and 39 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -46,47 +46,52 @@ export const AccessAction = ({
isOpen={isDropOpen}
>
<Box>
<Button
aria-label={t('Open the modal to update the role of this access')}
onClick={() => {
setIsModalRoleOpen(true);
setIsDropOpen(false);
}}
color="primary-text"
icon={
<span className="material-icons" aria-hidden="true">
edit
</span>
}
>
<Text $theme="primary">{t('Update role')}</Text>
</Button>
<Button
aria-label={t('Open the modal to delete this access')}
onClick={() => {
setIsModalDeleteOpen(true);
setIsDropOpen(false);
}}
color="primary-text"
icon={
<span className="material-icons" aria-hidden="true">
delete
</span>
}
>
<Text $theme="primary">{t('Remove from domain')}</Text>
</Button>
{(mailDomain.abilities.put || mailDomain.abilities.patch) && (
<Button
aria-label={t('Open the modal to update the role of this access')}
onClick={() => {
setIsModalRoleOpen(true);
setIsDropOpen(false);
}}
color="primary-text"
icon={
<span className="material-icons" aria-hidden="true">
edit
</span>
}
>
<Text $theme="primary">{t('Update role')}</Text>
</Button>
)}
{mailDomain.abilities.delete && (
<Button
aria-label={t('Open the modal to delete this access')}
onClick={() => {
setIsModalDeleteOpen(true);
setIsDropOpen(false);
}}
color="primary-text"
icon={
<span className="material-icons" aria-hidden="true">
delete
</span>
}
>
<Text $theme="primary">{t('Remove from domain')}</Text>
</Button>
)}
</Box>
</DropButton>
{isModalRoleOpen && (
<ModalRole
access={access}
currentRole={currentRole}
onClose={() => setIsModalRoleOpen(false)}
slug={mailDomain.slug}
/>
)}
{isModalDeleteOpen && (
{isModalRoleOpen &&
(mailDomain.abilities.put || mailDomain.abilities.patch) && (
<ModalRole
access={access}
currentRole={currentRole}
onClose={() => setIsModalRoleOpen(false)}
slug={mailDomain.slug}
/>
)}
{isModalDeleteOpen && mailDomain.abilities.delete && (
<ModalDelete
access={access}
currentRole={currentRole}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,26 @@ describe('AccessAction', () => {
).not.toBeInTheDocument();
});

it('does not render "Update role" button when mailDomain lacks "put" and "patch" abilities', async() => {
const mailDomainWithoutUpdate = {
...mockMailDomain,
abilities: {
...mockMailDomain.abilities,
put: false,
patch: false,
},
};

renderAccessAction(Role.ADMIN, mockAccess, mailDomainWithoutUpdate);

const openButton = screen.getByLabelText('Open the access options modal');
await userEvent.click(openButton);

expect(
screen.queryByLabelText('Open the modal to update the role of this access'),
).not.toBeInTheDocument();
});

it('opens the role update modal with correct props when "Update role" is clicked', async () => {
renderAccessAction();

Expand All @@ -101,6 +121,25 @@ describe('AccessAction', () => {
);
});

it('does not render "Remove from domain" button when mailDomain lacks "delete" ability', () => {
const mailDomainWithoutDelete = {
...mockMailDomain,
abilities: {
...mockMailDomain.abilities,
delete: false,
},
};

renderAccessAction(Role.ADMIN, mockAccess, mailDomainWithoutDelete);

const openButton = screen.getByLabelText('Open the access options modal');
userEvent.click(openButton);

expect(
screen.queryByLabelText('Open the modal to delete this access'),
).not.toBeInTheDocument();
});

it('opens the delete modal with correct props when "Remove from domain" is clicked', async () => {
renderAccessAction();

Expand Down

0 comments on commit d1ef239

Please sign in to comment.