diff --git a/.env b/.env new file mode 100644 index 0000000..ef282fa --- /dev/null +++ b/.env @@ -0,0 +1,3 @@ +# Jest configuration variables +# - possible values: ON, OFF +JEST_USE_SETUP=OFF \ No newline at end of file diff --git a/.eslintrc.js b/.eslintrc.js new file mode 100644 index 0000000..0cbd65c --- /dev/null +++ b/.eslintrc.js @@ -0,0 +1,65 @@ +const fs = require('fs'); +const path = require('path'); +const projectRootPath = fs.realpathSync(__dirname + '/../../../'); + +let voltoPath = path.join(projectRootPath, 'node_modules/@plone/volto'); +let configFile; +if (fs.existsSync(`${projectRootPath}/tsconfig.json`)) + configFile = `${projectRootPath}/tsconfig.json`; +else if (fs.existsSync(`${projectRootPath}/jsconfig.json`)) + configFile = `${projectRootPath}/jsconfig.json`; + +if (configFile) { + const jsConfig = require(configFile).compilerOptions; + const pathsConfig = jsConfig.paths; + if (pathsConfig['@plone/volto']) + voltoPath = `./${jsConfig.baseUrl}/${pathsConfig['@plone/volto'][0]}`; +} + +const AddonConfigurationRegistry = require(`${voltoPath}/addon-registry.js`); +const reg = new AddonConfigurationRegistry(projectRootPath); + +// Extends ESlint configuration for adding the aliases to `src` directories in Volto addons +const addonAliases = Object.keys(reg.packages).map((o) => [ + o, + reg.packages[o].modulePath, +]); + +const addonExtenders = reg.getEslintExtenders().map((m) => require(m)); + +const defaultConfig = { + extends: `${voltoPath}/.eslintrc`, + settings: { + 'import/resolver': { + alias: { + map: [ + ['@plone/volto', '@plone/volto/src'], + ['@plone/volto-slate', '@plone/volto/packages/volto-slate/src'], + ...addonAliases, + ['@package', `${__dirname}/src`], + ['@root', `${__dirname}/src`], + ['~', `${__dirname}/src`], + ], + extensions: ['.js', '.jsx', '.json'], + }, + 'babel-plugin-root-import': { + rootPathSuffix: 'src', + }, + }, + }, + rules: { + 'react/jsx-no-target-blank': [ + 'error', + { + allowReferrer: true, + }, + ], + } +}; + +const config = addonExtenders.reduce( + (acc, extender) => extender.modify(acc), + defaultConfig, +); + +module.exports = config; diff --git a/.gitignore b/.gitignore index 53b9801..f1be4ff 100644 --- a/.gitignore +++ b/.gitignore @@ -1,6 +1,5 @@ .vscode/ .history -.eslintrc.js .nyc_output project coverage diff --git a/.project.eslintrc.js b/.project.eslintrc.js deleted file mode 100644 index 765070f..0000000 --- a/.project.eslintrc.js +++ /dev/null @@ -1,48 +0,0 @@ -const fs = require('fs'); -const path = require('path'); - -const projectRootPath = fs.existsSync('./project') - ? fs.realpathSync('./project') - : fs.realpathSync('./../../../'); -const packageJson = require(path.join(projectRootPath, 'package.json')); -const jsConfig = require(path.join(projectRootPath, 'jsconfig.json')).compilerOptions; - -const pathsConfig = jsConfig.paths; - -let voltoPath = path.join(projectRootPath, 'node_modules/@plone/volto'); - -Object.keys(pathsConfig).forEach(pkg => { - if (pkg === '@plone/volto') { - voltoPath = `./${jsConfig.baseUrl}/${pathsConfig[pkg][0]}`; - } -}); -const AddonConfigurationRegistry = require(`${voltoPath}/addon-registry.js`); -const reg = new AddonConfigurationRegistry(projectRootPath); - -// Extends ESlint configuration for adding the aliases to `src` directories in Volto addons -const addonAliases = Object.keys(reg.packages).map(o => [ - o, - reg.packages[o].modulePath, -]); - - -module.exports = { - extends: `${projectRootPath}/node_modules/@plone/volto/.eslintrc`, - settings: { - 'import/resolver': { - alias: { - map: [ - ['@plone/volto', '@plone/volto/src'], - ...addonAliases, - ['@package', `${__dirname}/src`], - ['~', `${__dirname}/src`], - ], - extensions: ['.js', '.jsx', '.json'], - }, - 'babel-plugin-root-import': { - rootPathSuffix: 'src', - }, - }, - }, -}; - diff --git a/CHANGELOG.md b/CHANGELOG.md index 4feac50..4ef304e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,14 @@ All notable changes to this project will be documented in this file. Dates are d Generated by [`auto-changelog`](https://github.com/CookPete/auto-changelog). +### [6.0.0](https://github.com/eea/volto-widget-temporal-coverage/compare/5.2.0...6.0.0) - 22 April 2024 + +#### :rocket: New Features + +- feat: Release 6.0.0 - Volto 17 support [alin - [`0098e70`](https://github.com/eea/volto-widget-temporal-coverage/commit/0098e70cc331d4e181e2d336cb1ddb0525955e23)] + +#### :hammer_and_wrench: Others + ### [5.2.0](https://github.com/eea/volto-widget-temporal-coverage/compare/5.1.5...5.2.0) - 27 November 2023 #### :rocket: New Features diff --git a/Jenkinsfile b/Jenkinsfile index 4859e40..f656e0b 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -9,11 +9,12 @@ pipeline { environment { GIT_NAME = "volto-widget-temporal-coverage" NAMESPACE = "@eeacms" - SONARQUBE_TAGS = "volto.eea.europa.eu,www.eea.europa.eu-ims,climate-energy.eea.europa.eu,sustainability.eionet.europa.eu,forest.eea.europa.eu,biodiversity.europa.eu,clms.land.copernicus.eu,industry.eea.europa.eu,water.europa.eu-freshwater,demo-www.eea.europa.eu,clmsdemo.devel6cph.eea.europa.eu,water.europa.eu-marine,climate-adapt.eea.europa.eu,climate-advisory-board.devel4cph.eea.europa.eu,climate-advisory-board.europa.eu,www.eea.europa.eu-en" + SONARQUBE_TAGS = "volto.eea.europa.eu,www.eea.europa.eu-ims,climate-energy.eea.europa.eu,forest.eea.europa.eu,biodiversity.europa.eu,clms.land.copernicus.eu,industry.eea.europa.eu,water.europa.eu-freshwater,demo-www.eea.europa.eu,clmsdemo.devel6cph.eea.europa.eu,water.europa.eu-marine,climate-adapt.eea.europa.eu,climate-advisory-board.devel4cph.eea.europa.eu,climate-advisory-board.europa.eu,www.eea.europa.eu-en,insitu-frontend.eionet.europa.eu,insitu.copernicus.eu" DEPENDENCIES = "" BACKEND_PROFILES = "eea.kitkat:testing" BACKEND_ADDONS = "" - VOLTO = "16" + VOLTO = "17" + VOLTO16_BREAKING_CHANGES = "no" IMAGE_NAME = BUILD_TAG.toLowerCase() } @@ -44,6 +45,7 @@ pipeline { } steps { script { + checkout scm withCredentials([string(credentialsId: 'eea-jenkins-token', variable: 'GITHUB_TOKEN')]) { check_result = sh script: '''docker run --pull always -i --rm --name="$IMAGE_NAME-gitflow-check" -e GIT_TOKEN="$GITHUB_TOKEN" -e GIT_BRANCH="$BRANCH_NAME" -e GIT_ORG="$GIT_ORG" -e GIT_NAME="$GIT_NAME" eeacms/gitflow /check_if_testing_needed.sh''', returnStatus: true @@ -61,7 +63,6 @@ pipeline { allOf { not { environment name: 'CHANGE_ID', value: '' } environment name: 'CHANGE_TARGET', value: 'develop' - environment name: 'SKIP_TESTS', value: '' } allOf { environment name: 'CHANGE_ID', value: '' @@ -69,25 +70,27 @@ pipeline { not { changelog '.*^Automated release [0-9\\.]+$' } branch 'master' } - environment name: 'SKIP_TESTS', value: '' } } } - stages { - stage('Build test image') { - steps { - checkout scm - sh '''docker build --pull --build-arg="VOLTO_VERSION=$VOLTO" --build-arg="ADDON_NAME=$NAMESPACE/$GIT_NAME" --build-arg="ADDON_PATH=$GIT_NAME" . -t $IMAGE_NAME-frontend''' + parallel { + + stage('Volto 17') { + agent { node { label 'docker-1.13'} } + stages { + stage('Build test image') { + steps { + sh '''docker build --pull --build-arg="VOLTO_VERSION=$VOLTO" --build-arg="ADDON_NAME=$NAMESPACE/$GIT_NAME" --build-arg="ADDON_PATH=$GIT_NAME" . -t $IMAGE_NAME-frontend''' + } } - } - - stage('Fix code') { - when { + + stage('Fix code') { + when { environment name: 'CHANGE_ID', value: '' not { branch 'master' } - } - steps { - script { + } + steps { + script { fix_result = sh(script: '''docker run --name="$IMAGE_NAME-fix" --entrypoint=make --workdir=/app/src/addons/$GIT_NAME $IMAGE_NAME-frontend ci-fix''', returnStatus: true) sh '''docker cp $IMAGE_NAME-fix:/app/src/addons/$GIT_NAME/src .''' sh '''docker rm -v $IMAGE_NAME-fix''' @@ -105,31 +108,31 @@ pipeline { sh '''exit 1''' } } + } } - } - stage('ES lint') { - steps { - sh '''docker run --rm --name="$IMAGE_NAME-eslint" --entrypoint=make --workdir=/app/src/addons/$GIT_NAME $IMAGE_NAME-frontend lint''' + stage('ES lint') { + when { environment name: 'SKIP_TESTS', value: '' } + steps { + sh '''docker run --rm --name="$IMAGE_NAME-eslint" --entrypoint=make --workdir=/app/src/addons/$GIT_NAME $IMAGE_NAME-frontend lint''' + } } - } - stage('Style lint') { - steps { - sh '''docker run --rm --name="$IMAGE_NAME-stylelint" --entrypoint=make --workdir=/app/src/addons/$GIT_NAME $IMAGE_NAME-frontend stylelint''' + stage('Style lint') { + when { environment name: 'SKIP_TESTS', value: '' } + steps { + sh '''docker run --rm --name="$IMAGE_NAME-stylelint" --entrypoint=make --workdir=/app/src/addons/$GIT_NAME $IMAGE_NAME-frontend stylelint''' + } } - } - stage('Prettier') { - steps { - sh '''docker run --rm --name="$IMAGE_NAME-prettier" --entrypoint=make --workdir=/app/src/addons/$GIT_NAME $IMAGE_NAME-frontend prettier''' + stage('Prettier') { + when { environment name: 'SKIP_TESTS', value: '' } + steps { + sh '''docker run --rm --name="$IMAGE_NAME-prettier" --entrypoint=make --workdir=/app/src/addons/$GIT_NAME $IMAGE_NAME-frontend prettier''' + } } - } - - stage('Coverage Tests') { - parallel { - - stage('Unit tests') { + stage('Unit tests') { + when { environment name: 'SKIP_TESTS', value: '' } steps { script { try { @@ -155,17 +158,24 @@ pipeline { } } } - } + } - stage('Integration tests') { + stage('Integration tests') { + when { environment name: 'SKIP_TESTS', value: '' } steps { script { try { sh '''docker run --pull always --rm -d --name="$IMAGE_NAME-plone" -e SITE="Plone" -e PROFILES="$BACKEND_PROFILES" -e ADDONS="$BACKEND_ADDONS" eeacms/plone-backend''' - sh '''docker run -d --shm-size=3g --link $IMAGE_NAME-plone:plone --name="$IMAGE_NAME-cypress" -e "RAZZLE_INTERNAL_API_PATH=http://plone:8080/Plone" --entrypoint=make --workdir=/app/src/addons/$GIT_NAME $IMAGE_NAME-frontend start-ci''' + sh '''docker run -d --shm-size=4g --link $IMAGE_NAME-plone:plone --name="$IMAGE_NAME-cypress" -e "RAZZLE_INTERNAL_API_PATH=http://plone:8080/Plone" --entrypoint=make --workdir=/app/src/addons/$GIT_NAME $IMAGE_NAME-frontend start-ci''' + frontend = sh script:'''docker exec --workdir=/app/src/addons/${GIT_NAME} $IMAGE_NAME-cypress make check-ci''', returnStatus: true + if ( frontend != 0 ) { + sh '''docker logs $IMAGE_NAME-cypress; exit 1''' + } + sh '''timeout -s 9 1800 docker exec --workdir=/app/src/addons/${GIT_NAME} $IMAGE_NAME-cypress make cypress-ci''' } finally { try { + if ( frontend == 0 ) { sh '''rm -rf cypress-videos cypress-results cypress-coverage cypress-screenshots''' sh '''mkdir -p cypress-videos cypress-results cypress-coverage cypress-screenshots''' videos = sh script: '''docker cp $IMAGE_NAME-cypress:/app/src/addons/$GIT_NAME/cypress/videos cypress-videos/''', returnStatus: true @@ -189,6 +199,7 @@ pipeline { sh '''for file in $(find cypress-results -name *.xml); do if [ $(grep -E 'failures="[1-9].*"' $file | wc -l) -eq 0 ]; then testname=$(grep -E 'file=.*failures="0"' $file | sed 's#.* file=".*\\/\\(.*\\.[jsxt]\\+\\)" time.*#\\1#' ); rm -f cypress-videos/videos/$testname.mp4; fi; done''' archiveArtifacts artifacts: 'cypress-videos/**/*.mp4', fingerprint: true, allowEmptyArchive: true } + } } finally { catchError(buildResult: 'SUCCESS', stageResult: 'SUCCESS') { junit testResults: 'cypress-results/**/*.xml', allowEmptyResults: true @@ -204,16 +215,7 @@ pipeline { } } } - } } - } - } - post { - always { - sh script: "docker rmi $IMAGE_NAME-frontend", returnStatus: true - } - } - } stage('Report to SonarQube') { when { @@ -221,9 +223,11 @@ pipeline { allOf { not { environment name: 'CHANGE_ID', value: '' } environment name: 'CHANGE_TARGET', value: 'develop' + environment name: 'SKIP_TESTS', value: '' } allOf { environment name: 'CHANGE_ID', value: '' + environment name: 'SKIP_TESTS', value: '' anyOf { allOf { branch 'develop' @@ -248,14 +252,107 @@ pipeline { } } + + } + } + + stage('Volto 16') { + agent { node { label 'integration'} } + when { + environment name: 'SKIP_TESTS', value: '' + not { environment name: 'VOLTO16_BREAKING_CHANGES', value: 'yes' } + } + stages { + stage('Build test image') { + steps { + sh '''docker build --pull --build-arg="VOLTO_VERSION=16" --build-arg="ADDON_NAME=$NAMESPACE/$GIT_NAME" --build-arg="ADDON_PATH=$GIT_NAME" . -t $IMAGE_NAME-frontend16''' + } + } + + stage('Unit tests Volto 16') { + steps { + script { + try { + sh '''docker run --name="$IMAGE_NAME-volto16" --entrypoint=make --workdir=/app/src/addons/$GIT_NAME $IMAGE_NAME-frontend16 test-ci''' + sh '''rm -rf xunit-reports16''' + sh '''mkdir -p xunit-reports16''' + sh '''docker cp $IMAGE_NAME-volto16:/app/junit.xml xunit-reports16/''' + } finally { + catchError(buildResult: 'SUCCESS', stageResult: 'SUCCESS') { + junit testResults: 'xunit-reports16/junit.xml', allowEmptyResults: true + } + sh script: '''docker rm -v $IMAGE_NAME-volto16''', returnStatus: true + } + } + } + } + + stage('Integration tests Volto 16') { + steps { + script { + try { + sh '''docker run --pull always --rm -d --name="$IMAGE_NAME-plone16" -e SITE="Plone" -e PROFILES="$BACKEND_PROFILES" -e ADDONS="$BACKEND_ADDONS" eeacms/plone-backend''' + sh '''docker run -d --shm-size=4g --link $IMAGE_NAME-plone16:plone --name="$IMAGE_NAME-cypress16" -e "RAZZLE_INTERNAL_API_PATH=http://plone:8080/Plone" --entrypoint=make --workdir=/app/src/addons/$GIT_NAME $IMAGE_NAME-frontend16 start-ci''' + frontend = sh script:'''docker exec --workdir=/app/src/addons/${GIT_NAME} $IMAGE_NAME-cypress16 make check-ci''', returnStatus: true + if ( frontend != 0 ) { + sh '''docker logs $IMAGE_NAME-cypress16; exit 1''' + } + sh '''timeout -s 9 1800 docker exec --workdir=/app/src/addons/${GIT_NAME} $IMAGE_NAME-cypress16 make cypress-ci''' + } finally { + try { + if ( frontend == 0 ) { + sh '''rm -rf cypress-videos16 cypress-results16 cypress-coverage16 cypress-screenshots16''' + sh '''mkdir -p cypress-videos16 cypress-results16 cypress-coverage16 cypress-screenshots16''' + videos = sh script: '''docker cp $IMAGE_NAME-cypress16:/app/src/addons/$GIT_NAME/cypress/videos cypress-videos16/''', returnStatus: true + sh '''docker cp $IMAGE_NAME-cypress16:/app/src/addons/$GIT_NAME/cypress/reports cypress-results16/''' + screenshots = sh script: '''docker cp $IMAGE_NAME-cypress16:/app/src/addons/$GIT_NAME/cypress/screenshots cypress-screenshots16''', returnStatus: true + + archiveArtifacts artifacts: 'cypress-screenshots16/**', fingerprint: true, allowEmptyArchive: true + + if ( videos == 0 ) { + sh '''for file in $(find cypress-results16 -name *.xml); do if [ $(grep -E 'failures="[1-9].*"' $file | wc -l) -eq 0 ]; then testname=$(grep -E 'file=.*failures="0"' $file | sed 's#.* file=".*\\/\\(.*\\.[jsxt]\\+\\)" time.*#\\1#' ); rm -f cypress-videos16/videos/$testname.mp4; fi; done''' + archiveArtifacts artifacts: 'cypress-videos16/**/*.mp4', fingerprint: true, allowEmptyArchive: true + } + } + } finally { + catchError(buildResult: 'SUCCESS', stageResult: 'SUCCESS') { + junit testResults: 'cypress-results16/**/*.xml', allowEmptyResults: true + } + catchError(buildResult: 'SUCCESS', stageResult: 'SUCCESS') { + sh '''docker logs $IMAGE_NAME-cypress16''' + } + sh script: "docker stop $IMAGE_NAME-cypress16", returnStatus: true + sh script: "docker stop $IMAGE_NAME-plone16", returnStatus: true + sh script: "docker rm -v $IMAGE_NAME-plone16", returnStatus: true + sh script: "docker rm -v $IMAGE_NAME-cypress16", returnStatus: true + } + } + } + } + } + + } + } + } + post { + always { + sh script: "docker rmi $IMAGE_NAME-frontend", returnStatus: true + sh script: "docker rmi $IMAGE_NAME-frontend16", returnStatus: true + } + } + } + + stage('SonarQube compare to master') { when { anyOf { allOf { not { environment name: 'CHANGE_ID', value: '' } environment name: 'CHANGE_TARGET', value: 'develop' + environment name: 'SKIP_TESTS', value: '' } allOf { + environment name: 'SKIP_TESTS', value: '' environment name: 'CHANGE_ID', value: '' branch 'develop' not { changelog '.*^Automated release [0-9\\.]+$' } @@ -316,3 +413,4 @@ pipeline { } } } + diff --git a/Makefile b/Makefile index efbf2fb..522b577 100644 --- a/Makefile +++ b/Makefile @@ -46,7 +46,7 @@ endif DIR=$(shell basename $$(pwd)) NODE_MODULES?="../../../node_modules" PLONE_VERSION?=6 -VOLTO_VERSION?=16 +VOLTO_VERSION?=17 ADDON_PATH="${DIR}" ADDON_NAME="@eeacms/${ADDON_PATH}" DOCKER_COMPOSE=PLONE_VERSION=${PLONE_VERSION} VOLTO_VERSION=${VOLTO_VERSION} ADDON_NAME=${ADDON_NAME} ADDON_PATH=${ADDON_PATH} docker compose @@ -86,7 +86,7 @@ cypress-open: ## Open cypress integration tests .PHONY: cypress-run cypress-run: ## Run cypress integration tests - CYPRESS_API_PATH="${RAZZLE_DEV_PROXY_API_PATH}" NODE_ENV=development $(NODE_MODULES)/cypress/bin/cypress run --browser chromium + CYPRESS_API_PATH="${RAZZLE_DEV_PROXY_API_PATH}" NODE_ENV=development $(NODE_MODULES)/cypress/bin/cypress run .PHONY: test test: ## Run jest tests @@ -98,7 +98,7 @@ test-update: ## Update jest tests snapshots .PHONY: stylelint stylelint: ## Stylelint - $(NODE_MODULES)/stylelint/bin/stylelint.js --allow-empty-input 'src/**/*.{css,less}' + $(NODE_MODULES)/.bin/stylelint --allow-empty-input 'src/**/*.{css,less}' .PHONY: stylelint-overrides stylelint-overrides: @@ -106,7 +106,7 @@ stylelint-overrides: .PHONY: stylelint-fix stylelint-fix: ## Fix stylelint - $(NODE_MODULES)/stylelint/bin/stylelint.js --allow-empty-input 'src/**/*.{css,less}' --fix + $(NODE_MODULES)/.bin/stylelint --allow-empty-input 'src/**/*.{css,less}' --fix $(NODE_MODULES)/.bin/stylelint --custom-syntax less --allow-empty-input 'theme/**/*.overrides' 'src/**/*.overrides' --fix .PHONY: prettier @@ -119,11 +119,11 @@ prettier-fix: ## Fix prettier .PHONY: lint lint: ## ES Lint - $(NODE_MODULES)/eslint/bin/eslint.js --max-warnings=0 'src/**/*.{js,jsx}' + $(NODE_MODULES)/.bin/eslint --max-warnings=0 'src/**/*.{js,jsx}' .PHONY: lint-fix lint-fix: ## Fix ES Lint - $(NODE_MODULES)/eslint/bin/eslint.js --fix 'src/**/*.{js,jsx}' + $(NODE_MODULES)/.bin/eslint --fix 'src/**/*.{js,jsx}' .PHONY: i18n i18n: ## i18n @@ -155,8 +155,11 @@ start-ci: cd ../.. yarn start +.PHONY: check-ci +check-ci: + $(NODE_MODULES)/.bin/wait-on -t 240000 http://localhost:3000 + .PHONY: cypress-ci cypress-ci: $(NODE_MODULES)/.bin/wait-on -t 240000 http://localhost:3000 - NODE_ENV=development make cypress-run - + CYPRESS_API_PATH="${RAZZLE_DEV_PROXY_API_PATH}" NODE_ENV=development $(NODE_MODULES)/cypress/bin/cypress run --browser chromium diff --git a/cypress/support/e2e.js b/cypress/support/e2e.js index f696418..f8f752c 100644 --- a/cypress/support/e2e.js +++ b/cypress/support/e2e.js @@ -35,10 +35,6 @@ export const slateBeforeEach = (contentType = 'Document') => { path: 'cypress', }); cy.visit('/cypress/my-page'); - cy.waitForResourceToLoad('@navigation'); - cy.waitForResourceToLoad('@breadcrumbs'); - cy.waitForResourceToLoad('@actions'); - cy.waitForResourceToLoad('@types'); cy.waitForResourceToLoad('my-page'); cy.navigate('/cypress/my-page/edit'); }; diff --git a/jest-addon.config.js b/jest-addon.config.js index 3c86610..93ba86c 100644 --- a/jest-addon.config.js +++ b/jest-addon.config.js @@ -1,3 +1,5 @@ +require('dotenv').config({ path: __dirname + '/.env' }) + module.exports = { testMatch: ['**/src/addons/**/?(*.)+(spec|test).[jt]s?(x)'], collectCoverageFrom: [ @@ -9,18 +11,26 @@ module.exports = { '@plone/volto/cypress': '/node_modules/@plone/volto/cypress', '@plone/volto/babel': '/node_modules/@plone/volto/babel', '@plone/volto/(.*)$': '/node_modules/@plone/volto/src/$1', - '@package/(.*)$': '/src/$1', - '@root/(.*)$': '/src/$1', + '@package/(.*)$': '/node_modules/@plone/volto/src/$1', + '@root/(.*)$': '/node_modules/@plone/volto/src/$1', '@plone/volto-quanta/(.*)$': '/src/addons/volto-quanta/src/$1', + '@eeacms/search/(.*)$': '/src/addons/volto-searchlib/searchlib/$1', + '@eeacms/search': '/src/addons/volto-searchlib/searchlib', '@eeacms/(.*?)/(.*)$': '/node_modules/@eeacms/$1/src/$2', - '@plone/volto-slate': + '@plone/volto-slate$': '/node_modules/@plone/volto/packages/volto-slate/src', + '@plone/volto-slate/(.*)$': + '/node_modules/@plone/volto/packages/volto-slate/src/$1', '~/(.*)$': '/src/$1', 'load-volto-addons': '/node_modules/@plone/volto/jest-addons-loader.js', }, + transformIgnorePatterns: [ + '/node_modules/(?!(@plone|@root|@package|@eeacms)/).*/', + ], transform: { '^.+\\.js(x)?$': 'babel-jest', + '^.+\\.ts(x)?$': 'babel-jest', '^.+\\.(png)$': 'jest-file', '^.+\\.(jpg)$': 'jest-file', '^.+\\.(svg)$': './node_modules/@plone/volto/jest-svgsystem-transform.js', @@ -33,4 +43,9 @@ module.exports = { statements: 5, }, }, -}; + ...(process.env.JEST_USE_SETUP === 'ON' && { + setupFilesAfterEnv: [ + '/node_modules/@eeacms/volto-widget-temporal-coverage/jest.setup.js', + ], + }), +} diff --git a/jest.setup.js b/jest.setup.js new file mode 100644 index 0000000..85b16f7 --- /dev/null +++ b/jest.setup.js @@ -0,0 +1,65 @@ +import { jest } from '@jest/globals'; +import configureStore from 'redux-mock-store'; +import thunk from 'redux-thunk'; +import { blocksConfig } from '@plone/volto/config/Blocks'; +import installSlate from '@plone/volto-slate/index'; + +var mockSemanticComponents = jest.requireActual('semantic-ui-react'); +var mockComponents = jest.requireActual('@plone/volto/components'); +var config = jest.requireActual('@plone/volto/registry').default; + +config.blocks.blocksConfig = { + ...blocksConfig, + ...config.blocks.blocksConfig, +}; + +jest.doMock('semantic-ui-react', () => ({ + __esModule: true, + ...mockSemanticComponents, + Popup: ({ content, trigger }) => { + return ( +
+
{trigger}
+
{content}
+
+ ); + }, +})); + +jest.doMock('@plone/volto/components', () => { + return { + __esModule: true, + ...mockComponents, + SidebarPortal: ({ children }) => , + }; +}); + +jest.doMock('@plone/volto/registry', () => + [installSlate].reduce((acc, apply) => apply(acc), config), +); + +const mockStore = configureStore([thunk]); + +global.fetch = jest.fn(() => + Promise.resolve({ + json: () => Promise.resolve({}), + }), +); + +global.store = mockStore({ + intl: { + locale: 'en', + messages: {}, + formatMessage: jest.fn(), + }, + content: { + create: {}, + subrequests: [], + }, + connected_data_parameters: {}, + screen: { + page: { + width: 768, + }, + }, +}); diff --git a/package.json b/package.json index 482d190..75e13d9 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@eeacms/volto-widget-temporal-coverage", - "version": "5.2.0", + "version": "6.0.0", "description": "volto-widget-temporal-coverage: Volto add-on", "main": "src/index.js", "author": "European Environment Agency: IDM2 A-Team", @@ -20,6 +20,7 @@ "@cypress/code-coverage": "^3.10.0", "@plone/scripts": "*", "babel-plugin-transform-class-properties": "^6.24.1", + "dotenv": "^16.3.2", "husky": "^8.0.3", "lint-staged": "^14.0.1", "md5": "^2.3.0" diff --git a/src/components/manage/Widgets/TemporalWidget.test.jsx b/src/components/manage/Widgets/TemporalWidget.test.jsx index 493b2dd..7f3a958 100644 --- a/src/components/manage/Widgets/TemporalWidget.test.jsx +++ b/src/components/manage/Widgets/TemporalWidget.test.jsx @@ -1,8 +1,10 @@ import React from 'react'; -import { render } from '@testing-library/react'; +import { render, screen } from '@testing-library/react'; import configureStore from 'redux-mock-store'; import { Provider } from 'react-intl-redux'; import thunk from 'redux-thunk'; +import '@testing-library/jest-dom/extend-expect'; + import TemporalWidget from './TemporalWidget'; const mockStore = configureStore([thunk]); @@ -16,7 +18,7 @@ describe('TemporalWidget', () => { }, }); const state = store.getState(); - const component = render( + render( { /> , ); - expect(component.container).toMatchSnapshot(); + expect(screen.getByText('Temporal coverage')).toBeInTheDocument(); + expect(screen.getByText('Select...')).toBeInTheDocument(); }); it('renders an temporal widget edit component when temporal is null', () => { @@ -38,7 +41,7 @@ describe('TemporalWidget', () => { temporal: null, }); const state = store.getState(); - const component = render( + render( { /> , ); - expect(component.container).toMatchSnapshot(); }); it('renders an temporal widget edit component when temporal is an empty list', () => { @@ -60,7 +62,7 @@ describe('TemporalWidget', () => { temporal: [], }); const state = store.getState(); - const component = render( + render( { /> , ); - expect(component.container).toMatchSnapshot(); }); it('renders an temporal widget edit component', () => { @@ -82,7 +83,7 @@ describe('TemporalWidget', () => { temporal: [{ value: '1900', label: '1900' }], }); const state = store.getState(); - const component = render( + render( { /> , ); - expect(component.container).toMatchSnapshot(); + expect(screen.getByText('1900')).toBeInTheDocument(); }); it('renders an temporal widget edit component with ranges', () => { @@ -107,7 +108,7 @@ describe('TemporalWidget', () => { ], }); const state = store.getState(); - const component = render( + render( { /> , ); - expect(component.container).toMatchSnapshot(); + expect(screen.getByText('1900-1901')).toBeInTheDocument(); }); it('renders an temporal widget edit component with ranges and single values', () => { @@ -134,7 +135,7 @@ describe('TemporalWidget', () => { ], }); const state = store.getState(); - const component = render( + render( { /> , ); - expect(component.container).toMatchSnapshot(); + expect(screen.getByText('1900-1901')).toBeInTheDocument(); + expect(screen.getByText('1905')).toBeInTheDocument(); + expect(screen.getByText('1907')).toBeInTheDocument(); }); it('renders an temporal widget edit component with ranges and single values', () => { @@ -161,7 +164,7 @@ describe('TemporalWidget', () => { ], }); const state = store.getState(); - const component = render( + render( { /> , ); - expect(component.container).toMatchSnapshot(); + expect(screen.getByText('1900-1901')).toBeInTheDocument(); + expect(screen.getByText('1905')).toBeInTheDocument(); + expect(screen.getByText('1907')).toBeInTheDocument(); }); it('renders an temporal widget edit component with multiple ranges and single values', () => { @@ -189,7 +194,7 @@ describe('TemporalWidget', () => { ], }); const state = store.getState(); - const component = render( + render( { /> , ); - expect(component.container).toMatchSnapshot(); + expect(screen.getByText('1900-1901')).toBeInTheDocument(); + expect(screen.getByText('1905')).toBeInTheDocument(); + expect(screen.getByText('1907-1908')).toBeInTheDocument(); }); it('renders an temporal widget edit component with joined temporal ranges from existing temporal ranges and new temporal ranges', () => { @@ -214,7 +221,7 @@ describe('TemporalWidget', () => { ], }); const state = store.getState(); - const component = render( + render( { /> , ); - expect(component.container).toMatchSnapshot(); + expect(screen.getByText('1898-1905')).toBeInTheDocument(); }); it('renders an temporal widget edit component with existing temporal ranges and single values', () => { @@ -240,7 +247,7 @@ describe('TemporalWidget', () => { ], }); const state = store.getState(); - const component = render( + render( { /> , ); - expect(component.container).toMatchSnapshot(); + expect(screen.getByText('1890')).toBeInTheDocument(); + expect(screen.getByText('1900-1905')).toBeInTheDocument(); + expect(screen.getByText('1915')).toBeInTheDocument(); }); it('renders an temporal widget edit component with existing temporal ranges ignoring value already present', () => { @@ -265,7 +274,7 @@ describe('TemporalWidget', () => { ], }); const state = store.getState(); - const component = render( + render( { /> , ); - expect(component.container).toMatchSnapshot(); + expect(screen.getByText('1900-1905')).toBeInTheDocument(); }); }); diff --git a/src/components/manage/Widgets/__snapshots__/TemporalWidget.test.jsx.snap b/src/components/manage/Widgets/__snapshots__/TemporalWidget.test.jsx.snap deleted file mode 100644 index 9af7d3f..0000000 --- a/src/components/manage/Widgets/__snapshots__/TemporalWidget.test.jsx.snap +++ /dev/null @@ -1,1733 +0,0 @@ -// Jest Snapshot v1, https://goo.gl/fbAQLP - -exports[`TemporalWidget renders an empty temporal widget edit component when temporal is missing 1`] = ` -
-
-
-
-
-
-
-
-
- -
-
-
-
- -
-
-
- Select... -
-
-
- -
-
-
-
-
- -
-
-
- -
-
-
-
-
-
-
-
-
-
-`; - -exports[`TemporalWidget renders an temporal widget edit component 1`] = ` -
-
-
-
-
-
-
-
-
- -
-
-
-
- -
-
-
-
- 1900 -
-
- -
-
-
-
- -
-
-
-
-
- - -
-
-
- -
-
-
-
-
-
-
-
-
-
-`; - -exports[`TemporalWidget renders an temporal widget edit component when temporal is an empty list 1`] = ` -
-
-
-
-
-
-
-
-
- -
-
-
-
- -
-
-
- Select... -
-
-
- -
-
-
-
-
- -
-
-
- -
-
-
-
-
-
-
-
-
-
-`; - -exports[`TemporalWidget renders an temporal widget edit component when temporal is null 1`] = ` -
-
-
-
-
-
-
-
-
- -
-
-
-
- -
-
-
- Select... -
-
-
- -
-
-
-
-
- -
-
-
- -
-
-
-
-
-
-
-
-
-
-`; - -exports[`TemporalWidget renders an temporal widget edit component with existing temporal ranges and single values 1`] = ` -
-
-
-
-
-
-
-
-
- -
-
-
-
- -
-
-
-
- 1890 -
-
- -
-
-
-
- 1900-1905 -
-
- -
-
-
-
- 1915 -
-
- -
-
-
-
- -
-
-
-
-
- - -
-
-
- - - -
-
-
-
-
-
-
-
-
-
-`; - -exports[`TemporalWidget renders an temporal widget edit component with existing temporal ranges ignoring value already present 1`] = ` -
-
-
-
-
-
-
-
-
- -
-
-
-
- -
-
-
-
- 1900-1905 -
-
- -
-
-
-
- -
-
-
-
-
- - -
-
-
- -
-
-
-
-
-
-
-
-
-
-`; - -exports[`TemporalWidget renders an temporal widget edit component with joined temporal ranges from existing temporal ranges and new temporal ranges 1`] = ` -
-
-
-
-
-
-
-
-
- -
-
-
-
- -
-
-
-
- 1898-1905 -
-
- -
-
-
-
- -
-
-
-
-
- - -
-
-
- -
-
-
-
-
-
-
-
-
-
-`; - -exports[`TemporalWidget renders an temporal widget edit component with multiple ranges and single values 1`] = ` -
-
-
-
-
-
-
-
-
- -
-
-
-
- -
-
-
-
- 1900-1901 -
-
- -
-
-
-
- 1905 -
-
- -
-
-
-
- 1907-1908 -
-
- -
-
-
-
- -
-
-
-
-
- - -
-
-
- - - -
-
-
-
-
-
-
-
-
-
-`; - -exports[`TemporalWidget renders an temporal widget edit component with ranges 1`] = ` -
-
-
-
-
-
-
-
-
- -
-
-
-
- -
-
-
-
- 1900-1901 -
-
- -
-
-
-
- -
-
-
-
-
- - -
-
-
- -
-
-
-
-
-
-
-
-
-
-`; - -exports[`TemporalWidget renders an temporal widget edit component with ranges and single values 1`] = ` -
-
-
-
-
-
-
-
-
- -
-
-
-
- -
-
-
-
- 1900-1901 -
-
- -
-
-
-
- 1905 -
-
- -
-
-
-
- 1907 -
-
- -
-
-
-
- -
-
-
-
-
- - -
-
-
- - - -
-
-
-
-
-
-
-
-
-
-`; - -exports[`TemporalWidget renders an temporal widget edit component with ranges and single values 2`] = ` -
-
-
-
-
-
-
-
-
- -
-
-
-
- -
-
-
-
- 1900-1901 -
-
- -
-
-
-
- 1905 -
-
- -
-
-
-
- 1907 -
-
- -
-
-
-
- -
-
-
-
-
- - -
-
-
- - - -
-
-
-
-
-
-
-
-
-
-`; diff --git a/src/components/theme/SearchBlock/TemporalCoverageFacet/TemporalCoverageFacet.test.jsx b/src/components/theme/SearchBlock/TemporalCoverageFacet/TemporalCoverageFacet.test.jsx index 42cc6c1..00e0f65 100644 --- a/src/components/theme/SearchBlock/TemporalCoverageFacet/TemporalCoverageFacet.test.jsx +++ b/src/components/theme/SearchBlock/TemporalCoverageFacet/TemporalCoverageFacet.test.jsx @@ -1,12 +1,15 @@ import React from 'react'; -import { render } from '@testing-library/react'; +import { render, screen } from '@testing-library/react'; import configureStore from 'redux-mock-store'; import { Provider } from 'react-intl-redux'; import thunk from 'redux-thunk'; +import '@testing-library/jest-dom/extend-expect'; + import TemporalCoverageFacetFilterListEntry from './TemporalCoverageFacetFilterListEntry'; import { Tick } from './SliderComponents'; import { Ticks } from 'react-compound-slider'; import TemporalCoverageFacet from './TemporalCoverageFacet'; + const mockStore = configureStore([thunk]); it('renders TemporalCoverageFacet', () => { @@ -22,7 +25,7 @@ it('renders TemporalCoverageFacet', () => { ], }); - const component = render( + const { container } = render( { /> , ); - expect(component.container).toMatchSnapshot(); + expect( + container.querySelector('.temporal-facet .ui.form.years-input .ui.input'), + ).toBeInTheDocument(); + expect( + container.querySelector( + '.temporal-facet .ui.form.years-input .ui.input.right', + ), + ).toBeInTheDocument(); + + expect( + container.querySelector('input[max="1915"][min="1890"]'), + ).toBeInTheDocument(); + expect( + container.querySelector('.ui.input input[max="1915"][min="1890"]'), + ).toHaveValue(1890); + expect( + container.querySelector('.ui.input.right input[max="1915"][min="1890"]'), + ).toHaveValue(1915); + + expect(container.querySelector('.slider-handles')).toBeInTheDocument(); + expect( + container.querySelector( + '.slider-handles div[aria-valuemax="1915"][aria-valuemin="1890"][aria-valuenow="1890"][role="slider"]', + ), + ).toBeInTheDocument(); + expect( + container.querySelector( + '.slider-handles div[aria-valuemax="1915"][aria-valuemin="1890"][aria-valuenow="1915"][role="slider"]', + ), + ).toBeInTheDocument(); + + expect(container.querySelector('.slider-ticks')).toBeInTheDocument(); + expect(screen.getByText(1890)).toHaveStyle('left: 0%'); + expect(screen.getByText(1895)).toHaveStyle('left: 20%'); + expect(screen.getByText(1900)).toHaveStyle('left: 40%'); + expect(screen.getByText(1905)).toHaveStyle('left: 60%'); + expect(screen.getByText(1910)).toHaveStyle('left: 80%'); + expect(screen.getByText(1915)).toHaveStyle('left: 100%'); }); + it('renders TemporalCoverageFacetFilterListEntry', () => { const store = mockStore({ intl: { @@ -48,7 +89,7 @@ it('renders TemporalCoverageFacetFilterListEntry', () => { ], }); - const component = render( + const { container } = render( { /> , ); - expect(component.container).toMatchSnapshot(); + expect(container.querySelector('.ui.small.label > i')).toBeInTheDocument(); + expect(screen.getByText('Yes')).toBeInTheDocument(); }); it('test valueToQuery facet function', () => { @@ -78,7 +120,7 @@ it('test valueToQuery facet function', () => { }); it('renders Slider Ticks', () => { - const component = render( + const { container } = render( {({ ticks }) => (
@@ -89,5 +131,12 @@ it('renders Slider Ticks', () => { )} , ); - expect(component.container).toMatchSnapshot(); + + expect(container.querySelector('.slider-ticks')).toBeInTheDocument(); + expect(screen.getByText(0)).toHaveStyle('left: 0%'); + expect(screen.getByText(0.2)).toHaveStyle('left: 0.2%'); + expect(screen.getByText(0.4)).toHaveStyle('left: 0.4%'); + expect(screen.getByText(0.6)).toHaveStyle('left: 0.6%'); + expect(screen.getByText(0.8)).toHaveStyle('left: 0.8%'); + expect(screen.getByText(1)).toHaveStyle('left: 1%'); }); diff --git a/src/components/theme/SearchBlock/TemporalCoverageFacet/__snapshots__/TemporalCoverageFacet.test.jsx.snap b/src/components/theme/SearchBlock/TemporalCoverageFacet/__snapshots__/TemporalCoverageFacet.test.jsx.snap deleted file mode 100644 index 3696466..0000000 --- a/src/components/theme/SearchBlock/TemporalCoverageFacet/__snapshots__/TemporalCoverageFacet.test.jsx.snap +++ /dev/null @@ -1,225 +0,0 @@ -// Jest Snapshot v1, https://goo.gl/fbAQLP - -exports[`renders Slider Ticks 1`] = ` -
-
-
-
-
- 0 -
-
-
-
-
- 0.2 -
-
-
-
-
- 0.4 -
-
-
-
-
- 0.6 -
-
-
-
-
- 0.8 -
-
-
-
-
- 1 -
-
-
-
-`; - -exports[`renders TemporalCoverageFacet 1`] = ` -
-
-

-
-
- -
-
- -
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- 1890 -
-
-
-
-
- 1895 -
-
-
-
-
- 1900 -
-
-
-
-
- 1905 -
-
-
-
-
- 1910 -
-
-
-
-
- 1915 -
-
-
-
-
-
-`; - -exports[`renders TemporalCoverageFacetFilterListEntry 1`] = ` -
-
- Yes -