Skip to content

Commit

Permalink
Fix tests and improve test coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
ApsiV11 committed Dec 7, 2024
1 parent a58b442 commit a8f7c8c
Show file tree
Hide file tree
Showing 2 changed files with 68 additions and 10 deletions.
1 change: 1 addition & 0 deletions src/frontend/components/audit/Audit.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ export const Audit = () => {
<Form.Group controlId="formSearchBallot">
<Form.Label>{t('search_ballot')}</Form.Label>
<Form.Control
id="searchBallot"
type="text"
className="mb-3"
placeholder={t('ballot_id')}
Expand Down
77 changes: 67 additions & 10 deletions tests/voter-voting.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,33 +81,66 @@ test.describe('voting', () => {
).toBeVisible()
})

test('should show confirm vote dialog', async ({ page }) => {
await selectCandidate(page, 'Candidate 1')
await page.getByRole('button', { name: 'Vote' }).click()
await expect(page.getByText('Vote confirmation')).toBeVisible()
const modalLocator = page.locator('.modal-dialog')
await expect(modalLocator).toBeVisible()
await expect(
modalLocator.getByRole('button', { name: 'Confirm' })
).toBeVisible()
await expect(
modalLocator.getByRole('button', { name: 'Cancel' })
).toBeVisible()
await expect(modalLocator.locator('text=Candidate 1')).toBeVisible()
})

test('should submit vote', async ({ page }) => {
await selectCandidate(page, 'Candidate 1')
await page.getByRole('button', { name: 'Vote' }).click()
await page.getByRole('button', { name: 'Confirm' }).click()

await expect(page.getByText('You have already voted!')).toBeVisible()
await expect(page.getByText('Thank you for voting!')).toBeVisible()
})

test('should show ballot id on voting', async ({ page }) => {
test('should show ballot id copy button after voting', async ({ page }) => {
await selectCandidate(page, 'Candidate 1')

const responsePromise = page.waitForResponse('**/api/vote')
await page.getByRole('button', { name: 'Vote' }).click()
const response = await responsePromise
const ballotId = (await response.json()) as string
await page.getByRole('button', { name: 'Confirm' }).click()

await expect(
page.getByRole('button', { name: 'Copy ballot ID' })
).toBeVisible()
})

await expect(page.locator(`text=Ballot ID: ${ballotId}`)).toBeVisible()
test('should copy ballot id after voting', async ({ page }) => {
await selectCandidate(page, 'Candidate 1')

await page.getByRole('button', { name: 'Vote' }).click()
await page.getByRole('button', { name: 'Confirm' }).click()

await page.getByRole('button', { name: 'Copy ballot ID' }).click()
await expect(
page.locator('text=Ballot ID copied to clipboard')
).toBeVisible()
})

test("shoudn't show ballot id after refreshing the page", async ({
test("shoudn't show copy ballot id button after refreshing page", async ({
page
}) => {
await selectCandidate(page, 'Candidate 1')

await page.getByRole('button', { name: 'Vote' }).click()
await expect(page.getByText('Confirm vote')).toBeVisible()
await page.getByRole('button', { name: 'Confirm' }).click()

await page.reload()
await expect(page.getByText('You have already voted!')).toBeVisible()
await expect(page.locator('text=Ballot ID:')).not.toBeVisible()
await expect(
page.getByRole('button', { name: 'Copy ballot ID' })
).not.toBeVisible()
})
})

Expand All @@ -120,10 +153,11 @@ test.describe('audit view', () => {
await selectCandidate(page, 'Candidate 1')
const responsePromise = page.waitForResponse('**/api/vote')
await page.getByRole('button', { name: 'Vote' }).click()
await page.getByRole('button', { name: 'Confirm' }).click()
const response = await responsePromise
const ballotId = (await response.json()) as string

await expect(page.getByText('You have already voted!')).toBeVisible()
await expect(page.getByText('Thank you for voting!')).toBeVisible()
await changeElectionStatus(election.electionId, 'FINISHED')
await page.goto('/audit')
await expect(page.getByRole('heading', { name: 'Auditing' })).toBeVisible()
Expand All @@ -135,15 +169,38 @@ test.describe('audit view', () => {
test('should show empty ballot after voting has ended', async ({ page }) => {
const responsePromise = page.waitForResponse('**/api/vote')
await page.getByRole('button', { name: 'Vote' }).click()
await page.getByRole('button', { name: 'Confirm' }).click()
const response = await responsePromise
const ballotId = (await response.json()) as string

await expect(page.getByText('You have already voted!')).toBeVisible()
await expect(page.getByText('Thank you for voting!')).toBeVisible()
await changeElectionStatus(election.electionId, 'FINISHED')
await page.goto('/audit')
await expect(page.getByRole('heading', { name: 'Auditing' })).toBeVisible()

await expect(page.getByText(ballotId)).toBeVisible()
await expect(page.getByText('Empty ballot')).toBeVisible()
})

test('should allow to search for ballot', async ({ page }) => {
await selectCandidate(page, 'Candidate 1')
const responsePromise = page.waitForResponse('**/api/vote')
await page.getByRole('button', { name: 'Vote' }).click()
await page.getByRole('button', { name: 'Confirm' }).click()
const response = await responsePromise
const ballotId = (await response.json()) as string

await expect(page.getByText('Thank you for voting!')).toBeVisible()
await changeElectionStatus(election.electionId, 'FINISHED')
await page.goto('/audit')
await expect(page.getByRole('heading', { name: 'Auditing' })).toBeVisible()

await expect(page.getByText(ballotId)).toBeVisible()
await expect(page.getByText('Candidate 1')).toBeVisible()

await expect(page.locator('#searchBallot')).toBeVisible()
await page.fill('#searchBallot', ballotId)
await expect(page.getByText(ballotId)).toBeVisible()
await expect(page.getByText('Candidate 1')).toBeVisible()
})
})

0 comments on commit a8f7c8c

Please sign in to comment.