From e8c5e8267c2a50e645e824f404d470ab1a611444 Mon Sep 17 00:00:00 2001 From: Carine Dengler Date: Wed, 31 Jan 2024 21:59:52 +0100 Subject: [PATCH] test: show 'Open' button only to owner --- .../pages/form/components/ActionButtons/OpenButton.tsx | 9 ++++----- .../src/pages/form/components/utils/useChangeAction.tsx | 2 +- web/frontend/tests/forms.spec.ts | 8 ++++++++ 3 files changed, 13 insertions(+), 6 deletions(-) diff --git a/web/frontend/src/pages/form/components/ActionButtons/OpenButton.tsx b/web/frontend/src/pages/form/components/ActionButtons/OpenButton.tsx index 95fa3ec77..77a1b282b 100644 --- a/web/frontend/src/pages/form/components/ActionButtons/OpenButton.tsx +++ b/web/frontend/src/pages/form/components/ActionButtons/OpenButton.tsx @@ -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 && ( - + diff --git a/web/frontend/tests/forms.spec.ts b/web/frontend/tests/forms.spec.ts index 2a102c24d..0fbe2fffd 100644 --- a/web/frontend/tests/forms.spec.ts +++ b/web/frontend/tests/forms.spec.ts @@ -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,