diff --git a/web/frontend/tests/footer.spec.ts b/web/frontend/tests/footer.spec.ts index 9b3d7771a..b1f0fec80 100644 --- a/web/frontend/tests/footer.spec.ts +++ b/web/frontend/tests/footer.spec.ts @@ -1,20 +1,16 @@ import { expect, test } from '@playwright/test'; import { default as i18n } from 'i18next'; import { initI18n, setUp } from './shared'; -import { UPDATE, mockPersonalInfo } from './mocks'; +import { mockPersonalInfo } from './mocks'; initI18n(); test.beforeEach(async ({ page }) => { - if (UPDATE === true) { - return; - } await mockPersonalInfo(page); await setUp(page, '/about'); }); test('Assert copyright notice is visible', async ({ page }) => { - test.skip(UPDATE === true, 'Do not run regular tests when updating HAR files'); const footerCopyright = await page.getByTestId('footerCopyright'); await expect(footerCopyright).toBeVisible(); await expect(footerCopyright).toHaveText( @@ -23,7 +19,6 @@ test('Assert copyright notice is visible', async ({ page }) => { }); test('Assert version information is visible', async ({ page }) => { - test.skip(UPDATE === true, 'Do not run regular tests when updating HAR files'); const footerVersion = await page.getByTestId('footerVersion'); await expect(footerVersion).toBeVisible(); await expect(footerVersion).toHaveText( diff --git a/web/frontend/tests/formIndex.spec.ts b/web/frontend/tests/formIndex.spec.ts index 04b1656e0..e16f184f8 100644 --- a/web/frontend/tests/formIndex.spec.ts +++ b/web/frontend/tests/formIndex.spec.ts @@ -1,14 +1,11 @@ import { expect, test } from '@playwright/test'; import { default as i18n } from 'i18next'; import { assertHasFooter, assertHasNavBar, initI18n, setUp } from './shared'; -import { UPDATE, mockPersonalInfo, mockEvoting } from './mocks'; +import { mockPersonalInfo, mockEvoting } from './mocks'; initI18n(); test.beforeEach(async ({ page }) => { - if (UPDATE === true) { - return; - } // mock empty list per default await mockEvoting(page); await mockPersonalInfo(page); @@ -18,26 +15,22 @@ test.beforeEach(async ({ page }) => { // main elements test('Assert navigation bar is present', async ({ page }) => { - test.skip(UPDATE === true, 'Do not run regular tests when updating HAR files'); await assertHasNavBar(page); }); test('Assert footer is present', async ({ page }) => { - test.skip(UPDATE === true, 'Do not run regular tests when updating HAR files'); await assertHasFooter(page); }); // pagination bar test('Assert pagination bar is present', async ({ page }) => { - test.skip(UPDATE === true, 'Do not run regular tests when updating HAR files'); await expect(page.getByTestId('navPagination')).toBeVisible(); await expect(page.getByRole('button', { name: i18n.t('previous') })).toBeVisible(); await expect(page.getByRole('button', { name: i18n.t('next') })).toBeVisible(); }); test('Assert pagination works correctly for empty list', async ({ page }) => { - test.skip(UPDATE === true, 'Do not run regular tests when updating HAR files'); await expect(page.getByTestId('navPaginationMessage')).toHaveText(i18n.t('showingNOverMOfXResults', { n: 1, m: 1, x: 0 })); for (let key of ['next', 'previous']) { await expect(page.getByRole('button', { name: i18n.t(key) })).toBeDisabled(); @@ -45,7 +38,6 @@ test('Assert pagination works correctly for empty list', async ({ page }) => { }); test('Assert pagination works correctly for non-empty list', async ({ page }) => { - test.skip(UPDATE === true, 'Do not run regular tests when updating HAR files'); // mock non-empty list w/ 11 elements i.e. 2 pages await mockEvoting(page, false); await page.reload(); diff --git a/web/frontend/tests/hars/123456/get_dev_login.har b/web/frontend/tests/hars/123456/get_dev_login.har deleted file mode 100644 index 3b9cb5b4c..000000000 --- a/web/frontend/tests/hars/123456/get_dev_login.har +++ /dev/null @@ -1,14 +0,0 @@ -{ - "log": { - "version": "1.2", - "creator": { - "name": "Playwright", - "version": "1.40.1" - }, - "browser": { - "name": "chromium", - "version": "120.0.6099.28" - }, - "entries": [] - } -} \ No newline at end of file diff --git a/web/frontend/tests/hars/123456/personal_info.har b/web/frontend/tests/hars/123456/personal_info.har deleted file mode 100644 index 1482d5dda..000000000 --- a/web/frontend/tests/hars/123456/personal_info.har +++ /dev/null @@ -1,61 +0,0 @@ -{ - "log": { - "version": "1.2", - "creator": { - "name": "Playwright", - "version": "1.40.1" - }, - "browser": { - "name": "chromium", - "version": "120.0.6099.28" - }, - "entries": [ - { - "startedDateTime": "2023-12-07T15:16:05.427Z", - "time": 63.36, - "request": { - "method": "GET", - "url": "http://127.0.0.1:3000/api/personal_info", - "httpVersion": "HTTP/1.1", - "cookies": [], - "headers": [ - { "name": "Accept", "value": "*/*" }, - { "name": "Accept-Language", "value": "en-US" }, - { "name": "Cookie", "value": "connect.sid=s%3AxeUPf49ZYc9AUrUtzig9-O4g0Z_RVtVV.ChZVAx%2FL%2BIzfgIlkxzUxTLVduImdZIp68OdvODtveTU" }, - { "name": "Referer", "value": "http://127.0.0.1:3000/about" }, - { "name": "User-Agent", "value": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.6099.28 Safari/537.36" } - ], - "queryString": [], - "headersSize": -1, - "bodySize": -1 - }, - "response": { - "status": 200, - "statusText": "OK", - "httpVersion": "HTTP/1.1", - "cookies": [], - "headers": [ - { "name": "access-control-allow-origin", "value": "*" }, - { "name": "connection", "value": "keep-alive" }, - { "name": "content-length", "value": "184" }, - { "name": "content-type", "value": "application/json; charset=utf-8" }, - { "name": "date", "value": "Thu, 07 Dec 2023 15:16:05 GMT" }, - { "name": "etag", "value": "W/\"b8-oDA3lk2010ZRf1YsywmwSdt/ehI\"" }, - { "name": "keep-alive", "value": "timeout=5" }, - { "name": "x-powered-by", "value": "Express" } - ], - "content": { - "size": -1, - "mimeType": "application/json; charset=utf-8", - "_file": "a03037964db4d746517f562ccb09b049db7f7a12.json" - }, - "headersSize": -1, - "bodySize": -1, - "redirectURL": "" - }, - "cache": {}, - "timings": { "send": -1, "wait": -1, "receive": 63.36 } - } - ] - } -} \ No newline at end of file diff --git a/web/frontend/tests/hars/789012/get_dev_login.har b/web/frontend/tests/hars/789012/get_dev_login.har deleted file mode 100644 index 3b9cb5b4c..000000000 --- a/web/frontend/tests/hars/789012/get_dev_login.har +++ /dev/null @@ -1,14 +0,0 @@ -{ - "log": { - "version": "1.2", - "creator": { - "name": "Playwright", - "version": "1.40.1" - }, - "browser": { - "name": "chromium", - "version": "120.0.6099.28" - }, - "entries": [] - } -} \ No newline at end of file diff --git a/web/frontend/tests/hars/789012/personal_info.har b/web/frontend/tests/hars/789012/personal_info.har deleted file mode 100644 index 2f68ed6a7..000000000 --- a/web/frontend/tests/hars/789012/personal_info.har +++ /dev/null @@ -1,61 +0,0 @@ -{ - "log": { - "version": "1.2", - "creator": { - "name": "Playwright", - "version": "1.40.1" - }, - "browser": { - "name": "chromium", - "version": "120.0.6099.28" - }, - "entries": [ - { - "startedDateTime": "2023-12-07T15:14:39.129Z", - "time": 56.608, - "request": { - "method": "GET", - "url": "http://127.0.0.1:3000/api/personal_info", - "httpVersion": "HTTP/1.1", - "cookies": [], - "headers": [ - { "name": "Accept", "value": "*/*" }, - { "name": "Accept-Language", "value": "en-US" }, - { "name": "Cookie", "value": "connect.sid=s%3AAN1F283daySUs-3ytVagTfigWaedTgqO.iahChcGgJKx0khpkcm1jBBrQ89QsRN5cW9tOWnIgKgs" }, - { "name": "Referer", "value": "http://127.0.0.1:3000/about" }, - { "name": "User-Agent", "value": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.6099.28 Safari/537.36" } - ], - "queryString": [], - "headersSize": -1, - "bodySize": -1 - }, - "response": { - "status": 200, - "statusText": "OK", - "httpVersion": "HTTP/1.1", - "cookies": [], - "headers": [ - { "name": "access-control-allow-origin", "value": "*" }, - { "name": "connection", "value": "keep-alive" }, - { "name": "content-length", "value": "97" }, - { "name": "content-type", "value": "application/json; charset=utf-8" }, - { "name": "date", "value": "Thu, 07 Dec 2023 15:14:39 GMT" }, - { "name": "etag", "value": "W/\"61-XwUkDLM8ueWB6gziTE5yigTipdE\"" }, - { "name": "keep-alive", "value": "timeout=5" }, - { "name": "x-powered-by", "value": "Express" } - ], - "content": { - "size": -1, - "mimeType": "application/json; charset=utf-8", - "_file": "5f05240cb33cb9e581ea0ce24c4e728a04e2a5d1.json" - }, - "headersSize": -1, - "bodySize": -1, - "redirectURL": "" - }, - "cache": {}, - "timings": { "send": -1, "wait": -1, "receive": 56.608 } - } - ] - } -} \ No newline at end of file diff --git a/web/frontend/tests/hars/anonymous/9fd2ff4fc1fb163717539fb04aec420feeb11e5a.html b/web/frontend/tests/hars/anonymous/9fd2ff4fc1fb163717539fb04aec420feeb11e5a.html deleted file mode 100644 index e2c1c215e..000000000 --- a/web/frontend/tests/hars/anonymous/9fd2ff4fc1fb163717539fb04aec420feeb11e5a.html +++ /dev/null @@ -1 +0,0 @@ -Unauthenticated \ No newline at end of file diff --git a/web/frontend/tests/hars/anonymous/personal_info.har b/web/frontend/tests/hars/anonymous/personal_info.har deleted file mode 100644 index 91474fd6a..000000000 --- a/web/frontend/tests/hars/anonymous/personal_info.har +++ /dev/null @@ -1,60 +0,0 @@ -{ - "log": { - "version": "1.2", - "creator": { - "name": "Playwright", - "version": "1.40.1" - }, - "browser": { - "name": "chromium", - "version": "120.0.6099.28" - }, - "entries": [ - { - "startedDateTime": "2023-12-07T15:11:00.609Z", - "time": 50.718, - "request": { - "method": "GET", - "url": "http://127.0.0.1:3000/api/personal_info", - "httpVersion": "HTTP/1.1", - "cookies": [], - "headers": [ - { "name": "Accept", "value": "*/*" }, - { "name": "Accept-Language", "value": "en-US" }, - { "name": "Referer", "value": "http://127.0.0.1:3000/about" }, - { "name": "User-Agent", "value": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.6099.28 Safari/537.36" } - ], - "queryString": [], - "headersSize": -1, - "bodySize": -1 - }, - "response": { - "status": 401, - "statusText": "Unauthorized", - "httpVersion": "HTTP/1.1", - "cookies": [], - "headers": [ - { "name": "connection", "value": "keep-alive" }, - { "name": "content-length", "value": "15" }, - { "name": "content-type", "value": "text/html; charset=utf-8" }, - { "name": "date", "value": "Thu, 07 Dec 2023 15:11:00 GMT" }, - { "name": "etag", "value": "W/\"f-n9L/T8H7FjcXU5+wSuxCD+6xHlo\"" }, - { "name": "keep-alive", "value": "timeout=5" }, - { "name": "set-cookie", "value": "connect.sid=s%3AQhEmafnnGB6uPjxRFKwNdJg9MDQYmbkB.r0PBLNSKHdFLqMKbOVv%2FrgQVtN1i6JnbLElS%2Fzt7q%2F8; Path=/; Expires=Fri, 08 Dec 2023 15:11:00 GMT; HttpOnly" }, - { "name": "x-powered-by", "value": "Express" } - ], - "content": { - "size": -1, - "mimeType": "text/html; charset=utf-8", - "_file": "9fd2ff4fc1fb163717539fb04aec420feeb11e5a.html" - }, - "headersSize": -1, - "bodySize": -1, - "redirectURL": "" - }, - "cache": {}, - "timings": { "send": -1, "wait": -1, "receive": 50.718 } - } - ] - } -} \ No newline at end of file diff --git a/web/frontend/tests/hars/123456/a03037964db4d746517f562ccb09b049db7f7a12.json b/web/frontend/tests/json/personal_info/123456.json similarity index 100% rename from web/frontend/tests/hars/123456/a03037964db4d746517f562ccb09b049db7f7a12.json rename to web/frontend/tests/json/personal_info/123456.json diff --git a/web/frontend/tests/hars/789012/5f05240cb33cb9e581ea0ce24c4e728a04e2a5d1.json b/web/frontend/tests/json/personal_info/789012.json similarity index 100% rename from web/frontend/tests/hars/789012/5f05240cb33cb9e581ea0ce24c4e728a04e2a5d1.json rename to web/frontend/tests/json/personal_info/789012.json diff --git a/web/frontend/tests/mocks.ts b/web/frontend/tests/mocks.ts index b6acb1931..4b28d3918 100644 --- a/web/frontend/tests/mocks.ts +++ b/web/frontend/tests/mocks.ts @@ -1,24 +1,25 @@ export const SCIPER_ADMIN = '123456'; export const SCIPER_USER = '789012'; -export const UPDATE = false; export async function mockPersonalInfo(page: any, sciper?: string) { // clear current mock await page.unroute('/api/personal_info'); - await page.routeFromHAR(`./tests/hars/${sciper ?? 'anonymous'}/personal_info.har`, { - url: '/api/personal_info', - update: UPDATE, + await page.route('/api/personal_info', async (route) => { + if (sciper) { + route.fulfill({ path: `./tests/json/personal_info/${sciper}.json` }); + } + else { + route.fulfill({ status: 401, contentType: 'text/html', body: 'Unauthenticated'}) + } }); } export async function mockGetDevLogin(page: any) { - await page.routeFromHAR(`./tests/hars/${SCIPER_ADMIN}/get_dev_login.har`, { - url: `/api/get_dev_login/${SCIPER_ADMIN}`, - update: UPDATE, + await page.route(`/api/get_dev_login/${SCIPER_ADMIN}`, async (route) => { + await route.fulfill({}); }); - await page.routeFromHAR(`./tests/hars/${SCIPER_USER}/get_dev_login.har`, { - url: `/api/get_dev_login/${SCIPER_USER}`, - update: UPDATE, + await page.route(`/api/get_dev_login/${SCIPER_USER}`, async (route) => { + await route.fulfill({}); }); if ( process.env.REACT_APP_SCIPER_ADMIN !== undefined && diff --git a/web/frontend/tests/navbar.spec.ts b/web/frontend/tests/navbar.spec.ts index 71fed91a7..8dcef7851 100644 --- a/web/frontend/tests/navbar.spec.ts +++ b/web/frontend/tests/navbar.spec.ts @@ -7,50 +7,23 @@ import { logIn, setUp, } from './shared'; -import { SCIPER_ADMIN, SCIPER_USER, UPDATE, mockLogout, mockPersonalInfo } from './mocks'; +import { SCIPER_ADMIN, SCIPER_USER, mockLogout, mockPersonalInfo } from './mocks'; initI18n(); test.beforeEach(async ({ page }) => { - if (UPDATE === true) { - return; - } - await mockPersonalInfo(page); - await setUp(page, '/about'); -}); - -// helper tests to update related HAR files - -test('Assert anonymous user HAR files are up-to-date', async ({ page }) => { - test.skip(UPDATE === false, 'Do not update HAR files'); await mockPersonalInfo(page); await setUp(page, '/about'); }); -test('Assert non-admin user HAR files are up-to-date', async ({ page }) => { - test.skip(UPDATE === false, 'Do not update HAR files'); - await mockPersonalInfo(page, SCIPER_USER); - await page.context().request.get(`/api/get_dev_login/${SCIPER_USER}`); - await setUp(page, '/about'); -}); - -test('Assert admin user HAR files are up-to-date', async ({ page }) => { - test.skip(UPDATE === false, 'Do not update HAR files'); - await mockPersonalInfo(page, SCIPER_ADMIN); - await page.context().request.get(`/api/get_dev_login/${SCIPER_ADMIN}`); - await setUp(page, '/about'); -}); - // unauthenticated test('Assert cookie is set', async ({ page }) => { - test.skip(UPDATE === true, 'Do not run regular tests when updating HAR files'); const cookies = await page.context().cookies(); await expect(cookies.find((cookie) => cookie.name === 'connect.sid')).toBeTruthy(); }); test('Assert D-Voting logo is present', async ({ page }) => { - test.skip(UPDATE === true, 'Do not run regular tests when updating HAR files'); const logo = await page.getByAltText(i18n.t('Workflow')); await expect(logo).toBeVisible(); await logo.click(); @@ -58,7 +31,6 @@ test('Assert D-Voting logo is present', async ({ page }) => { }); test('Assert link to form table is present', async ({ page }) => { - test.skip(UPDATE === true, 'Do not run regular tests when updating HAR files'); const forms = await page.getByRole('link', { name: i18n.t('navBarStatus') }); await expect(forms).toBeVisible(); await forms.click(); @@ -66,7 +38,6 @@ test('Assert link to form table is present', async ({ page }) => { }); test('Assert "Login" button calls login API', async ({ page }) => { - test.skip(UPDATE === true, 'Do not run regular tests when updating HAR files'); page.waitForRequest(new RegExp('/api/get_dev_login/[0-9]{6}')); await page.getByRole('button', { name: i18n.t('login') }).click(); }); @@ -74,7 +45,6 @@ test('Assert "Login" button calls login API', async ({ page }) => { // authenticated non-admin test('Assert "Profile" button is visible upon logging in', async ({ page }) => { - test.skip(UPDATE === true, 'Do not run regular tests when updating HAR files'); await assertOnlyVisibleToAuthenticated( page, page.getByRole('button', { name: i18n.t('Profile') }) @@ -82,7 +52,6 @@ test('Assert "Profile" button is visible upon logging in', async ({ page }) => { }); test('Assert "Logout" calls logout API', async ({ page, baseURL }) => { - test.skip(UPDATE === true, 'Do not run regular tests when updating HAR files'); await mockLogout(page); await logIn(page, SCIPER_USER); page.waitForRequest( @@ -100,7 +69,6 @@ test('Assert "Logout" calls logout API', async ({ page, baseURL }) => { // admin test('Assert "Create form" button is (only) visible to admin', async ({ page }) => { - test.skip(UPDATE === true, 'Do not run regular tests when updating HAR files'); await assertOnlyVisibleToAdmin( page, page.getByRole('link', { name: i18n.t('navBarCreateForm') }) @@ -108,6 +76,5 @@ test('Assert "Create form" button is (only) visible to admin', async ({ page }) }); test('Assert "Admin" button is (only) visible to admin', async ({ page }) => { - test.skip(UPDATE === true, 'Do not run regular tests when updating HAR files'); await assertOnlyVisibleToAdmin(page, page.getByRole('link', { name: i18n.t('navBarAdmin') })); });