Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Migrate to React v18 (vol 2) #1208

Merged
merged 18 commits into from
Nov 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ jobs:
uses: actions/setup-node@v4
with:
node-version: ${{ matrix.node-version }}
- run: npm install
- run: npm install --legacy-peer-deps
- run: npm run testBuild
- run: npm test
- run: npm run browserTestCLI
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ WORKDIR /servicemap-ui
# A wildcard is used to ensure both package.json AND package-lock.json are copied
# where available (npm@5+)
COPY package*.json ./
RUN npm install
RUN npm install --legacy-peer-deps

COPY . .
RUN npm run build
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,12 +42,12 @@ Launches the application using `node dist` command and then launches TestCafe te

## How to use
For development:
- Make sure npm packages are installed by running `npm install`in project root.
- Make sure npm packages are installed by running `npm install --legacy-peer-deps`in project root.
- Make sure you have environment variables set. `.env.example` should have all required values so you can copy it to `.env`.
- Then you can start development server using `npm run dev`. Which watches files and updates on code changes.

To run in production mode:
- Make sure npm packages are installed by running `npm install`in project root.
- Make sure npm packages are installed by running `npm install --legacy-peer-deps`in project root.
- Make sure you have environment variables set. `.env.example` should have all required values so you can copy it to `.env`.
- Build files by running `npm run build`
- Then you can just run the app with `npm start`
Expand Down
36 changes: 5 additions & 31 deletions browserTests/.testcaferc.js
Original file line number Diff line number Diff line change
@@ -1,34 +1,8 @@
const config = require('./config');
const testcafe = require('testcafe');
const { server } = config;

async function setCookies(t) {
const afterOneYear = new Date();
afterOneYear.setDate(afterOneYear.getDate() + 365);
const url = await testcafe.ClientFunction(() => document.location.href)();
await t.setCookies({
name: 'city-of-helsinki-cookie-consents',
// value: '{"city-of-helsinki-cookie-consents":true,"matomo":false}',
value: '%7B%22city-of-helsinki-cookie-consents%22%3Atrue%2C%22matomo%22%3Atrue%7D',
domain: `${server.address}`,
path: '/',
expires: afterOneYear,
maxAge: 365 * 24 * 60 * 60,
secure: false,
httpOnly: false,
sameSite: 'Strict',
})
.navigateTo(url);
}

