@eeacms/volto-widget-toggle 2.2.1 → 2.2.5
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/.coverage.babel.config.js +9 -0
- package/CHANGELOG.md +27 -4
- package/Jenkinsfile +122 -41
- package/README.md +87 -0
- package/bootstrap +14 -3
- package/cypress/fixtures/example.json +5 -0
- package/cypress/integration/block-basics.js +33 -0
- package/cypress/plugins/index.js +26 -0
- package/cypress/support/commands.js +315 -0
- package/cypress/support/index.js +53 -0
- package/cypress.json +1 -0
- package/package.json +11 -3
- package/src/components/manage/Widgets/CheckboxWidget.jsx +15 -4
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
const defaultBabel = require('@plone/volto/babel');
|
|
2
|
+
|
|
3
|
+
function applyDefault(api) {
|
|
4
|
+
const voltoBabel = defaultBabel(api);
|
|
5
|
+
voltoBabel.plugins.push('@babel/plugin-transform-modules-commonjs', 'transform-class-properties', 'istanbul');
|
|
6
|
+
return voltoBabel;
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
module.exports = applyDefault;
|
package/CHANGELOG.md
CHANGED
|
@@ -4,9 +4,35 @@ 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
|
+
#### [2.2.5](https://github.com/eea/volto-widget-toggle/compare/2.2.4...2.2.5)
|
|
8
|
+
|
|
9
|
+
- Add SonarQube badges [`eb74b75`](https://github.com/eea/volto-widget-toggle/commit/eb74b75a72725a3a240e44c1bfd3f086854b0296)
|
|
10
|
+
|
|
11
|
+
#### [2.2.4](https://github.com/eea/volto-widget-toggle/compare/2.2.3...2.2.4)
|
|
12
|
+
|
|
13
|
+
> 10 December 2021
|
|
14
|
+
|
|
15
|
+
- Develop [`#6`](https://github.com/eea/volto-widget-toggle/pull/6)
|
|
16
|
+
- Correct Cypress tests [`#5`](https://github.com/eea/volto-widget-toggle/pull/5)
|
|
17
|
+
- Refs #142010 - Optimize Volto-addons gitflow pipelines [`2bd2039`](https://github.com/eea/volto-widget-toggle/commit/2bd203979963ee5cb15592470e1d341d1bd65291)
|
|
18
|
+
|
|
19
|
+
#### [2.2.3](https://github.com/eea/volto-widget-toggle/compare/2.2.2...2.2.3)
|
|
20
|
+
|
|
21
|
+
> 28 June 2021
|
|
22
|
+
|
|
23
|
+
- refactor code, introduce defaultValue prop to handle default state when value is null or undefined [`#4`](https://github.com/eea/volto-widget-toggle/pull/4)
|
|
24
|
+
- refactor code, introduce defaultValue prop to handle default state when value is null [`560d23f`](https://github.com/eea/volto-widget-toggle/commit/560d23f785e7780cdb30197c2ebc999b85961f46)
|
|
25
|
+
|
|
26
|
+
#### [2.2.2](https://github.com/eea/volto-widget-toggle/compare/2.2.1...2.2.2)
|
|
27
|
+
|
|
28
|
+
> 4 June 2021
|
|
29
|
+
|
|
30
|
+
- Cypress coverage [`#3`](https://github.com/eea/volto-widget-toggle/pull/3)
|
|
31
|
+
|
|
7
32
|
#### [2.2.1](https://github.com/eea/volto-widget-toggle/compare/2.2.0...2.2.1)
|
|
8
33
|
|
|
9
|
-
|
|
34
|
+
> 14 May 2021
|
|
35
|
+
|
|
10
36
|
|
|
11
37
|
#### [2.2.0](https://github.com/eea/volto-widget-toggle/compare/2.1.0...2.2.0)
|
|
12
38
|
|
|
@@ -20,7 +46,6 @@ Generated by [`auto-changelog`](https://github.com/CookPete/auto-changelog).
|
|
|
20
46
|
> 8 March 2021
|
|
21
47
|
|
|
22
48
|
- Release 2.1.0 [`8a77751`](https://github.com/eea/volto-widget-toggle/commit/8a77751a8eaa3817f4831a21365768387321dc50)
|
|
23
|
-
- Cleanup DEPENDENCIES from Jenkinsfile [`41eb8ba`](https://github.com/eea/volto-widget-toggle/commit/41eb8ba076da6feed4bfc8f05ed1c18678b4a434)
|
|
24
49
|
|
|
25
50
|
### [2.0.0](https://github.com/eea/volto-widget-toggle/compare/1.0.1...2.0.0)
|
|
26
51
|
|
|
@@ -35,8 +60,6 @@ Generated by [`auto-changelog`](https://github.com/CookPete/auto-changelog).
|
|
|
35
60
|
|
|
36
61
|
- Release 1.0.1 [`454220f`](https://github.com/eea/volto-widget-toggle/commit/454220fa61495427f874fb9b56401fe69689f4fe)
|
|
37
62
|
- Auto-release npm [`10b31b3`](https://github.com/eea/volto-widget-toggle/commit/10b31b3b64330d41f69a033a45030e49d20c16b5)
|
|
38
|
-
- [JENKINS] - Add pipeline, update docs [`fb5c3ac`](https://github.com/eea/volto-widget-toggle/commit/fb5c3ac401b10e07dd67949d01eae116d7458a79)
|
|
39
|
-
- yarn prettier [`5136059`](https://github.com/eea/volto-widget-toggle/commit/51360595bf452c815e526ce10f15aa8a84ad186f)
|
|
40
63
|
|
|
41
64
|
### [1.0.0](https://github.com/eea/volto-widget-toggle/compare/0.1.0...1.0.0)
|
|
42
65
|
|
package/Jenkinsfile
CHANGED
|
@@ -4,12 +4,37 @@ pipeline {
|
|
|
4
4
|
environment {
|
|
5
5
|
GIT_NAME = "volto-widget-toggle"
|
|
6
6
|
NAMESPACE = "@eeacms"
|
|
7
|
-
SONARQUBE_TAGS = "volto.eea.europa.eu"
|
|
7
|
+
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"
|
|
8
|
+
DEPENDENCIES = ""
|
|
8
9
|
}
|
|
9
10
|
|
|
10
11
|
stages {
|
|
11
12
|
|
|
13
|
+
stage('Release') {
|
|
14
|
+
when {
|
|
15
|
+
allOf {
|
|
16
|
+
environment name: 'CHANGE_ID', value: ''
|
|
17
|
+
branch 'master'
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
steps {
|
|
21
|
+
node(label: 'docker') {
|
|
22
|
+
withCredentials([string(credentialsId: 'eea-jenkins-token', variable: 'GITHUB_TOKEN'),string(credentialsId: 'eea-jenkins-npm-token', variable: 'NPM_TOKEN')]) {
|
|
23
|
+
sh '''docker pull eeacms/gitflow'''
|
|
24
|
+
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'''
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
|
|
12
30
|
stage('Code') {
|
|
31
|
+
when {
|
|
32
|
+
allOf {
|
|
33
|
+
environment name: 'CHANGE_ID', value: ''
|
|
34
|
+
not { changelog '.*^Automated release [0-9\\.]+$' }
|
|
35
|
+
not { branch 'master' }
|
|
36
|
+
}
|
|
37
|
+
}
|
|
13
38
|
steps {
|
|
14
39
|
parallel(
|
|
15
40
|
|
|
@@ -35,6 +60,15 @@ pipeline {
|
|
|
35
60
|
}
|
|
36
61
|
|
|
37
62
|
stage('Tests') {
|
|
63
|
+
when {
|
|
64
|
+
allOf {
|
|
65
|
+
environment name: 'CHANGE_ID', value: ''
|
|
66
|
+
anyOf {
|
|
67
|
+
not { changelog '.*^Automated release [0-9\\.]+$' }
|
|
68
|
+
branch 'master'
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
}
|
|
38
72
|
steps {
|
|
39
73
|
parallel(
|
|
40
74
|
|
|
@@ -44,13 +78,13 @@ pipeline {
|
|
|
44
78
|
try {
|
|
45
79
|
sh '''docker pull plone/volto-addon-ci'''
|
|
46
80
|
sh '''docker run -i --name="$BUILD_TAG-volto" -e NAMESPACE="$NAMESPACE" -e GIT_NAME=$GIT_NAME -e GIT_BRANCH="$BRANCH_NAME" -e GIT_CHANGE_ID="$CHANGE_ID" plone/volto-addon-ci'''
|
|
81
|
+
sh '''rm -rf xunit-reports'''
|
|
47
82
|
sh '''mkdir -p xunit-reports'''
|
|
48
83
|
sh '''docker cp $BUILD_TAG-volto:/opt/frontend/my-volto-project/coverage xunit-reports/'''
|
|
49
84
|
sh '''docker cp $BUILD_TAG-volto:/opt/frontend/my-volto-project/junit.xml xunit-reports/'''
|
|
50
85
|
sh '''docker cp $BUILD_TAG-volto:/opt/frontend/my-volto-project/unit_tests_log.txt xunit-reports/'''
|
|
51
|
-
stash name: "xunit-reports", includes: "xunit-reports
|
|
52
|
-
|
|
53
|
-
archiveArtifacts artifacts: 'xunit-reports/unit_tests_log.txt', fingerprint: true
|
|
86
|
+
stash name: "xunit-reports", includes: "xunit-reports/**"
|
|
87
|
+
archiveArtifacts artifacts: "xunit-reports/unit_tests_log.txt", fingerprint: true
|
|
54
88
|
publishHTML (target : [
|
|
55
89
|
allowMissing: false,
|
|
56
90
|
alwaysLinkToLastBuild: true,
|
|
@@ -61,20 +95,85 @@ pipeline {
|
|
|
61
95
|
reportTitles: 'Unit Tests Code Coverage'
|
|
62
96
|
])
|
|
63
97
|
} finally {
|
|
64
|
-
|
|
98
|
+
catchError(buildResult: 'SUCCESS', stageResult: 'SUCCESS') {
|
|
99
|
+
junit testResults: 'xunit-reports/junit.xml', allowEmptyResults: true
|
|
100
|
+
}
|
|
101
|
+
sh script: '''docker rm -v $BUILD_TAG-volto''', returnStatus: true
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
)
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
stage('Integration tests') {
|
|
111
|
+
when {
|
|
112
|
+
allOf {
|
|
113
|
+
environment name: 'CHANGE_ID', value: ''
|
|
114
|
+
anyOf {
|
|
115
|
+
not { changelog '.*^Automated release [0-9\\.]+$' }
|
|
116
|
+
branch 'master'
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
steps {
|
|
121
|
+
parallel(
|
|
122
|
+
|
|
123
|
+
"Cypress": {
|
|
124
|
+
node(label: 'docker') {
|
|
125
|
+
script {
|
|
126
|
+
try {
|
|
127
|
+
sh '''docker pull plone; docker run -d --name="$BUILD_TAG-plone" -e SITE="Plone" -e PROFILES="profile-plone.restapi:blocks" plone fg'''
|
|
128
|
+
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'''
|
|
129
|
+
} finally {
|
|
130
|
+
try {
|
|
131
|
+
sh '''rm -rf cypress-reports cypress-results cypress-coverage'''
|
|
132
|
+
sh '''mkdir -p cypress-reports cypress-results cypress-coverage'''
|
|
133
|
+
sh '''docker cp $BUILD_TAG-cypress:/opt/frontend/my-volto-project/src/addons/$GIT_NAME/cypress/videos cypress-reports/'''
|
|
134
|
+
sh '''docker cp $BUILD_TAG-cypress:/opt/frontend/my-volto-project/src/addons/$GIT_NAME/cypress/reports cypress-results/'''
|
|
135
|
+
coverage = sh script: '''docker cp $BUILD_TAG-cypress:/opt/frontend/my-volto-project/src/addons/$GIT_NAME/coverage cypress-coverage/''', returnStatus: true
|
|
136
|
+
if ( coverage == 0 ) {
|
|
137
|
+
publishHTML (target : [allowMissing: false,
|
|
138
|
+
alwaysLinkToLastBuild: true,
|
|
139
|
+
keepAll: true,
|
|
140
|
+
reportDir: 'cypress-coverage/coverage/lcov-report',
|
|
141
|
+
reportFiles: 'index.html',
|
|
142
|
+
reportName: 'CypressCoverage',
|
|
143
|
+
reportTitles: 'Integration Tests Code Coverage'])
|
|
144
|
+
}
|
|
145
|
+
archiveArtifacts artifacts: 'cypress-reports/videos/*.mp4', fingerprint: true
|
|
146
|
+
stash name: "cypress-coverage", includes: "cypress-coverage/**", allowEmpty: true
|
|
147
|
+
}
|
|
148
|
+
finally {
|
|
149
|
+
catchError(buildResult: 'SUCCESS', stageResult: 'SUCCESS') {
|
|
150
|
+
junit testResults: 'cypress-results/**/*.xml', allowEmptyResults: true
|
|
151
|
+
}
|
|
152
|
+
sh script: "docker stop $BUILD_TAG-plone", returnStatus: true
|
|
153
|
+
sh script: "docker rm -v $BUILD_TAG-plone", returnStatus: true
|
|
154
|
+
sh script: "docker rm -v $BUILD_TAG-cypress", returnStatus: true
|
|
155
|
+
|
|
156
|
+
}
|
|
65
157
|
}
|
|
66
158
|
}
|
|
67
159
|
}
|
|
68
160
|
}
|
|
161
|
+
|
|
69
162
|
)
|
|
70
163
|
}
|
|
71
164
|
}
|
|
72
165
|
|
|
73
166
|
stage('Report to SonarQube') {
|
|
74
|
-
// Exclude Pull-Requests
|
|
75
167
|
when {
|
|
76
168
|
allOf {
|
|
77
169
|
environment name: 'CHANGE_ID', value: ''
|
|
170
|
+
anyOf {
|
|
171
|
+
branch 'master'
|
|
172
|
+
allOf {
|
|
173
|
+
branch 'develop'
|
|
174
|
+
not { changelog '.*^Automated release [0-9\\.]+$' }
|
|
175
|
+
}
|
|
176
|
+
}
|
|
78
177
|
}
|
|
79
178
|
}
|
|
80
179
|
steps {
|
|
@@ -82,11 +181,12 @@ pipeline {
|
|
|
82
181
|
script{
|
|
83
182
|
checkout scm
|
|
84
183
|
unstash "xunit-reports"
|
|
184
|
+
unstash "cypress-coverage"
|
|
85
185
|
def scannerHome = tool 'SonarQubeScanner';
|
|
86
186
|
def nodeJS = tool 'NodeJS11';
|
|
87
187
|
withSonarQubeEnv('Sonarqube') {
|
|
88
188
|
sh '''sed -i "s#/opt/frontend/my-volto-project/src/addons/${GIT_NAME}/##g" xunit-reports/coverage/lcov.info'''
|
|
89
|
-
sh "export PATH=$PATH:${scannerHome}/bin:${nodeJS}/bin; sonar-scanner -Dsonar.javascript.lcov.reportPaths=./xunit-reports/coverage/lcov.info -Dsonar.sources=./src -Dsonar.
|
|
189
|
+
sh "export PATH=$PATH:${scannerHome}/bin:${nodeJS}/bin; sonar-scanner -Dsonar.javascript.lcov.reportPaths=./xunit-reports/coverage/lcov.info,./cypress-coverage/coverage/lcov.info -Dsonar.sources=./src -Dsonar.projectKey=$GIT_NAME-$BRANCH_NAME -Dsonar.projectVersion=$BRANCH_NAME-$BUILD_NUMBER"
|
|
90
190
|
sh '''try=2; while [ \$try -gt 0 ]; do curl -s -XPOST -u "${SONAR_AUTH_TOKEN}:" "${SONAR_HOST_URL}api/project_tags/set?project=${GIT_NAME}-${BRANCH_NAME}&tags=${SONARQUBE_TAGS},${BRANCH_NAME}" > set_tags_result; if [ \$(grep -ic error set_tags_result ) -eq 0 ]; then try=0; else cat set_tags_result; echo "... Will retry"; sleep 60; try=\$(( \$try - 1 )); fi; done'''
|
|
91
191
|
}
|
|
92
192
|
}
|
|
@@ -104,55 +204,36 @@ pipeline {
|
|
|
104
204
|
steps {
|
|
105
205
|
node(label: 'docker') {
|
|
106
206
|
script {
|
|
107
|
-
if ( env.CHANGE_BRANCH != "develop"
|
|
108
|
-
error "Pipeline aborted due to PR not made from develop
|
|
207
|
+
if ( env.CHANGE_BRANCH != "develop" ) {
|
|
208
|
+
error "Pipeline aborted due to PR not made from develop branch"
|
|
109
209
|
}
|
|
110
210
|
withCredentials([string(credentialsId: 'eea-jenkins-token', variable: 'GITHUB_TOKEN')]) {
|
|
111
211
|
sh '''docker pull eeacms/gitflow'''
|
|
112
|
-
sh '''docker run -i --rm --name="$BUILD_TAG-gitflow-pr" -e GIT_CHANGE_TARGET="$CHANGE_TARGET" -e GIT_CHANGE_BRANCH="$CHANGE_BRANCH" -e GIT_CHANGE_AUTHOR="$CHANGE_AUTHOR" -e GIT_CHANGE_TITLE="$CHANGE_TITLE" -e GIT_TOKEN="$GITHUB_TOKEN" -e GIT_BRANCH="$BRANCH_NAME" -e GIT_CHANGE_ID="$CHANGE_ID" -e GIT_ORG="$GIT_ORG" -e GIT_NAME="$GIT_NAME" eeacms/gitflow'''
|
|
212
|
+
sh '''docker run -i --rm --name="$BUILD_TAG-gitflow-pr" -e GIT_CHANGE_TARGET="$CHANGE_TARGET" -e GIT_CHANGE_BRANCH="$CHANGE_BRANCH" -e GIT_CHANGE_AUTHOR="$CHANGE_AUTHOR" -e GIT_CHANGE_TITLE="$CHANGE_TITLE" -e GIT_TOKEN="$GITHUB_TOKEN" -e GIT_BRANCH="$BRANCH_NAME" -e GIT_CHANGE_ID="$CHANGE_ID" -e GIT_ORG="$GIT_ORG" -e GIT_NAME="$GIT_NAME" -e LANGUAGE=javascript eeacms/gitflow'''
|
|
113
213
|
}
|
|
114
214
|
}
|
|
115
215
|
}
|
|
116
216
|
}
|
|
117
217
|
}
|
|
118
218
|
|
|
119
|
-
stage('Release') {
|
|
120
|
-
when {
|
|
121
|
-
allOf {
|
|
122
|
-
environment name: 'CHANGE_ID', value: ''
|
|
123
|
-
branch 'master'
|
|
124
|
-
}
|
|
125
|
-
}
|
|
126
|
-
steps {
|
|
127
|
-
node(label: 'docker') {
|
|
128
|
-
withCredentials([string(credentialsId: 'eea-jenkins-token', variable: 'GITHUB_TOKEN'),string(credentialsId: 'eea-jenkins-npm-token', variable: 'NPM_TOKEN')]) {
|
|
129
|
-
sh '''docker pull eeacms/gitflow'''
|
|
130
|
-
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" eeacms/gitflow'''
|
|
131
|
-
}
|
|
132
|
-
}
|
|
133
|
-
}
|
|
134
|
-
}
|
|
135
219
|
}
|
|
136
220
|
|
|
137
221
|
post {
|
|
222
|
+
always {
|
|
223
|
+
cleanWs(cleanWhenAborted: true, cleanWhenFailure: true, cleanWhenNotBuilt: true, cleanWhenSuccess: true, cleanWhenUnstable: true, deleteDirs: true)
|
|
224
|
+
}
|
|
138
225
|
changed {
|
|
139
226
|
script {
|
|
140
|
-
def
|
|
141
|
-
|
|
142
|
-
def subject = "${status}: Job '${env.JOB_NAME} [${env.BUILD_NUMBER}]'"
|
|
143
|
-
def summary = "${subject} (${url})"
|
|
144
|
-
def details = """<h1>${env.JOB_NAME} - Build #${env.BUILD_NUMBER} - ${status}</h1>
|
|
145
|
-
<p>Check console output at <a href="${url}">${env.JOB_BASE_NAME} - #${env.BUILD_NUMBER}</a></p>
|
|
227
|
+
def details = """<h1>${env.JOB_NAME} - Build #${env.BUILD_NUMBER} - ${currentBuild.currentResult}</h1>
|
|
228
|
+
<p>Check console output at <a href="${env.BUILD_URL}/display/redirect">${env.JOB_BASE_NAME} - #${env.BUILD_NUMBER}</a></p>
|
|
146
229
|
"""
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
emailext (subject: '$DEFAULT_SUBJECT', to: '$DEFAULT_RECIPIENTS', body: details)
|
|
230
|
+
emailext(
|
|
231
|
+
subject: '$DEFAULT_SUBJECT',
|
|
232
|
+
body: details,
|
|
233
|
+
attachLog: true,
|
|
234
|
+
compressLog: true,
|
|
235
|
+
recipientProviders: [[$class: 'DevelopersRecipientProvider'], [$class: 'CulpritsRecipientProvider']]
|
|
236
|
+
)
|
|
156
237
|
}
|
|
157
238
|
}
|
|
158
239
|
}
|
package/README.md
CHANGED
|
@@ -1,7 +1,19 @@
|
|
|
1
1
|
# volto-widget-toggle
|
|
2
|
+
|
|
2
3
|
[](https://github.com/eea/volto-widget-toggle/releases)
|
|
4
|
+
|
|
3
5
|
[](https://ci.eionet.europa.eu/view/Github/job/volto-addons/job/volto-widget-toggle/job/master/display/redirect)
|
|
6
|
+
[](https://sonarqube.eea.europa.eu/dashboard?id=volto-widget-toggle-master)
|
|
7
|
+
[](https://sonarqube.eea.europa.eu/dashboard?id=volto-widget-toggle-master)
|
|
8
|
+
[](https://sonarqube.eea.europa.eu/dashboard?id=volto-widget-toggle-master)
|
|
9
|
+
[](https://sonarqube.eea.europa.eu/dashboard?id=volto-widget-toggle-master)
|
|
10
|
+
|
|
4
11
|
[](https://ci.eionet.europa.eu/view/Github/job/volto-addons/job/volto-widget-toggle/job/develop/display/redirect)
|
|
12
|
+
[](https://sonarqube.eea.europa.eu/dashboard?id=volto-widget-toggle-develop)
|
|
13
|
+
[](https://sonarqube.eea.europa.eu/dashboard?id=volto-widget-toggle-develop)
|
|
14
|
+
[](https://sonarqube.eea.europa.eu/dashboard?id=volto-widget-toggle-develop)
|
|
15
|
+
[](https://sonarqube.eea.europa.eu/dashboard?id=volto-widget-toggle-develop)
|
|
16
|
+
|
|
5
17
|
|
|
6
18
|
[Volto](https://github.com/plone/volto) add-on: Replace any checkbox with a nice toggle button within edit forms
|
|
7
19
|
|
|
@@ -44,6 +56,81 @@
|
|
|
44
56
|
|
|
45
57
|
1. Happy editing!
|
|
46
58
|
|
|
59
|
+
## Release
|
|
60
|
+
|
|
61
|
+
### Automatic release using Jenkins
|
|
62
|
+
|
|
63
|
+
* 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.
|
|
64
|
+
* It runs on every commit on `master` branch, which is protected from direct commits, only allowing pull request merge commits.
|
|
65
|
+
* 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.
|
|
66
|
+
* 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.
|
|
67
|
+
* 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.
|
|
68
|
+
* The version format must be MAJOR.MINOR.PATCH. By default, next release is set to next minor version (with patch 0).
|
|
69
|
+
* 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.
|
|
70
|
+
* Automated commits and commits with [JENKINS] or [YARN] in the commit log are excluded from `CHANGELOG.md` file.
|
|
71
|
+
|
|
72
|
+
### Manual release from the develop branch ( beta release )
|
|
73
|
+
|
|
74
|
+
#### Installation and configuration of release-it
|
|
75
|
+
|
|
76
|
+
You need to first install the [release-it](https://github.com/release-it/release-it) client.
|
|
77
|
+
|
|
78
|
+
```
|
|
79
|
+
npm install -g release-it
|
|
80
|
+
```
|
|
81
|
+
|
|
82
|
+
Release-it uses the configuration written in the [`.release-it.json`](./.release-it.json) file located in the root of the repository.
|
|
83
|
+
|
|
84
|
+
Release-it is a tool that automates 4 important steps in the release process:
|
|
85
|
+
|
|
86
|
+
1. Version increase in `package.json` ( increased from the current version in `package.json`)
|
|
87
|
+
2. `CHANGELOG.md` automatic generation from commit messages ( grouped by releases )
|
|
88
|
+
3. GitHub release on the commit with the changelog and package.json modification on the develop branch
|
|
89
|
+
4. NPM release ( by default it's disabled, but can be enabled in the configuration file )
|
|
90
|
+
|
|
91
|
+
To configure the authentification, you need to export GITHUB_TOKEN for [GitHub](https://github.com/settings/tokens)
|
|
92
|
+
|
|
93
|
+
```
|
|
94
|
+
export GITHUB_TOKEN=XXX-XXXXXXXXXXXXXXXXXXXXXX
|
|
95
|
+
```
|
|
96
|
+
|
|
97
|
+
To configure npm, you can use the `npm login` command or use a configuration file with a TOKEN :
|
|
98
|
+
|
|
99
|
+
```
|
|
100
|
+
echo "//registry.npmjs.org/:_authToken=YYYYYYYYYYYYYYYYYYYYYYYYYYYYYY" > .npmrc
|
|
101
|
+
```
|
|
102
|
+
|
|
103
|
+
#### Using release-it tool
|
|
104
|
+
|
|
105
|
+
There are 3 yarn scripts that can be run to do the release
|
|
106
|
+
|
|
107
|
+
##### yarn release-beta
|
|
108
|
+
|
|
109
|
+
Automatically calculates and presents 3 beta versions - patch, minor and major for you to choose ( or Other for manual input).
|
|
110
|
+
|
|
111
|
+
```
|
|
112
|
+
? Select increment (next version):
|
|
113
|
+
❯ prepatch (0.1.1-beta.0)
|
|
114
|
+
preminor (0.2.0-beta.0)
|
|
115
|
+
premajor (1.0.0-beta.0)
|
|
116
|
+
Other, please specify...
|
|
117
|
+
```
|
|
118
|
+
|
|
119
|
+
##### yarn release-major-beta
|
|
120
|
+
|
|
121
|
+
Same as `yarn release-beta`, but with premajor version pre-selected.
|
|
122
|
+
|
|
123
|
+
##### yarn release
|
|
124
|
+
|
|
125
|
+
Generic command, does not automatically add the `beta` to version, but you can still manually write it if you choose Other.
|
|
126
|
+
|
|
127
|
+
#### Important notes
|
|
128
|
+
|
|
129
|
+
> 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.
|
|
130
|
+
|
|
131
|
+
> 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).
|
|
132
|
+
|
|
133
|
+
|
|
47
134
|
## How to contribute
|
|
48
135
|
|
|
49
136
|
See [DEVELOP.md](https://github.com/eea/volto-widget-toggle/blob/master/DEVELOP.md).
|
package/bootstrap
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
const path = require('path');
|
|
2
2
|
const fs = require('fs');
|
|
3
|
+
const ejs = require('ejs');
|
|
3
4
|
|
|
4
5
|
const currentDir = path.basename(process.cwd());
|
|
5
6
|
|
|
@@ -8,13 +9,23 @@ const bootstrap = function (ofile) {
|
|
|
8
9
|
if (err) {
|
|
9
10
|
return console.log(err);
|
|
10
11
|
}
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
12
|
+
const result = ejs.render(data, {
|
|
13
|
+
addonName: `@eeacms/${currentDir}`,
|
|
14
|
+
name: currentDir
|
|
15
|
+
});
|
|
16
|
+
const output = ofile.replace('.tpl', '');
|
|
17
|
+
fs.writeFile(output, result, 'utf8', function (err) {
|
|
14
18
|
if (err) {
|
|
15
19
|
return console.log(err);
|
|
16
20
|
}
|
|
17
21
|
});
|
|
22
|
+
if (ofile.includes('.tpl')) {
|
|
23
|
+
fs.unlink(ofile, (err) => {
|
|
24
|
+
if (err) {
|
|
25
|
+
return console.error(err);
|
|
26
|
+
}
|
|
27
|
+
});
|
|
28
|
+
}
|
|
18
29
|
});
|
|
19
30
|
}
|
|
20
31
|
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { setupBeforeEach, tearDownAfterEach } from '../support';
|
|
2
|
+
|
|
3
|
+
describe('Blocks Tests', () => {
|
|
4
|
+
beforeEach(setupBeforeEach);
|
|
5
|
+
afterEach(tearDownAfterEach);
|
|
6
|
+
|
|
7
|
+
it('Add Block: Empty', () => {
|
|
8
|
+
// without this the clear command below does nothing sometimes
|
|
9
|
+
cy.wait(500);
|
|
10
|
+
|
|
11
|
+
// Change page title
|
|
12
|
+
cy.get('[contenteditable=true]').first().clear();
|
|
13
|
+
|
|
14
|
+
cy.get('[contenteditable=true]').first().type('My Add-on Page');
|
|
15
|
+
|
|
16
|
+
cy.get('.documentFirstHeading').contains('My Add-on Page');
|
|
17
|
+
|
|
18
|
+
cy.get('[contenteditable=true]').first().type('{enter}');
|
|
19
|
+
|
|
20
|
+
// Add block
|
|
21
|
+
cy.get('.ui.basic.icon.button.block-add-button').first().click();
|
|
22
|
+
cy.get('.blocks-chooser .title').contains('Media').click();
|
|
23
|
+
cy.get('.content.active.media .button.image').contains('Image').click();
|
|
24
|
+
|
|
25
|
+
// Save
|
|
26
|
+
cy.get('#toolbar-save').click();
|
|
27
|
+
cy.url().should('eq', Cypress.config().baseUrl + '/cypress/my-page');
|
|
28
|
+
|
|
29
|
+
// then the page view should contain our changes
|
|
30
|
+
cy.contains('My Add-on Page');
|
|
31
|
+
cy.get('.block.image');
|
|
32
|
+
});
|
|
33
|
+
});
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
/// <reference types="cypress" />
|
|
2
|
+
// ***********************************************************
|
|
3
|
+
// This example plugins/index.js can be used to load plugins
|
|
4
|
+
//
|
|
5
|
+
// You can change the location of this file or turn off loading
|
|
6
|
+
// the plugins file with the 'pluginsFile' configuration option.
|
|
7
|
+
//
|
|
8
|
+
// You can read more here:
|
|
9
|
+
// https://on.cypress.io/plugins-guide
|
|
10
|
+
// ***********************************************************
|
|
11
|
+
|
|
12
|
+
// This function is called when a project is opened or re-opened (e.g. due to
|
|
13
|
+
// the project's config changing)
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* @type {Cypress.PluginConfig}
|
|
17
|
+
*/
|
|
18
|
+
module.exports = (on, config) => {
|
|
19
|
+
// `on` is used to hook into various events Cypress emits
|
|
20
|
+
// `config` is the resolved Cypress config
|
|
21
|
+
/* coverage-start
|
|
22
|
+
require('@cypress/code-coverage/task')(on, config)
|
|
23
|
+
on('file:preprocessor', require('@cypress/code-coverage/use-babelrc'))
|
|
24
|
+
return config
|
|
25
|
+
coverage-end */
|
|
26
|
+
};
|
|
@@ -0,0 +1,315 @@
|
|
|
1
|
+
/* eslint no-console: ["error", { allow: ["log"] }] */
|
|
2
|
+
|
|
3
|
+
// --- AUTOLOGIN -------------------------------------------------------------
|
|
4
|
+
Cypress.Commands.add('autologin', () => {
|
|
5
|
+
let api_url, user, password;
|
|
6
|
+
api_url = Cypress.env('API_PATH') || 'http://localhost:8080/Plone';
|
|
7
|
+
user = 'admin';
|
|
8
|
+
password = 'admin';
|
|
9
|
+
|
|
10
|
+
return cy
|
|
11
|
+
.request({
|
|
12
|
+
method: 'POST',
|
|
13
|
+
url: `${api_url}/@login`,
|
|
14
|
+
headers: { Accept: 'application/json' },
|
|
15
|
+
body: { login: user, password: password },
|
|
16
|
+
})
|
|
17
|
+
.then((response) => cy.setCookie('auth_token', response.body.token));
|
|
18
|
+
});
|
|
19
|
+
|
|
20
|
+
// --- CREATE CONTENT --------------------------------------------------------
|
|
21
|
+
Cypress.Commands.add(
|
|
22
|
+
'createContent',
|
|
23
|
+
({
|
|
24
|
+
contentType,
|
|
25
|
+
contentId,
|
|
26
|
+
contentTitle,
|
|
27
|
+
path = '',
|
|
28
|
+
allow_discussion = false,
|
|
29
|
+
}) => {
|
|
30
|
+
let api_url, auth;
|
|
31
|
+
api_url = Cypress.env('API_PATH') || 'http://localhost:8080/Plone';
|
|
32
|
+
auth = {
|
|
33
|
+
user: 'admin',
|
|
34
|
+
pass: 'admin',
|
|
35
|
+
};
|
|
36
|
+
if (contentType === 'File') {
|
|
37
|
+
return cy.request({
|
|
38
|
+
method: 'POST',
|
|
39
|
+
url: `${api_url}/${path}`,
|
|
40
|
+
headers: {
|
|
41
|
+
Accept: 'application/json',
|
|
42
|
+
},
|
|
43
|
+
auth: auth,
|
|
44
|
+
body: {
|
|
45
|
+
'@type': contentType,
|
|
46
|
+
id: contentId,
|
|
47
|
+
title: contentTitle,
|
|
48
|
+
file: {
|
|
49
|
+
data: 'dGVzdGZpbGUK',
|
|
50
|
+
encoding: 'base64',
|
|
51
|
+
filename: 'lorem.txt',
|
|
52
|
+
'content-type': 'text/plain',
|
|
53
|
+
},
|
|
54
|
+
allow_discussion: allow_discussion,
|
|
55
|
+
},
|
|
56
|
+
});
|
|
57
|
+
}
|
|
58
|
+
if (contentType === 'Image') {
|
|
59
|
+
return cy.request({
|
|
60
|
+
method: 'POST',
|
|
61
|
+
url: `${api_url}/${path}`,
|
|
62
|
+
headers: {
|
|
63
|
+
Accept: 'application/json',
|
|
64
|
+
},
|
|
65
|
+
auth: auth,
|
|
66
|
+
body: {
|
|
67
|
+
'@type': contentType,
|
|
68
|
+
id: contentId,
|
|
69
|
+
title: contentTitle,
|
|
70
|
+
image: {
|
|
71
|
+
data:
|
|
72
|
+
'iVBORw0KGgoAAAANSUhEUgAAANcAAAA4CAMAAABZsZ3QAAAAM1BMVEX29fK42OU+oMvn7u9drtIPisHI4OhstdWZyt4fkcXX5+sAg74umMhNp86p0eJ7vNiKw9v/UV4wAAAAAXRSTlMAQObYZgAABBxJREFUeF7tmuty4yAMhZG4X2zn/Z92J5tsBJwWXG/i3XR6frW2Y/SBLIRAfaQUDNt8E5tLUt9BycfcKfq3R6Mlfyimtx4rzp+K3dtibXkor99zsEqLYZltblTecciogoh+TXfY1Ve4dn07rCDGG9dHSEEOg/GmXl0U1XDxTKxNK5De7BxsyyBr6gGm2/vPxKJ8F6f7BXKfRMp1xIWK9A+5ks25alSb353dWnDJN1k35EL5f8dVGifTf/4tjUuuFq7u4srmXC60yAmldLXIWbg65RKU87lcGxJCFqUPv0IacW0PmSivOZFLE908inPToMmii/roG+MRV/O8FU88i8tFsxV3a06MFUw0Qu7RmAtdV5/HVVaOVMTWNOWSwMljLhzhcB6XIS7OK5V6AvRDNN7t5VJWQs1J40UmalbK56usBG/CuCHSYuc+rkUGeMCViNRARPrzW52N3oQLe6WifNliSuuGaH3czbVNudI9s7ZLUCLHVwWlyES522o1t14uvmbblmVTKqFjaZYJFSTPP4dLL1kU1z7p0lzdbRulmEWLxoQX+z9ce7A8GqEEucllLxePuZwdJl1Lezu0hoswvTPt61DrFcRuujV/2cmlxaGBC7Aw6cpovGANwRiSdOAWJ5AGy4gLL64dl0QhUEAuEUNws+XxV+OKGPdw/hESGYF9XEGaFC7sNLMSXWJjHsnanYi87VK428N2uxpOjOFANcagLM5l+7mSycM8KknZpKLcGi6jmzWGr/vLurZ/0g4u9AZuAoeb5r1ceQhyiTPY1E4wUR6u/F3H2ojSpXMMriBPT9cezTto8Cx+MsglHL4fv1Rxrb1LVw9yvyQpJ3AhFnLZfuRLH2QsOG3FGGD20X/th/u5bFAt16Bt308KjF+MNOXgl/SquIEySX3GhaZvc67KZbDxcCDORz2N8yCWPaY5lyQZO7lQ29fnZbt3Xu6qoge4+DjXl/MocySPOp9rlvdyznahRyHEYd77v3LhugOXDv4J65QXfl803BDAdaWBEDhfVx7nKofjoVCgxnUAqw/UAUDPn788BDvQuG4TDtdtUPvzjSlXAB8DvaDOhhrmhwbywylXAm8CvaouikJTL93gs3y7Yy4VYbIxOHrcMizPqWOjqO9l3Uz52kibQy4xxOgqhJvD+w5rvokOcAlGvNCfeqCv1ste1stzLm0f71Iq3ZfTrPfuE5nhPtF+LvQE2lffQC7pYtQy3tdzdrKvd5TLVVzDetScS3nEKmmwDyt1Cev1kX3YfbvzNK4fzrlw+cB6vm+uiUgf2zdXI62241LawCb7Pi5FXFPF8KpzDoF/Sw2lg+GrHNbno1mhPu+VCF/vfMnw06PnUl6j48dVHD3jHNHPua+fc3o/5yp/zsGi0vYtzi3Pz5mHd4T6BWMIlewacd63AAAAAElFTkSuQmCC',
|
|
73
|
+
encoding: 'base64',
|
|
74
|
+
filename: 'image.png',
|
|
75
|
+
'content-type': 'image/png',
|
|
76
|
+
},
|
|
77
|
+
},
|
|
78
|
+
});
|
|
79
|
+
}
|
|
80
|
+
if (['Document', 'Folder', 'CMSFolder'].includes(contentType)) {
|
|
81
|
+
return cy
|
|
82
|
+
.request({
|
|
83
|
+
method: 'POST',
|
|
84
|
+
url: `${api_url}/${path}`,
|
|
85
|
+
headers: {
|
|
86
|
+
Accept: 'application/json',
|
|
87
|
+
},
|
|
88
|
+
auth: auth,
|
|
89
|
+
body: {
|
|
90
|
+
'@type': contentType,
|
|
91
|
+
id: contentId,
|
|
92
|
+
title: contentTitle,
|
|
93
|
+
blocks: {
|
|
94
|
+
'd3f1c443-583f-4e8e-a682-3bf25752a300': { '@type': 'title' },
|
|
95
|
+
'7624cf59-05d0-4055-8f55-5fd6597d84b0': { '@type': 'text' },
|
|
96
|
+
},
|
|
97
|
+
blocks_layout: {
|
|
98
|
+
items: [
|
|
99
|
+
'd3f1c443-583f-4e8e-a682-3bf25752a300',
|
|
100
|
+
'7624cf59-05d0-4055-8f55-5fd6597d84b0',
|
|
101
|
+
],
|
|
102
|
+
},
|
|
103
|
+
allow_discussion: allow_discussion,
|
|
104
|
+
},
|
|
105
|
+
})
|
|
106
|
+
.then(() => console.log(`${contentType} created`));
|
|
107
|
+
} else {
|
|
108
|
+
return cy
|
|
109
|
+
.request({
|
|
110
|
+
method: 'POST',
|
|
111
|
+
url: `${api_url}/${path}`,
|
|
112
|
+
headers: {
|
|
113
|
+
Accept: 'application/json',
|
|
114
|
+
},
|
|
115
|
+
auth: auth,
|
|
116
|
+
body: {
|
|
117
|
+
'@type': contentType,
|
|
118
|
+
id: contentId,
|
|
119
|
+
title: contentTitle,
|
|
120
|
+
allow_discussion: allow_discussion,
|
|
121
|
+
},
|
|
122
|
+
})
|
|
123
|
+
.then(() => console.log(`${contentType} created`));
|
|
124
|
+
}
|
|
125
|
+
},
|
|
126
|
+
);
|
|
127
|
+
|
|
128
|
+
// --- REMOVE CONTENT --------------------------------------------------------
|
|
129
|
+
Cypress.Commands.add('removeContent', (path) => {
|
|
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: 'DELETE',
|
|
139
|
+
url: `${api_url}/${path}`,
|
|
140
|
+
headers: {
|
|
141
|
+
Accept: 'application/json',
|
|
142
|
+
},
|
|
143
|
+
auth: auth,
|
|
144
|
+
body: {},
|
|
145
|
+
})
|
|
146
|
+
.then(() => console.log(`${path} removed`));
|
|
147
|
+
});
|
|
148
|
+
|
|
149
|
+
// --- SET WORKFLOW ----------------------------------------------------------
|
|
150
|
+
Cypress.Commands.add(
|
|
151
|
+
'setWorkflow',
|
|
152
|
+
({
|
|
153
|
+
path = '/',
|
|
154
|
+
actor = 'admin',
|
|
155
|
+
review_state = 'publish',
|
|
156
|
+
time = '1995-07-31T18:30:00',
|
|
157
|
+
title = '',
|
|
158
|
+
comment = '',
|
|
159
|
+
effective = '2018-01-21T08:00:00',
|
|
160
|
+
expires = '2019-01-21T08:00:00',
|
|
161
|
+
include_children = true,
|
|
162
|
+
}) => {
|
|
163
|
+
let api_url, auth;
|
|
164
|
+
api_url = Cypress.env('API_PATH') || 'http://localhost:8080/Plone';
|
|
165
|
+
auth = {
|
|
166
|
+
user: 'admin',
|
|
167
|
+
pass: 'admin',
|
|
168
|
+
};
|
|
169
|
+
return cy.request({
|
|
170
|
+
method: 'POST',
|
|
171
|
+
url: `${api_url}/${path}/@workflow/${review_state}`,
|
|
172
|
+
headers: {
|
|
173
|
+
Accept: 'application/json',
|
|
174
|
+
},
|
|
175
|
+
auth: auth,
|
|
176
|
+
body: {
|
|
177
|
+
actor: actor,
|
|
178
|
+
review_state: review_state,
|
|
179
|
+
time: time,
|
|
180
|
+
title: title,
|
|
181
|
+
comment: comment,
|
|
182
|
+
effective: effective,
|
|
183
|
+
expires: expires,
|
|
184
|
+
include_children: include_children,
|
|
185
|
+
},
|
|
186
|
+
});
|
|
187
|
+
},
|
|
188
|
+
);
|
|
189
|
+
|
|
190
|
+
// --- waitForResourceToLoad ----------------------------------------------------------
|
|
191
|
+
Cypress.Commands.add('waitForResourceToLoad', (fileName, type) => {
|
|
192
|
+
const resourceCheckInterval = 40;
|
|
193
|
+
|
|
194
|
+
return new Cypress.Promise((resolve) => {
|
|
195
|
+
const checkIfResourceHasBeenLoaded = () => {
|
|
196
|
+
const resource = cy
|
|
197
|
+
.state('window')
|
|
198
|
+
.performance.getEntriesByType('resource')
|
|
199
|
+
.filter((entry) => !type || entry.initiatorType === type)
|
|
200
|
+
.find((entry) => entry.name.includes(fileName));
|
|
201
|
+
|
|
202
|
+
if (resource) {
|
|
203
|
+
resolve();
|
|
204
|
+
|
|
205
|
+
return;
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
setTimeout(checkIfResourceHasBeenLoaded, resourceCheckInterval);
|
|
209
|
+
};
|
|
210
|
+
|
|
211
|
+
checkIfResourceHasBeenLoaded();
|
|
212
|
+
});
|
|
213
|
+
});
|
|
214
|
+
|
|
215
|
+
// Low level command reused by `setSelection` and low level command `setCursor`
|
|
216
|
+
Cypress.Commands.add('selection', { prevSubject: true }, (subject, fn) => {
|
|
217
|
+
cy.wrap(subject).trigger('mousedown').then(fn).trigger('mouseup');
|
|
218
|
+
|
|
219
|
+
cy.document().trigger('selectionchange');
|
|
220
|
+
return cy.wrap(subject);
|
|
221
|
+
});
|
|
222
|
+
|
|
223
|
+
Cypress.Commands.add(
|
|
224
|
+
'setSelection',
|
|
225
|
+
{ prevSubject: true },
|
|
226
|
+
(subject, query, endQuery) => {
|
|
227
|
+
return cy.wrap(subject).selection(($el) => {
|
|
228
|
+
if (typeof query === 'string') {
|
|
229
|
+
const anchorNode = getTextNode($el[0], query);
|
|
230
|
+
const focusNode = endQuery ? getTextNode($el[0], endQuery) : anchorNode;
|
|
231
|
+
const anchorOffset = anchorNode.wholeText.indexOf(query);
|
|
232
|
+
const focusOffset = endQuery
|
|
233
|
+
? focusNode.wholeText.indexOf(endQuery) + endQuery.length
|
|
234
|
+
: anchorOffset + query.length;
|
|
235
|
+
setBaseAndExtent(anchorNode, anchorOffset, focusNode, focusOffset);
|
|
236
|
+
} else if (typeof query === 'object') {
|
|
237
|
+
const el = $el[0];
|
|
238
|
+
const anchorNode = getTextNode(el.querySelector(query.anchorQuery));
|
|
239
|
+
const anchorOffset = query.anchorOffset || 0;
|
|
240
|
+
const focusNode = query.focusQuery
|
|
241
|
+
? getTextNode(el.querySelector(query.focusQuery))
|
|
242
|
+
: anchorNode;
|
|
243
|
+
const focusOffset = query.focusOffset || 0;
|
|
244
|
+
setBaseAndExtent(anchorNode, anchorOffset, focusNode, focusOffset);
|
|
245
|
+
}
|
|
246
|
+
});
|
|
247
|
+
},
|
|
248
|
+
);
|
|
249
|
+
|
|
250
|
+
// Low level command reused by `setCursorBefore` and `setCursorAfter`, equal to `setCursorAfter`
|
|
251
|
+
Cypress.Commands.add(
|
|
252
|
+
'setCursor',
|
|
253
|
+
{ prevSubject: true },
|
|
254
|
+
(subject, query, atStart) => {
|
|
255
|
+
return cy.wrap(subject).selection(($el) => {
|
|
256
|
+
const node = getTextNode($el[0], query);
|
|
257
|
+
const offset =
|
|
258
|
+
node.wholeText.indexOf(query) + (atStart ? 0 : query.length);
|
|
259
|
+
const document = node.ownerDocument;
|
|
260
|
+
document.getSelection().removeAllRanges();
|
|
261
|
+
document.getSelection().collapse(node, offset);
|
|
262
|
+
});
|
|
263
|
+
// Depending on what you're testing, you may need to chain a `.click()` here to ensure
|
|
264
|
+
// further commands are picked up by whatever you're testing (this was required for Slate, for example).
|
|
265
|
+
},
|
|
266
|
+
);
|
|
267
|
+
|
|
268
|
+
Cypress.Commands.add(
|
|
269
|
+
'setCursorBefore',
|
|
270
|
+
{ prevSubject: true },
|
|
271
|
+
(subject, query) => {
|
|
272
|
+
cy.wrap(subject).setCursor(query, true);
|
|
273
|
+
},
|
|
274
|
+
);
|
|
275
|
+
|
|
276
|
+
Cypress.Commands.add(
|
|
277
|
+
'setCursorAfter',
|
|
278
|
+
{ prevSubject: true },
|
|
279
|
+
(subject, query) => {
|
|
280
|
+
cy.wrap(subject).setCursor(query);
|
|
281
|
+
},
|
|
282
|
+
);
|
|
283
|
+
|
|
284
|
+
// Helper functions
|
|
285
|
+
function getTextNode(el, match) {
|
|
286
|
+
const walk = document.createTreeWalker(el, NodeFilter.SHOW_TEXT, null, false);
|
|
287
|
+
if (!match) {
|
|
288
|
+
return walk.nextNode();
|
|
289
|
+
}
|
|
290
|
+
|
|
291
|
+
let node;
|
|
292
|
+
while ((node = walk.nextNode())) {
|
|
293
|
+
if (node.wholeText.includes(match)) {
|
|
294
|
+
return node;
|
|
295
|
+
}
|
|
296
|
+
}
|
|
297
|
+
}
|
|
298
|
+
|
|
299
|
+
function setBaseAndExtent(...args) {
|
|
300
|
+
const document = args[0].ownerDocument;
|
|
301
|
+
document.getSelection().removeAllRanges();
|
|
302
|
+
document.getSelection().setBaseAndExtent(...args);
|
|
303
|
+
}
|
|
304
|
+
|
|
305
|
+
Cypress.Commands.add('navigate', (route = '') => {
|
|
306
|
+
return cy.window().its('appHistory').invoke('push', route);
|
|
307
|
+
});
|
|
308
|
+
|
|
309
|
+
Cypress.Commands.add('store', () => {
|
|
310
|
+
return cy.window().its('store').invoke('getStore', '');
|
|
311
|
+
});
|
|
312
|
+
|
|
313
|
+
Cypress.Commands.add('settings', (key, value) => {
|
|
314
|
+
return cy.window().its('settings');
|
|
315
|
+
});
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
// ***********************************************************
|
|
2
|
+
// This example support/index.js is processed and
|
|
3
|
+
// loaded automatically before your test files.
|
|
4
|
+
//
|
|
5
|
+
// This is a great place to put global configuration and
|
|
6
|
+
// behavior that modifies Cypress.
|
|
7
|
+
//
|
|
8
|
+
// You can change the location of this file or turn off
|
|
9
|
+
// automatically serving support files with the
|
|
10
|
+
// 'supportFile' configuration option.
|
|
11
|
+
//
|
|
12
|
+
// You can read more here:
|
|
13
|
+
// https://on.cypress.io/configuration
|
|
14
|
+
// ***********************************************************
|
|
15
|
+
|
|
16
|
+
// Import commands.js using ES2015 syntax:
|
|
17
|
+
import './commands';
|
|
18
|
+
|
|
19
|
+
// Alternatively you can use CommonJS syntax:
|
|
20
|
+
// require('./commands')
|
|
21
|
+
|
|
22
|
+
/* coverage-start
|
|
23
|
+
//Generate code-coverage
|
|
24
|
+
import '@cypress/code-coverage/support';
|
|
25
|
+
coverage-end */
|
|
26
|
+
|
|
27
|
+
export const setupBeforeEach = () => {
|
|
28
|
+
cy.autologin();
|
|
29
|
+
cy.createContent({
|
|
30
|
+
contentType: 'Folder',
|
|
31
|
+
contentId: 'cypress',
|
|
32
|
+
contentTitle: 'Cypress',
|
|
33
|
+
});
|
|
34
|
+
cy.createContent({
|
|
35
|
+
contentType: 'Document',
|
|
36
|
+
contentId: 'my-page',
|
|
37
|
+
contentTitle: 'My Page',
|
|
38
|
+
path: 'cypress',
|
|
39
|
+
});
|
|
40
|
+
cy.visit('/cypress/my-page');
|
|
41
|
+
cy.waitForResourceToLoad('@navigation');
|
|
42
|
+
cy.waitForResourceToLoad('@breadcrumbs');
|
|
43
|
+
cy.waitForResourceToLoad('@actions');
|
|
44
|
+
cy.waitForResourceToLoad('@types');
|
|
45
|
+
cy.waitForResourceToLoad('my-page');
|
|
46
|
+
cy.navigate('/cypress/my-page/edit');
|
|
47
|
+
cy.get(`.block.title h1`);
|
|
48
|
+
};
|
|
49
|
+
|
|
50
|
+
export const tearDownAfterEach = () => {
|
|
51
|
+
cy.autologin();
|
|
52
|
+
cy.removeContent('cypress');
|
|
53
|
+
};
|
package/cypress.json
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@eeacms/volto-widget-toggle",
|
|
3
|
-
"version": "2.2.
|
|
3
|
+
"version": "2.2.5",
|
|
4
4
|
"description": "volto-widget-toggle: Volto add-on to replace checkboxes with toggle buttons",
|
|
5
5
|
"main": "src/index.js",
|
|
6
6
|
"author": "European Environment Agency: IDM2 A-Team",
|
|
@@ -19,15 +19,23 @@
|
|
|
19
19
|
"url": "git@github.com:eea/volto-widget-toggle.git"
|
|
20
20
|
},
|
|
21
21
|
"dependencies": {},
|
|
22
|
+
"devDependencies": {
|
|
23
|
+
"@cypress/code-coverage": "^3.9.5",
|
|
24
|
+
"babel-plugin-transform-class-properties": "^6.24.1"
|
|
25
|
+
},
|
|
22
26
|
"scripts": {
|
|
23
27
|
"release": "release-it",
|
|
24
|
-
"
|
|
28
|
+
"release-major-beta": "release-it major --preRelease=beta",
|
|
29
|
+
"release-beta": "release-it --preRelease=beta",
|
|
30
|
+
"bootstrap": "npm install -g ejs; npm link ejs; node bootstrap",
|
|
25
31
|
"stylelint": "../../../node_modules/stylelint/bin/stylelint.js --allow-empty-input 'src/**/*.{css,less}'",
|
|
26
32
|
"stylelint:overrides": "../../../node_modules/.bin/stylelint --syntax less --allow-empty-input 'theme/**/*.overrides' 'src/**/*.overrides'",
|
|
27
33
|
"stylelint:fix": "yarn stylelint --fix && yarn stylelint:overrides --fix",
|
|
28
34
|
"prettier": "../../../node_modules/.bin/prettier --single-quote --check 'src/**/*.{js,jsx,json,css,less,md}'",
|
|
29
35
|
"prettier:fix": "../../../node_modules/.bin/prettier --single-quote --write 'src/**/*.{js,jsx,json,css,less,md}'",
|
|
30
36
|
"lint": "../../../node_modules/eslint/bin/eslint.js --max-warnings=0 'src/**/*.{js,jsx}'",
|
|
31
|
-
"lint:fix": "../../../node_modules/eslint/bin/eslint.js --fix 'src/**/*.{js,jsx}'"
|
|
37
|
+
"lint:fix": "../../../node_modules/eslint/bin/eslint.js --fix 'src/**/*.{js,jsx}'",
|
|
38
|
+
"cypress:run": "../../../node_modules/cypress/bin/cypress run",
|
|
39
|
+
"cypress:open": "../../../node_modules/cypress/bin/cypress open"
|
|
32
40
|
}
|
|
33
41
|
}
|
|
@@ -16,19 +16,30 @@ import { FormFieldWrapper } from '@plone/volto/components';
|
|
|
16
16
|
* @returns {string} Markup of the component.
|
|
17
17
|
*/
|
|
18
18
|
const CheckboxWidget = (props) => {
|
|
19
|
-
const {
|
|
20
|
-
|
|
19
|
+
const {
|
|
20
|
+
id,
|
|
21
|
+
title,
|
|
22
|
+
value,
|
|
23
|
+
onChange,
|
|
24
|
+
isDisabled,
|
|
25
|
+
defaultValue = false,
|
|
26
|
+
} = props;
|
|
27
|
+
|
|
28
|
+
React.useEffect(() => {
|
|
29
|
+
if (value === null && defaultValue) onChange(id, defaultValue); //value===null prevents assigning default value on every render
|
|
30
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
31
|
+
}, []);
|
|
32
|
+
|
|
21
33
|
return (
|
|
22
34
|
<FormFieldWrapper {...props} columns={1}>
|
|
23
35
|
<div className="wrapper">
|
|
24
36
|
<Checkbox
|
|
25
37
|
toggle
|
|
26
38
|
name={`field-${id}`}
|
|
27
|
-
checked={
|
|
39
|
+
checked={value ?? defaultValue}
|
|
28
40
|
disabled={isDisabled}
|
|
29
41
|
onChange={(event, { checked }) => {
|
|
30
42
|
onChange(id, checked);
|
|
31
|
-
setChecked(checked);
|
|
32
43
|
}}
|
|
33
44
|
label={<label htmlFor={`field-${id}`}>{title}</label>}
|
|
34
45
|
/>
|