Skip to content

Commit

Permalink
chore: fixing e2e tests HAUKI-672
Browse files Browse the repository at this point in the history
  • Loading branch information
mikkojamG committed Dec 13, 2024
1 parent 4a53ed7 commit eca8098
Show file tree
Hide file tree
Showing 7 changed files with 60 additions and 17 deletions.
11 changes: 5 additions & 6 deletions e2e/tests/resource-page.spec.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,18 @@
// 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;
let resourceUrl: string;
let resource: Resource;

test.beforeAll(async ({ browser }) => {
resourceUrl = await getResourceUrl();
resource = await getResource();
resourceUrl = await getResourceUrl();

page = await browser.newPage();
await page.goto(resourceUrl);
Expand Down Expand Up @@ -40,6 +41,7 @@ test.describe('Resource page', async () => {

test('Location name', async () => {
const resourceTitle = resource.name.fi;

await expect(page.getByText(resourceTitle)).toBeVisible();
});

Expand Down Expand Up @@ -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')
Expand Down
3 changes: 3 additions & 0 deletions e2e/utils.ts
Original file line number Diff line number Diff line change
@@ -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);

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
12 changes: 9 additions & 3 deletions playwright.config.ts
Original file line number Diff line number Diff line change
@@ -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({
Expand All @@ -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,

Expand Down Expand Up @@ -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'),
Expand Down
28 changes: 26 additions & 2 deletions src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,7 @@ const App = (): JSX.Element => {
/>
<Route
id="create-new-opening-period-route-child"
path="/resource/:parentId/child/:id/period/new/"
path="/resource/:parentId/child/:id/period/new"
element={
<PermissionResolver>
<HaukiHeader />
Expand Down Expand Up @@ -297,7 +297,7 @@ const App = (): JSX.Element => {
/>
<Route
id="add-exception-route-child"
path="/resource/:parentId/child/:id/exception/new/"
path="/resource/:parentId/child/:id/exception/new"
element={
<PermissionResolver>
<HaukiHeader />
Expand All @@ -309,6 +309,18 @@ const App = (): JSX.Element => {
/>
<Route
id="add-exception-route"
path="/resource/:id/exception/new/"
element={
<PermissionResolver>
<HaukiHeader />
<Main id="main">
<AddExceptionOpeningHoursPage />
</Main>
</PermissionResolver>
}
/>
<Route
id="edit-exception-route-child"
path="/resource/:parentId/child/:id/exception/:datePeriodId"
element={
<PermissionResolver>
Expand All @@ -319,6 +331,18 @@ const App = (): JSX.Element => {
</PermissionResolver>
}
/>
<Route
id="edit-exception-route"
path="/resource/:id/exception/:datePeriodId"
element={
<PermissionResolver>
<HaukiHeader />
<Main id="main">
<EditExceptionOpeningHoursPage />
</Main>
</PermissionResolver>
}
/>
</Routes>
</Router>
</AuthContext.Provider>
Expand Down
6 changes: 5 additions & 1 deletion src/common/utils/url/url.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 };
15 changes: 11 additions & 4 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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"
Expand Down

0 comments on commit eca8098

Please sign in to comment.