@eeacms/volto-embed 8.0.0 → 9.0.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 CHANGED
@@ -4,11 +4,21 @@ 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
- ### [8.0.0](https://github.com/eea/volto-embed/compare/7.0.2...8.0.0) - 17 November 2023
7
+ ### [9.0.0](https://github.com/eea/volto-embed/compare/8.0.0...9.0.0) - 23 November 2023
8
8
 
9
- #### :rocket: New Features
9
+ #### :bug: Bug Fixes
10
+
11
+ - fix: sonarqube [Miu Razvan - [`712eb36`](https://github.com/eea/volto-embed/commit/712eb36b87bbd9e0dbae67260081056ae2a0dfd6)]
12
+
13
+ #### :hammer_and_wrench: Others
10
14
 
11
- - feat: add new embed_maps block [Miu Razvan - [`0bbea27`](https://github.com/eea/volto-embed/commit/0bbea272c46623683c6c70f7b0c2da6513c31031)]
15
+ - update [Miu Razvan - [`8612b33`](https://github.com/eea/volto-embed/commit/8612b3348f486c121614073c950a5794e3fc979b)]
16
+ - update [Miu Razvan - [`7ee9b67`](https://github.com/eea/volto-embed/commit/7ee9b6700e88f2901066919443624313ef08dd1a)]
17
+ - update [Miu Razvan - [`926beb8`](https://github.com/eea/volto-embed/commit/926beb87d2c44907aebe57369312eea7bf22d656)]
18
+ - update [Miu Razvan - [`da351ae`](https://github.com/eea/volto-embed/commit/da351ae9ffaaef756f7a665618a03fd04cb9b01d)]
19
+ - use volto-datablocks@develop dependency [Miu Razvan - [`b379d84`](https://github.com/eea/volto-embed/commit/b379d8478657dd39dad066181b349cee7ac2531d)]
20
+ - add tets + fixes [Miu Razvan - [`b013196`](https://github.com/eea/volto-embed/commit/b013196cbaebaada27dd9ae5a0e4fe6908637152)]
21
+ ## [8.0.0](https://github.com/eea/volto-embed/compare/7.0.2...8.0.0) - 17 November 2023
12
22
 
13
23
  #### :hammer_and_wrench: Others
14
24
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@eeacms/volto-embed",
3
- "version": "8.0.0",
3
+ "version": "9.0.0",
4
4
  "description": "Embed external content",
5
5
  "main": "src/index.js",
6
6
  "author": "European Environment Agency: IDM2 A-Team",
@@ -20,8 +20,7 @@
20
20
  ],
21
21
  "dependencies": {
22
22
  "@eeacms/volto-corsproxy": "*",
23
- "@eeacms/volto-datablocks": "*",
24
- "react-visibility-sensor": "5.1.1"
23
+ "@eeacms/volto-datablocks": "*"
25
24
  },
26
25
  "devDependencies": {
27
26
  "@cypress/code-coverage": "^3.10.0",
@@ -72,4 +71,4 @@
72
71
  "cypress:open": "make cypress-open",
73
72
  "prepare": "husky install"
74
73
  }
75
- }
74
+ }
@@ -0,0 +1,75 @@
1
+ import React from 'react';
2
+ import renderer from 'react-test-renderer';
3
+ import configureStore from 'redux-mock-store';
4
+ import { Provider } from 'react-intl-redux';
5
+ import config from '@plone/volto/registry';
6
+
7
+ import Edit from './Edit';
8
+ import installEmbedMaps from '.';
9
+
10
+ installEmbedMaps(config);
11
+
12
+ const mockStore = configureStore();
13
+
14
+ jest.mock('@plone/volto/components', () => ({
15
+ __esModule: true,
16
+ SidebarPortal: jest.requireActual(
17
+ '@plone/volto/components/manage/Sidebar/SidebarPortal',
18
+ ).default,
19
+ UniversalLink: ({ children, href }) => {
20
+ return <a href={href}>{children}</a>;
21
+ },
22
+ }));
23
+
24
+ const store = mockStore({
25
+ intl: {
26
+ locale: 'en',
27
+ messages: {},
28
+ },
29
+ content: {
30
+ create: {},
31
+ },
32
+ connected_data_parameters: {},
33
+ });
34
+
35
+ test('renders an edit embed map block component', () => {
36
+ const component = renderer.create(
37
+ <Provider store={store}>
38
+ <Edit
39
+ id="my-map"
40
+ data={{
41
+ '@type': 'embed_maps',
42
+ with_notes: false,
43
+ with_sources: false,
44
+ with_more_info: true,
45
+ with_share: true,
46
+ with_enlarge: true,
47
+ url: '/path/to/map',
48
+ maps: {
49
+ '@id': '/path/to/map',
50
+ title: 'My map',
51
+ url:
52
+ 'https://www.google.com/maps/embed?pb=!1m18!1m12!1m3!1d3027.7835278268726!2d14.38842915203974!3d40.634655679238854!2m3!1f0!2f0!3f0!3m2!1i1024!2i768!4f13.1!3m3!1m2!1s0x133b994881d943cb%3A0x6ab93db57d3272f0!2sHotel+Mediterraneo+Sorrento!5e0!3m2!1sen!2ses!4v1550168740166',
53
+ },
54
+ dataprotection: {
55
+ enabled: false,
56
+ },
57
+ useVisibilitySensor: false,
58
+ }}
59
+ pathname="/news"
60
+ selected={false}
61
+ block="1234"
62
+ index={1}
63
+ onChangeBlock={() => {}}
64
+ onSelectBlock={() => {}}
65
+ onDeleteBlock={() => {}}
66
+ onFocusPreviousBlock={() => {}}
67
+ onFocusNextBlock={() => {}}
68
+ handleKeyDown={() => {}}
69
+ content={{}}
70
+ />
71
+ </Provider>,
72
+ );
73
+ const json = component.toJSON();
74
+ expect(json).toMatchSnapshot();
75
+ });
@@ -1,14 +1,24 @@
1
1
  import React, { useEffect, useMemo } from 'react';
2
2
  import { connect } from 'react-redux';
3
3
  import { Message } from 'semantic-ui-react';
4
+ import { getContent } from '@plone/volto/actions';
4
5
  import { flattenToAppURL } from '@plone/volto/helpers';
5
- import Map from '@eeacms/volto-embed/Map/Map';
6
+ import EmbedMap from '@eeacms/volto-embed/EmbedMap/EmbedMap';
7
+ import { pickMetadata } from '@eeacms/volto-embed/helpers';
6
8
 
7
- import { getContent } from '@plone/volto/actions';
9
+ function getMaps(props) {
10
+ const content = props.mapsContent || {};
11
+ const maps = content.maps || props.data?.maps || {};
12
+ return {
13
+ ...pickMetadata(content),
14
+ ...maps,
15
+ };
16
+ }
8
17
 
9
18
  function View(props) {
19
+ const { id, getContent, mode } = props;
10
20
  const {
11
- url,
21
+ useVisibilitySensor = true,
12
22
  with_notes = true,
13
23
  with_sources = true,
14
24
  with_more_info = true,
@@ -16,32 +26,16 @@ function View(props) {
16
26
  with_enlarge = true,
17
27
  } = props.data;
18
28
 
19
- const maps = useMemo(() => {
20
- if (props.data.maps) {
21
- return props.data.maps;
22
- }
23
- if (props.mapsContent?.maps) {
24
- return {
25
- ...props.mapsContent.maps,
26
- '@id': props.mapsContent['@id'],
27
- title: props.mapsContent['title'],
28
- publisher: props.mapsContent['publisher'],
29
- geo_coverage: props.mapsContent['geo_coverage'],
30
- temporal_coverage: props.mapsContent['temporal_coverage'],
31
- other_organisations: props.mapsContent['other_organisations'],
32
- data_provenance: props.mapsContent['data_provenance'],
33
- figure_note: props.mapsContent['figure_note'],
34
- };
35
- }
36
- return undefined;
37
- }, [props.data.maps, props.mapsContent]);
29
+ const url = flattenToAppURL(props.data.url || '');
30
+
31
+ const maps = useMemo(() => getMaps(props), [props]);
38
32
 
39
33
  useEffect(() => {
40
- if (props.data.url && !props.data.maps) {
41
- props.getContent(flattenToAppURL(props.data.url), null, props.id);
34
+ const mapsId = maps['@id'] ? flattenToAppURL(maps['@id']) : undefined;
35
+ if (mode === 'edit' && url && url !== mapsId) {
36
+ getContent(url, null, id);
42
37
  }
43
- /* eslint-disable-next-line */
44
- }, [props.data.url]);
38
+ }, [id, getContent, mode, url, maps]);
45
39
 
46
40
  if (props.mode === 'edit' && !url) {
47
41
  return <Message>Please select a map from block editor.</Message>;
@@ -53,9 +47,10 @@ function View(props) {
53
47
 
54
48
  return (
55
49
  <div className="embed-map">
56
- <Map
50
+ <EmbedMap
57
51
  data={{
58
52
  ...maps,
53
+ useVisibilitySensor,
59
54
  with_notes,
60
55
  with_sources,
61
56
  with_more_info,
@@ -0,0 +1,60 @@
1
+ import React from 'react';
2
+ import renderer from 'react-test-renderer';
3
+ import configureStore from 'redux-mock-store';
4
+ import { Provider } from 'react-intl-redux';
5
+ import config from '@plone/volto/registry';
6
+
7
+ import View from './View';
8
+ import installEmbedMaps from '.';
9
+
10
+ installEmbedMaps(config);
11
+
12
+ const mockStore = configureStore();
13
+
14
+ jest.mock('@plone/volto/components', () => ({
15
+ __esModule: true,
16
+ UniversalLink: ({ children, href }) => {
17
+ return <a href={href}>{children}</a>;
18
+ },
19
+ }));
20
+
21
+ test('renders a view embed map block component', () => {
22
+ const store = mockStore({
23
+ intl: {
24
+ locale: 'en',
25
+ messages: {},
26
+ },
27
+ content: {
28
+ create: {},
29
+ },
30
+ connected_data_parameters: {},
31
+ });
32
+ const component = renderer.create(
33
+ <Provider store={store}>
34
+ <View
35
+ id="my-map"
36
+ data={{
37
+ '@type': 'embed_maps',
38
+ with_notes: false,
39
+ with_sources: false,
40
+ with_more_info: true,
41
+ with_share: true,
42
+ with_enlarge: true,
43
+ url: '/path/to/map',
44
+ maps: {
45
+ '@id': '/path/to/map',
46
+ title: 'My map',
47
+ url:
48
+ 'https://www.google.com/maps/embed?pb=!1m18!1m12!1m3!1d3027.7835278268726!2d14.38842915203974!3d40.634655679238854!2m3!1f0!2f0!3f0!3m2!1i1024!2i768!4f13.1!3m3!1m2!1s0x133b994881d943cb%3A0x6ab93db57d3272f0!2sHotel+Mediterraneo+Sorrento!5e0!3m2!1sen!2ses!4v1550168740166',
49
+ },
50
+ dataprotection: {
51
+ enabled: false,
52
+ },
53
+ useVisibilitySensor: false,
54
+ }}
55
+ />
56
+ </Provider>,
57
+ );
58
+ const json = component.toJSON();
59
+ expect(json).toMatchSnapshot();
60
+ });
@@ -3,7 +3,7 @@ import EmbedView from './View';
3
3
 
4
4
  import sliderSVG from '@plone/volto/icons/slider.svg';
5
5
 
6
- const embedConfig = (config) => {
6
+ const applyConfig = (config) => {
7
7
  config.blocks.blocksConfig.embed_maps = {
8
8
  id: 'embed_maps',
9
9
  title: 'Embed Map',
@@ -19,4 +19,4 @@ const embedConfig = (config) => {
19
19
  return config;
20
20
  };
21
21
 
22
- export default embedConfig;
22
+ export default applyConfig;
@@ -229,6 +229,7 @@ class Edit extends Component {
229
229
  <PrivacyProtection
230
230
  data={this.props.data}
231
231
  editable={this.props.editable}
232
+ useVisibilitySensor={this.props.data.useVisibilitySensor ?? true}
232
233
  >
233
234
  <iframe
234
235
  title={this.props.intl.formatMessage(
@@ -0,0 +1,79 @@
1
+ import React from 'react';
2
+ import renderer from 'react-test-renderer';
3
+ import configureStore from 'redux-mock-store';
4
+ import { Provider } from 'react-intl-redux';
5
+ import config from '@plone/volto/registry';
6
+
7
+ import Edit from './Edit';
8
+
9
+ const mockStore = configureStore();
10
+
11
+ jest.mock('@plone/volto/components', () => ({
12
+ __esModule: true,
13
+ SidebarPortal: jest.requireActual(
14
+ '@plone/volto/components/manage/Sidebar/SidebarPortal',
15
+ ).default,
16
+ UniversalLink: ({ children, href }) => {
17
+ return <a href={href}>{children}</a>;
18
+ },
19
+ }));
20
+
21
+ const store = mockStore({
22
+ intl: {
23
+ locale: 'en',
24
+ messages: {},
25
+ },
26
+ content: {
27
+ create: {},
28
+ },
29
+ connected_data_parameters: {},
30
+ });
31
+
32
+ config.blocks.blocksConfig = {
33
+ ...config.blocks.blocksConfig,
34
+ maps: {
35
+ id: 'maps',
36
+ title: 'Maps',
37
+ group: 'media',
38
+ extensions: {},
39
+ variations: [],
40
+ restricted: false,
41
+ mostUsed: true,
42
+ sidebarTab: 1,
43
+ security: {
44
+ addPermission: [],
45
+ view: [],
46
+ },
47
+ },
48
+ };
49
+
50
+ test('renders an edit map block component', () => {
51
+ const component = renderer.create(
52
+ <Provider store={store}>
53
+ <Edit
54
+ data={{
55
+ '@type': 'maps',
56
+ url:
57
+ 'https://www.google.com/maps/embed?pb=!1m18!1m12!1m3!1d3027.7835278268726!2d14.38842915203974!3d40.634655679238854!2m3!1f0!2f0!3f0!3m2!1i1024!2i768!4f13.1!3m3!1m2!1s0x133b994881d943cb%3A0x6ab93db57d3272f0!2sHotel+Mediterraneo+Sorrento!5e0!3m2!1sen!2ses!4v1550168740166',
58
+ dataprotection: {
59
+ enabled: false,
60
+ },
61
+ useVisibilitySensor: false,
62
+ }}
63
+ pathname="/news"
64
+ selected={false}
65
+ block="1234"
66
+ index={1}
67
+ onChangeBlock={() => {}}
68
+ onSelectBlock={() => {}}
69
+ onDeleteBlock={() => {}}
70
+ onFocusPreviousBlock={() => {}}
71
+ onFocusNextBlock={() => {}}
72
+ handleKeyDown={() => {}}
73
+ content={{}}
74
+ />
75
+ </Provider>,
76
+ );
77
+ const json = component.toJSON();
78
+ expect(json).toMatchSnapshot();
79
+ });
@@ -40,7 +40,11 @@ const View = ({ data, intl, id }) => {
40
40
  'full-width': data.align === 'full',
41
41
  })}
42
42
  >
43
- <PrivacyProtection data={data} id={id}>
43
+ <PrivacyProtection
44
+ data={data}
45
+ id={id}
46
+ useVisibilitySensor={data.useVisibilitySensor}
47
+ >
44
48
  <iframe
45
49
  title={intl.formatMessage(messages.EmbededGoogleMaps)}
46
50
  src={data.url}
@@ -0,0 +1,67 @@
1
+ import React from 'react';
2
+ import renderer from 'react-test-renderer';
3
+ import configureStore from 'redux-mock-store';
4
+ import { Provider } from 'react-intl-redux';
5
+ import config from '@plone/volto/registry';
6
+
7
+ import View from './View';
8
+ import installEmbedMaps from '.';
9
+
10
+ installEmbedMaps(config);
11
+
12
+ const mockStore = configureStore();
13
+
14
+ jest.mock('@plone/volto/components', () => ({
15
+ __esModule: true,
16
+ UniversalLink: ({ children, href }) => {
17
+ return <a href={href}>{children}</a>;
18
+ },
19
+ }));
20
+
21
+ config.blocks.blocksConfig = {
22
+ ...config.blocks.blocksConfig,
23
+ maps: {
24
+ id: 'maps',
25
+ title: 'Maps',
26
+ group: 'media',
27
+ extensions: {},
28
+ variations: [],
29
+ restricted: false,
30
+ mostUsed: true,
31
+ sidebarTab: 1,
32
+ security: {
33
+ addPermission: [],
34
+ view: [],
35
+ },
36
+ },
37
+ };
38
+
39
+ test('renders a view map block component', () => {
40
+ const store = mockStore({
41
+ intl: {
42
+ locale: 'en',
43
+ messages: {},
44
+ },
45
+ content: {
46
+ create: {},
47
+ },
48
+ connected_data_parameters: {},
49
+ });
50
+ const component = renderer.create(
51
+ <Provider store={store}>
52
+ <View
53
+ data={{
54
+ '@type': 'maps',
55
+ url:
56
+ 'https://www.google.com/maps/embed?pb=!1m18!1m12!1m3!1d3027.7835278268726!2d14.38842915203974!3d40.634655679238854!2m3!1f0!2f0!3f0!3m2!1i1024!2i768!4f13.1!3m3!1m2!1s0x133b994881d943cb%3A0x6ab93db57d3272f0!2sHotel+Mediterraneo+Sorrento!5e0!3m2!1sen!2ses!4v1550168740166',
57
+ useVisibilitySensor: false,
58
+ dataprotection: {
59
+ enabled: false,
60
+ },
61
+ }}
62
+ />
63
+ </Provider>,
64
+ );
65
+ const json = component.toJSON();
66
+ expect(json).toMatchSnapshot();
67
+ });
@@ -21,7 +21,7 @@ const messages = defineMessages({
21
21
  },
22
22
  });
23
23
 
24
- function Map({ data, intl, id, screen }) {
24
+ function EmbedMap({ data, intl, id, screen }) {
25
25
  const el = useRef();
26
26
  const [mobile, setMobile] = useState(false);
27
27
 
@@ -53,7 +53,12 @@ function Map({ data, intl, id, screen }) {
53
53
  'full-width': data.align === 'full',
54
54
  })}
55
55
  >
56
- <PrivacyProtection data={data} id={id} height={data.height}>
56
+ <PrivacyProtection
57
+ data={data}
58
+ id={id}
59
+ height={data.height}
60
+ useVisibilitySensor={data.useVisibilitySensor ?? true}
61
+ >
57
62
  <iframe
58
63
  title={intl.formatMessage(messages.EmbededGoogleMaps)}
59
64
  src={data.url}
@@ -66,14 +71,14 @@ function Map({ data, intl, id, screen }) {
66
71
  </div>
67
72
  <div className={cx('visualization-toolbar', { mobile })}>
68
73
  <div className="left-col">
69
- {data.with_notes && <FigureNote note={data.figure_note || []} />}
74
+ {data.with_notes && <FigureNote notes={data.figure_note || []} />}
70
75
  {data.with_sources && <Sources sources={data.sources} />}
71
76
  {data.with_more_info && <MoreInfo href={data['@id']} />}
72
77
  </div>
73
78
  <div className="right-col">
74
79
  {data.with_enlarge && (
75
80
  <Enlarge className="enlarge-embed-maps">
76
- <Map
81
+ <EmbedMap
77
82
  data={{
78
83
  ...data,
79
84
  height: '100%',
@@ -98,4 +103,4 @@ function Map({ data, intl, id, screen }) {
98
103
  export default compose(
99
104
  injectIntl,
100
105
  connect((state) => ({ screen: state.screen })),
101
- )(Map);
106
+ )(EmbedMap);
@@ -0,0 +1,66 @@
1
+ import React from 'react';
2
+ import renderer from 'react-test-renderer';
3
+ import configureStore from 'redux-mock-store';
4
+ import { Provider } from 'react-intl-redux';
5
+ import config from '@plone/volto/registry';
6
+
7
+ import EmbedMap from './EmbedMap';
8
+
9
+ const mockStore = configureStore();
10
+
11
+ jest.mock('@plone/volto/components', () => ({
12
+ __esModule: true,
13
+ UniversalLink: ({ children, href }) => {
14
+ return <a href={href}>{children}</a>;
15
+ },
16
+ }));
17
+
18
+ config.blocks.blocksConfig = {
19
+ ...config.blocks.blocksConfig,
20
+ maps: {
21
+ id: 'maps',
22
+ title: 'Maps',
23
+ group: 'media',
24
+ extensions: {},
25
+ variations: [],
26
+ restricted: false,
27
+ mostUsed: true,
28
+ sidebarTab: 1,
29
+ security: {
30
+ addPermission: [],
31
+ view: [],
32
+ },
33
+ },
34
+ };
35
+
36
+ test('renders map component', () => {
37
+ const store = mockStore({
38
+ intl: {
39
+ locale: 'en',
40
+ messages: {},
41
+ },
42
+ content: {
43
+ create: {},
44
+ },
45
+ connected_data_parameters: {},
46
+ });
47
+ const component = renderer.create(
48
+ <Provider store={store}>
49
+ <EmbedMap
50
+ id="my-map"
51
+ data={{
52
+ with_notes: false,
53
+ with_sources: false,
54
+ with_more_info: true,
55
+ with_share: true,
56
+ with_enlarge: true,
57
+ url:
58
+ 'https://www.google.com/maps/embed?pb=!1m18!1m12!1m3!1d3027.7835278268726!2d14.38842915203974!3d40.634655679238854!2m3!1f0!2f0!3f0!3m2!1i1024!2i768!4f13.1!3m3!1m2!1s0x133b994881d943cb%3A0x6ab93db57d3272f0!2sHotel+Mediterraneo+Sorrento!5e0!3m2!1sen!2ses!4v1550168740166',
59
+ useVisibilitySensor: false,
60
+ }}
61
+ />
62
+ </Provider>,
63
+ );
64
+ const json = component.toJSON();
65
+ expect(json).toMatchSnapshot();
66
+ });
@@ -87,6 +87,7 @@ const PrivacyProtection = (props) => {
87
87
  intl,
88
88
  path,
89
89
  cookies,
90
+ useVisibilitySensor = true,
90
91
  } = props;
91
92
  const {
92
93
  enabled = false,
@@ -173,6 +174,7 @@ const PrivacyProtection = (props) => {
173
174
  <Placeholder.Image rectangular />
174
175
  </Placeholder>
175
176
  )}
177
+ useVisibilitySensor={useVisibilitySensor}
176
178
  >
177
179
  <div
178
180
  className={cx('privacy-protection-wrapper', className)}
@@ -38,8 +38,7 @@ export default function FigureNote({ notes = [] }) {
38
38
  <button className={cx('trigger-button', { open })}>Note</button>
39
39
  </div>
40
40
  }
41
- >
42
- <Popup.Content>{serializeText(notes)}</Popup.Content>
43
- </Popup>
41
+ content={serializeText(notes)}
42
+ />
44
43
  );
45
44
  }
@@ -0,0 +1,96 @@
1
+ import React from 'react';
2
+ import renderer from 'react-test-renderer';
3
+ import configureStore from 'redux-mock-store';
4
+ import { Provider } from 'react-intl-redux';
5
+ import config from '@plone/volto/registry';
6
+
7
+ import { Enlarge, FigureNote, MoreInfo, Share, Sources } from '.';
8
+
9
+ const mockStore = configureStore();
10
+
11
+ jest.mock('@plone/volto/components', () => ({
12
+ __esModule: true,
13
+ UniversalLink: ({ children, href }) => {
14
+ return <a href={href}>{children}</a>;
15
+ },
16
+ }));
17
+
18
+ jest.mock('@plone/volto-slate/editor/render', () => ({
19
+ __esModule: true,
20
+ serializeNodes: (nodes) => {
21
+ return nodes.map((node, index) => {
22
+ const Tag = node.type;
23
+ return (
24
+ <Tag key={`node-${index}`}>
25
+ {node.children.map((item, index) => (
26
+ <span key={`item-${index}`}>{item.text}</span>
27
+ ))}
28
+ </Tag>
29
+ );
30
+ });
31
+ },
32
+ serializeNodesToText: (nodes) => {
33
+ return nodes
34
+ .reduce((texts, node) => {
35
+ if (node.children) {
36
+ node.children.forEach((item) => {
37
+ texts.push(item.text);
38
+ });
39
+ }
40
+ return texts;
41
+ }, [])
42
+ .join('');
43
+ },
44
+ }));
45
+
46
+ config.blocks.blocksConfig = {
47
+ ...config.blocks.blocksConfig,
48
+ maps: {
49
+ id: 'maps',
50
+ title: 'Maps',
51
+ group: 'media',
52
+ extensions: {},
53
+ variations: [],
54
+ restricted: false,
55
+ mostUsed: true,
56
+ sidebarTab: 1,
57
+ security: {
58
+ addPermission: [],
59
+ view: [],
60
+ },
61
+ },
62
+ };
63
+
64
+ test('renders toolbar components', () => {
65
+ const store = mockStore({
66
+ intl: {
67
+ locale: 'en',
68
+ messages: {},
69
+ },
70
+ content: {
71
+ create: {},
72
+ },
73
+ connected_data_parameters: {},
74
+ });
75
+ const component = renderer.create(
76
+ <Provider store={store}>
77
+ <div className="visualization-toolbar">
78
+ <div className="left-col">
79
+ <FigureNote
80
+ notes={[{ type: 'p', children: [{ text: 'This is a note' }] }]}
81
+ />
82
+ <Sources sources={[]} />
83
+ <MoreInfo href={'/path/to/embeded/content'} />
84
+ </div>
85
+ <div className="right-col">
86
+ <Enlarge className="enlarge-embed-maps">
87
+ <div>Some enlarged content</div>
88
+ </Enlarge>
89
+ <Share href="/path/to/embeded/content" />
90
+ </div>
91
+ </div>
92
+ </Provider>,
93
+ );
94
+ const json = component.toJSON();
95
+ expect(json).toMatchSnapshot();
96
+ });
@@ -1,11 +1,11 @@
1
1
  import React from 'react';
2
2
  import { Container } from 'semantic-ui-react';
3
- import Map from '@eeacms/volto-embed/Map/Map';
3
+ import EmbedMap from '@eeacms/volto-embed/EmbedMap/EmbedMap';
4
4
 
5
5
  const MapView = (props) => {
6
6
  return (
7
7
  <Container>
8
- <Map data={props.content.maps} id={props.content['@id']} />
8
+ <EmbedMap data={props.content.maps} id={props.content['@id']} />
9
9
  </Container>
10
10
  );
11
11
  };
@@ -0,0 +1,68 @@
1
+ import React from 'react';
2
+ import renderer from 'react-test-renderer';
3
+ import configureStore from 'redux-mock-store';
4
+ import { Provider } from 'react-intl-redux';
5
+ import config from '@plone/volto/registry';
6
+
7
+ import MapView from './MapView';
8
+
9
+ const mockStore = configureStore();
10
+
11
+ jest.mock('@plone/volto/components', () => ({
12
+ __esModule: true,
13
+ UniversalLink: ({ children, href }) => {
14
+ return <a href={href}>{children}</a>;
15
+ },
16
+ }));
17
+
18
+ config.blocks.blocksConfig = {
19
+ ...config.blocks.blocksConfig,
20
+ maps: {
21
+ id: 'maps',
22
+ title: 'Maps',
23
+ group: 'media',
24
+ extensions: {},
25
+ variations: [],
26
+ restricted: false,
27
+ mostUsed: true,
28
+ sidebarTab: 1,
29
+ security: {
30
+ addPermission: [],
31
+ view: [],
32
+ },
33
+ },
34
+ };
35
+
36
+ test('renders map component', () => {
37
+ const store = mockStore({
38
+ intl: {
39
+ locale: 'en',
40
+ messages: {},
41
+ },
42
+ content: {
43
+ create: {},
44
+ },
45
+ connected_data_parameters: {},
46
+ });
47
+ const component = renderer.create(
48
+ <Provider store={store}>
49
+ <MapView
50
+ content={{
51
+ maps: {
52
+ '@id': '/path/to/map',
53
+ with_notes: false,
54
+ with_sources: false,
55
+ with_more_info: true,
56
+ with_share: true,
57
+ with_enlarge: true,
58
+ url:
59
+ 'https://www.google.com/maps/embed?pb=!1m18!1m12!1m3!1d3027.7835278268726!2d14.38842915203974!3d40.634655679238854!2m3!1f0!2f0!3f0!3m2!1i1024!2i768!4f13.1!3m3!1m2!1s0x133b994881d943cb%3A0x6ab93db57d3272f0!2sHotel+Mediterraneo+Sorrento!5e0!3m2!1sen!2ses!4v1550168740166',
60
+ useVisibilitySensor: false,
61
+ },
62
+ }}
63
+ />
64
+ </Provider>,
65
+ );
66
+ const json = component.toJSON();
67
+ expect(json).toMatchSnapshot();
68
+ });
@@ -1,5 +1,5 @@
1
- import Map from '@eeacms/volto-embed/Map/Map';
1
+ import EmbedMap from '@eeacms/volto-embed/EmbedMap/EmbedMap';
2
2
 
3
3
  export default function MapsViewWidget({ id, value }) {
4
- return <Map data={value} id={id} />;
4
+ return <EmbedMap data={value} id={id} />;
5
5
  }
@@ -5,7 +5,7 @@ import { Button, Modal, Grid, Label, Input, Message } from 'semantic-ui-react';
5
5
  import { map } from 'lodash';
6
6
  import { FormFieldWrapper, InlineForm } from '@plone/volto/components';
7
7
  import { addPrivacyProtectionToSchema } from '@eeacms/volto-embed';
8
- import Map from '@eeacms/volto-embed/Map/Map';
8
+ import EmbedMap from '@eeacms/volto-embed/EmbedMap/EmbedMap';
9
9
  import { MapsSchema } from '@eeacms/volto-embed/Blocks/Maps/schema';
10
10
 
11
11
  import clearSVG from '@plone/volto/icons/clear.svg';
@@ -103,7 +103,7 @@ function MapEditorModal({ id, onClose, onChange, ...rest }) {
103
103
  computer={8}
104
104
  className="tableau-visualization-column"
105
105
  >
106
- <Map data={value} id={id} />
106
+ <EmbedMap data={value} id={id} />
107
107
  </Grid.Column>
108
108
  </Grid>
109
109
  )}
@@ -204,7 +204,7 @@ export default function MapsWidget(props) {
204
204
  </Button>
205
205
  </div>
206
206
  {description && <p className="help">{description}</p>}
207
- {value.url && <Map {...props} data={value} />}
207
+ {value.url && <EmbedMap {...props} data={value} />}
208
208
  {mapEditor && (
209
209
  <MapEditorModal
210
210
  id={id}
package/src/helpers.js ADDED
@@ -0,0 +1,16 @@
1
+ import { pick } from 'lodash';
2
+
3
+ export function pickMetadata(content) {
4
+ return {
5
+ ...pick(content, [
6
+ '@id',
7
+ 'title',
8
+ 'data_provenance',
9
+ 'figure_note',
10
+ 'other_organisations',
11
+ 'temporan_coverage',
12
+ 'publisher',
13
+ 'geo_coverage',
14
+ ]),
15
+ };
16
+ }
@@ -1,119 +0,0 @@
1
- /* eslint-disable no-unused-vars */
2
- import React from 'react';
3
- import config from '@plone/volto/registry';
4
- import { render, fireEvent, screen } from '@testing-library/react';
5
- import { Provider } from 'react-intl-redux';
6
- import configureStore from 'redux-mock-store';
7
- import Edit from './Edit';
8
- import '@testing-library/jest-dom/extend-expect';
9
-
10
- const mockStore = configureStore();
11
-
12
- const store = mockStore(() => ({
13
- connected_data_parameters: {},
14
- router: {
15
- location: {
16
- pathname: '',
17
- },
18
- },
19
- intl: {
20
- locale: 'en',
21
- messages: {},
22
- },
23
- }));
24
-
25
- config.blocks.blocksConfig = {
26
- ...config.blocks.blocksConfig,
27
- maps: {
28
- id: 'maps',
29
- title: 'Maps',
30
- group: 'media',
31
- extensions: {},
32
- variations: [],
33
- restricted: false,
34
- mostUsed: true,
35
- sidebarTab: 1,
36
- security: {
37
- addPermission: [],
38
- view: [],
39
- },
40
- },
41
- };
42
-
43
- jest.mock(
44
- '@eeacms/volto-embed/PrivacyProtection/PrivacyProtection',
45
- () => ({ children }) => children,
46
- );
47
-
48
- describe('Edit', () => {
49
- it('renders without crashing', () => {
50
- render(
51
- <Provider store={store}>
52
- <Edit
53
- selected={false}
54
- block="block"
55
- index={1}
56
- data={{
57
- '@type': 'maps',
58
- url:
59
- 'https://www.google.com/maps/embed?pb=!1m18!1m12!1m3!1d3027.7835278268726!2d14.38842915203974!3d40.634655679238854!2m3!1f0!2f0!3f0!3m2!1i1024!2i768!4f13.1!3m3!1m2!1s0x133b994881d943cb%3A0x6ab93db57d3272f0!2sHotel+Mediterraneo+Sorrento!5e0!3m2!1sen!2ses!4v1550168740166',
60
- }}
61
- pathname="/"
62
- onChangeBlock={() => {}}
63
- onSelectBlock={() => {}}
64
- onDeleteBlock={() => {}}
65
- onFocusPreviousBlock={() => {}}
66
- onFocusNextBlock={() => {}}
67
- handleKeyDown={() => {}}
68
- />
69
- </Provider>,
70
- );
71
- });
72
-
73
- it('submits url when button is clicked', async () => {
74
- const url =
75
- 'https://www.google.com/maps/embed?pb=!1m18!1m12!1m3!1d3027.7835278268726!2d14.38842915203974!3d40.634655679238854!2m3!1f0!2f0!3f0!3m2!1i1024!2i768!4f13.1!3m3!1m2!1s0x133b994881d943cb%3A0x6ab93db57d3272f0!2sHotel+Mediterraneo+Sorrento!5e0!3m2!1sen!2ses!4v1550168740166';
76
-
77
- const { container, getByPlaceholderText } = render(
78
- <Provider store={store}>
79
- <Edit
80
- selected={false}
81
- block="block"
82
- index={1}
83
- data={{
84
- '@type': 'maps',
85
- dataprotection: {
86
- privacy_statement: 'test',
87
- },
88
- }}
89
- pathname="/"
90
- onChangeBlock={() => {}}
91
- onSelectBlock={() => {}}
92
- onDeleteBlock={() => {}}
93
- onFocusPreviousBlock={() => {}}
94
- onFocusNextBlock={() => {}}
95
- handleKeyDown={() => {}}
96
- />
97
- </Provider>,
98
- );
99
-
100
- const input = getByPlaceholderText('Enter map Embed Code');
101
-
102
- fireEvent.click(input);
103
- fireEvent.change(input, { target: { value: url } });
104
- // screen.debug();
105
- // expect(input.value).toBe(url);
106
-
107
- // fireEvent.click(container.querySelector('button.cancel'));
108
-
109
- // fireEvent.keyDown(input, { key: 'Enter', code: 'Enter' });
110
- // fireEvent.keyDown(input, { key: 'Escape', code: 'Escape' });
111
- // fireEvent.keyDown(input, { key: 'KeyA', code: 'KeyA' });
112
-
113
- // fireEvent.change(input, { target: { value: '<iframe src="test"/>' } });
114
- // fireEvent.keyDown(input, { key: 'Enter', code: 'Enter' });
115
-
116
- // const button = container.querySelector('button.ui.basic.primary.button');
117
- // fireEvent.click(button);
118
- });
119
- });
File without changes