@eeacms/volto-embed 10.0.3 → 10.1.0
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 +14 -18
- package/package.json +1 -1
- package/src/PrivacyProtection/helpers.test.js +34 -0
- package/src/Toolbar/Sources.test.jsx +72 -0
- package/src/Widgets/MapWidget.test.jsx +96 -0
- package/src/Widgets/MapsWidget.jsx +40 -5
- package/src/index.js +5 -0
- package/src/middlewares/preview_image.js +93 -0
- package/src/middlewares/preview_image.test.js +49 -0
package/CHANGELOG.md
CHANGED
|
@@ -4,6 +4,20 @@ 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
|
+
### [10.1.0](https://github.com/eea/volto-embed/compare/10.0.3...10.1.0) - 11 September 2024
|
|
8
|
+
|
|
9
|
+
#### :hammer_and_wrench: Others
|
|
10
|
+
|
|
11
|
+
- Update version [dobri1408 - [`21e7852`](https://github.com/eea/volto-embed/commit/21e7852cfa27bedd7e3670402bf89d7f3b6fdc06)]
|
|
12
|
+
- cleanup preview image loaded [dobri1408 - [`b3e60ff`](https://github.com/eea/volto-embed/commit/b3e60ffedd7e7f7790afbc76e99df4e001e57550)]
|
|
13
|
+
- double check preview [dobri1408 - [`35c6210`](https://github.com/eea/volto-embed/commit/35c621031b4cd25777ac19a2789eac08ffd48176)]
|
|
14
|
+
- tests [dobri1408 - [`70c3620`](https://github.com/eea/volto-embed/commit/70c3620057ffd203105b80ff1c9121a39947c212)]
|
|
15
|
+
- tests [dobri1408 - [`8aa1bfe`](https://github.com/eea/volto-embed/commit/8aa1bfe536968b42cd76abc91b685b28ce485e28)]
|
|
16
|
+
- tests [dobri1408 - [`879f6a7`](https://github.com/eea/volto-embed/commit/879f6a70d329228d974f347cea983621194433a3)]
|
|
17
|
+
- Create preview_image.test.js [dobri1408 - [`fbb7cdb`](https://github.com/eea/volto-embed/commit/fbb7cdb69c1d43a928024d2c83a0dee87faae7af)]
|
|
18
|
+
- Update MapsWidget.jsx [dobri1408 - [`cd46123`](https://github.com/eea/volto-embed/commit/cd46123d39c71d034a2aa9919ad04e7364a08e8d)]
|
|
19
|
+
- Update MapsWidget.jsx [dobri1408 - [`e36c6a9`](https://github.com/eea/volto-embed/commit/e36c6a9c0269622cabf2069d6b8cd082cfbe879b)]
|
|
20
|
+
- preview image middlware [dobri1408 - [`5a0f8e9`](https://github.com/eea/volto-embed/commit/5a0f8e9231d8f5f760dcbd82bbab4a84778d1202)]
|
|
7
21
|
### [10.0.3](https://github.com/eea/volto-embed/compare/10.0.2...10.0.3) - 24 July 2024
|
|
8
22
|
|
|
9
23
|
#### :bug: Bug Fixes
|
|
@@ -18,7 +32,6 @@ Generated by [`auto-changelog`](https://github.com/CookPete/auto-changelog).
|
|
|
18
32
|
- add useScreenHeight prop [Miu Razvan - [`a261a59`](https://github.com/eea/volto-embed/commit/a261a593892f44845579b2c0aa764e22bbf48e73)]
|
|
19
33
|
- fix tests [Miu Razvan - [`0798660`](https://github.com/eea/volto-embed/commit/0798660ce054a7a60e4c3888cb63ba9c131a42f8)]
|
|
20
34
|
- Set interactiv map height to window innerheight, ref #272831 [Miu Razvan - [`5ac9eb5`](https://github.com/eea/volto-embed/commit/5ac9eb5e66cdc626b33d0bdad5b80994af2d7d79)]
|
|
21
|
-
- Add Sonarqube tag using insitu-frontend addons list [EEA Jenkins - [`d99c3dc`](https://github.com/eea/volto-embed/commit/d99c3dc2151f6576b127e3c751fabaae3ad676b8)]
|
|
22
35
|
### [10.0.2](https://github.com/eea/volto-embed/compare/10.0.1...10.0.2) - 7 June 2024
|
|
23
36
|
|
|
24
37
|
#### :bug: Bug Fixes
|
|
@@ -104,7 +117,6 @@ Generated by [`auto-changelog`](https://github.com/CookPete/auto-changelog).
|
|
|
104
117
|
|
|
105
118
|
- test: increase coverage [kreafox - [`2d8e43c`](https://github.com/eea/volto-embed/commit/2d8e43cf3988564306b6aa7b885b0ff398043ce0)]
|
|
106
119
|
- test: increase coverage [kreafox - [`1fa9052`](https://github.com/eea/volto-embed/commit/1fa9052a3c015361e3a7eae043c418b696262fbe)]
|
|
107
|
-
- test: [JENKINS] fail with logs on coverage [valentinab25 - [`eaabce8`](https://github.com/eea/volto-embed/commit/eaabce87f1ed4b88a25bfc59a75285e858413d6a)]
|
|
108
120
|
- test: increase cypress timeout [kreafox - [`9bb40a5`](https://github.com/eea/volto-embed/commit/9bb40a5df2b29a55edec24a57fcd6e65f270f13c)]
|
|
109
121
|
- test: updates [kreafox - [`5b54d02`](https://github.com/eea/volto-embed/commit/5b54d02c6b6392e25f07ef1e286bdbced999592e)]
|
|
110
122
|
- test: update snapshot [kreafox - [`338f23e`](https://github.com/eea/volto-embed/commit/338f23ee5c6c75ccb6ee2d8d474298553fe3bd53)]
|
|
@@ -161,13 +173,11 @@ Generated by [`auto-changelog`](https://github.com/CookPete/auto-changelog).
|
|
|
161
173
|
- update [Miu Razvan - [`926beb8`](https://github.com/eea/volto-embed/commit/926beb87d2c44907aebe57369312eea7bf22d656)]
|
|
162
174
|
- update [Miu Razvan - [`da351ae`](https://github.com/eea/volto-embed/commit/da351ae9ffaaef756f7a665618a03fd04cb9b01d)]
|
|
163
175
|
- use volto-datablocks@develop dependency [Miu Razvan - [`b379d84`](https://github.com/eea/volto-embed/commit/b379d8478657dd39dad066181b349cee7ac2531d)]
|
|
164
|
-
- test: [JENKINS] Use java17 for sonarqube scanner [valentinab25 - [`ddf685a`](https://github.com/eea/volto-embed/commit/ddf685a9481d780a1df2e4f991f93676478c3e05)]
|
|
165
176
|
## [8.0.0](https://github.com/eea/volto-embed/compare/7.0.2...8.0.0) - 17 November 2023
|
|
166
177
|
|
|
167
178
|
#### :hammer_and_wrench: Others
|
|
168
179
|
|
|
169
180
|
- tests: add cypress tests [nileshgulia1 - [`e4b2803`](https://github.com/eea/volto-embed/commit/e4b28033114170639787d77976dc13b7f697f704)]
|
|
170
|
-
- test: [JENKINS] Run cypress in started frontend container [valentinab25 - [`83d91d5`](https://github.com/eea/volto-embed/commit/83d91d5716a9ce8ebbbff01a7838711298684be4)]
|
|
171
181
|
- fix error [Claudia Ifrim - [`553f3af`](https://github.com/eea/volto-embed/commit/553f3af004af034c721dcd6b01de55c258a88c49)]
|
|
172
182
|
- bump version [Miu Razvan - [`363694a`](https://github.com/eea/volto-embed/commit/363694ae50cdec941fb53b396b75e9a4554d44fb)]
|
|
173
183
|
### [7.0.2](https://github.com/eea/volto-embed/compare/7.0.1...7.0.2) - 10 November 2023
|
|
@@ -177,7 +187,6 @@ Generated by [`auto-changelog`](https://github.com/CookPete/auto-changelog).
|
|
|
177
187
|
#### :hammer_and_wrench: Others
|
|
178
188
|
|
|
179
189
|
- add missing less variable [Miu Razvan - [`47683a7`](https://github.com/eea/volto-embed/commit/47683a7816581d117bb88f16e3087864aaa52f5e)]
|
|
180
|
-
- test: [JENKINS] Add cpu limit on cypress docker [valentinab25 - [`ba168e4`](https://github.com/eea/volto-embed/commit/ba168e49554a51a6015a98a77dc0ceab76320218)]
|
|
181
190
|
## [7.0.0](https://github.com/eea/volto-embed/compare/6.0.1...7.0.0) - 6 November 2023
|
|
182
191
|
|
|
183
192
|
#### :rocket: New Features
|
|
@@ -187,15 +196,12 @@ Generated by [`auto-changelog`](https://github.com/CookPete/auto-changelog).
|
|
|
187
196
|
#### :house: Internal changes
|
|
188
197
|
|
|
189
198
|
- style: Automated code fix [eea-jenkins - [`c34d6f4`](https://github.com/eea/volto-embed/commit/c34d6f47fd33f728d40254a12c05fe385b27f2e9)]
|
|
190
|
-
- chore: [JENKINS] Refactor automated testing [valentinab25 - [`673f3ff`](https://github.com/eea/volto-embed/commit/673f3ff355baa8d3646e4558ff2be00f36b5a45a)]
|
|
191
199
|
- chore: husky, lint-staged use fixed versions [valentinab25 - [`31169f7`](https://github.com/eea/volto-embed/commit/31169f73887837463daee76d63b6516046ad49aa)]
|
|
192
200
|
|
|
193
201
|
#### :hammer_and_wrench: Others
|
|
194
202
|
|
|
195
203
|
- update tests [Miu Razvan - [`c906b79`](https://github.com/eea/volto-embed/commit/c906b79149e853f718d924871ce2e633e5e427c8)]
|
|
196
204
|
- update tests [Miu Razvan - [`11625b6`](https://github.com/eea/volto-embed/commit/11625b65846388a846d1bdf7ebb2e1f8bd103c91)]
|
|
197
|
-
- test: [JENKINS] Increase shm-size to cypress docker [valentinab25 - [`5e7a155`](https://github.com/eea/volto-embed/commit/5e7a15505334c9b81f07172116b49eaefc692ebf)]
|
|
198
|
-
- test: [JENKINS] Improve cypress time [valentinab25 - [`eeb6dcb`](https://github.com/eea/volto-embed/commit/eeb6dcb4b0f8af07496450e6e7783932ebe88bf7)]
|
|
199
205
|
- Release 7.0.0 [Alin Voinea - [`cbc5c79`](https://github.com/eea/volto-embed/commit/cbc5c79f1b66daf0d599d9de5a1bc7d137bafed8)]
|
|
200
206
|
- add act in unit tests [Miu Razvan - [`ecf5b2f`](https://github.com/eea/volto-embed/commit/ecf5b2fe553d99ad6a11570d3d34852d557fbe85)]
|
|
201
207
|
- update [Miu Razvan - [`049cc14`](https://github.com/eea/volto-embed/commit/049cc140bb6ffea4eb3f1555e693e9973ef63d0e)]
|
|
@@ -218,7 +224,6 @@ Generated by [`auto-changelog`](https://github.com/CookPete/auto-changelog).
|
|
|
218
224
|
|
|
219
225
|
- test: EN locales, pre-commit fix, feature PRs checks Refs #257193 [valentinab25 - [`dc2de20`](https://github.com/eea/volto-embed/commit/dc2de2084b53043f240ee1efa2588b5037326ed7)]
|
|
220
226
|
- test: Fix package.json scripts to use makefile [Alin Voinea - [`b4ffca2`](https://github.com/eea/volto-embed/commit/b4ffca24bb8cc4ba2007cc1040cc7b55dc7cc779)]
|
|
221
|
-
- test: Fix eslint and yarn i18n [Alin Voinea - [`1563d0a`](https://github.com/eea/volto-embed/commit/1563d0ab1f54e775a16705bfd3d267303eb2a526)]
|
|
222
227
|
- i18n: Add en [Alin Voinea - [`b4e0694`](https://github.com/eea/volto-embed/commit/b4e0694ee40ecc195536fd1826adfab8876c5061)]
|
|
223
228
|
- test: Update Makefile and docker-compose to align it with Jenkinsfile [valentinab25 - [`8f228ca`](https://github.com/eea/volto-embed/commit/8f228ca0644cee0f777a01114895583f387a395c)]
|
|
224
229
|
- test: increase test coverage - refs #254313 [ana-oprea - [`30354d8`](https://github.com/eea/volto-embed/commit/30354d8a10a78e4fc322e37f4be20ff85cd00bbc)]
|
|
@@ -247,9 +252,6 @@ Generated by [`auto-changelog`](https://github.com/CookPete/auto-changelog).
|
|
|
247
252
|
|
|
248
253
|
- Add react-countup to resolutions [kreafox - [`36eb637`](https://github.com/eea/volto-embed/commit/36eb637c0cb9413b0b0e0ce53e621b2289929d65)]
|
|
249
254
|
- Move generic classes to privacy-protection [kreafox - [`715d559`](https://github.com/eea/volto-embed/commit/715d559e370bf7a3489b64d357b0a6cd7b1a3af2)]
|
|
250
|
-
- Add Sonarqube tag using eea-website-frontend addons list [EEA Jenkins - [`5715b4d`](https://github.com/eea/volto-embed/commit/5715b4d3fcc14a34e031c383275c685d88f4db44)]
|
|
251
|
-
- Add Sonarqube tag using eea-website-frontend addons list [EEA Jenkins - [`ef24ac0`](https://github.com/eea/volto-embed/commit/ef24ac05b17f4f4dbf05ceafbee677012a7f28f5)]
|
|
252
|
-
- Add Sonarqube tag using eea-website-frontend addons list [EEA Jenkins - [`81f957b`](https://github.com/eea/volto-embed/commit/81f957b51aef7be59214530b774de8547bee3f5f)]
|
|
253
255
|
### [5.0.2](https://github.com/eea/volto-embed/compare/5.0.1...5.0.2) - 20 March 2023
|
|
254
256
|
|
|
255
257
|
#### :hammer_and_wrench: Others
|
|
@@ -264,7 +266,6 @@ Generated by [`auto-changelog`](https://github.com/CookPete/auto-changelog).
|
|
|
264
266
|
- update .project.eslintrc.js [Miu Razvan - [`628fd40`](https://github.com/eea/volto-embed/commit/628fd402b00d075ce319b9be92ff5f0e4d0ca2c4)]
|
|
265
267
|
- rename schema.jsx [Miu Razvan - [`62794e3`](https://github.com/eea/volto-embed/commit/62794e398eab5117132e5622cab735f6cf4f79fd)]
|
|
266
268
|
- improving code quality as per sonarqube reported issues [tedw87 - [`c7842f7`](https://github.com/eea/volto-embed/commit/c7842f7795f344e9d30538ddf2da04e97e319ebe)]
|
|
267
|
-
- Add Sonarqube tag using cca-frontend addons list [EEA Jenkins - [`fe3a2de`](https://github.com/eea/volto-embed/commit/fe3a2de6180796c3d6b569733d2b9365a669c23e)]
|
|
268
269
|
## [5.0.0](https://github.com/eea/volto-embed/compare/4.0.4...5.0.0) - 31 October 2022
|
|
269
270
|
|
|
270
271
|
#### :hammer_and_wrench: Others
|
|
@@ -284,8 +285,6 @@ Generated by [`auto-changelog`](https://github.com/CookPete/auto-changelog).
|
|
|
284
285
|
|
|
285
286
|
- use specific alpha for addon test [andreiggr - [`e6df633`](https://github.com/eea/volto-embed/commit/e6df633aa4d2b0ee7eeb6b5aafa21528f14cd1df)]
|
|
286
287
|
- add optional height to privacy container [andreiggr - [`e2ac711`](https://github.com/eea/volto-embed/commit/e2ac711db4e461b474cade42109346a73bb8ecbd)]
|
|
287
|
-
- Add Sonarqube tag using marine-frontend addons list [EEA Jenkins - [`9f3f358`](https://github.com/eea/volto-embed/commit/9f3f35882fb367d72c7916abe7cbf366dbd8d5b6)]
|
|
288
|
-
- Add Sonarqube tag using bise-frontend addons list [EEA Jenkins - [`7677140`](https://github.com/eea/volto-embed/commit/767714006abf7cbe336c5ab00d76c7232d5bc798)]
|
|
289
288
|
### [4.0.2](https://github.com/eea/volto-embed/compare/4.0.1...4.0.2) - 15 July 2022
|
|
290
289
|
|
|
291
290
|
#### :hammer_and_wrench: Others
|
|
@@ -325,7 +324,6 @@ Generated by [`auto-changelog`](https://github.com/CookPete/auto-changelog).
|
|
|
325
324
|
|
|
326
325
|
- Update package.json [Nilesh - [`0ec673a`](https://github.com/eea/volto-embed/commit/0ec673a8178731b8c1e010101caee2a3c9fafaca)]
|
|
327
326
|
- Update package.json [Nilesh - [`b8b94ec`](https://github.com/eea/volto-embed/commit/b8b94ec64672229f464b9108b4ac01a848827c00)]
|
|
328
|
-
- Add Sonarqube tag using freshwater-frontend addons list [EEA Jenkins - [`cfe04d8`](https://github.com/eea/volto-embed/commit/cfe04d885255bb8e472a3b268b98e3d7b9022437)]
|
|
329
327
|
- Refs #142010 - Optimize Volto-addons gitflow pipelines [valentinab25 - [`bf197dd`](https://github.com/eea/volto-embed/commit/bf197dd6516f9c18994add19b1141e061a96e2b6)]
|
|
330
328
|
- no hardcoded text [Daniela Mormocea - [`4001bb4`](https://github.com/eea/volto-embed/commit/4001bb414df05c1516f95e4dcec4a328406dc63f)]
|
|
331
329
|
- fix [Daniela Mormocea - [`a41ca9a`](https://github.com/eea/volto-embed/commit/a41ca9a2795a59f2633fb97938244e335dca8c43)]
|
|
@@ -399,8 +397,6 @@ Generated by [`auto-changelog`](https://github.com/CookPete/auto-changelog).
|
|
|
399
397
|
- revert use of custom bg image [nileshgulia1 - [`63a74b7`](https://github.com/eea/volto-embed/commit/63a74b7e671d85b602b0190c7a18e6d6ad71341b)]
|
|
400
398
|
- PrivacyProtection update & accept bg image [Andrei Grigore - [`f3f05d1`](https://github.com/eea/volto-embed/commit/f3f05d1d21fc88b90de3f68a995242b6c359e03a)]
|
|
401
399
|
- fix loading of cookies [nileshgulia1 - [`46348d8`](https://github.com/eea/volto-embed/commit/46348d8321b4633a3d5fdcbfb2c4f01912d7ed2a)]
|
|
402
|
-
- Add Sonarqube tag using frontend addons list [EEA Jenkins - [`a1e1f50`](https://github.com/eea/volto-embed/commit/a1e1f50db8a1ebc11261c3a24c39687c00ca7eea)]
|
|
403
|
-
- Add Sonarqube tag using frontend addons list [EEA Jenkins - [`1e1471e`](https://github.com/eea/volto-embed/commit/1e1471ebab5ba6e5bf0c231ddd0de94d8fe6c846)]
|
|
404
400
|
### [2.0.1](https://github.com/eea/volto-embed/compare/2.0.0...2.0.1) - 28 May 2021
|
|
405
401
|
|
|
406
402
|
#### :hammer_and_wrench: Others
|
package/package.json
CHANGED
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { createImageUrl } from './helpers';
|
|
2
|
+
|
|
3
|
+
describe('createImageUrl', () => {
|
|
4
|
+
it('should create a valid image URL from the base64 encoded data', () => {
|
|
5
|
+
// Mock data for the test
|
|
6
|
+
const mockResult = {
|
|
7
|
+
data: 'aGVsbG8gd29ybGQ=', // "hello world" in base64
|
|
8
|
+
'content-type': 'image/png',
|
|
9
|
+
};
|
|
10
|
+
|
|
11
|
+
// Mock the atob function
|
|
12
|
+
jest.spyOn(window, 'atob').mockImplementation(() => 'hello world');
|
|
13
|
+
|
|
14
|
+
// Mock the URL.createObjectURL function
|
|
15
|
+
const mockUrl = 'blob:http://localhost:3000/some-url';
|
|
16
|
+
global.URL.createObjectURL = jest.fn().mockReturnValue(mockUrl);
|
|
17
|
+
|
|
18
|
+
// Call the function
|
|
19
|
+
const imageUrl = createImageUrl(mockResult);
|
|
20
|
+
|
|
21
|
+
// Assertions
|
|
22
|
+
expect(window.atob).toHaveBeenCalledWith(mockResult.data);
|
|
23
|
+
expect(URL.createObjectURL).toHaveBeenCalledWith(expect.any(Blob));
|
|
24
|
+
expect(imageUrl).toBe(mockUrl);
|
|
25
|
+
|
|
26
|
+
// Verify the Blob creation
|
|
27
|
+
const blobArgs = URL.createObjectURL.mock.calls[0][0];
|
|
28
|
+
expect(blobArgs.type).toBe(mockResult['content-type']);
|
|
29
|
+
expect(blobArgs.size).toBe(11); // "hello world" is 11 bytes
|
|
30
|
+
|
|
31
|
+
// Clean up mocks
|
|
32
|
+
jest.restoreAllMocks();
|
|
33
|
+
});
|
|
34
|
+
});
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { render, fireEvent, screen } from '@testing-library/react';
|
|
3
|
+
import Sources from './Sources';
|
|
4
|
+
import '@testing-library/jest-dom/extend-expect';
|
|
5
|
+
|
|
6
|
+
const mockSources = [
|
|
7
|
+
{
|
|
8
|
+
chart_source: 'Source 1',
|
|
9
|
+
chart_source_link: 'http://example.com/source1',
|
|
10
|
+
organisation: 'Organisation 1',
|
|
11
|
+
title: 'Title 1',
|
|
12
|
+
link: 'http://example.com/link1',
|
|
13
|
+
},
|
|
14
|
+
{
|
|
15
|
+
chart_source: 'Source 2',
|
|
16
|
+
chart_source_link: 'http://example.com/source2',
|
|
17
|
+
organisation: 'Organisation 2',
|
|
18
|
+
title: 'Title 2',
|
|
19
|
+
link: 'http://example.com/link2',
|
|
20
|
+
},
|
|
21
|
+
];
|
|
22
|
+
|
|
23
|
+
describe('Sources', () => {
|
|
24
|
+
it('renders the Sources button', () => {
|
|
25
|
+
render(<Sources sources={mockSources} />);
|
|
26
|
+
expect(screen.getByText('Sources')).toBeInTheDocument();
|
|
27
|
+
});
|
|
28
|
+
|
|
29
|
+
it('opens and closes the popup on click', () => {
|
|
30
|
+
render(<Sources sources={mockSources} />);
|
|
31
|
+
|
|
32
|
+
const triggerButton = screen.getByText('Sources');
|
|
33
|
+
|
|
34
|
+
expect(screen.queryByText('Source 1')).toBeInTheDocument();
|
|
35
|
+
|
|
36
|
+
fireEvent.click(triggerButton);
|
|
37
|
+
expect(screen.getByText('Source 1')).toBeInTheDocument();
|
|
38
|
+
expect(screen.getByText('Source 2')).toBeInTheDocument();
|
|
39
|
+
|
|
40
|
+
fireEvent.click(triggerButton);
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
it('renders sources correctly', () => {
|
|
44
|
+
render(<Sources sources={mockSources} />);
|
|
45
|
+
|
|
46
|
+
const triggerButton = screen.getByText('Sources');
|
|
47
|
+
fireEvent.click(triggerButton);
|
|
48
|
+
|
|
49
|
+
expect(screen.getByText('Source 1')).toBeInTheDocument();
|
|
50
|
+
expect(screen.getByText('Source 2')).toBeInTheDocument();
|
|
51
|
+
|
|
52
|
+
expect(screen.getByText('Source 1').closest('a')).toHaveAttribute(
|
|
53
|
+
'href',
|
|
54
|
+
'http://example.com/source1',
|
|
55
|
+
);
|
|
56
|
+
expect(screen.getByText('Source 2').closest('a')).toHaveAttribute(
|
|
57
|
+
'href',
|
|
58
|
+
'http://example.com/source2',
|
|
59
|
+
);
|
|
60
|
+
});
|
|
61
|
+
|
|
62
|
+
it('renders a message when there are no sources', () => {
|
|
63
|
+
render(<Sources sources={[]} />);
|
|
64
|
+
|
|
65
|
+
const triggerButton = screen.getByText('Sources');
|
|
66
|
+
fireEvent.click(triggerButton);
|
|
67
|
+
|
|
68
|
+
expect(
|
|
69
|
+
screen.getByText('Data provenance is not set for this visualization.'),
|
|
70
|
+
).toBeInTheDocument();
|
|
71
|
+
});
|
|
72
|
+
});
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { render } from '@testing-library/react';
|
|
3
|
+
import { Provider } from 'react-redux';
|
|
4
|
+
import configureStore from 'redux-mock-store';
|
|
5
|
+
import MapsViewWidget from './MapsViewWidget';
|
|
6
|
+
import EmbedMap from '@eeacms/volto-embed/EmbedMap/EmbedMap';
|
|
7
|
+
import { pickMetadata } from '@eeacms/volto-embed/helpers';
|
|
8
|
+
import '@testing-library/jest-dom/extend-expect'; // Importă jest-dom
|
|
9
|
+
|
|
10
|
+
jest.mock('@eeacms/volto-embed/EmbedMap/EmbedMap', () =>
|
|
11
|
+
jest.fn(() => <div>Mocked EmbedMap</div>),
|
|
12
|
+
);
|
|
13
|
+
jest.mock('@eeacms/volto-embed/helpers', () => ({
|
|
14
|
+
pickMetadata: jest.fn(),
|
|
15
|
+
}));
|
|
16
|
+
|
|
17
|
+
const mockStore = configureStore([]);
|
|
18
|
+
|
|
19
|
+
describe('MapsViewWidget', () => {
|
|
20
|
+
let store;
|
|
21
|
+
|
|
22
|
+
beforeEach(() => {
|
|
23
|
+
store = mockStore({
|
|
24
|
+
content: {
|
|
25
|
+
data: {
|
|
26
|
+
metadata: {
|
|
27
|
+
title: 'Test Title',
|
|
28
|
+
description: 'Test Description',
|
|
29
|
+
},
|
|
30
|
+
},
|
|
31
|
+
},
|
|
32
|
+
});
|
|
33
|
+
});
|
|
34
|
+
|
|
35
|
+
it('should render EmbedMap with the correct data props', () => {
|
|
36
|
+
const mockValue = {
|
|
37
|
+
map_url: 'http://example.com/map',
|
|
38
|
+
};
|
|
39
|
+
const mockId = 'map-widget-1';
|
|
40
|
+
|
|
41
|
+
pickMetadata.mockReturnValue({
|
|
42
|
+
title: 'Test Title',
|
|
43
|
+
description: 'Test Description',
|
|
44
|
+
});
|
|
45
|
+
|
|
46
|
+
const { getByText } = render(
|
|
47
|
+
<Provider store={store}>
|
|
48
|
+
<MapsViewWidget id={mockId} value={mockValue} />
|
|
49
|
+
</Provider>,
|
|
50
|
+
);
|
|
51
|
+
|
|
52
|
+
expect(EmbedMap).toHaveBeenCalledWith(
|
|
53
|
+
{
|
|
54
|
+
data: {
|
|
55
|
+
map_url: 'http://example.com/map',
|
|
56
|
+
title: 'Test Title',
|
|
57
|
+
description: 'Test Description',
|
|
58
|
+
with_share: true,
|
|
59
|
+
},
|
|
60
|
+
id: mockId,
|
|
61
|
+
},
|
|
62
|
+
{},
|
|
63
|
+
);
|
|
64
|
+
|
|
65
|
+
expect(getByText('Mocked EmbedMap')).toBeInTheDocument(); // Verifică dacă elementul este în document
|
|
66
|
+
});
|
|
67
|
+
|
|
68
|
+
it('should handle empty value prop correctly', () => {
|
|
69
|
+
const mockId = 'map-widget-2';
|
|
70
|
+
|
|
71
|
+
pickMetadata.mockReturnValue({
|
|
72
|
+
title: 'Test Title',
|
|
73
|
+
description: 'Test Description',
|
|
74
|
+
});
|
|
75
|
+
|
|
76
|
+
const { getByText } = render(
|
|
77
|
+
<Provider store={store}>
|
|
78
|
+
<MapsViewWidget id={mockId} value={null} />
|
|
79
|
+
</Provider>,
|
|
80
|
+
);
|
|
81
|
+
|
|
82
|
+
expect(EmbedMap).toHaveBeenCalledWith(
|
|
83
|
+
{
|
|
84
|
+
data: {
|
|
85
|
+
title: 'Test Title',
|
|
86
|
+
description: 'Test Description',
|
|
87
|
+
with_share: true,
|
|
88
|
+
},
|
|
89
|
+
id: mockId,
|
|
90
|
+
},
|
|
91
|
+
{},
|
|
92
|
+
);
|
|
93
|
+
|
|
94
|
+
expect(getByText('Mocked EmbedMap')).toBeInTheDocument(); // Verifică dacă elementul este în document
|
|
95
|
+
});
|
|
96
|
+
});
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import React, { useMemo, useState } from 'react';
|
|
1
|
+
import React, { useMemo, useState, useEffect } from 'react';
|
|
2
2
|
import { useIntl, FormattedMessage, defineMessages } from 'react-intl';
|
|
3
3
|
import { Icon } from '@plone/volto/components';
|
|
4
4
|
import { Button, Modal, Grid, Label, Input, Message } from 'semantic-ui-react';
|
|
@@ -7,6 +7,7 @@ import { FormFieldWrapper, InlineForm } from '@plone/volto/components';
|
|
|
7
7
|
import { addPrivacyProtectionToSchema } from '@eeacms/volto-embed';
|
|
8
8
|
import EmbedMap from '@eeacms/volto-embed/EmbedMap/EmbedMap';
|
|
9
9
|
import { MapsSchema } from '@eeacms/volto-embed/Blocks/Maps/schema';
|
|
10
|
+
import { getBaseUrl } from '@plone/volto/helpers';
|
|
10
11
|
|
|
11
12
|
import clearSVG from '@plone/volto/icons/clear.svg';
|
|
12
13
|
import aheadSVG from '@plone/volto/icons/ahead.svg';
|
|
@@ -19,6 +20,17 @@ const messages = defineMessages({
|
|
|
19
20
|
},
|
|
20
21
|
});
|
|
21
22
|
|
|
23
|
+
function blobToBase64(blob) {
|
|
24
|
+
return new Promise((resolve, reject) => {
|
|
25
|
+
const reader = new FileReader();
|
|
26
|
+
reader.onloadend = () => {
|
|
27
|
+
resolve(reader.result);
|
|
28
|
+
};
|
|
29
|
+
reader.onerror = reject;
|
|
30
|
+
reader.readAsDataURL(blob);
|
|
31
|
+
});
|
|
32
|
+
}
|
|
33
|
+
|
|
22
34
|
function MapEditorModal({ id, onClose, onChange, ...rest }) {
|
|
23
35
|
const intl = useIntl();
|
|
24
36
|
const [value, setValue] = useState(rest.value || {});
|
|
@@ -189,14 +201,37 @@ function MapEditorModal({ id, onClose, onChange, ...rest }) {
|
|
|
189
201
|
}
|
|
190
202
|
|
|
191
203
|
export default function MapsWidget(props) {
|
|
192
|
-
const { id, title, description, error, value } = props;
|
|
204
|
+
const { id, title, description, error, value, onChange } = props;
|
|
193
205
|
const [mapEditor, setMapEditor] = useState(false);
|
|
194
206
|
|
|
195
|
-
function
|
|
196
|
-
|
|
207
|
+
function onChangeMap(value) {
|
|
208
|
+
onChange(id, value);
|
|
197
209
|
setMapEditor(false);
|
|
198
210
|
}
|
|
199
211
|
|
|
212
|
+
useEffect(() => {
|
|
213
|
+
if (value && value.url && value.preview_url_loaded !== value.url) {
|
|
214
|
+
fetch(
|
|
215
|
+
`${getBaseUrl(
|
|
216
|
+
'',
|
|
217
|
+
)}/cors-proxy/https://screenshot.eea.europa.eu/api/v1/retrieve_image_for_url?url=${encodeURIComponent(
|
|
218
|
+
value.url,
|
|
219
|
+
)}&w=1920&h=1000&waitfor=4000`,
|
|
220
|
+
)
|
|
221
|
+
.then((e) => e.blob())
|
|
222
|
+
.then((myBlob) => {
|
|
223
|
+
blobToBase64(myBlob).then((base64String) => {
|
|
224
|
+
onChange(id, {
|
|
225
|
+
...value,
|
|
226
|
+
preview: base64String,
|
|
227
|
+
preview_url_loaded: value.url,
|
|
228
|
+
});
|
|
229
|
+
});
|
|
230
|
+
})
|
|
231
|
+
.catch(() => {});
|
|
232
|
+
}
|
|
233
|
+
}, [value, onChange, id]);
|
|
234
|
+
|
|
200
235
|
return (
|
|
201
236
|
<FormFieldWrapper {...props} columns={1}>
|
|
202
237
|
<div className="wrapper">
|
|
@@ -218,7 +253,7 @@ export default function MapsWidget(props) {
|
|
|
218
253
|
<MapEditorModal
|
|
219
254
|
id={id}
|
|
220
255
|
value={value || {}}
|
|
221
|
-
onChange={
|
|
256
|
+
onChange={onChangeMap}
|
|
222
257
|
onClose={() => setMapEditor(false)}
|
|
223
258
|
/>
|
|
224
259
|
)}
|
package/src/index.js
CHANGED
|
@@ -2,6 +2,7 @@ import installBlocks from './Blocks';
|
|
|
2
2
|
import MapView from './Views/MapView';
|
|
3
3
|
import MapsViewWidget from './Widgets/MapsViewWidget';
|
|
4
4
|
import MapsWidget from './Widgets/MapsWidget';
|
|
5
|
+
import { preview_image } from './middlewares/preview_image';
|
|
5
6
|
export {
|
|
6
7
|
PrivacyProtection,
|
|
7
8
|
addPrivacyProtectionToSchema,
|
|
@@ -16,5 +17,9 @@ export default function applyConfig(config) {
|
|
|
16
17
|
...config.settings.allowed_cors_destinations,
|
|
17
18
|
'screenshot.eea.europa.eu',
|
|
18
19
|
];
|
|
20
|
+
config.settings.storeExtenders = [
|
|
21
|
+
...(config.settings.storeExtenders || []),
|
|
22
|
+
preview_image,
|
|
23
|
+
];
|
|
19
24
|
return [installBlocks].reduce((acc, apply) => apply(acc), config);
|
|
20
25
|
}
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
import {
|
|
2
|
+
CREATE_CONTENT,
|
|
3
|
+
UPDATE_CONTENT,
|
|
4
|
+
} from '@plone/volto/constants/ActionTypes';
|
|
5
|
+
|
|
6
|
+
const cleanAction = (action) => {
|
|
7
|
+
if (action?.request?.data?.maps) {
|
|
8
|
+
const mapVisualizationData = {
|
|
9
|
+
...action.request.data.maps,
|
|
10
|
+
};
|
|
11
|
+
if (mapVisualizationData.preview && mapVisualizationData.preview_url_loaded)
|
|
12
|
+
delete mapVisualizationData.preview;
|
|
13
|
+
delete mapVisualizationData.preview_url_loaded;
|
|
14
|
+
|
|
15
|
+
return {
|
|
16
|
+
...action,
|
|
17
|
+
request: {
|
|
18
|
+
...action.request,
|
|
19
|
+
data: {
|
|
20
|
+
...action.request.data,
|
|
21
|
+
|
|
22
|
+
maps: mapVisualizationData,
|
|
23
|
+
},
|
|
24
|
+
},
|
|
25
|
+
};
|
|
26
|
+
} else return action;
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
export const preview_image = (middlewares) => [
|
|
30
|
+
(store) => (next) => async (action) => {
|
|
31
|
+
if (![CREATE_CONTENT, UPDATE_CONTENT].includes(action.type)) {
|
|
32
|
+
return next(action);
|
|
33
|
+
}
|
|
34
|
+
const state = store.getState();
|
|
35
|
+
const contentData = state.content.data;
|
|
36
|
+
const lastPreviewImage = Object.keys(action?.request?.data).includes(
|
|
37
|
+
'preview_image',
|
|
38
|
+
)
|
|
39
|
+
? action?.request?.data.preview_image
|
|
40
|
+
: contentData?.preview_image;
|
|
41
|
+
const type = action?.request?.data?.['@type'] || contentData['@type'];
|
|
42
|
+
|
|
43
|
+
if (
|
|
44
|
+
!contentData ||
|
|
45
|
+
type !== 'map_interactive' ||
|
|
46
|
+
contentData.preview_image_saved ||
|
|
47
|
+
!action?.request?.data?.maps?.preview
|
|
48
|
+
) {
|
|
49
|
+
return next(cleanAction(action));
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
if (
|
|
53
|
+
lastPreviewImage &&
|
|
54
|
+
lastPreviewImage.filename !==
|
|
55
|
+
'preview_image_generated_map_interactive.png'
|
|
56
|
+
) {
|
|
57
|
+
return next(cleanAction(action));
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
try {
|
|
61
|
+
const previewImage = {
|
|
62
|
+
preview_image: {
|
|
63
|
+
data: action.request.data.maps.preview.split(',')[1],
|
|
64
|
+
encoding: 'base64',
|
|
65
|
+
'content-type': 'image/png',
|
|
66
|
+
filename: 'preview_image_generated_map_interactive.png',
|
|
67
|
+
},
|
|
68
|
+
preview_image_saved: true,
|
|
69
|
+
};
|
|
70
|
+
|
|
71
|
+
const mapVisualizationData = {
|
|
72
|
+
...action.request.data.maps,
|
|
73
|
+
};
|
|
74
|
+
delete mapVisualizationData.preview;
|
|
75
|
+
delete mapVisualizationData.preview_url_loaded;
|
|
76
|
+
|
|
77
|
+
return next({
|
|
78
|
+
...action,
|
|
79
|
+
request: {
|
|
80
|
+
...action.request,
|
|
81
|
+
data: {
|
|
82
|
+
...action.request.data,
|
|
83
|
+
...previewImage,
|
|
84
|
+
maps: mapVisualizationData,
|
|
85
|
+
},
|
|
86
|
+
},
|
|
87
|
+
});
|
|
88
|
+
} catch (error) {
|
|
89
|
+
return next(action);
|
|
90
|
+
}
|
|
91
|
+
},
|
|
92
|
+
...middlewares,
|
|
93
|
+
];
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import { preview_image } from './preview_image';
|
|
2
|
+
describe('preview_image middleware', () => {
|
|
3
|
+
let store;
|
|
4
|
+
let next;
|
|
5
|
+
let action;
|
|
6
|
+
let middlewares;
|
|
7
|
+
|
|
8
|
+
beforeEach(() => {
|
|
9
|
+
store = {
|
|
10
|
+
getState: jest.fn(() => ({
|
|
11
|
+
content: {
|
|
12
|
+
data: {
|
|
13
|
+
'@type': 'map_interactive',
|
|
14
|
+
preview_image: 'existing_image.png',
|
|
15
|
+
preview_image_saved: false,
|
|
16
|
+
},
|
|
17
|
+
},
|
|
18
|
+
})),
|
|
19
|
+
};
|
|
20
|
+
next = jest.fn();
|
|
21
|
+
middlewares = [];
|
|
22
|
+
});
|
|
23
|
+
|
|
24
|
+
it('existing image', () => {
|
|
25
|
+
action = { type: 'UPDATE_CONTENT', request: { data: {} } };
|
|
26
|
+
const middleware = preview_image(middlewares)[0]; // Accesăm prima funcție din array
|
|
27
|
+
middleware(store)(next)(action); // Executăm funcția de middleware
|
|
28
|
+
expect(next).toHaveBeenCalledWith(action); // Verificăm că funcția next a fost apelată cu acțiunea originală
|
|
29
|
+
});
|
|
30
|
+
it('redo the image', () => {
|
|
31
|
+
store = {
|
|
32
|
+
getState: jest.fn(() => ({
|
|
33
|
+
content: {
|
|
34
|
+
data: {
|
|
35
|
+
'@type': 'map_interactive',
|
|
36
|
+
preview_image: 'preview_image_generated_map_interactive.png',
|
|
37
|
+
preview_image_saved: false,
|
|
38
|
+
},
|
|
39
|
+
},
|
|
40
|
+
})),
|
|
41
|
+
};
|
|
42
|
+
next = jest.fn();
|
|
43
|
+
middlewares = [];
|
|
44
|
+
action = { type: 'UPDATE_CONTENT', request: { data: {} } };
|
|
45
|
+
const middleware = preview_image(middlewares)[0]; // Accesăm prima funcție din array
|
|
46
|
+
middleware(store)(next)(action); // Executăm funcția de middleware
|
|
47
|
+
expect(next).toHaveBeenCalledWith(action); // Verificăm că funcția next a fost apelată cu acțiunea originală
|
|
48
|
+
});
|
|
49
|
+
});
|