@eeacms/volto-slate-metadata-mentions 3.0.0 → 4.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -4,13 +4,40 @@ All notable changes to this project will be documented in this file. Dates are d
4
4
 
5
5
  Generated by [`auto-changelog`](https://github.com/CookPete/auto-changelog).
6
6
 
7
- #### [3.0.0](https://github.com/eea/volto-slate-metadata-mentions/compare/2.4.0...3.0.0)
7
+ #### [4.0.1](https://github.com/eea/volto-slate-metadata-mentions/compare/4.0.0...4.0.1)
8
8
 
9
- - Release 3.0.0 [`ae35590`](https://github.com/eea/volto-slate-metadata-mentions/commit/ae35590e02d7088793eaf104e5efd5774bc7f91c)
9
+ - Use a button factory [`#19`](https://github.com/eea/volto-slate-metadata-mentions/pull/19)
10
+ - Add SonarQube badges [`5d68285`](https://github.com/eea/volto-slate-metadata-mentions/commit/5d68285dd04f86628ba7f9174c1945412b5fb9a1)
11
+ - Refs #142010 - Optimize Volto-addons gitflow pipelines [`3a6a696`](https://github.com/eea/volto-slate-metadata-mentions/commit/3a6a69612652cd947d54f77c430bdca21b82a0df)
12
+
13
+ ### [4.0.0](https://github.com/eea/volto-slate-metadata-mentions/compare/3.0.2...4.0.0)
14
+
15
+ > 24 September 2021
16
+
17
+ - Release 4.0.0 [`#18`](https://github.com/eea/volto-slate-metadata-mentions/pull/18)
18
+ - Use new slate namespaced pluginids [`#17`](https://github.com/eea/volto-slate-metadata-mentions/pull/17)
19
+ - Allow also dict fields: temporal, geolocation [`49be384`](https://github.com/eea/volto-slate-metadata-mentions/commit/49be3845a5fed9957139ebe88d24adc44b2521d5)
20
+
21
+ #### [3.0.2](https://github.com/eea/volto-slate-metadata-mentions/compare/3.0.1...3.0.2)
22
+
23
+ > 10 September 2021
24
+
25
+ - Fix cypress api_url [`#16`](https://github.com/eea/volto-slate-metadata-mentions/pull/16)
26
+
27
+ #### [3.0.1](https://github.com/eea/volto-slate-metadata-mentions/compare/3.0.0...3.0.1)
28
+
29
+ > 9 September 2021
30
+
31
+ - Fix to work with volto-slate 3.0.0. Cypress [`#15`](https://github.com/eea/volto-slate-metadata-mentions/pull/15)
32
+
33
+ ### [3.0.0](https://github.com/eea/volto-slate-metadata-mentions/compare/2.4.0...3.0.0)
34
+
35
+ > 3 September 2021
36
+
37
+ - Release 3.0.0 [`#14`](https://github.com/eea/volto-slate-metadata-mentions/pull/14)
10
38
  - Update package metadata [`af8c5b3`](https://github.com/eea/volto-slate-metadata-mentions/commit/af8c5b3bf2ce6d9520b3d9378c648a37d8d519d3)
11
39
  - Add ErrorBoundary to Widgets [`f9c7e0d`](https://github.com/eea/volto-slate-metadata-mentions/commit/f9c7e0de20c13305e9dfe09a968753f44e3224ce)
12
40
  - Make sure it doesn't crash if used with SlateJSONField [`60dbd38`](https://github.com/eea/volto-slate-metadata-mentions/commit/60dbd389f217b7341eb0c369abd044424357ab05)
13
- - Add Sonarqube tag using frontend addons list [`7c7f219`](https://github.com/eea/volto-slate-metadata-mentions/commit/7c7f2196bafde9bbb3ecead19d65ff109080e1f1)
14
41
 
15
42
  #### [2.4.0](https://github.com/eea/volto-slate-metadata-mentions/compare/2.3.1...2.4.0)
16
43
 
@@ -53,7 +80,6 @@ Generated by [`auto-changelog`](https://github.com/CookPete/auto-changelog).
53
80
 
54
81
  > 13 May 2021
55
82
 
56
- - [JENKINS] - Auto-release pipeline [`#4`](https://github.com/eea/volto-slate-metadata-mentions/pull/4)
57
83
  - fixed issue with decoration not being removed on cancel if creating a new element [`#5`](https://github.com/eea/volto-slate-metadata-mentions/pull/5)
58
84
  - fixed issue with decoration not being removed if user does not add any mentions on a new element, also should not remove if the user does not change an existing [`e5a6336`](https://github.com/eea/volto-slate-metadata-mentions/commit/e5a6336755730650407d1df7fbe5134af7ce39cd)
59
85
 
@@ -84,8 +110,6 @@ Generated by [`auto-changelog`](https://github.com/CookPete/auto-changelog).
84
110
  > 17 November 2020
85
111
 
86
112
  - Release 1.0.0 [`6575ab3`](https://github.com/eea/volto-slate-metadata-mentions/commit/6575ab300c7889ccfea1d9c20266f1c074ea2b4f)
87
- - [JENKINS] - Fix dependencies [`aef9cf8`](https://github.com/eea/volto-slate-metadata-mentions/commit/aef9cf8b252a8dfab3ebb91977dde05bae2113af)
88
- - [JENKINS] - Add pipeline, update docs [`7b52b37`](https://github.com/eea/volto-slate-metadata-mentions/commit/7b52b37fb673ee3aa05b559d3e1a0188e3c013c1)
89
113
 
90
114
  #### [0.4.2](https://github.com/eea/volto-slate-metadata-mentions/compare/0.4.1...0.4.2)
91
115
 
@@ -173,7 +197,6 @@ Generated by [`auto-changelog`](https://github.com/CookPete/auto-changelog).
173
197
  - Cleanup [`4edb16c`](https://github.com/eea/volto-slate-metadata-mentions/commit/4edb16c39bd1632a285aae1dc4b23bc3121b30af)
174
198
  - Remove unused uid normalizer [`6006d90`](https://github.com/eea/volto-slate-metadata-mentions/commit/6006d9070ca8418c508f002032eca087c851b489)
175
199
  - Cosmetics [`15424a4`](https://github.com/eea/volto-slate-metadata-mentions/commit/15424a48b14117a19c00167966a8fa15bcff8504)
176
- - yarn lint [`45403b3`](https://github.com/eea/volto-slate-metadata-mentions/commit/45403b3962c2c995e22c8c40535098948f6f8d2b)
177
200
  - lint [`9eedfe6`](https://github.com/eea/volto-slate-metadata-mentions/commit/9eedfe614e9202a2fd3d97c5d8cf53a52a43a3a4)
178
201
  - Update widgets to use children; lint [`17b5eec`](https://github.com/eea/volto-slate-metadata-mentions/commit/17b5eecc0ce445c123fd57abbc14e045f4920370)
179
202
  - Style token widget [`4fa52f5`](https://github.com/eea/volto-slate-metadata-mentions/commit/4fa52f5cc7cfde140e482048792c6f1782b4ee4e)
package/Jenkinsfile CHANGED
@@ -4,13 +4,39 @@ pipeline {
4
4
  environment {
5
5
  GIT_NAME = "volto-slate-metadata-mentions"
6
6
  NAMESPACE = "@eeacms"
7
- SONARQUBE_TAGS = "volto.eea.europa.eu,biodiversity.europa.eu"
7
+ SONARQUBE_TAGS = "volto.eea.europa.eu,biodiversity.europa.eu,www.eea.europa.eu-ims,climate-energy.eea.europa.eu,sustainability.eionet.europa.eu,forest.eea.europa.eu,clms.land.copernicus.eu,industry.eea.europa.eu,water.europa.eu-freshwater"
8
8
  DEPENDENCIES = ""
9
+ PLONE_VERSIONS = "plone.schema=1.3.0 plone.restapi=8.9.1"
10
+ PLONE_ADDONS = "eea.schema.slate"
9
11
  }
10
12
 
11
13
  stages {
12
14
 
15
+ stage('Release') {
16
+ when {
17
+ allOf {
18
+ environment name: 'CHANGE_ID', value: ''
19
+ branch 'master'
20
+ }
21
+ }
22
+ steps {
23
+ node(label: 'docker') {
24
+ withCredentials([string(credentialsId: 'eea-jenkins-token', variable: 'GITHUB_TOKEN'),string(credentialsId: 'eea-jenkins-npm-token', variable: 'NPM_TOKEN')]) {
25
+ sh '''docker pull eeacms/gitflow'''
26
+ sh '''docker run -i --rm --name="$BUILD_TAG-gitflow-master" -e GIT_BRANCH="$BRANCH_NAME" -e GIT_NAME="$GIT_NAME" -e GIT_TOKEN="$GITHUB_TOKEN" -e NPM_TOKEN="$NPM_TOKEN" -e LANGUAGE=javascript eeacms/gitflow'''
27
+ }
28
+ }
29
+ }
30
+ }
31
+
13
32
  stage('Code') {
33
+ when {
34
+ allOf {
35
+ environment name: 'CHANGE_ID', value: ''
36
+ not { changelog '.*^Automated release [0-9\\.]+$' }
37
+ not { branch 'master' }
38
+ }
39
+ }
14
40
  steps {
15
41
  parallel(
16
42
 
@@ -36,6 +62,15 @@ pipeline {
36
62
  }
37
63
 
38
64
  stage('Tests') {
65
+ when {
66
+ allOf {
67
+ environment name: 'CHANGE_ID', value: ''
68
+ anyOf {
69
+ not { changelog '.*^Automated release [0-9\\.]+$' }
70
+ branch 'master'
71
+ }
72
+ }
73
+ }
39
74
  steps {
40
75
  parallel(
41
76
 
@@ -75,6 +110,15 @@ pipeline {
75
110
  }
76
111
 
77
112
  stage('Integration tests') {
113
+ when {
114
+ allOf {
115
+ environment name: 'CHANGE_ID', value: ''
116
+ anyOf {
117
+ not { changelog '.*^Automated release [0-9\\.]+$' }
118
+ branch 'master'
119
+ }
120
+ }
121
+ }
78
122
  steps {
79
123
  parallel(
80
124
 
@@ -82,7 +126,7 @@ pipeline {
82
126
  node(label: 'docker') {
83
127
  script {
84
128
  try {
85
- sh '''docker pull plone; docker run -d --name="$BUILD_TAG-plone" -e SITE="Plone" -e PROFILES="profile-plone.restapi:blocks" plone fg'''
129
+ sh '''docker pull plone; docker run -d --name="$BUILD_TAG-plone" -e SITE="Plone" -e ADDONS="$PLONE_ADDONS" -e VERSIONS="$PLONE_VERSIONS" -e PROFILES="profile-plone.restapi:blocks" plone fg'''
86
130
  sh '''docker pull plone/volto-addon-ci; docker run -i --name="$BUILD_TAG-cypress" --link $BUILD_TAG-plone:plone -e NAMESPACE="$NAMESPACE" -e GIT_NAME=$GIT_NAME -e GIT_BRANCH="$BRANCH_NAME" -e GIT_CHANGE_ID="$CHANGE_ID" -e DEPENDENCIES="$DEPENDENCIES" plone/volto-addon-ci cypress'''
87
131
  } finally {
88
132
  try {
@@ -122,10 +166,16 @@ pipeline {
122
166
  }
123
167
 
124
168
  stage('Report to SonarQube') {
125
- // Exclude Pull-Requests
126
169
  when {
127
170
  allOf {
128
171
  environment name: 'CHANGE_ID', value: ''
172
+ anyOf {
173
+ branch 'master'
174
+ allOf {
175
+ branch 'develop'
176
+ not { changelog '.*^Automated release [0-9\\.]+$' }
177
+ }
178
+ }
129
179
  }
130
180
  }
131
181
  steps {
@@ -156,8 +206,8 @@ pipeline {
156
206
  steps {
157
207
  node(label: 'docker') {
158
208
  script {
159
- if ( env.CHANGE_BRANCH != "develop" && !( env.CHANGE_BRANCH.startsWith("hotfix")) ) {
160
- error "Pipeline aborted due to PR not made from develop or hotfix branch"
209
+ if ( env.CHANGE_BRANCH != "develop" ) {
210
+ error "Pipeline aborted due to PR not made from develop branch"
161
211
  }
162
212
  withCredentials([string(credentialsId: 'eea-jenkins-token', variable: 'GITHUB_TOKEN')]) {
163
213
  sh '''docker pull eeacms/gitflow'''
@@ -168,23 +218,6 @@ pipeline {
168
218
  }
169
219
  }
170
220
 
171
- stage('Release') {
172
- when {
173
- allOf {
174
- environment name: 'CHANGE_ID', value: ''
175
- branch 'master'
176
- }
177
- }
178
- steps {
179
- node(label: 'docker') {
180
- withCredentials([string(credentialsId: 'eea-jenkins-token', variable: 'GITHUB_TOKEN'),string(credentialsId: 'eea-jenkins-npm-token', variable: 'NPM_TOKEN')]) {
181
- sh '''docker pull eeacms/gitflow'''
182
- sh '''docker run -i --rm --name="$BUILD_TAG-gitflow-master" -e GIT_BRANCH="$BRANCH_NAME" -e GIT_NAME="$GIT_NAME" -e GIT_TOKEN="$GITHUB_TOKEN" -e NPM_TOKEN="$NPM_TOKEN" -e LANGUAGE=javascript eeacms/gitflow'''
183
- }
184
- }
185
- }
186
- }
187
-
188
221
  }
189
222
 
190
223
  post {
package/Makefile CHANGED
@@ -2,6 +2,9 @@ SHELL=/bin/bash
2
2
 
3
3
  DIR=$(shell basename $$(pwd))
4
4
  ADDON ?= "@eeacms/volto-slate-metadata-mentions"
5
+ PLONE_ADDONS ?= "eea.schema.slate"
6
+ PLONE_VERSIONS ?= "plone.schema=1.3.0 plone.restapi=8.9.1"
7
+ PLONE_PROFILES ?= "profile-plone.restapi:blocks"
5
8
 
6
9
  # We like colors
7
10
  # From: https://coderwall.com/p/izxssa/colored-makefile-for-golang-projects
@@ -24,6 +27,12 @@ project:
24
27
 
25
28
  all: project
26
29
 
30
+ .PHONY: start-docker-backend
31
+ start-docker-backend:
32
+ @echo "$(GREEN)==> Start Plone Backend$(RESET)"
33
+ docker pull plone
34
+ docker run -it --rm -e SITE="Plone" -e ADDONS=$(PLONE_ADDONS) -e VERSIONS=$(PLONE_VERSIONS) -e PROFILES=$(PLONE_PROFILES) -p 8080:8080 plone fg
35
+
27
36
  .PHONY: start-test-backend
28
37
  start-test-backend: ## Start Test Plone Backend
29
38
  @echo "$(GREEN)==> Start Test Plone Backend$(RESET)"
package/README.md CHANGED
@@ -1,7 +1,19 @@
1
1
  # volto-slate-metadata-mentions
2
+
2
3
  [![Releases](https://img.shields.io/github/v/release/eea/volto-slate-metadata-mentions)](https://github.com/eea/volto-slate-metadata-mentions/releases)
4
+
3
5
  [![Pipeline](https://ci.eionet.europa.eu/buildStatus/icon?job=volto-addons%2Fvolto-slate-metadata-mentions%2Fmaster&subject=master)](https://ci.eionet.europa.eu/view/Github/job/volto-addons/job/volto-slate-metadata-mentions/job/master/display/redirect)
6
+ [![Lines of Code](https://sonarqube.eea.europa.eu/api/project_badges/measure?project=volto-slate-metadata-mentions-master&metric=ncloc)](https://sonarqube.eea.europa.eu/dashboard?id=volto-slate-metadata-mentions-master)
7
+ [![Coverage](https://sonarqube.eea.europa.eu/api/project_badges/measure?project=volto-slate-metadata-mentions-master&metric=coverage)](https://sonarqube.eea.europa.eu/dashboard?id=volto-slate-metadata-mentions-master)
8
+ [![Bugs](https://sonarqube.eea.europa.eu/api/project_badges/measure?project=volto-slate-metadata-mentions-master&metric=bugs)](https://sonarqube.eea.europa.eu/dashboard?id=volto-slate-metadata-mentions-master)
9
+ [![Duplicated Lines (%)](https://sonarqube.eea.europa.eu/api/project_badges/measure?project=volto-slate-metadata-mentions-master&metric=duplicated_lines_density)](https://sonarqube.eea.europa.eu/dashboard?id=volto-slate-metadata-mentions-master)
10
+
4
11
  [![Pipeline](https://ci.eionet.europa.eu/buildStatus/icon?job=volto-addons%2Fvolto-slate-metadata-mentions%2Fdevelop&subject=develop)](https://ci.eionet.europa.eu/view/Github/job/volto-addons/job/volto-slate-metadata-mentions/job/develop/display/redirect)
12
+ [![Lines of Code](https://sonarqube.eea.europa.eu/api/project_badges/measure?project=volto-slate-metadata-mentions-develop&metric=ncloc)](https://sonarqube.eea.europa.eu/dashboard?id=volto-slate-metadata-mentions-develop)
13
+ [![Coverage](https://sonarqube.eea.europa.eu/api/project_badges/measure?project=volto-slate-metadata-mentions-develop&metric=coverage)](https://sonarqube.eea.europa.eu/dashboard?id=volto-slate-metadata-mentions-develop)
14
+ [![Bugs](https://sonarqube.eea.europa.eu/api/project_badges/measure?project=volto-slate-metadata-mentions-develop&metric=bugs)](https://sonarqube.eea.europa.eu/dashboard?id=volto-slate-metadata-mentions-develop)
15
+ [![Duplicated Lines (%)](https://sonarqube.eea.europa.eu/api/project_badges/measure?project=volto-slate-metadata-mentions-develop&metric=duplicated_lines_density)](https://sonarqube.eea.europa.eu/dashboard?id=volto-slate-metadata-mentions-develop)
16
+
5
17
 
6
18
  [Volto Slate](https://github.com/eea/volto-slate/tree/develop) Metadata Mentions
7
19
 
@@ -66,6 +78,81 @@
66
78
 
67
79
  1. Happy editing!
68
80
 
81
+ ## Release
82
+
83
+ ### Automatic release using Jenkins
84
+
85
+ * The automatic release is started by creating a [Pull Request](../../compare/master...develop) from `develop` to `master`. The pull request status checks correlated to the branch and PR Jenkins jobs need to be processed successfully. 1 review from a github user with rights is mandatory.
86
+ * It runs on every commit on `master` branch, which is protected from direct commits, only allowing pull request merge commits.
87
+ * The automatic release is done by [Jenkins](https://ci.eionet.europa.eu). The status of the release job can be seen both in the Readme.md badges and the green check/red cross/yellow circle near the last commit information. If you click on the icon, you will have the list of checks that were run. The `continuous-integration/jenkins/branch` link goes to the Jenkins job execution webpage.
88
+ * Automated release scripts are located in the `eeacms/gitflow` docker image, specifically [js-release.sh](https://github.com/eea/eea.docker.gitflow/blob/master/src/js-release.sh) script. It uses the `release-it` tool.
89
+ * As long as a PR request is open from develop to master, the PR Jenkins job will automatically re-create the CHANGELOG.md and package.json files to be production-ready.
90
+ * The version format must be MAJOR.MINOR.PATCH. By default, next release is set to next minor version (with patch 0).
91
+ * You can manually change the version in `package.json`. The new version must not be already present in the tags/releases of the repository, otherwise it will be automatically increased by the script. Any changes to the version will trigger a `CHANGELOG.md` re-generation.
92
+ * Automated commits and commits with [JENKINS] or [YARN] in the commit log are excluded from `CHANGELOG.md` file.
93
+
94
+ ### Manual release from the develop branch ( beta release )
95
+
96
+ #### Installation and configuration of release-it
97
+
98
+ You need to first install the [release-it](https://github.com/release-it/release-it) client.
99
+
100
+ ```
101
+ npm install -g release-it
102
+ ```
103
+
104
+ Release-it uses the configuration written in the [`.release-it.json`](./.release-it.json) file located in the root of the repository.
105
+
106
+ Release-it is a tool that automates 4 important steps in the release process:
107
+
108
+ 1. Version increase in `package.json` ( increased from the current version in `package.json`)
109
+ 2. `CHANGELOG.md` automatic generation from commit messages ( grouped by releases )
110
+ 3. GitHub release on the commit with the changelog and package.json modification on the develop branch
111
+ 4. NPM release ( by default it's disabled, but can be enabled in the configuration file )
112
+
113
+ To configure the authentification, you need to export GITHUB_TOKEN for [GitHub](https://github.com/settings/tokens)
114
+
115
+ ```
116
+ export GITHUB_TOKEN=XXX-XXXXXXXXXXXXXXXXXXXXXX
117
+ ```
118
+
119
+ To configure npm, you can use the `npm login` command or use a configuration file with a TOKEN :
120
+
121
+ ```
122
+ echo "//registry.npmjs.org/:_authToken=YYYYYYYYYYYYYYYYYYYYYYYYYYYYYY" > .npmrc
123
+ ```
124
+
125
+ #### Using release-it tool
126
+
127
+ There are 3 yarn scripts that can be run to do the release
128
+
129
+ ##### yarn release-beta
130
+
131
+ Automatically calculates and presents 3 beta versions - patch, minor and major for you to choose ( or Other for manual input).
132
+
133
+ ```
134
+ ? Select increment (next version):
135
+ ❯ prepatch (0.1.1-beta.0)
136
+ preminor (0.2.0-beta.0)
137
+ premajor (1.0.0-beta.0)
138
+ Other, please specify...
139
+ ```
140
+
141
+ ##### yarn release-major-beta
142
+
143
+ Same as `yarn release-beta`, but with premajor version pre-selected.
144
+
145
+ ##### yarn release
146
+
147
+ Generic command, does not automatically add the `beta` to version, but you can still manually write it if you choose Other.
148
+
149
+ #### Important notes
150
+
151
+ > Do not use release-it tool on master branch, the commit on CHANGELOG.md file and the version increase in the package.json file can't be done without a PULL REQUEST.
152
+
153
+ > Do not keep Pull Requests from develop to master branches open when you are doing beta releases from the develop branch. As long as a PR to master is open, an automatic script will run on every commit and will update both the version and the changelog to a production-ready state - ( MAJOR.MINOR.PATCH mandatory format for version).
154
+
155
+
69
156
  ## How to contribute
70
157
 
71
158
  See [DEVELOP.md](DEVELOP.md).
@@ -0,0 +1,42 @@
1
+ import { slateBeforeEach, slateAfterEach } from '../support';
2
+
3
+ describe('Block Tests: Metadata', () => {
4
+ beforeEach(slateBeforeEach);
5
+ afterEach(slateAfterEach);
6
+
7
+ it('As editor I can add metadata mentions', function () {
8
+ // Complete chained commands
9
+ cy.getSlateEditorAndType('Colorless green ideas sleep furiously.');
10
+
11
+ // Metadata mention
12
+ cy.setSlateSelection('sleep', 'furiously');
13
+ cy.clickSlateButton('Metadata');
14
+
15
+ cy.get('.sidebar-container div[id="field-id"]')
16
+ .click({ multiple: true })
17
+ .type('Publishing Date{enter}');
18
+ cy.get('.sidebar-container .form .header button:first-of-type').click();
19
+
20
+ // Remove link
21
+ cy.setSlateSelection('sleep');
22
+ cy.clickSlateButton('Remove metadata');
23
+
24
+ // Re-add link
25
+ cy.setSlateSelection('green', 'sleep');
26
+ cy.clickSlateButton('Metadata');
27
+
28
+ cy.get('.sidebar-container div[id="field-id"]')
29
+ .click({ multiple: true })
30
+ .type('Summary{enter}');
31
+ cy.get('.sidebar-container [id="blockform-fieldset-metadata"] textarea')
32
+ .click({ multiple: true })
33
+ .type('blue cats sleep');
34
+ cy.get('.sidebar-container .form .header button:first-of-type').click();
35
+
36
+ // Save
37
+ cy.toolbarSave();
38
+
39
+ // then the page view should contain a link
40
+ cy.contains('Colorless blue cats sleep furiously.');
41
+ });
42
+ });
@@ -92,7 +92,7 @@ Cypress.Commands.add(
92
92
  title: contentTitle,
93
93
  blocks: {
94
94
  'd3f1c443-583f-4e8e-a682-3bf25752a300': { '@type': 'title' },
95
- '7624cf59-05d0-4055-8f55-5fd6597d84b0': { '@type': 'text' },
95
+ '7624cf59-05d0-4055-8f55-5fd6597d84b0': { '@type': 'slate' },
96
96
  },
97
97
  blocks_layout: {
98
98
  items: [
@@ -125,6 +125,100 @@ Cypress.Commands.add(
125
125
  },
126
126
  );
127
127
 
128
+ // --- Add DX Content-Type ----------------------------------------------------------
129
+ Cypress.Commands.add('addContentType', (name) => {
130
+ let api_url, auth;
131
+ api_url = Cypress.env('API_PATH') || 'http://localhost:8080/Plone';
132
+ auth = {
133
+ user: 'admin',
134
+ pass: 'admin',
135
+ };
136
+ return cy
137
+ .request({
138
+ method: 'POST',
139
+ url: `${api_url}/@controlpanels/dexterity-types/${name}`,
140
+ headers: {
141
+ Accept: 'application/json',
142
+ },
143
+ auth: auth,
144
+ body: {
145
+ title: name,
146
+ },
147
+ })
148
+ .then(() => console.log(`${name} content-type added.`));
149
+ });
150
+
151
+ // --- Remove DX behavior ----------------------------------------------------------
152
+ Cypress.Commands.add('removeContentType', (name) => {
153
+ let api_url, auth;
154
+ api_url = Cypress.env('API_PATH') || 'http://localhost:8080/Plone';
155
+ auth = {
156
+ user: 'admin',
157
+ pass: 'admin',
158
+ };
159
+ return cy
160
+ .request({
161
+ method: 'DELETE',
162
+ url: `${api_url}/@controlpanels/dexterity-types/${name}`,
163
+ headers: {
164
+ Accept: 'application/json',
165
+ },
166
+ auth: auth,
167
+ body: {},
168
+ })
169
+ .then(() => console.log(`${name} content-type removed.`));
170
+ });
171
+
172
+ // --- Add DX field ----------------------------------------------------------
173
+ Cypress.Commands.add('addSlateJSONField', (type, name) => {
174
+ let api_url, auth;
175
+ api_url = Cypress.env('API_PATH') || 'http://localhost:8080/Plone';
176
+ auth = {
177
+ user: 'admin',
178
+ pass: 'admin',
179
+ };
180
+ return cy
181
+ .request({
182
+ method: 'POST',
183
+ url: `${api_url}/@types/${type}`,
184
+ headers: {
185
+ Accept: 'application/json',
186
+ },
187
+ auth: auth,
188
+ body: {
189
+ id: name,
190
+ title: name,
191
+ description: 'Slate JSON Field',
192
+ factory: 'SlateJSONField',
193
+ required: false,
194
+ },
195
+ })
196
+ .then(() => console.log(`${name} SlateJSONField field added to ${type}`));
197
+ });
198
+
199
+ // --- Remove DX field ----------------------------------------------------------
200
+ Cypress.Commands.add('removeSlateJSONField', (type, name) => {
201
+ let api_url, auth;
202
+ api_url = Cypress.env('API_PATH') || 'http://localhost:8080/Plone';
203
+ auth = {
204
+ user: 'admin',
205
+ pass: 'admin',
206
+ };
207
+ return cy
208
+ .request({
209
+ method: 'DELETE',
210
+ url: `${api_url}/@types/${type}/${name}`,
211
+ headers: {
212
+ Accept: 'application/json',
213
+ },
214
+ auth: auth,
215
+ body: {},
216
+ })
217
+ .then(() =>
218
+ console.log(`${name} SlateJSONField field removed from ${type}`),
219
+ );
220
+ });
221
+
128
222
  // --- REMOVE CONTENT --------------------------------------------------------
129
223
  Cypress.Commands.add('removeContent', (path) => {
130
224
  let api_url, auth;
@@ -146,6 +240,41 @@ Cypress.Commands.add('removeContent', (path) => {
146
240
  .then(() => console.log(`${path} removed`));
147
241
  });
148
242
 
243
+ Cypress.Commands.add('typeInSlate', { prevSubject: true }, (subject, text) => {
244
+ return (
245
+ cy
246
+ .wrap(subject)
247
+ .then((subject) => {
248
+ subject[0].dispatchEvent(
249
+ new InputEvent('beforeinput', {
250
+ inputType: 'insertText',
251
+ data: text,
252
+ }),
253
+ );
254
+ return subject;
255
+ })
256
+ // TODO: do this only for Electron-based browser which does not understand instantaneously
257
+ // that the user inserted some text in the block
258
+ .wait(1000)
259
+ );
260
+ });
261
+
262
+ Cypress.Commands.add('lineBreakInSlate', { prevSubject: true }, (subject) => {
263
+ return (
264
+ cy
265
+ .wrap(subject)
266
+ .then((subject) => {
267
+ subject[0].dispatchEvent(
268
+ new InputEvent('beforeinput', { inputType: 'insertLineBreak' }),
269
+ );
270
+ return subject;
271
+ })
272
+ // TODO: do this only for Electron-based browser which does not understand instantaneously
273
+ // that the block was split
274
+ .wait(1000)
275
+ );
276
+ });
277
+
149
278
  // --- SET WORKFLOW ----------------------------------------------------------
150
279
  Cypress.Commands.add(
151
280
  'setWorkflow',
@@ -247,6 +376,47 @@ Cypress.Commands.add(
247
376
  },
248
377
  );
249
378
 
379
+ Cypress.Commands.add('getSlateEditorAndType', (type) => {
380
+ cy.get('.content-area .slate-editor [contenteditable=true]')
381
+ .focus()
382
+ .click()
383
+ .wait(1000)
384
+ .type(type);
385
+ });
386
+
387
+ Cypress.Commands.add('setSlateSelection', (subject, query, endQuery) => {
388
+ cy.get('.slate-editor.selected [contenteditable=true]')
389
+ .focus()
390
+ .click()
391
+ .setSelection(subject, query, endQuery)
392
+ .wait(1000);
393
+ });
394
+
395
+ Cypress.Commands.add('setSlateCursor', (subject, query, endQuery) => {
396
+ cy.get('.slate-editor.selected [contenteditable=true]')
397
+ .focus()
398
+ .click()
399
+ .setCursor(subject, query, endQuery)
400
+ .wait(1000);
401
+ });
402
+
403
+ Cypress.Commands.add('clickSlateButton', (button) => {
404
+ cy.get(`.slate-inline-toolbar .button-wrapper a[title="${button}"]`).click();
405
+ });
406
+
407
+ Cypress.Commands.add('toolbarSave', () => {
408
+ cy.wait(1000);
409
+
410
+ // Save
411
+ cy.get('#toolbar-save').click();
412
+ cy.waitForResourceToLoad('@navigation');
413
+ cy.waitForResourceToLoad('@breadcrumbs');
414
+ cy.waitForResourceToLoad('@actions');
415
+ cy.waitForResourceToLoad('@types');
416
+ cy.waitForResourceToLoad('my-page');
417
+ cy.url().should('eq', Cypress.config().baseUrl + '/cypress/my-page');
418
+ });
419
+
250
420
  // Low level command reused by `setCursorBefore` and `setCursorAfter`, equal to `setCursorAfter`
251
421
  Cypress.Commands.add(
252
422
  'setCursor',
@@ -15,7 +15,6 @@
15
15
 
16
16
  // Import commands.js using ES2015 syntax:
17
17
  import './commands';
18
-
19
18
  // Alternatively you can use CommonJS syntax:
20
19
  // require('./commands')
21
20
 
@@ -24,7 +23,7 @@ import './commands';
24
23
  import '@cypress/code-coverage/support';
25
24
  coverage-end */
26
25
 
27
- export const setupBeforeEach = () => {
26
+ export const slateBeforeEach = (contentType = 'Document') => {
28
27
  cy.autologin();
29
28
  cy.createContent({
30
29
  contentType: 'Folder',
@@ -32,7 +31,7 @@ export const setupBeforeEach = () => {
32
31
  contentTitle: 'Cypress',
33
32
  });
34
33
  cy.createContent({
35
- contentType: 'Document',
34
+ contentType: contentType,
36
35
  contentId: 'my-page',
37
36
  contentTitle: 'My Page',
38
37
  path: 'cypress',
@@ -44,10 +43,85 @@ export const setupBeforeEach = () => {
44
43
  cy.waitForResourceToLoad('@types');
45
44
  cy.waitForResourceToLoad('my-page');
46
45
  cy.navigate('/cypress/my-page/edit');
47
- cy.get(`.block.title [data-contents]`);
48
46
  };
49
47
 
50
- export const tearDownAfterEach = () => {
48
+ export const slateAfterEach = () => {
51
49
  cy.autologin();
52
50
  cy.removeContent('cypress');
53
51
  };
52
+
53
+ export const slateJsonBeforeEach = (contentType = 'slate') => {
54
+ cy.autologin();
55
+ cy.addContentType(contentType);
56
+ cy.addSlateJSONField(contentType, 'slate');
57
+ slateBeforeEach(contentType);
58
+ };
59
+
60
+ export const slateJsonAfterEach = (contentType = 'slate') => {
61
+ cy.autologin();
62
+ cy.removeContentType(contentType);
63
+ slateAfterEach();
64
+ };
65
+
66
+ export const getSelectedSlateEditor = () => {
67
+ return cy.get('.slate-editor.selected [contenteditable=true]').click();
68
+ };
69
+
70
+ export const createSlateBlock = () => {
71
+ cy.get('.ui.basic.icon.button.block-add-button').first().click();
72
+ cy.get('.blocks-chooser .title').contains('Text').click();
73
+ cy.get('.ui.basic.icon.button.slate').contains('Text').click();
74
+ return getSelectedSlateEditor();
75
+ };
76
+
77
+ export const getSlateBlockValue = (sb) => {
78
+ return sb.invoke('attr', 'data-slate-value').then((str) => {
79
+ return typeof str === 'undefined' ? [] : JSON.parse(str);
80
+ });
81
+ };
82
+
83
+ export const createSlateBlockWithList = ({
84
+ numbered,
85
+ firstItemText,
86
+ secondItemText,
87
+ }) => {
88
+ let s1 = createSlateBlock();
89
+
90
+ s1.typeInSlate(firstItemText + secondItemText);
91
+
92
+ // select all contents of slate block
93
+ // - this opens hovering toolbar
94
+ cy.contains(firstItemText + secondItemText).then((el) => {
95
+ selectSlateNodeOfWord(el);
96
+ });
97
+
98
+ // TODO: do not hardcode these selectors:
99
+ if (numbered) {
100
+ // this is the numbered list option in the hovering toolbar
101
+ cy.get('.slate-inline-toolbar > :nth-child(9)').click();
102
+ } else {
103
+ // this is the bulleted list option in the hovering toolbar
104
+ cy.get('.slate-inline-toolbar > :nth-child(10)').click();
105
+ }
106
+
107
+ // move the text cursor
108
+ const sse = getSelectedSlateEditor();
109
+ sse.type('{leftarrow}');
110
+ for (let i = 0; i < firstItemText.length; ++i) {
111
+ sse.type('{rightarrow}');
112
+ }
113
+
114
+ // simulate pressing Enter
115
+ getSelectedSlateEditor().lineBreakInSlate();
116
+
117
+ return s1;
118
+ };
119
+
120
+ export const selectSlateNodeOfWord = (el) => {
121
+ return cy.window().then((win) => {
122
+ var event = new CustomEvent('Test_SelectWord', {
123
+ detail: el[0],
124
+ });
125
+ win.document.dispatchEvent(event);
126
+ });
127
+ };
package/cypress.json CHANGED
@@ -1,9 +1,14 @@
1
1
  {
2
2
  "baseUrl": "http://localhost:3000",
3
3
  "viewportWidth": 1280,
4
- "defaultCommandTimeout": 15000,
4
+ "defaultCommandTimeout": 8888,
5
+ "chromeWebSecurity": false,
5
6
  "reporter": "junit",
6
7
  "video": true,
8
+ "retries": {
9
+ "runMode": 8,
10
+ "openMode": 0
11
+ },
7
12
  "reporterOptions": {
8
13
  "mochaFile": "cypress/reports/cypress-[hash].xml",
9
14
  "jenkinsMode": true,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@eeacms/volto-slate-metadata-mentions",
3
- "version": "3.0.0",
3
+ "version": "4.0.1",
4
4
  "description": "Volto Slate Metadata Mentions Plugin",
5
5
  "main": "src/index.js",
6
6
  "author": "European Environment Agency: IDM2 A-Team",
@@ -33,6 +33,8 @@
33
33
  },
34
34
  "scripts": {
35
35
  "release": "release-it",
36
+ "release-major-beta": "release-it major --preRelease=beta",
37
+ "release-beta": "release-it --preRelease=beta",
36
38
  "bootstrap": "npm install -g ejs; npm link ejs; node bootstrap",
37
39
  "test": "make test",
38
40
  "test:fix": "make test-update",
@@ -45,6 +47,8 @@
45
47
  "prettier:fix": "if [ -d ./project ]; then ./project/node_modules/.bin/prettier --single-quote --write 'src/**/*.{js,jsx,json,css,less,md}'; else ../../../node_modules/.bin/prettier --single-quote --write 'src/**/*.{js,jsx,json,css,less,md}'; fi",
46
48
  "lint": "if [ -d ./project ]; then ./project/node_modules/eslint/bin/eslint.js --max-warnings=0 'src/**/*.{js,jsx}'; else ../../../node_modules/eslint/bin/eslint.js --max-warnings=0 'src/**/*.{js,jsx}'; fi",
47
49
  "lint:fix": "if [ -d ./project ]; then ./project/node_modules/eslint/bin/eslint.js --fix 'src/**/*.{js,jsx}'; else ../../../node_modules/eslint/bin/eslint.js --fix 'src/**/*.{js,jsx}'; fi",
50
+ "cypress:backend": "make start-docker-backend",
51
+ "cypress:frontend": "make && cd project && yarn start",
48
52
  "cypress:run": "if [ -d ./project ]; then ./project/node_modules/cypress/bin/cypress run; else ../../../node_modules/cypress/bin/cypress run; fi",
49
53
  "cypress:open": "if [ -d ./project ]; then ./project/node_modules/cypress/bin/cypress open; else ../../../node_modules/cypress/bin/cypress open; fi"
50
54
  }
@@ -27,12 +27,15 @@ export default (props) => {
27
27
  (state) => state?.schema?.schema?.properties || {},
28
28
  );
29
29
 
30
+ const pid = `${editor.uid}-${pluginId}`;
31
+
30
32
  // Get formData
31
33
  // const context = useFormStateContext();
32
34
  // const { contextData, setContextData } = context;
33
35
  // const metaData = contextData.formData;
34
- const metaData =
35
- editor.getBlockProps().metadata || editor.getBlockProps().properties;
36
+ const metaData = editor.getBlockProps
37
+ ? editor.getBlockProps().metadata || editor.getBlockProps().properties
38
+ : {};
36
39
 
37
40
  const dispatch = useDispatch();
38
41
  const [formData, setFormData] = React.useState({});
@@ -60,7 +63,9 @@ export default (props) => {
60
63
 
61
64
  const saveDataToEditor = React.useCallback(
62
65
  (formData) => {
63
- const { onChangeField } = editor.getBlockProps(); // TODO: provide fake block props in volto-slate. onChangeField is onChange
66
+ const { onChangeField } = editor.getBlockProps
67
+ ? editor.getBlockProps()
68
+ : {}; // TODO: provide fake block props in volto-slate. onChangeField is onChange
64
69
  if (hasValue(formData)) {
65
70
  // hasValue(formData) = !!formData.footnote
66
71
  insertElement(editor, { id: formData?.id, widget: formData?.widget });
@@ -104,10 +109,7 @@ export default (props) => {
104
109
  choices: Object.keys(properties)
105
110
  .map((key) => {
106
111
  const val = properties[key];
107
- if (key !== 'id' && val?.type !== 'dict') {
108
- return [key, val?.title || key];
109
- }
110
- return false;
112
+ return [key, val?.title || key];
111
113
  })
112
114
  .filter((val) => !!val),
113
115
  },
@@ -125,8 +127,9 @@ export default (props) => {
125
127
 
126
128
  const onChangeValues = React.useCallback(
127
129
  (id, value) => {
128
- const metaData =
129
- editor.getBlockProps().metadata || editor.getBlockProps().properties;
130
+ const metaData = editor.getBlockProps
131
+ ? editor.getBlockProps().metadata || editor.getBlockProps().properties
132
+ : {};
130
133
  if (id === 'id') {
131
134
  setFormData({
132
135
  ...formData,
@@ -165,9 +168,7 @@ export default (props) => {
165
168
  <button
166
169
  onClick={() => {
167
170
  saveDataToEditor(formData);
168
- dispatch(
169
- setPluginOptions(pluginId, { show_sidebar_editor: false }),
170
- );
171
+ dispatch(setPluginOptions(pid, { show_sidebar_editor: false }));
171
172
  ReactEditor.focus(editor);
172
173
  }}
173
174
  >
@@ -176,9 +177,7 @@ export default (props) => {
176
177
  <button
177
178
  onClick={() => {
178
179
  checkForCancel();
179
- dispatch(
180
- setPluginOptions(pluginId, { show_sidebar_editor: false }),
181
- );
180
+ dispatch(setPluginOptions(pid, { show_sidebar_editor: false }));
182
181
  setFormData({});
183
182
  ReactEditor.focus(editor);
184
183
  }}
@@ -25,6 +25,7 @@ const ElementToolbarButton = (props) => {
25
25
  ];
26
26
 
27
27
  const properties = editor?.getBlockProps?.() || {};
28
+ const pid = `${editor.uid}-${pluginId}`;
28
29
  const visible = config.settings.layoutOnlySlateMetadataMentions
29
30
  ? properties?.manage
30
31
  : true;
@@ -37,7 +38,7 @@ const ElementToolbarButton = (props) => {
37
38
  active={isElement}
38
39
  onMouseDown={() => {
39
40
  if (!isElement) insertElement(editor, {});
40
- dispatch(setPluginOptions(pluginId, { show_sidebar_editor: true }));
41
+ dispatch(setPluginOptions(pid, { show_sidebar_editor: true }));
41
42
  }}
42
43
  icon={toolbarButtonIcon}
43
44
  />
@@ -36,6 +36,10 @@ const omittedProps = [
36
36
  'persistentHelper',
37
37
  ];
38
38
 
39
+ const btnFactory = (options) => (props) => (
40
+ <ToolbarButton {...props} {...options} title="Metadata" />
41
+ );
42
+
39
43
  export default (config) => {
40
44
  const opts = {
41
45
  title: 'Metadata',
@@ -63,13 +67,7 @@ export default (config) => {
63
67
  ];
64
68
 
65
69
  // Custom mention Toolbar Button
66
- slate.buttons['mention'] = (props) => (
67
- <ToolbarButton
68
- {...props}
69
- title="Metadata"
70
- {...omit(pluginOptions, omittedProps)}
71
- />
72
- );
70
+ slate.buttons['mention'] = btnFactory(omit(pluginOptions, omittedProps));
73
71
 
74
72
  return config;
75
73
  };
@@ -22,7 +22,7 @@ export const MentionElement = ({
22
22
  // props
23
23
  const editor = useEditorContext();
24
24
 
25
- if (editor) {
25
+ if (editor?.getBlockProps) {
26
26
  const blockProps = editor.getBlockProps();
27
27
  metadata = blockProps.metadata || blockProps.properties || {};
28
28
  }
@@ -1,32 +0,0 @@
1
- import { setupBeforeEach, tearDownAfterEach } from '../support';
2
-
3
- describe('Blocks Tests', () => {
4
- beforeEach(setupBeforeEach);
5
- afterEach(tearDownAfterEach);
6
-
7
- it('Add Block: Empty', () => {
8
- // Change page title
9
- cy.get('.documentFirstHeading > .public-DraftStyleDefault-block')
10
- .clear()
11
- .type('My Add-on Page')
12
- .get('.documentFirstHeading span[data-text]')
13
- .contains('My Add-on Page');
14
-
15
- cy.get('.documentFirstHeading > .public-DraftStyleDefault-block').type(
16
- '{enter}',
17
- );
18
-
19
- // Add block
20
- cy.get('.ui.basic.icon.button.block-add-button').first().click();
21
- cy.get('.blocks-chooser .title').contains('Media').click();
22
- cy.get('.content.active.media .button.image').contains('Image').click();
23
-
24
- // Save
25
- cy.get('#toolbar-save').click();
26
- cy.url().should('eq', Cypress.config().baseUrl + '/cypress/my-page');
27
-
28
- // then the page view should contain our changes
29
- cy.contains('My Add-on Page');
30
- cy.get('.block.image');
31
- });
32
- });