module.exports = {
hooks: {
test: {
before: async t => {
await setCookies(t);
},
after: async () => {
},
},
browsers: ["firefox:headless"], // Browsers to run tests on
skipJsErrors: true, // Ignores JavaScript errors
quarantineMode: {
successThreshold: 1,
attemptLimit: 10
},
}
5 changes: 3 additions & 2 deletions browserTests/generic/browserTest.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,16 @@ import { Selector } from 'testcafe';
import { waitForReact } from 'testcafe-react-selectors';

import { paletteDefault, paletteDark } from '../../src/themes'
import { getBaseUrl, getLocation } from '../utility';
import { acceptCookieConcent, getBaseUrl, getLocation } from '../utility';

const siteRoot = `${getBaseUrl()}`;

// TODO: move these to the related view folders
fixture`General tests`
.page`${siteRoot}/fi`
.beforeEach(async () => {
.beforeEach(async (t) => {
await waitForReact();
await acceptCookieConcent(t);
});

test('Language does change', async (t) => {
Expand Down
11 changes: 7 additions & 4 deletions browserTests/generic/mapTest.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
import { waitForReact } from 'testcafe-react-selectors';
import { Selector } from 'testcafe';
import { getBaseUrl } from '../utility';
import { acceptCookieConcent, getBaseUrl } from '../utility';

/* eslint-disable */
fixture`Map tests`
.page`${getBaseUrl()}/fi`
.beforeEach(async () => {
.beforeEach(async (t) => {
await waitForReact();
await acceptCookieConcent(t);
});

test.skip('Transit marker visible after zoom', async (t) => {
Expand All @@ -29,8 +30,9 @@ test.skip('Transit marker visible after zoom', async (t) => {

fixture`Search unit geometry test`
.page`${getBaseUrl()}/fi/search?q=latu`
.beforeEach(async () => {
.beforeEach(async (t) => {
await waitForReact();
await acceptCookieConcent(t);
});

test('Unit geometry is drawn on map', async (t) => {
Expand All @@ -43,8 +45,9 @@ test('Unit geometry is drawn on map', async (t) => {

fixture`Unit page geometry test`
.page`${getBaseUrl()}/fi/unit/56544`
.beforeEach(async () => {
.beforeEach(async (t) => {
await waitForReact();
await acceptCookieConcent(t);
});

test('Unit geometry is drawn on map', async (t) => {
Expand Down
5 changes: 3 additions & 2 deletions browserTests/generic/navigationTest.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { waitForReact } from 'testcafe-react-selectors';
import { Selector } from 'testcafe';
import { getBaseUrl } from '../utility';
import { acceptCookieConcent, getBaseUrl } from '../utility';
import {
embedderToolButton,
embedderToolCloseButton,
Expand All @@ -14,8 +14,9 @@ import {

fixture`Navigation home page`
.page`${getBaseUrl()}/fi`
.beforeEach(async () => {
.beforeEach(async (t) => {
await waitForReact();
await acceptCookieConcent(t);
});

test('Should navigate to embedder tool', async (t) => {
Expand Down
2 changes: 1 addition & 1 deletion browserTests/utility/focusIndicatorTest.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Selector, ClientFunction } from 'testcafe';
import { ClientFunction, Selector } from 'testcafe';
import { getContrast, getElementBG, getParentElementBG, getFocusedElement } from '../../src/utils/componentContrast';

export default () => {
Expand Down
12 changes: 11 additions & 1 deletion browserTests/utility/index.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,17 @@
import { ClientFunction } from 'testcafe';
import { ClientFunction, Selector } from 'testcafe';

const config = require('../config');

export const getLocation = ClientFunction(() => document.location.href);

export const getBaseUrl = () => `http://${config.server.address}:${config.server.port}`;

export const acceptCookieConcent = async (t) => {
if (t) {
return;
// const cookieConsentApproveButton = Selector('button[data-testid="cookie-consent-approve-button"]');
// await t
// .expect(cookieConsentApproveButton.exists).ok('Cookie consent approve button should exist')
// .click(cookieConsentApproveButton);
}
}
5 changes: 3 additions & 2 deletions browserTests/views/addressTest.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
/* eslint-disable */
import { Selector } from 'testcafe';
import { ReactSelector, waitForReact } from 'testcafe-react-selectors';
import { getBaseUrl, getLocation } from '../utility';
import { acceptCookieConcent, getBaseUrl, getLocation } from '../utility';
import { addressSearchBarInput } from '../utility/pageObjects';

const testLocation = `${getBaseUrl()}/fi/address/helsinki/Topeliuksenkatu 27`;

fixture`Address view test`
.page`${testLocation}`
.beforeEach(async () => {
.beforeEach(async (t) => {
await waitForReact();
await acceptCookieConcent(t);
});

test('AddressView does render correct view', async (t) => {
Expand Down
5 changes: 3 additions & 2 deletions browserTests/views/areaTest.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/* eslint-disable */
import { Selector } from 'testcafe';
import { waitForReact } from 'testcafe-react-selectors';
import { getBaseUrl, getLocation } from '../utility';
import { acceptCookieConcent, getBaseUrl, getLocation } from '../utility';
import {
accordionSelector,
addressSearchBarInput,
Expand All @@ -12,8 +12,9 @@ import {

fixture`Area view test`
.page`${getBaseUrl()}/fi/area`
.beforeEach(async () => {
.beforeEach(async (t) => {
await waitForReact();
await acceptCookieConcent(t);
});

const drawerButtons = Selector('[data-sm="ServiceTabComponent"]').find(accordionSelector);
Expand Down
5 changes: 3 additions & 2 deletions browserTests/views/homeTest.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
/* eslint-disable */
import { Selector } from 'testcafe';
import { waitForReact } from 'testcafe-react-selectors';
import { getBaseUrl, getLocation } from '../utility';
import { acceptCookieConcent, getBaseUrl, getLocation } from '../utility';
import { feedbackButton, infoButton } from '../utility/pageObjects';

const viewUrl = `${getBaseUrl()}/fi/`;

fixture`Home view test`
.page`${viewUrl}`
.beforeEach(async () => {
.beforeEach(async (t) => {
await waitForReact();
await acceptCookieConcent(t);
});

test('Test home page navigation button clicks take user to correct pages', async (t) => {
Expand Down
5 changes: 3 additions & 2 deletions browserTests/views/mobilityTreeTest.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,17 @@ import { Selector } from 'testcafe';
import { waitForReact } from 'testcafe-react-selectors';

import finnish from '../../src/i18n/fi';
import { getBaseUrl, getLocation } from '../utility';
import { acceptCookieConcent, getBaseUrl, getLocation } from '../utility';
import { treeSearchTest, treeViewAccordionTest } from '../utility/TreeViewTest';

const searchBackButton = Selector('#SearchBar .SMBackButton');

/* eslint-disable */
fixture`Mobility tree page tests`
.page`${getBaseUrl()}/fi/mobility`
.beforeEach(async () => {
.beforeEach(async (t) => {
await waitForReact();
await acceptCookieConcent(t);
});

treeViewAccordionTest();
Expand Down
20 changes: 13 additions & 7 deletions browserTests/views/searchTest.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/* eslint-disable */
import { Selector } from 'testcafe';
import { ReactSelector, waitForReact } from 'testcafe-react-selectors';
import { getBaseUrl, getLocation } from '../utility';
import { acceptCookieConcent, getBaseUrl, getLocation } from '../utility';
import {
addressSearchBarInput,
cityDropdown,
Expand Down Expand Up @@ -30,8 +30,9 @@ const addressInput = Selector(addressSearchBarInput);

fixture`Search view test`
.page`${searchPage}`
.beforeEach(async () => {
.beforeEach(async (t) => {
await waitForReact();
await acceptCookieConcent(t);
});

const searchUnits = async (t, search = 'uimastadion') => {
Expand Down Expand Up @@ -335,8 +336,9 @@ const cityChips = Selector(`${cityDropdown} ${settingChip}`);

fixture`Search view custom url with city and org param test`
.page`${homePage}`
.beforeEach(async () => {
.beforeEach(async (t) => {
await waitForReact();
await acceptCookieConcent(t);
});


Expand Down Expand Up @@ -425,8 +427,9 @@ test('Should not mess up organization settings between embedded and normal view'

fixture`Search view custom url with accessibility param test`
.page`${homePage}`
.beforeEach(async () => {
.beforeEach(async (t) => {
await waitForReact();
await acceptCookieConcent(t);
});


Expand All @@ -450,8 +453,9 @@ test('Should override accessibility settings', async(t) => {

fixture`Search view should set settings to url test`
.page`${homePage}`
.beforeEach(async () => {
.beforeEach(async (t) => {
await waitForReact();
await acceptCookieConcent(t);
});


Expand Down Expand Up @@ -484,8 +488,9 @@ test('Should set user settings to url', async(t) => {

fixture`Search view should set home address with url test`
.page`${homePage}/search?q=maauimala&hcity=helsinki&hstreet=Annankatu+12`
.beforeEach(async () => {
.beforeEach(async (t) => {
await waitForReact();
await acceptCookieConcent(t);
});

// test('Should set home address from url', async(t) => {
Expand All @@ -497,8 +502,9 @@ fixture`Search view should set home address with url test`

fixture`Search view should set map type with url test`
.page`${homePage}/search?q=maauimala&hcity=helsinki&map=guidemap`
.beforeEach(async () => {
.beforeEach(async (t) => {
await waitForReact();
await acceptCookieConcent(t);
});

test('Should set map type from url', async(t) => {
Expand Down
8 changes: 5 additions & 3 deletions browserTests/views/serviceTest.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Selector } from 'testcafe';
import { ReactSelector, waitForReact } from 'testcafe-react-selectors';
import { getBaseUrl } from '../utility';
import { acceptCookieConcent, getBaseUrl } from '../utility';

import paginationTest from '../utility/paginationTest';
import resultOrdererTest from '../utility/resultOrdererTest';
Expand All @@ -10,8 +10,9 @@ const coordinates = ['60.281936', '24.949933'];
/* eslint-disable */
fixture`Service page coordinate tests`
.page`${getBaseUrl()}/fi/service/813?lat=${coordinates[0]}&lon=${coordinates[1]}`
.beforeEach(async () => {
.beforeEach(async (t) => {
await waitForReact();
await acceptCookieConcent(t);
});

test('User marker is drawn on map based on coordinates', async (t) => {
Expand All @@ -27,8 +28,9 @@ const servicePage = `${getBaseUrl()}/fi/service/813`;

fixture`Service page tests`
.page`${servicePage}`
.beforeEach(async () => {
.beforeEach(async (t) => {
await waitForReact();
await acceptCookieConcent(t);
});


Expand Down
5 changes: 3 additions & 2 deletions browserTests/views/serviceTreeTest.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Selector } from 'testcafe';
import { waitForReact } from 'testcafe-react-selectors';

import { getBaseUrl, getLocation } from '../utility';
import { acceptCookieConcent, getBaseUrl, getLocation } from '../utility';
import finnish from '../../src/i18n/fi';
import { treeSearchTest, treeViewAccordionTest } from '../utility/TreeViewTest';

Expand All @@ -10,8 +10,9 @@ const searchBackButton = Selector('#SearchBar .SMBackButton');
/* eslint-disable */
fixture`Service tree page tests`
.page`${getBaseUrl()}/fi/services`
.beforeEach(async () => {
.beforeEach(async (t) => {
await waitForReact();
await acceptCookieConcent(t);
});

treeViewAccordionTest();
Expand Down
5 changes: 3 additions & 2 deletions browserTests/views/settingsTest.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/* eslint-disable */
import { Selector } from 'testcafe';
import { waitForReact } from 'testcafe-react-selectors';
import { getBaseUrl } from '../utility';
import { acceptCookieConcent, getBaseUrl } from '../utility';
import {
cityDropdown,
mapToolsButton,
Expand All @@ -17,8 +17,9 @@ const organisationDropdownSelector = Selector(organisationDropdown)

fixture`Settings view tests`
.page`${getBaseUrl()}/fi/`
.beforeEach(async () => {
.beforeEach(async (t) => {
await waitForReact();
await acceptCookieConcent(t);
});

test('Settings does opens and closes correctly', async (t) => {
Expand Down
Loading