Skip to content

Commit

Permalink
test: test adding voters
Browse files Browse the repository at this point in the history
  • Loading branch information
PascalinDe committed Feb 9, 2024
1 parent f1784a1 commit 65ed665
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 0 deletions.
1 change: 1 addition & 0 deletions web/frontend/src/pages/form/components/AddVotersModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,7 @@ export const AddVotersModal: FC<AddVotersModalProps> = ({
</div>
<div className="bg-gray-50 px-4 py-3 sm:px-6 sm:flex sm:flex-row-reverse">
<button
data-testid="addVotersConfirm"
type="button"
className="w-full inline-flex justify-center rounded-md border border-transparent shadow-sm px-4 py-2 bg-indigo-600 text-base font-medium text-white hover:bg-indigo-700 focus:outline-none focus:ring-2 focus:ring-offset-2 focus:ring-indigo-500 sm:ml-3 sm:w-auto sm:text-sm"
onClick={confirmChoice}>
Expand Down
28 changes: 28 additions & 0 deletions web/frontend/tests/forms.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import {
mockDKGActors as mockAPIDKGActors,
mockPersonalInfo,
mockProxies,
mockAddRole,
} from './mocks/api';
import { FORMID, mockDKGActors, mockFormsFormID } from './mocks/evoting';
import Worker0 from './json/api/proxies/dela-worker-0.json';
Expand Down Expand Up @@ -132,6 +133,33 @@ test('Assert "Add voters" button is only visible to owner', async ({ page }) =>
);
});

test('Assert "Add voters" button allows to add voters', async ({ page, baseURL }) => {
await setUpMocks(page, 0, 6);
await mockAddRole(page);
await logIn(page, SCIPER_OTHER_ADMIN);
// we expect one call per new voter
for (const sciper of [SCIPER_OTHER_ADMIN, SCIPER_ADMIN, SCIPER_USER]) {
page.waitForRequest(async (request) => {
const body = await request.postDataJSON();
return (
request.url() === `${baseURL}/api/add_role` &&
request.method() === 'POST' &&
body.permission === 'vote' &&
body.subject === FORMID &&
body.userId.toString() === sciper
);
});
}
await page.getByTestId('addVotersButton').click();
// menu should be visible
const textbox = await page.getByRole('textbox', { name: 'SCIPERs' });
await expect(textbox).toBeVisible();
// add 3 voters (owner admin, non-owner admin, user)
await textbox.fill(`${SCIPER_OTHER_ADMIN}\n${SCIPER_ADMIN}\n${SCIPER_USER}`);
// click on confirmation
await page.getByTestId('addVotersConfirm').click();
});

test('Assert "Initialize" button is only visible to owner', async ({ page }) => {
await assertIsOnlyVisibleInStates(
page,
Expand Down
6 changes: 6 additions & 0 deletions web/frontend/tests/mocks/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,3 +81,9 @@ export async function mockLogout(page: page) {
await route.fulfill({});
});
}

export async function mockAddRole(page: page) {
await page.route('/api/add_role', async (route) => {
await route.fulfill({ status: 200 });
});
}

0 comments on commit 65ed665

Please sign in to comment.