Skip to content

Commit

Permalink
test: add form list display tests
Browse files Browse the repository at this point in the history
  • Loading branch information
PascalinDe committed Jan 11, 2024
1 parent 380b157 commit ee64e2b
Showing 1 changed file with 50 additions and 12 deletions.
62 changes: 50 additions & 12 deletions web/frontend/tests/formIndex.spec.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
import { expect, test } from '@playwright/test';
import { default as i18n } from 'i18next';
import { assertHasFooter, assertHasNavBar, initI18n, setUp, translate } from './shared';
import { mockEvoting, mockPersonalInfo } from './mocks';
import { assertHasFooter, assertHasNavBar, initI18n, setUp, translate, logIn } from './shared';

Check failure on line 3 in web/frontend/tests/formIndex.spec.ts

View workflow job for this annotation

GitHub Actions / Web frontend Lint

Member 'logIn' of the import declaration should be sorted alphabetically
import { mockEvoting, mockPersonalInfo, SCIPER_USER, SCIPER_ADMIN } from './mocks';

Check failure on line 4 in web/frontend/tests/formIndex.spec.ts

View workflow job for this annotation

GitHub Actions / Web frontend Lint

Member 'SCIPER_USER' of the import declaration should be sorted alphabetically
import Forms from './json/formList.json';
import User from './json/personal_info/789012.json';
import Admin from './json/personal_info/123456.json';

initI18n();

Expand Down Expand Up @@ -85,6 +87,33 @@ test('Assert no forms are displayed for empty list', async ({ page }) => {
}).toHaveLength(1);

Check failure on line 87 in web/frontend/tests/formIndex.spec.ts

View workflow job for this annotation

GitHub Actions / Web frontend Lint

Replace `··})` with `····})⏎····`
});

async function assertQuickAction(row: locator, form: object, sciper?: string) {
const user = sciper === SCIPER_USER ? User

Check failure on line 91 in web/frontend/tests/formIndex.spec.ts

View workflow job for this annotation

GitHub Actions / Web frontend Lint

Replace `⏎··········:·sciper·===·SCIPER_ADMIN·?·Admin⏎·········` with `·:·sciper·===·SCIPER_ADMIN·?·Admin`
: sciper === SCIPER_ADMIN ? Admin
: undefined;
const quickAction = row.getByTestId('quickAction');
switch(form.Status) {

Check failure on line 95 in web/frontend/tests/formIndex.spec.ts

View workflow job for this annotation

GitHub Actions / Web frontend Lint

Insert `·`
case 1:
// only authenticated user w/ right to vote sees 'vote' button
if ((user) && (form.FormID in user.authorization) && (user.authorization[form.FormID].includes('vote'))) {

Check failure on line 98 in web/frontend/tests/formIndex.spec.ts

View workflow job for this annotation

GitHub Actions / Web frontend Lint

Replace `(user)·&&·(form.FormID·in·user.authorization)·&&·(user.authorization[form.FormID].includes('vote'))` with `⏎········user·&&⏎········form.FormID·in·user.authorization·&&⏎········user.authorization[form.FormID].includes('vote')⏎······`
await expect(quickAction).toHaveText(i18n.t('vote'));
await expect(await quickAction.getByRole('link')).toHaveAttribute('href', `/ballot/show/${form.FormID}`);
await expect(quickAction).toBeVisible();
}
else {
await expect(quickAction).toBeHidden();
}
break;
case 5:
// any user can see the results of a past election
await expect(quickAction).toHaveText(i18n.t('seeResult'));
await expect(await quickAction.getByRole('link')).toHaveAttribute('href', `/forms/${form.FormID}/result`);
break;
default:
await expect(quickAction).toBeHidden();
}
}

test('Assert forms are displayed correctly for unauthenticated user', async ({ page, baseURL }) => {

Check warning on line 117 in web/frontend/tests/formIndex.spec.ts

View workflow job for this annotation

GitHub Actions / Web frontend Lint

'baseURL' is defined but never used. Allowed unused args must match /^_/u
await mockEvoting(page, false);
await page.reload();
Expand All @@ -97,16 +126,25 @@ test('Assert forms are displayed correctly for unauthenticated user', async ({ p
let link = await row.getByRole('link', { name: name });
await expect(link).toBeVisible();
await expect(link).toHaveAttribute('href', `/forms/${form.FormID}`);
const quickAction = row.getByTestId('quickAction');
// any user can see the results of a past election
if (form.Status === 5) {
await expect(quickAction).toHaveText(i18n.t('seeResult'));
await expect(await quickAction.getByRole('link')).toHaveAttribute('href', `/forms/${form.FormID}/result`);
}
else {
await expect(quickAction).toBeHidden();
}
await assertQuickAction(row, form);
}
await goForward(page);
await expect(await table.getByRole('row', { name: translate(Forms.Forms.at(-1).Title) })).toBeVisible();
let row = await table.getByRole('row', { name: translate(Forms.Forms.at(-1).Title) });
await expect(row).toBeVisible();
await assertQuickAction(row, Forms.Forms.at(-1));
});

test('Assert quick actions are displayed correctly for authenticated users', async ({ page, baseURL }) => {

Check warning on line 137 in web/frontend/tests/formIndex.spec.ts

View workflow job for this annotation

GitHub Actions / Web frontend Lint

'baseURL' is defined but never used. Allowed unused args must match /^_/u
for (let sciper of [SCIPER_USER, SCIPER_ADMIN]) {
await logIn(page, sciper);
await mockEvoting(page, false);
await page.reload();
const table = await page.getByRole('table');
for (let form of Forms.Forms.slice(0, -1)) {
let row = await table.getByRole('row', { name: translate(form.Title) });
await assertQuickAction(row, form, sciper);
}
await goForward(page);
await assertQuickAction(await table.getByRole('row', { name: translate(Forms.Forms.at(-1).Title) }), Forms.Forms.at(-1));
}
});

0 comments on commit ee64e2b

Please sign in to comment.