Skip to content

Commit

Permalink
test: move evoting mocks
Browse files Browse the repository at this point in the history
  • Loading branch information
PascalinDe committed Jan 17, 2024
1 parent 21b91cf commit e957507
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 30 deletions.
10 changes: 5 additions & 5 deletions web/frontend/tests/formIndex.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { expect, test } from '@playwright/test';
import { default as i18n } from 'i18next';
import { assertHasFooter, assertHasNavBar, initI18n, logIn, setUp, translate } from './shared';
import { SCIPER_ADMIN, SCIPER_USER, mockPersonalInfo } from './mocks/api';
import { mockEvoting } from './mocks';
import { mockForms } from './mocks/evoting';
import Forms from './json/formList.json';
import User from './json/api/personal_info/789012.json';
import Admin from './json/api/personal_info/123456.json';
Expand All @@ -15,7 +15,7 @@ async function goForward(page: page) {

test.beforeEach(async ({ page }) => {
// mock empty list per default
await mockEvoting(page);
await mockForms(page);
await mockPersonalInfo(page);
await setUp(page, '/form/index');
});
Expand Down Expand Up @@ -49,7 +49,7 @@ test('Assert pagination works correctly for empty list', async ({ page }) => {

test('Assert pagination works correctly for non-empty list', async ({ page }) => {
// mock non-empty list w/ 11 elements i.e. 2 pages
await mockEvoting(page, false);
await mockForms(page, false);
await page.reload();
const next = await page.getByRole('button', { name: i18n.t('next') });
const previous = await page.getByRole('button', { name: i18n.t('previous') });
Expand Down Expand Up @@ -120,7 +120,7 @@ async function assertQuickAction(row: locator, form: object, sciper?: string) {
}

test('Assert forms are displayed correctly for unauthenticated user', async ({ page }) => {
await mockEvoting(page, false);
await mockForms(page, false);
await page.reload();
const table = await page.getByRole('table');
for (let form of Forms.Forms.slice(0, -1)) {
Expand All @@ -142,7 +142,7 @@ test('Assert forms are displayed correctly for unauthenticated user', async ({ p
test('Assert quick actions are displayed correctly for authenticated users', async ({ page }) => {
for (let sciper of [SCIPER_USER, SCIPER_ADMIN]) {
await logIn(page, sciper);
await mockEvoting(page, false);
await mockForms(page, false);
await page.reload();
const table = await page.getByRole('table');
for (let form of Forms.Forms.slice(0, -1)) {
Expand Down
25 changes: 0 additions & 25 deletions web/frontend/tests/mocks.ts

This file was deleted.

26 changes: 26 additions & 0 deletions web/frontend/tests/mocks/evoting.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,32 @@ import Worker3 from './../json/api/proxies/dela-worker-3.json'

export const FORMID = 'b63bcb854121051f2d8cff04bf0ac9b524b534b704509a16a423448bde3321b4';

export async function mockForms(page: page, empty: boolean = true) {
// clear current mock
await page.unroute(`${process.env.DELA_PROXY_URL}/evoting/forms`);
await page.route(`${process.env.DELA_PROXY_URL}/evoting/forms`, async (route) => {
if (route.request().method() === 'OPTIONS') {
await route.fulfill({
status: 200,
headers: {
'Access-Control-Allow-Headers': '*',
'Access-Control-Allow-Origin': '*',
},
});
} else if (empty) {
await route.fulfill({
status: 200,
contentType: 'application/json',
body: '{"Forms": []}',
});
} else {
await route.fulfill({
path: './tests/json/formList.json',
});
}
});
}

export async function mockFormsFormID(page: page, formStatus: number) {
// clear current mock
await page.unroute(`${process.env.DELA_PROXY_URL}/evoting/forms/${FORMID}`);
Expand Down

0 comments on commit e957507

Please sign in to comment.