Skip to content

Commit

Permalink
Merge pull request #1213 from City-of-Helsinki/develop
Browse files Browse the repository at this point in the history
Release v2.0.31
  • Loading branch information
japauliina authored Dec 2, 2024
2 parents 4d60b83 + 4999a88 commit a20a3d1
Show file tree
Hide file tree
Showing 153 changed files with 15,731 additions and 15,642 deletions.
1 change: 0 additions & 1 deletion .dockerignore
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
node_modules/
dist/
build/
.env
.env.example
.travis.yml
.docker-compose.yml
1 change: 1 addition & 0 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ FEATURE_SERVICEMAP_PAGE_TRACKING="false"
# MATOMO_MOBILITY_DIMENSION_ID=
# MATOMO_SENSES_DIMENSION_ID=
# MATOMO_NO_RESULTS_DIMENSION_ID=
# MATOMO_ENABLED=

# If false SHOW_AREA_SELECTION hides area related functionality.
# Defaulting to true.
Expand Down
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
17 changes: 13 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,19 +38,28 @@ Launches Jest test runner.<br>
Launches TestCafe test runner and performs browser tests on headless chrome.<br>

### `npm run browserTestCLI`
Launches the application using `node dist` command and then launches TestCafe test runner in headless mode. Mainly used by Travis CI.
Launches the application using `node dist` command and then launches TestCafe test runner in headless mode. Mainly used in GitHub Actions.

## 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.
- Open the application by loading `localhost:2048` in the browser

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`
- Then you can run the app with `npm start`
- Open the application by loading `localhost:2048` in the browser

To run with docker compose:
- Install Docker if not installed, check that port `2048` is free, not occupied by running server.
- Make sure you have environment variables set. `.env.example` should have all required values so you can copy it to `.env`.
- Run `docker compose up`
- Open the application by loading `localhost:2048` in the browser


## Environment variables
This is a documentation (some day hopefully exhaustive) of environment variables and how to use them.
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
11 changes: 10 additions & 1 deletion browserTests/utility/index.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,16 @@
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) {
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
Loading

0 comments on commit a20a3d1

Please sign in to comment.