Skip to content

Commit 6d16002

Browse files
authored
Merge pull request #188 from c4dt/fix-playwright
Fix Playwright tests that did not include several last minute changes
2 parents f73ec9d + 14409f5 commit 6d16002

File tree

5 files changed

+21
-47
lines changed

5 files changed

+21
-47
lines changed

.env.example

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,3 +20,6 @@ REACT_APP_RANDOMIZE_VOTE_ID=true # randomize voter ID for
2020
REACT_APP_SCIPER_ADMIN=123456 # debugging admin ID /!\ disable in production /!\
2121
REACT_APP_BLOCKLIST= # comma-separad form IDs to hide from non-admin users
2222
SESSION_SECRET=kaibaaF9 # choose any secret
23+
REACT_APP_VERSION="unknown"
24+
REACT_APP_BUILD="unknown"
25+
REACT_APP_BUILD_TIME="after_2024_03"

web/frontend/tests/ballot.spec.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ test('Assert ballot is displayed properly', async ({ page }) => {
7171
await expect(
7272
page.getByText(i18n.t('selectBetween', { minSelect: select.MinN, maxSelect: select.MaxN }))
7373
).toBeVisible();
74-
for (const choice of select.Choices.map((x) => JSON.parse(x))) {
74+
for (const choice of select.Choices.map((x) => JSON.parse(x.Choice))) {
7575
await expect(page.getByRole('checkbox', { name: choice.en })).toBeVisible();
7676
}
7777
}
@@ -100,7 +100,7 @@ test('Assert minimum/maximum number of choices are handled correctly', async ({
100100
await test.step(
101101
`Assert maximum number of choices (${select.MaxN}) are handled correctly`,
102102
async () => {
103-
for (const choice of select.Choices.map((x) => JSON.parse(x))) {
103+
for (const choice of select.Choices.map((x) => JSON.parse(x.Choice))) {
104104
await page.getByRole('checkbox', { name: choice.en }).setChecked(true);
105105
}
106106
await castVoteButton.click();
@@ -134,12 +134,12 @@ test('Assert that correct number of choices are accepted', async ({ page, baseUR
134134
});
135135
await page
136136
.getByRole('checkbox', {
137-
name: JSON.parse(Form.Configuration.Scaffold.at(0).Selects.at(0).Choices.at(0)).en,
137+
name: JSON.parse(Form.Configuration.Scaffold.at(0).Selects.at(0).Choices.at(0).Choice).en,
138138
})
139139
.setChecked(true);
140140
await page
141141
.getByRole('checkbox', {
142-
name: JSON.parse(Form.Configuration.Scaffold.at(1).Selects.at(0).Choices.at(0)).en,
142+
name: JSON.parse(Form.Configuration.Scaffold.at(1).Selects.at(0).Choices.at(0).Choice).en,
143143
})
144144
.setChecked(true);
145145
await page.getByRole('button', { name: i18n.t('castVote') }).click();

web/frontend/tests/formIndex.spec.ts

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -146,10 +146,6 @@ test('Assert all forms are displayed correctly for unauthenticated user', async
146146
let name = translate(form.Title);
147147
let row = await table.getByRole('row', { name: name });
148148
await expect(row).toBeVisible();
149-
// row entry leads to form view
150-
let link = await row.getByRole('link', { name: name });
151-
await expect(link).toBeVisible();
152-
await expect(link).toHaveAttribute('href', `/forms/${form.FormID}`);
153149
await assertQuickAction(row, form);
154150
}
155151
await goForward(page);

web/frontend/tests/forms.spec.ts

Lines changed: 11 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import { assertHasFooter, assertHasNavBar, initI18n, logIn, setUp } from './shar
44
import {
55
SCIPER_ADMIN,
66
SCIPER_OTHER_ADMIN,
7-
SCIPER_OTHER_USER,
87
SCIPER_USER,
98
mockDKGActors as mockAPIDKGActors,
109
mockAddRole,
@@ -49,7 +48,7 @@ async function setUpMocks(
4948
}
5049
await mockDKGActors(page, dkgActorsStatus, initialized);
5150
await mockAPIDKGActors(page);
52-
await mockPersonalInfo(page);
51+
await mockPersonalInfo(page, SCIPER_ADMIN); // initially log in as admin to be able to access page
5352
await mockDKGActorsFormID(page);
5453
await mockServicesShuffle(page);
5554
await mockForms(page);
@@ -70,13 +69,6 @@ test('Assert footer is present', async ({ page }) => {
7069
});
7170

7271
async function assertIsOnlyVisibleToOwner(page: Page, locator: Locator) {
73-
await test.step('Assert is hidden to unauthenticated user', async () => {
74-
await expect(locator).toBeHidden();
75-
});
76-
await test.step('Assert is hidden to authenticated non-admin user', async () => {
77-
await logIn(page, SCIPER_USER);
78-
await expect(locator).toBeHidden();
79-
});
8072
await test.step('Assert is hidden to non-owner admin', async () => {
8173
await logIn(page, SCIPER_ADMIN);
8274
await expect(locator).toBeHidden();
@@ -151,19 +143,16 @@ test('Assert "Add voters" button allows to add voters', async ({ page, baseURL }
151143
await setUpMocks(page, 0, 6);
152144
await mockAddRole(page);
153145
await logIn(page, SCIPER_OTHER_ADMIN);
154-
// we expect one call per new voter
155-
for (const sciper of [SCIPER_OTHER_ADMIN, SCIPER_ADMIN, SCIPER_USER]) {
156-
page.waitForRequest(async (request) => {
157-
const body = await request.postDataJSON();
158-
return (
159-
request.url() === `${baseURL}/api/add_role` &&
160-
request.method() === 'POST' &&
161-
body.permission === 'vote' &&
162-
body.subject === FORMID &&
163-
body.userId.toString() === sciper
164-
);
165-
});
166-
}
146+
page.waitForRequest(async (request) => {
147+
const body = await request.postDataJSON();
148+
return (
149+
request.url() === `${baseURL}/api/add_role` &&
150+
request.method() === 'POST' &&
151+
body.permission === 'vote' &&
152+
body.subject === FORMID &&
153+
body.userIds.toString() === [SCIPER_OTHER_ADMIN, SCIPER_ADMIN, SCIPER_USER].join(',')
154+
);
155+
});
167156
await page.getByTestId('addVotersButton').click();
168157
// menu should be visible
169158
const textbox = await page.getByRole('textbox', { name: 'SCIPERs' });
@@ -388,17 +377,6 @@ test('Assert "Vote" button is visible to admin/non-admin voter user', async ({ p
388377
[1],
389378
// eslint-disable-next-line @typescript-eslint/no-shadow
390379
async function (page: Page, locator: Locator) {
391-
await test.step('Assert is hidden to unauthenticated user', async () => {
392-
await expect(locator).toBeHidden();
393-
});
394-
await test.step('Assert is hidden to authenticated non-voter user', async () => {
395-
await logIn(page, SCIPER_OTHER_USER);
396-
await expect(locator).toBeHidden();
397-
});
398-
await test.step('Assert is visible to authenticated voter user', async () => {
399-
await logIn(page, SCIPER_USER);
400-
await expect(locator).toBeVisible();
401-
});
402380
await test.step('Assert is hidden to non-voter admin', async () => {
403381
await logIn(page, SCIPER_OTHER_ADMIN);
404382
await expect(locator).toBeHidden();
@@ -413,11 +391,6 @@ test('Assert "Vote" button is visible to admin/non-admin voter user', async ({ p
413391

414392
test('Assert "Vote" button gets voting form', async ({ page }) => {
415393
await setUpMocks(page, 1, 6);
416-
await logIn(page, SCIPER_USER);
417-
page.waitForRequest(`${process.env.DELA_PROXY_URL}/evoting/forms/${FORMID}`);
418-
await page.getByRole('button', { name: i18n.t('vote') }).click();
419-
// go back to form management page
420-
await setUp(page, `/forms/${FORMID}`);
421394
await logIn(page, SCIPER_ADMIN);
422395
page.waitForRequest(`${process.env.DELA_PROXY_URL}/evoting/forms/${FORMID}`);
423396
await page.getByRole('button', { name: i18n.t('vote') }).click();

web/frontend/tests/result.spec.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,9 @@ test('Assert individual results are displayed correctly', async ({ page }) => {
114114
j + 1
115115
}]`
116116
);
117-
await expect(resultRow.locator('xpath=./div[2]')).toContainText(JSON.parse(choice).en);
117+
await expect(resultRow.locator('xpath=./div[2]')).toContainText(
118+
JSON.parse(choice.Choice).en
119+
);
118120
if (result.at(j)) {
119121
await expect(resultRow.getByRole('checkbox')).toBeChecked();
120122
} else {

0 commit comments

Comments
 (0)