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 691a45b..0000000 --- a/.project.eslintrc.js +++ /dev/null @@ -1,47 +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 f3026fc..e5d7406 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,17 +4,26 @@ 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). +### [11.0.0](https://github.com/eea/volto-accordion-block/compare/10.4.6...11.0.0) - 22 April 2024 + +#### :rocket: New Features + +- feat: Volto 17 support - refs #264527 [EEA Jenkins - [`ce3484b`](https://github.com/eea/volto-accordion-block/commit/ce3484bf1c0d88003eec966ccb61bc111285b271)] + +#### :house: Internal changes + +- chore: package.json [Alin Voinea - [`76ce14b`](https://github.com/eea/volto-accordion-block/commit/76ce14bca36587e3319730b963650d0f753e3e1e)] + +#### :hammer_and_wrench: Others + +- Release 11.0.0: Volto 17 support [alin - [`9061ae4`](https://github.com/eea/volto-accordion-block/commit/9061ae4030a2d21090a0cc722fc9fbf4b29b57e6)] +- test: Update jest,Jenkinsfile,lint to volto-addons-template PR30 [valentinab25 - [`5f1c692`](https://github.com/eea/volto-accordion-block/commit/5f1c69269a0c42b0eab2359bf43d2edfb7d1a4d8)] +- test: Update jest,Jenkinsfile,lint to volto-addons-template PR30 [valentinab25 - [`026d927`](https://github.com/eea/volto-accordion-block/commit/026d9274274f516e6504921a5f55920a5569276a)] +- test: Update jest,Jenkinsfile,lint to volto-addons-template PR30 [valentinab25 - [`6c2690c`](https://github.com/eea/volto-accordion-block/commit/6c2690c3207ad801fff0587d3178f6144f28a017)] ### [10.4.6](https://github.com/eea/volto-accordion-block/compare/10.4.5...10.4.6) - 18 January 2024 #### :hammer_and_wrench: Others -- test: [JENKINS] fix jest config, fail with logs on coverage [valentinab25 - [`12f799a`](https://github.com/eea/volto-accordion-block/commit/12f799a09c3dd56a3ba0e779d9e767fe53db6de9)] -- test: [JENKINS] fix jest config, fail with logs on coverage [valentinab25 - [`937a4e1`](https://github.com/eea/volto-accordion-block/commit/937a4e1035237a655e94839b08dc4eb6a4061e79)] -- test: [JENKINS] fix jest config, fail with logs on coverage [valentinab25 - [`fc0f16a`](https://github.com/eea/volto-accordion-block/commit/fc0f16a474aaeeb13edfbad374f564433ef92a53)] -- test: [JENKINS] fix jest config, fail with logs on coverage [valentinab25 - [`8240697`](https://github.com/eea/volto-accordion-block/commit/82406970359c5fb3b21b18dd013db46626bb2944)] -- test: [JENKINS] fix jest config, fail with logs on coverage [valentinab25 - [`1f88bab`](https://github.com/eea/volto-accordion-block/commit/1f88babd0ea2545731fa013833d66b08d1449fbb)] -- test: [JENKINS] fix jest config, fail with logs on coverage [valentinab25 - [`e4312b7`](https://github.com/eea/volto-accordion-block/commit/e4312b7a23caf8285f3c28b50c12603dcca39c6e)] -- test: [JENKINS] fix jest config, fail with logs on coverage [valentinab25 - [`afb8392`](https://github.com/eea/volto-accordion-block/commit/afb839211575a167905238f91aa24089da3f1a20)] ### [10.4.5](https://github.com/eea/volto-accordion-block/compare/10.4.4...10.4.5) - 10 December 2023 ### [10.4.4](https://github.com/eea/volto-accordion-block/compare/10.4.3...10.4.4) - 24 November 2023 @@ -25,15 +34,9 @@ Generated by [`auto-changelog`](https://github.com/CookPete/auto-changelog). #### :house: Internal changes -- chore: [JENKINS] Refactor automated testing [valentinab25 - [`cfdf1cd`](https://github.com/eea/volto-accordion-block/commit/cfdf1cd3f34f4e92b14c0ef83c629066f7ae96e7)] #### :hammer_and_wrench: Others -- test: [JENKINS] Use java17 for sonarqube scanner [valentinab25 - [`0766840`](https://github.com/eea/volto-accordion-block/commit/07668401fffb6d6cb12a71c828c9f1e2ccbf760b)] -- test: [JENKINS] Run cypress in started frontend container [valentinab25 - [`d96919b`](https://github.com/eea/volto-accordion-block/commit/d96919b3f278832d6ba199786342a7eca0fddab1)] -- test: [JENKINS] Add cpu limit on cypress docker [valentinab25 - [`4243468`](https://github.com/eea/volto-accordion-block/commit/4243468110ee1a7a28814386001fad3097b18f11)] -- test: [JENKINS] Increase shm-size to cypress docker [valentinab25 - [`41fe792`](https://github.com/eea/volto-accordion-block/commit/41fe792ece0931c3e1561611f9def7df543014c9)] -- test: [JENKINS] Improve cypress time [valentinab25 - [`c8dc782`](https://github.com/eea/volto-accordion-block/commit/c8dc78243f5529604031b5c8bb806c6b1c4bbdcc)] ### [10.4.3](https://github.com/eea/volto-accordion-block/compare/10.4.2...10.4.3) - 17 October 2023 #### :house: Internal changes @@ -232,8 +235,6 @@ Generated by [`auto-changelog`](https://github.com/CookPete/auto-changelog). #### :house: Internal changes -- chore: [JENKINS] Remove alpha testing version [valentinab25 - [`83cfef7`](https://github.com/eea/volto-accordion-block/commit/83cfef72305789fe95c4d463956d446e934e37bd)] -- chore: [JENKINS] Deprecate circularity website [valentinab25 - [`e8d2ff3`](https://github.com/eea/volto-accordion-block/commit/e8d2ff341ff2db8baec52b9e839e2ace6eee7c1a)] #### :hammer_and_wrench: Others @@ -241,7 +242,6 @@ Generated by [`auto-changelog`](https://github.com/CookPete/auto-changelog). - test: jest should look for addons in node_modules Refs #253277 [valentinab25 - [`d077684`](https://github.com/eea/volto-accordion-block/commit/d07768431760471c1d33352e097874dee37edd41)] - test: Add unit tests for util - refs #253277 [ana-oprea - [`9385394`](https://github.com/eea/volto-accordion-block/commit/9385394cf834dd944d98ab9fdc10e65abdad636d)] - test: Fix test config, coverage Refs #253277 [valentinab25 - [`67a0667`](https://github.com/eea/volto-accordion-block/commit/67a0667ee563e8ee01c5e660cd2b127eaa1da4fc)] -- Add Sonarqube tag using eea-website-frontend addons list [EEA Jenkins - [`9c06bd0`](https://github.com/eea/volto-accordion-block/commit/9c06bd0f3d262bb553541ec884c659d31fea70d5)] ## [8.0.0](https://github.com/eea/volto-accordion-block/compare/7.1.0...8.0.0) - 24 March 2023 #### :rocket: New Features @@ -254,7 +254,6 @@ Generated by [`auto-changelog`](https://github.com/CookPete/auto-changelog). - test(cypress): Use latest stable Volto for tests [Alin Voinea - [`161325b`](https://github.com/eea/volto-accordion-block/commit/161325bfb990e1ef8bd66a7c26aacf17b5e3989c)] - Release 7.1.0 [Alin Voinea - [`207318f`](https://github.com/eea/volto-accordion-block/commit/207318f45321d9caf2e9e88a36786d6a6dfbfce6)] -- Add Sonarqube tag using eea-website-frontend addons list [EEA Jenkins - [`a1279b2`](https://github.com/eea/volto-accordion-block/commit/a1279b20f134b8da44ca45e1e3eecf50401372f8)] ## [7.0.0](https://github.com/eea/volto-accordion-block/compare/6.0.0...7.0.0) - 7 February 2023 #### :nail_care: Enhancements @@ -266,12 +265,7 @@ Generated by [`auto-changelog`](https://github.com/CookPete/auto-changelog). - Release 7.0.0 [Alin Voinea - [`661c6fd`](https://github.com/eea/volto-accordion-block/commit/661c6fd04aa704ba09172737f9e00e7de8b17673)] - theme-picker version [Andrei Grigore - [`2d7d7fb`](https://github.com/eea/volto-accordion-block/commit/2d7d7fb64b6f51fb02410140ae4b69eda26dea06)] - Add theme picker widget [dana-cfc4 - [`b567515`](https://github.com/eea/volto-accordion-block/commit/b5675150e1b5a811e1686404cbefcd9e6b92d515)] -- Add Sonarqube tag using advisory-board-frontend addons list [EEA Jenkins - [`dd14109`](https://github.com/eea/volto-accordion-block/commit/dd14109b3df7aee49ab1fdb57b8ac749193723c7)] -- Add Sonarqube tag using advisory-board-frontend addons list [EEA Jenkins - [`6169240`](https://github.com/eea/volto-accordion-block/commit/6169240953e8b81fbf1200bfa7b77c1be3be318f)] - test(Jenkins): Run tests and cypress with latest canary @plone/volto [Alin Voinea - [`bbf12a0`](https://github.com/eea/volto-accordion-block/commit/bbf12a07558ea1f2c9d6e62fa4bf897d1c27ad71)] -- Add Sonarqube tag using cca-frontend addons list [EEA Jenkins - [`cb18b3c`](https://github.com/eea/volto-accordion-block/commit/cb18b3c7d12318a671e6031054cb6cb98c5e4766)] -- yarn 3 [Alin Voinea - [`26994da`](https://github.com/eea/volto-accordion-block/commit/26994dab66bce3873911fee6fb46fc51dfce44d7)] -- Add Sonarqube tag using demo-kitkat-frontend addons list [EEA Jenkins - [`5803993`](https://github.com/eea/volto-accordion-block/commit/5803993b263352f7d3a5e4c14f5ac5b1607a1dc2)] ## [6.0.0](https://github.com/eea/volto-accordion-block/compare/5.0.0...6.0.0) - 16 November 2022 #### :nail_care: Enhancements @@ -301,7 +295,6 @@ Generated by [`auto-changelog`](https://github.com/CookPete/auto-changelog). #### :hammer_and_wrench: Others -- Add Sonarqube tag using marine-frontend addons list [EEA Jenkins - [`3c0236e`](https://github.com/eea/volto-accordion-block/commit/3c0236ef0e055bbbac852b66139767cee8631aad)] - test(cypress): Add missing md5 dependency [Alin Voinea - [`1afae5d`](https://github.com/eea/volto-accordion-block/commit/1afae5d677de53778d5727334f9a6add8120d046)] ## [4.0.0](https://github.com/eea/volto-accordion-block/compare/3.5.0...4.0.0) - 27 September 2022 @@ -319,14 +312,12 @@ Generated by [`auto-changelog`](https://github.com/CookPete/auto-changelog). - Release 3.6.0 [Alin Voinea - [`2c84012`](https://github.com/eea/volto-accordion-block/commit/2c840125496e23e1f1587e9e1ba2713ef538491e)] - test(prettier): Fix stylelint [Alin Voinea - [`e3fd717`](https://github.com/eea/volto-accordion-block/commit/e3fd717b60d67a09b500282837470707f57747a1)] - Use volto@16.0.0-alpha.14 in cypress tests [Miu Razvan - [`f4dd7a1`](https://github.com/eea/volto-accordion-block/commit/f4dd7a1221ef2437b813d45b232efbf8c04bb8c5)] -- Add Sonarqube tag using eea-website-frontend addons list [EEA Jenkins - [`20652bc`](https://github.com/eea/volto-accordion-block/commit/20652bcea7bd1f4f7271cf0b2fe8223401401a4f)] - update(jest): add @plone/volto-slate resolver refs- #153447 [nileshgulia1 - [`7a1af55`](https://github.com/eea/volto-accordion-block/commit/7a1af55061b0c75ecb77fdbae9e2e6586df3b50c)] ### [3.5.0](https://github.com/eea/volto-accordion-block/compare/3.4.16...3.5.0) - 30 June 2022 #### :hammer_and_wrench: Others - Release 3.5.0 [Alin Voinea - [`c237343`](https://github.com/eea/volto-accordion-block/commit/c237343daa82eb0fb0ddb49e04ee6c49578b8fd2)] -- Add Sonarqube tag using circularity-frontend addons list [EEA Jenkins - [`5de2964`](https://github.com/eea/volto-accordion-block/commit/5de296427472925998273bf9c164ba5b65895a14)] ### [3.4.16](https://github.com/eea/volto-accordion-block/compare/3.4.15...3.4.16) - 17 May 2022 #### :hammer_and_wrench: Others @@ -336,8 +327,6 @@ Generated by [`auto-changelog`](https://github.com/CookPete/auto-changelog). #### :hammer_and_wrench: Others -- Add Sonarqube tag using clms-frontend addons list [EEA Jenkins - [`66fada5`](https://github.com/eea/volto-accordion-block/commit/66fada5a7084e1adb36ef5ff950d498391729eab)] -- Add Sonarqube tag using eea-website-frontend addons list [EEA Jenkins - [`9d96b9d`](https://github.com/eea/volto-accordion-block/commit/9d96b9d392004dd8791c061c5fa39deee253c16a)] ### [3.4.14](https://github.com/eea/volto-accordion-block/compare/3.4.13...3.4.14) - 3 March 2022 #### :rocket: New Features @@ -361,7 +350,6 @@ Generated by [`auto-changelog`](https://github.com/CookPete/auto-changelog). #### :hammer_and_wrench: Others -- Add Sonarqube tag using freshwater-frontend addons list [EEA Jenkins - [`197c242`](https://github.com/eea/volto-accordion-block/commit/197c2426f18e3b74296c18ef86781e63596bcd4b)] ### [3.4.10](https://github.com/eea/volto-accordion-block/compare/3.4.9...3.4.10) - 10 December 2021 #### :hammer_and_wrench: Others @@ -380,14 +368,11 @@ Generated by [`auto-changelog`](https://github.com/CookPete/auto-changelog). #### :hammer_and_wrench: Others - cy: make tests run with both slate and draftjs [nileshgulia1 - [`e51f7a5`](https://github.com/eea/volto-accordion-block/commit/e51f7a5c36804240d90e19baa9c7b321e41a7c23)] -- Add Sonarqube tag using industry-frontend addons list [EEA Jenkins - [`9f515c3`](https://github.com/eea/volto-accordion-block/commit/9f515c3e1055b07ea5ea7ac8dbf72eb2e4b79c74)] ### [3.4.7](https://github.com/eea/volto-accordion-block/compare/3.4.6...3.4.7) - 25 October 2021 #### :hammer_and_wrench: Others - Refs #34 ensure floated images from content area don't spill over next accordion title [David Ichim - [`79abc8c`](https://github.com/eea/volto-accordion-block/commit/79abc8c1b13eb26fb78b9dbe53fc2711c02a1ed1)] -- Add Sonarqube tag using clms-frontend addons list [EEA Jenkins - [`f5c2cf9`](https://github.com/eea/volto-accordion-block/commit/f5c2cf969763a5400e4d9fb66bafad761cd17f2f)] -- Add Sonarqube tag using bise-frontend addons list [EEA Jenkins - [`92cd189`](https://github.com/eea/volto-accordion-block/commit/92cd1891291a33e92c1f4488ff2afb90642d2706)] ### [3.4.6](https://github.com/eea/volto-accordion-block/compare/3.4.5...3.4.6) - 6 October 2021 #### :house: Internal changes @@ -396,7 +381,6 @@ Generated by [`auto-changelog`](https://github.com/CookPete/auto-changelog). #### :hammer_and_wrench: Others -- Add Sonarqube tag using sustainability-frontend addons list [EEA Jenkins - [`c0bc59d`](https://github.com/eea/volto-accordion-block/commit/c0bc59d897ece309834ffef8ddea516aceef1e5f)] ### [3.4.5](https://github.com/eea/volto-accordion-block/compare/3.4.4...3.4.5) - 29 September 2021 #### :hammer_and_wrench: Others @@ -408,7 +392,6 @@ Generated by [`auto-changelog`](https://github.com/CookPete/auto-changelog). #### :hammer_and_wrench: Others -- Add Sonarqube tag using climate-energy-frontend addons list [EEA Jenkins - [`046f3aa`](https://github.com/eea/volto-accordion-block/commit/046f3aae09e1725d44bcdc371d07ed32e8309423)] ### [3.4.3](https://github.com/eea/volto-accordion-block/compare/3.4.2...3.4.3) - 17 September 2021 ### [3.4.2](https://github.com/eea/volto-accordion-block/compare/3.4.1...3.4.2) - 16 September 2021 @@ -418,7 +401,6 @@ Generated by [`auto-changelog`](https://github.com/CookPete/auto-changelog). #### :hammer_and_wrench: Others - Add missing onChangeField to make it work with Metadata section block - refs #137434 [Alin Voinea - [`5253b74`](https://github.com/eea/volto-accordion-block/commit/5253b74a52043a3ad7e2e813abaf2d27f0e83a7a)] -- Add Sonarqube tag using ims-frontend addons list [EEA Jenkins - [`1e4d3dc`](https://github.com/eea/volto-accordion-block/commit/1e4d3dc937bc63825bd1fc6156eca9b6d073a40b)] ### [3.4.0](https://github.com/eea/volto-accordion-block/compare/3.3.1...3.4.0) - 7 September 2021 #### :hammer_and_wrench: Others @@ -431,7 +413,6 @@ Generated by [`auto-changelog`](https://github.com/CookPete/auto-changelog). #### :hammer_and_wrench: Others - Release 3.3.0 [Alin Voinea - [`2cbb1d5`](https://github.com/eea/volto-accordion-block/commit/2cbb1d53ce62b9cb42751c4c4997577ba4165649)] -- Add Sonarqube tag using forests-frontend addons list [EEA Jenkins - [`ab257ac`](https://github.com/eea/volto-accordion-block/commit/ab257acb0c2c8e38b906fcce8f6e148e4690d473)] ### [3.2.4](https://github.com/eea/volto-accordion-block/compare/3.2.3...3.2.4) - 21 July 2021 ### [3.2.3](https://github.com/eea/volto-accordion-block/compare/3.2.2...3.2.3) - 27 May 2021 @@ -558,7 +539,6 @@ Generated by [`auto-changelog`](https://github.com/CookPete/auto-changelog). - remove unused vars [nileshgulia1 - [`5e2c1e9`](https://github.com/eea/volto-accordion-block/commit/5e2c1e990f5ccf9b81f123ff18cacc7769ac696c)] - accordion title, via Input (semantic ui) [nileshgulia1 - [`0b2aef7`](https://github.com/eea/volto-accordion-block/commit/0b2aef76dd828ef2e0fc5061023a259d6279c11c)] - add accordion title as a slate editor [nileshgulia1 - [`38e841d`](https://github.com/eea/volto-accordion-block/commit/38e841d9a1a2d1d6a9d657ed6d611220615cbd40)] -- yarn prettier [Alin Voinea - [`afc2d37`](https://github.com/eea/volto-accordion-block/commit/afc2d379490cc4bdd4e2c2296229fac5d549d6a1)] - make title editable [nileshgulia1 - [`e3233b0`](https://github.com/eea/volto-accordion-block/commit/e3233b00f3e0e1b0ef240a035d4aca7384a23b3c)] ### 0.1.0 - 9 November 2020 diff --git a/Jenkinsfile b/Jenkinsfile index e9ecf2b..d2e3c1c 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -9,11 +9,12 @@ pipeline { environment { GIT_NAME = "volto-accordion-block" NAMESPACE = "@eeacms" - SONARQUBE_TAGS = "volto.eea.europa.eu,forest.eea.europa.eu,www.eea.europa.eu-ims,climate-energy.eea.europa.eu,sustainability.eionet.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,forest.eea.europa.eu,www.eea.europa.eu-ims,climate-energy.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,9 +158,10 @@ pipeline { } } } - } + } - stage('Integration tests') { + stage('Integration tests') { + when { environment name: 'SKIP_TESTS', value: '' } steps { script { try { @@ -211,16 +215,7 @@ pipeline { } } } - } } - } - } - post { - always { - sh script: "docker rmi $IMAGE_NAME-frontend", returnStatus: true - } - } - } stage('Report to SonarQube') { when { @@ -228,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' @@ -255,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\\.]+$' } @@ -323,3 +413,4 @@ pipeline { } } } + diff --git a/Makefile b/Makefile index c583f3f..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 @@ -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 diff --git a/cypress/e2e/01-blocks-accordion.cy.js b/cypress/e2e/01-blocks-accordion.cy.js index a12b127..c52c0bf 100644 --- a/cypress/e2e/01-blocks-accordion.cy.js +++ b/cypress/e2e/01-blocks-accordion.cy.js @@ -122,6 +122,7 @@ describe('Blocks Tests', () => { cy.get('.accordion:nth-child(2) > .title > .icon').click(); cy.get('div.content') .should('have.class', 'active') + .last() .within(() => { cy.get('p').contains('children'); }); diff --git a/cypress/e2e/02-dexterity-controlpanel-layout.cy.js b/cypress/e2e/02-dexterity-controlpanel-layout.cy.js index 740d839..826af4b 100644 --- a/cypress/e2e/02-dexterity-controlpanel-layout.cy.js +++ b/cypress/e2e/02-dexterity-controlpanel-layout.cy.js @@ -6,11 +6,6 @@ describe('ControlPanel: Dexterity Content-Types Layout', () => { it('Edit Blocks Layout for Book', () => { cy.visit('/controlpanel/dexterity-types'); - cy.waitForResourceToLoad('@navigation'); - cy.waitForResourceToLoad('@breadcrumbs'); - cy.waitForResourceToLoad('@actions'); - cy.waitForResourceToLoad('@types'); - cy.get('a[href="/controlpanel/dexterity-types/book"]').should( 'have.text', 'book', @@ -81,11 +76,6 @@ describe('ControlPanel: Dexterity Content-Types Layout', () => { cy.get('#toolbar-save').click(); cy.visit('/cypress'); - cy.waitForResourceToLoad('@navigation'); - cy.waitForResourceToLoad('@breadcrumbs'); - cy.waitForResourceToLoad('@actions'); - cy.waitForResourceToLoad('@types'); - cy.get('button[class="add"]').click(); cy.get('#toolbar-add-book').click(); cy.get('.block.title').contains('Book title'); diff --git a/cypress/support/e2e.js b/cypress/support/e2e.js index 90fe032..715cf7a 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 736fba7..8cccbd2 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: [ @@ -12,6 +14,8 @@ module.exports = { '@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$': '/node_modules/@plone/volto/packages/volto-slate/src', @@ -26,6 +30,7 @@ module.exports = { ], transform: { '^.+\\.js(x)?$': 'babel-jest', + '^.+\\.ts(x)?$': 'babel-jest', '^.+\\.(png)$': 'jest-file', '^.+\\.(jpg)$': 'jest-file', '^.+\\.(svg)$': './node_modules/@plone/volto/jest-svgsystem-transform.js', @@ -38,7 +43,9 @@ module.exports = { statements: 5, }, }, - setupFilesAfterEnv: [ - '/node_modules/@eeacms/volto-accordion-block/jest.setup.js', - ], -}; + ...(process.env.JEST_USE_SETUP === 'ON' && { + setupFilesAfterEnv: [ + '/node_modules/@eeacms/volto-accordion-block/jest.setup.js', + ], + }), +} diff --git a/package.json b/package.json index ff3fc91..188bd9f 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@eeacms/volto-accordion-block", - "version": "10.4.6", + "version": "11.0.0", "description": "volto-accordion-block: Volto accordion block", "main": "src/index.js", "author": "European Environment Agency: IDM2 A-Team", @@ -24,6 +24,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/Blocks/Accordion/AccordionEdit.test.jsx b/src/components/manage/Blocks/Accordion/AccordionEdit.test.jsx index ec8856d..8949ca7 100644 --- a/src/components/manage/Blocks/Accordion/AccordionEdit.test.jsx +++ b/src/components/manage/Blocks/Accordion/AccordionEdit.test.jsx @@ -1,7 +1,6 @@ -import { render, fireEvent } from '@testing-library/react'; +import { render, fireEvent, screen, waitFor } from '@testing-library/react'; import React from 'react'; import AccordionEdit from './AccordionEdit'; -import renderer from 'react-test-renderer'; import config from '@plone/volto/registry'; import { Provider } from 'react-intl-redux'; import configureStore from 'redux-mock-store'; @@ -61,23 +60,6 @@ describe('AccordionEdit', () => { }; const index = 0; - it('should render correctly', () => { - const component = renderer.create( - - - , - ); - const json = component.toJSON(); - expect(json).toMatchSnapshot(); - }); - it('should render correctly', () => { const { getByText } = render( @@ -184,4 +166,76 @@ describe('AccordionEdit', () => { const contentElement = getByText('Accordion Content'); expect(contentElement).toBeInTheDocument(); }); + + it('should toggle the accordion content when the title is clicked', async () => { + const { container } = render( + + +
Accordion Content
+
+
, + ); + + const accordionTitle = container.querySelector('.accordion-title'); + const accordionContent = container.querySelector('.content'); + + fireEvent.click(accordionTitle); + + await waitFor(() => { + expect(accordionContent).not.toBeVisible(); + }); + + fireEvent.click(accordionTitle); + + await waitFor(() => { + expect(accordionContent).toBeVisible(); + }); + }); + + it('should render the title as read-only when readOnlyTitles is true', () => { + render( + + + , + ); + + const titleSpan = screen.getByText('Panel Title'); + expect(titleSpan.tagName).toBe('SPAN'); + expect(screen.queryByDisplayValue('Panel Title')).not.toBeInTheDocument(); + }); + + it('should apply the correct alignment class based on right_arrows prop', () => { + const { container, rerender } = render( + + + , + ); + + let accordionTitle = container.querySelector('.accordion-title'); + expect(accordionTitle).toHaveClass('align-arrow-left'); + + rerender( + + + , + ); + + accordionTitle = container.querySelector('.accordion-title'); + expect(accordionTitle).toHaveClass('align-arrow-right'); + }); }); diff --git a/src/components/manage/Blocks/Accordion/Edit.test.jsx b/src/components/manage/Blocks/Accordion/Edit.test.jsx index b2c361e..192b5e5 100644 --- a/src/components/manage/Blocks/Accordion/Edit.test.jsx +++ b/src/components/manage/Blocks/Accordion/Edit.test.jsx @@ -1,5 +1,5 @@ import React from 'react'; -import renderer from 'react-test-renderer'; +import { render, fireEvent, screen } from '@testing-library/react'; import { Provider } from 'react-intl-redux'; import configureStore from 'redux-mock-store'; import { MemoryRouter } from 'react-router-dom'; @@ -8,9 +8,44 @@ import Edit from './Edit'; import config from '@plone/volto/registry'; jest.mock('@plone/volto/components', () => ({ - BlocksForm: jest.fn(() =>
RenderBlocks
), + BlocksForm: jest.fn( + ({ children, onSelectBlock, onChangeFormData, properties }) => { + const blockList = properties.blocks + ? Object.entries(properties.blocks) + : []; + return ( +
+ {blockList.map(([blockId, blockData], index) => ( +
+ {children( + { + child: blockData, + childId: blockId, + index, + }, +
EditBlock
, + { + allowedBlocks: [], + block: blockId, + data: blockData, + id: blockId, + index, + onChangeBlock: jest.fn(), + onSelectBlock, + onChangeFormData, + properties, + selected: false, + type: blockData['@type'], + }, + )} +
+ ))} +
+ ); + }, + ), Icon: () =>
Icon
, - SidebarPortal: () =>
SidebarPortal
, + SidebarPortal: ({ children }) =>
{children}
, BlocksToolbar: () =>
BlocksToolbar
, BlockDataForm: () =>
BlockDataForm
, })); @@ -18,6 +53,7 @@ jest.mock('@plone/volto/components', () => ({ jest.mock('@plone/volto/helpers', () => ({ withBlockExtensions: jest.fn((Component) => Component), emptyBlocksForm: jest.fn(), + getBlocksLayoutFieldname: () => 'blocks_layout', })); config.blocks.blocksConfig.accordion = { @@ -33,6 +69,14 @@ config.blocks.blocksConfig.accordion = { }, size: 'tiny', iconComponent: 'SemanticIcon', + unfiltered: { + rightPosition: 'chevron left', + leftPosition: 'chevron right', + }, + filtered: { + rightPosition: 'chevron down', + leftPosition: 'chevron down', + }, }, }; @@ -46,18 +90,112 @@ const store = mockStore({ const mockData = { title: 'Accordion', + data: { + blocks: { + 1: { + '@type': 'accordionPanel', + title: 'Panel 1', + blocks_layout: { + items: ['block1', 'block2'], + }, + }, + 2: { + '@type': 'accordionPanel', + title: 'Panel 2', + blocks_layout: { + items: ['block3', 'block4'], + }, + }, + }, + blocks_layout: { + items: ['1', '2'], + }, + }, }; describe('Edit Component', () => { - it('renders without crashing', () => { - const component = renderer.create( + it('renders the accordion title correctly', () => { + const onChangeBlock = jest.fn(); + render( + + + + + , + ); + + expect(screen.getByText('Accordion')).toBeInTheDocument(); + }); + + it('renders the accordion panels correctly', () => { + const onChangeBlock = jest.fn(); + render( + + + + + , + ); + expect(screen.getByDisplayValue('Panel 1')).toBeInTheDocument(); + expect(screen.getByDisplayValue('Panel 2')).toBeInTheDocument(); + }); + + it('calls onChangeBlock when the title changes', () => { + const onChangeBlock = jest.fn(); + render( + + + + + , + ); + const titleInput = screen.getByDisplayValue('Panel 1'); + fireEvent.change(titleInput, { target: { value: 'New Panel Title' } }); + expect(onChangeBlock).toHaveBeenCalled(); + }); + + it('filters the accordion panels based on the filter value', () => { + const onChangeBlock = jest.fn(); + render( + + + + + , + ); + const filterInput = screen.getByPlaceholderText('Type to filter...'); + fireEvent.change(filterInput, { target: { value: 'Panel 1' } }); + + expect(screen.getByPlaceholderText('Enter Title')).toHaveDisplayValue( + 'Panel 1', + ); + expect(screen.queryByDisplayValue('Panel 2')).not.toBeInTheDocument(); + }); + + it('renders the block toolbar when a block is selected', () => { + const onChangeBlock = jest.fn(); + render( + + + + + , + ); + expect(screen.getByText('BlocksToolbar')).toBeInTheDocument(); + }); + + it('renders the block data form in the sidebar portal', () => { + const onChangeBlock = jest.fn(); + render( - + , ); - const json = component.toJSON(); - expect(json).toMatchSnapshot(); + expect(screen.getByText('BlockDataForm')).toBeInTheDocument(); }); }); diff --git a/src/components/manage/Blocks/Accordion/EditBlockWrapper.jsx b/src/components/manage/Blocks/Accordion/EditBlockWrapper.jsx index 8c31fd1..46603e6 100644 --- a/src/components/manage/Blocks/Accordion/EditBlockWrapper.jsx +++ b/src/components/manage/Blocks/Accordion/EditBlockWrapper.jsx @@ -36,14 +36,8 @@ const messages = defineMessages({ class EditBlockWrapper extends React.Component { render() { - const { - intl, - blockProps, - draginfo, - extraControls, - disabled, - children, - } = this.props; + const { intl, blockProps, draginfo, extraControls, disabled, children } = + this.props; const { block, diff --git a/src/components/manage/Blocks/Accordion/LayoutSchema.js b/src/components/manage/Blocks/Accordion/LayoutSchema.js index 4151aed..7e41d8f 100644 --- a/src/components/manage/Blocks/Accordion/LayoutSchema.js +++ b/src/components/manage/Blocks/Accordion/LayoutSchema.js @@ -63,8 +63,7 @@ const messages = defineMessages({ defaultMessage: 'Fixed layout', }, FixedlayoutNewPanesTabs: { - id: - 'Fixed layout, New panes (tabs) created by Editor within this block will be ignored', + id: 'Fixed layout, New panes (tabs) created by Editor within this block will be ignored', defaultMessage: 'Fixed layout, New panes (tabs) created by Editor within this block will be ignored', }, diff --git a/src/components/manage/Blocks/Accordion/View.test.jsx b/src/components/manage/Blocks/Accordion/View.test.jsx index bee3001..0009753 100644 --- a/src/components/manage/Blocks/Accordion/View.test.jsx +++ b/src/components/manage/Blocks/Accordion/View.test.jsx @@ -1,10 +1,9 @@ import React from 'react'; import View from './View'; -import renderer from 'react-test-renderer'; -import { render, fireEvent } from '@testing-library/react'; +import { render, fireEvent, screen } from '@testing-library/react'; import configureStore from 'redux-mock-store'; import { Provider } from 'react-intl-redux'; -import { MemoryRouter } from 'react-router-dom'; +import { MemoryRouter, Route } from 'react-router-dom'; import config from '@plone/volto/registry'; import * as utils from './util'; import '@testing-library/jest-dom/extend-expect'; @@ -20,6 +19,14 @@ config.blocks.blocksConfig.accordion = { rightPosition: 'chevron down', leftPosition: 'chevron down', }, + unfiltered: { + rightPosition: 'chevron left', + leftPosition: 'chevron right', + }, + filtered: { + rightPosition: 'chevron down', + leftPosition: 'chevron down', + }, size: 'tiny', iconComponent: 'SemanticIcon', }, @@ -67,33 +74,35 @@ const mockData1 = { non_exclusive: true, }; -describe('View Component', () => { - it('renders without crashing', () => { - utils.accordionBlockHasValue.mockReturnValue(true); - const component = renderer.create( - - - - - , - ); - const json = component.toJSON(); - expect(json).toMatchSnapshot(); - }); - - it('renders null', () => { - utils.accordionBlockHasValue.mockReturnValue(false); - const component = renderer.create( - - - - - , - ); - const json = component.toJSON(); - expect(json).toMatchSnapshot(); - }); +const mockData2 = { + data: { + blocks: { + 1: { + '@type': 'accordionPanel', + title: 'Panel 1', + blocks_layout: { + items: ['block1', 'block2'], + }, + }, + 2: { + '@type': 'accordionPanel', + title: 'Panel 2', + blocks_layout: { + items: ['block3', 'block4'], + }, + }, + }, + blocks_layout: { + items: ['1', '2'], + }, + }, + right_arrows: false, + non_exclusive: true, + collapsed: false, + filtering: false, +}; +describe('View Component', () => { it('renders with panels', () => { utils.accordionBlockHasValue.mockReturnValue(true); const { rerender, getByText } = render( @@ -163,4 +172,51 @@ describe('View Component', () => { const contentElement = getByText('RenderBlocks'); expect(contentElement).toBeInTheDocument(); }); + + it('filters the accordion panels based on the filter value', () => { + render( + + + + + , + ); + + const filterInput = screen.getByPlaceholderText('Type to filter...'); + fireEvent.change(filterInput, { target: { value: 'Panel 1' } }); + + expect(screen.getByText('Panel 1')).toBeInTheDocument(); + expect(screen.queryByText('Panel 2')).not.toBeInTheDocument(); + }); + + it('updates the URL query parameter when a panel is clicked', () => { + render( + + + +
{location.search}
} + /> +
+
, + ); + + const panel1Title = screen.getByText('Panel 1'); + fireEvent.click(panel1Title); + + expect(screen.getByText('?activeAccordion=')).toBeInTheDocument(); + }); + + it('renders the accordion panels in diff view mode', () => { + render( + + + + + , + ); + + expect(screen.getByText('RenderBlocks')).toBeInTheDocument(); + }); }); diff --git a/src/components/manage/Blocks/Accordion/__snapshots__/AccordionEdit.test.jsx.snap b/src/components/manage/Blocks/Accordion/__snapshots__/AccordionEdit.test.jsx.snap deleted file mode 100644 index bcf501d..0000000 --- a/src/components/manage/Blocks/Accordion/__snapshots__/AccordionEdit.test.jsx.snap +++ /dev/null @@ -1,52 +0,0 @@ -// Jest Snapshot v1, https://goo.gl/fbAQLP - -exports[`AccordionEdit should render correctly 1`] = ` -
-

-