From eca8098f37605ee927f76a49af6dc30ced6efc5f Mon Sep 17 00:00:00 2001 From: mikkojamG Date: Fri, 13 Dec 2024 12:49:04 +0200 Subject: [PATCH] chore: fixing e2e tests HAUKI-672 --- e2e/tests/resource-page.spec.ts | 11 +++++------ e2e/utils.ts | 3 +++ package.json | 2 +- playwright.config.ts | 12 +++++++++--- src/App.tsx | 28 ++++++++++++++++++++++++++-- src/common/utils/url/url.ts | 6 +++++- yarn.lock | 15 +++++++++++---- 7 files changed, 60 insertions(+), 17 deletions(-) diff --git a/e2e/tests/resource-page.spec.ts b/e2e/tests/resource-page.spec.ts index 5ddc01b82..39342d016 100644 --- a/e2e/tests/resource-page.spec.ts +++ b/e2e/tests/resource-page.spec.ts @@ -1,8 +1,9 @@ // eslint-disable-next-line import/no-extraneous-dependencies import { Page, expect, test } from '@playwright/test'; -import { getResource, getResourceUrl } from '../utils'; -import { Resource } from '../../src/common/lib/types'; +import { getResourceUrl, getResource } from '../utils'; + import { testData } from '../constants'; +import { Resource } from '../../src/common/lib/types'; test.describe('Resource page', async () => { let page: Page; @@ -10,8 +11,8 @@ test.describe('Resource page', async () => { let resource: Resource; test.beforeAll(async ({ browser }) => { - resourceUrl = await getResourceUrl(); resource = await getResource(); + resourceUrl = await getResourceUrl(); page = await browser.newPage(); await page.goto(resourceUrl); @@ -40,6 +41,7 @@ test.describe('Resource page', async () => { test('Location name', async () => { const resourceTitle = resource.name.fi; + await expect(page.getByText(resourceTitle)).toBeVisible(); }); @@ -174,10 +176,7 @@ test.describe('Resource page', async () => { }); test('Dates - day selection', async () => { - const createNewPeriodUrl = `/resource/${resource.id}/period/new`; - await page.getByRole('button', { name: 'Lisää aukioloaika +' }).click(); - await page.goto(createNewPeriodUrl); await page .getByLabel('Aukiolomääritys 1') diff --git a/e2e/utils.ts b/e2e/utils.ts index de67b02d0..9ceab3b26 100644 --- a/e2e/utils.ts +++ b/e2e/utils.ts @@ -1,8 +1,11 @@ import { promisify } from 'util'; import { exec } from 'child_process'; +import dns from 'node:dns'; import { DatePeriod, Resource } from '../src/common/lib/types'; import { apiUrl, testData } from './constants'; +dns.setDefaultResultOrder('ipv4first'); + const getAuthParams = async () => { const execAsync = promisify(exec); diff --git a/package.json b/package.json index 7442066f3..f357454ee 100644 --- a/package.json +++ b/package.json @@ -15,7 +15,7 @@ "@testing-library/user-event": "^12.2.2", "@types/jest": "^26.0.24", "@types/lodash": "4.14.192", - "@types/node": "^12.20.37", + "@types/node": "^22.10.2", "@types/react": "^17.0.1", "@types/react-dom": "^17.0.1", "@types/react-router-dom": "^5.3.2", diff --git a/playwright.config.ts b/playwright.config.ts index 8fbe1e64c..a2ea4569a 100644 --- a/playwright.config.ts +++ b/playwright.config.ts @@ -1,5 +1,5 @@ // eslint-disable-next-line import/no-extraneous-dependencies -import { defineConfig } from '@playwright/test'; +import { defineConfig, devices } from '@playwright/test'; import { e2eTestUrl } from './e2e/constants'; export default defineConfig({ @@ -11,6 +11,8 @@ export default defineConfig({ /* Fail the build on CI if you accidentally left test.only in the source code. */ forbidOnly: !!process.env.CI, + retries: 1, + // Timeout for each test in milliseconds timeout: 60 * 1000, @@ -49,8 +51,12 @@ export default defineConfig({ projects: [ { - name: 'Tests', - testMatch: [/tests/], + name: 'chromium', + use: { ...devices['Desktop Chrome'] }, + }, + { + name: 'firefox', + use: { ...devices['Desktop Firefox'] }, }, ], globalTeardown: require.resolve('./e2e/tests/global.teardown.ts'), diff --git a/src/App.tsx b/src/App.tsx index 67d6643d8..b1c6c718e 100644 --- a/src/App.tsx +++ b/src/App.tsx @@ -225,7 +225,7 @@ const App = (): JSX.Element => { /> @@ -297,7 +297,7 @@ const App = (): JSX.Element => { /> @@ -309,6 +309,18 @@ const App = (): JSX.Element => { /> + +
+ +
+ + } + /> + @@ -319,6 +331,18 @@ const App = (): JSX.Element => { } /> + + +
+ +
+ + } + /> diff --git a/src/common/utils/url/url.ts b/src/common/utils/url/url.ts index f971d0ea7..5e56eae18 100644 --- a/src/common/utils/url/url.ts +++ b/src/common/utils/url/url.ts @@ -3,7 +3,11 @@ import querystring from 'querystring'; export type SearchParameters = { [key: string]: string | string[] }; const parseSearchParameters = (queryStr: string): SearchParameters => { - return querystring.parse(queryStr.replace('?', '')); + const parsed = querystring.parse(queryStr.replace('?', '')); + + return Object.fromEntries( + Object.entries(parsed).filter(([, value]) => value !== undefined) + ) as SearchParameters; }; export default { parseSearchParameters }; diff --git a/yarn.lock b/yarn.lock index 9e2da317c..34d04cf34 100644 --- a/yarn.lock +++ b/yarn.lock @@ -1536,10 +1536,12 @@ dependencies: undici-types "~5.26.4" -"@types/node@^12.20.37": - version "12.20.55" - resolved "https://registry.yarnpkg.com/@types/node/-/node-12.20.55.tgz#c329cbd434c42164f846b909bd6f85b5537f6240" - integrity sha512-J8xLz7q2OFulZ2cyGTLE1TbbZcjpno7FaN6zdJNrgAdrJ+DZzh/uFR6YrTb4C+nXakvud8Q4+rbhoIWlYQbUFQ== +"@types/node@^22.10.2": + version "22.10.2" + resolved "https://registry.yarnpkg.com/@types/node/-/node-22.10.2.tgz#a485426e6d1fdafc7b0d4c7b24e2c78182ddabb9" + integrity sha512-Xxr6BBRCAOQixvonOye19wnzyDiUtTeqldOOmj3CkeblonbccA12PFwlufvRdrpjXxqnmUaeiU5EOA+7s5diUQ== + dependencies: + undici-types "~6.20.0" "@types/normalize-package-data@^2.4.0": version "2.4.4" @@ -6124,6 +6126,11 @@ undici-types@~5.26.4: resolved "https://registry.yarnpkg.com/undici-types/-/undici-types-5.26.5.tgz#bcd539893d00b56e964fd2657a4866b221a65617" integrity sha512-JlCMO+ehdEIKqlFxk6IfVoAUVmgz7cU7zD/h9XZ0qzeosSHmUJVOzSQvvYSYWXkFXC+IfLKSIffhv0sVZup6pA== +undici-types@~6.20.0: + version "6.20.0" + resolved "https://registry.yarnpkg.com/undici-types/-/undici-types-6.20.0.tgz#8171bf22c1f588d1554d55bf204bc624af388433" + integrity sha512-Ny6QZ2Nju20vw1SRHe3d9jVu6gJ+4e3+MMpqu7pqE5HT6WsTSlce++GQmK5UXS8mzV8DSYHrQH+Xrf2jVcuKNg== + update-browserslist-db@^1.0.13: version "1.0.13" resolved "https://registry.yarnpkg.com/update-browserslist-db/-/update-browserslist-db-1.0.13.tgz#3c5e4f5c083661bd38ef64b6328c26ed6c8248c4"