forked from dedis/d-voting
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: non-voter user should not be able to see voting screen
- Loading branch information
1 parent
2f6c648
commit e8c9270
Showing
6 changed files
with
75 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
import { expect, test } from '@playwright/test'; | ||
import { default as i18n } from 'i18next'; | ||
import { assertHasFooter, assertHasNavBar, initI18n, logIn, setUp } from './shared'; | ||
import { FORMID } from './mocks/shared'; | ||
import { mockPersonalInfo, SCIPER_ADMIN, SCIPER_OTHER_ADMIN, SCIPER_USER, SCIPER_OTHER_USER } from './mocks/api'; | ||
Check failure on line 5 in web/frontend/tests/ballot.spec.ts GitHub Actions / Web frontend Lint
Check failure on line 5 in web/frontend/tests/ballot.spec.ts GitHub Actions / Web frontend Lint
|
||
import { mockFormsFormID } from './mocks/evoting'; | ||
|
||
initI18n(); | ||
|
||
test.beforeEach(async ({ page }) => { | ||
await mockFormsFormID(page, 1); | ||
await logIn(page, SCIPER_ADMIN); | ||
await setUp(page, `/ballot/show/${FORMID}`); | ||
}); | ||
|
||
test('Assert navigation bar is present', async ({ page }) => { | ||
await assertHasNavBar(page); | ||
}); | ||
|
||
test('Assert footer is present', async ({ page }) => { | ||
await assertHasFooter(page); | ||
}); | ||
|
||
test('Assert ballot form is correctly handled for anonymous users, non-voter users and voter users', async ({ page }) => { | ||
const castVoteButton = await page.getByRole('button', { name: i18n.t('castVote') }); | ||
await test.step('Assert anonymous is redirected to login page', async () => { | ||
await mockPersonalInfo(page); | ||
await page.reload({ waitUntil: 'networkidle' }); | ||
await expect(page).toHaveURL('/login'); | ||
}); | ||
await test.step('Assert non-voter gets page that they are not allowed to vote', async () => { | ||
await logIn(page, SCIPER_OTHER_USER); | ||
await page.goto(`/ballot/show/${FORMID}`, { waitUntil: 'networkidle' }); | ||
await expect(page).toHaveURL(`/ballot/show/${FORMID}`); | ||
await expect(castVoteButton).toBeHidden(); | ||
await expect(page.getByText(i18n.t('voteNotVoter'))).toBeVisible(); | ||
await expect(page.getByText(i18n.t('voteNotVoterDescription'))).toBeVisible(); | ||
}); | ||
await test.step('Assert voter gets ballot', async () => { | ||
await logIn(page, SCIPER_USER); | ||
await page.goto(`/ballot/show/${FORMID}`, { waitUntil: 'networkidle' }); | ||
await expect(page).toHaveURL(`/ballot/show/${FORMID}`); | ||
await expect(castVoteButton).toBeVisible(); | ||
await expect(page.getByText(i18n.t('vote'))).toBeVisible(); | ||
await expect(page.getByText(i18n.t('voteExplanation'))).toBeVisible(); | ||
}); | ||
}); |