Skip to content

Commit

Permalink
test: show 'Open' button only to owner
Browse files Browse the repository at this point in the history
  • Loading branch information
PascalinDe committed Jan 31, 2024
1 parent 3287685 commit e8c5e82
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,14 @@ import { useContext } from 'react';
import { useTranslation } from 'react-i18next';
import { OngoingAction, Status } from 'types/form';
import ActionButton from './ActionButton';
import { isManager } from './utils';

const SUBJECT_ELECTION = 'election';
const ACTION_CREATE = 'create';
const OpenButton = ({ status, handleOpen, ongoingAction }) => {
const authCtx = useContext(AuthContext);
const OpenButton = ({ status, handleOpen, ongoingAction, formID }) => {
const { t } = useTranslation();
const { authorization, isLogged } = useContext(AuthContext);

return (
authCtx.isAllowed(SUBJECT_ELECTION, ACTION_CREATE) &&
isManager(formID, authorization, isLogged) &&
status === Status.Setup && (
<ActionButton
handleClick={handleOpen}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -507,7 +507,7 @@ const useChangeAction = (
case Status.Setup:
return (
<>
<OpenButton status={status} handleOpen={handleOpen} ongoingAction={ongoingAction} />
<OpenButton status={status} handleOpen={handleOpen} ongoingAction={ongoingAction} formID={formID} />
<DeleteButton handleDelete={handleDelete} formID={formID} />
<AddVotersButton handleAddVoters={handleAddVoters} formID={formID} />
</>
Expand Down
8 changes: 8 additions & 0 deletions web/frontend/tests/forms.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,14 @@ test('Assert "Setup" button is only visible to owner', async ({ page }) => {
);
});

test('Assert "Open" button is only visible to owner', async ({ page }) => {
await assertIsOnlyVisibleToOwnerStates(
page,
page.getByRole('button', { name: i18n.t('open') }),
[0]
);
});

test('Assert "Cancel" button is only visible to owner', async ({ page }) => {
await assertIsOnlyVisibleToOwnerStates(
page,
Expand Down

0 comments on commit e8c5e82

Please sign in to comment.