@eeacms/volto-hero-block 5.3.1 → 5.4.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 +17 -16
- package/README.md +1 -1
- package/jest-addon.config.js +2 -2
- package/package.json +1 -1
- package/src/components/Blocks/Hero/Copyright.test.jsx +35 -0
- package/src/components/Blocks/Hero/Edit.jsx +3 -1
- package/src/components/Blocks/Hero/Hero.jsx +3 -2
- package/src/components/Blocks/Hero/Hero.test.jsx +40 -0
- package/src/components/Blocks/Hero/View.jsx +3 -1
- package/src/helpers.js +19 -1
- package/src/helpers.test.js +66 -0
package/CHANGELOG.md
CHANGED
|
@@ -4,6 +4,23 @@ 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
|
+
### [5.4.0](https://github.com/eea/volto-hero-block/compare/5.3.1...5.4.0) - 12 June 2023
|
|
8
|
+
|
|
9
|
+
#### :house: Internal changes
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
#### :hammer_and_wrench: Others
|
|
13
|
+
|
|
14
|
+
- Release 5.4.0 [Alin Voinea - [`1b54e52`](https://github.com/eea/volto-hero-block/commit/1b54e52ad0f3185917d19015220037efb407422c)]
|
|
15
|
+
- test: jest should look for addons in node_modules Refs #253277 [valentinab25 - [`531ac2a`](https://github.com/eea/volto-hero-block/commit/531ac2a53eec82921d21d2606553580597fc8c82)]
|
|
16
|
+
- test: Add cypress test for basic functionality and demo gif to README - refs #253277 [ana-oprea - [`9f8cd97`](https://github.com/eea/volto-hero-block/commit/9f8cd978e1cd776f44be1adc23aae19cf1efda49)]
|
|
17
|
+
- test: Add unit tests for Hero, Copyright and helpers - refs #253277 [ana-oprea - [`3949378`](https://github.com/eea/volto-hero-block/commit/3949378060a7eb373e8ded529f7047d5c5a60aa9)]
|
|
18
|
+
- test: Fix test config, coverage Refs #253277 [valentinab25 - [`33c1d94`](https://github.com/eea/volto-hero-block/commit/33c1d949c32b69556c05a74cc28ed9aef4112f83)]
|
|
19
|
+
- merge develop into this branch [Miu Razvan - [`cc1cda3`](https://github.com/eea/volto-hero-block/commit/cc1cda3edcbd2c2cbbdda8a3ec03d7084b6eca5c)]
|
|
20
|
+
- clean up [Miu Razvan - [`2a51fcf`](https://github.com/eea/volto-hero-block/commit/2a51fcf5a79a6497a3f7609216efe944c45a0af0)]
|
|
21
|
+
- other: update getFieldURL function [Miu Razvan - [`8c9ee98`](https://github.com/eea/volto-hero-block/commit/8c9ee980e898cb09a553f5956871c0b285c80280)]
|
|
22
|
+
- update with getFieldURL on buttonLink [tedw87 - [`4d1fd61`](https://github.com/eea/volto-hero-block/commit/4d1fd61faba366a96a54c23e67d7d306364924fe)]
|
|
23
|
+
- refactor code [tedw87 - [`0bf669d`](https://github.com/eea/volto-hero-block/commit/0bf669d7d150d1b9e33ff6e727d6cf47f6d4871e)]
|
|
7
24
|
### [5.3.1](https://github.com/eea/volto-hero-block/compare/5.3.0...5.3.1) - 22 May 2023
|
|
8
25
|
|
|
9
26
|
#### :hammer_and_wrench: Others
|
|
@@ -11,7 +28,6 @@ Generated by [`auto-changelog`](https://github.com/CookPete/auto-changelog).
|
|
|
11
28
|
- put return statement [Dobricean Ioan Dorian - [`8eff5fd`](https://github.com/eea/volto-hero-block/commit/8eff5fdf977fcbb8cc952d3f45b577b02ca59cb9)]
|
|
12
29
|
- change name and refactor to be more efficent [Dobricean Ioan Dorian - [`ff24145`](https://github.com/eea/volto-hero-block/commit/ff2414542833998ef282376de3fbda8698287849)]
|
|
13
30
|
- stop-image-disappear over and over [Dobricean Ioan Dorian - [`c5b6f54`](https://github.com/eea/volto-hero-block/commit/c5b6f545ac422d95b8d802349aa4cf27af820829)]
|
|
14
|
-
- Add Sonarqube tag using industry-frontend addons list [EEA Jenkins - [`3d38dd0`](https://github.com/eea/volto-hero-block/commit/3d38dd09a36525bda448f67a6d218bc7690a4cc3)]
|
|
15
31
|
### [5.3.0](https://github.com/eea/volto-hero-block/compare/5.2.0...5.3.0) - 27 March 2023
|
|
16
32
|
|
|
17
33
|
#### :rocket: New Features
|
|
@@ -50,11 +66,9 @@ Generated by [`auto-changelog`](https://github.com/CookPete/auto-changelog).
|
|
|
50
66
|
- fix onScreen hook error #16 from eea/fix-onscreen-hook [ichim-david - [`9123541`](https://github.com/eea/volto-hero-block/commit/91235413f423d7e6c4788d70b687b3ed5d4884b4)]
|
|
51
67
|
- no need for comments [andreiggr - [`a14f9c3`](https://github.com/eea/volto-hero-block/commit/a14f9c3bdddfa22e6b4bbc8318f0ca5bdc9c2d38)]
|
|
52
68
|
- fix hook [andreiggr - [`f7fae73`](https://github.com/eea/volto-hero-block/commit/f7fae73007f79af2f06da1d9b72a53ad86fef4ac)]
|
|
53
|
-
- Add Sonarqube tag using eea-website-frontend addons list [EEA Jenkins - [`6b78fc0`](https://github.com/eea/volto-hero-block/commit/6b78fc044a933ab9b4b4694901aa26628ef0a836)]
|
|
54
69
|
- eslint [andreiggr - [`68451b7`](https://github.com/eea/volto-hero-block/commit/68451b725420015fbd5b695e97b8742988d49913)]
|
|
55
70
|
- lazy load huge img on first 10px [andreiggr - [`67dc7d3`](https://github.com/eea/volto-hero-block/commit/67dc7d3475188d692e053032c2639dd1a585c029)]
|
|
56
71
|
- lazy load huge bgimage wip [andreiggr - [`86e45ec`](https://github.com/eea/volto-hero-block/commit/86e45ece842f1cd7452920dffa3a9b4aea945f56)]
|
|
57
|
-
- Add Sonarqube tag using ims-frontend addons list [EEA Jenkins - [`87cbb38`](https://github.com/eea/volto-hero-block/commit/87cbb383290a168f85703573670e17f4e1ed7747)]
|
|
58
72
|
## [4.0.0](https://github.com/eea/volto-hero-block/compare/3.0.1...4.0.0) - 7 February 2023
|
|
59
73
|
|
|
60
74
|
#### :nail_care: Enhancements
|
|
@@ -80,7 +94,6 @@ Generated by [`auto-changelog`](https://github.com/CookPete/auto-changelog).
|
|
|
80
94
|
|
|
81
95
|
#### :hammer_and_wrench: Others
|
|
82
96
|
|
|
83
|
-
- Add Sonarqube tag using advisory-board-frontend addons list [EEA Jenkins - [`ab85c7b`](https://github.com/eea/volto-hero-block/commit/ab85c7bd5bd1e3aec95e02f9b4d026b1203d5739)]
|
|
84
97
|
## [3.0.0](https://github.com/eea/volto-hero-block/compare/2.1.0...3.0.0) - 22 December 2022
|
|
85
98
|
|
|
86
99
|
#### :rocket: New Features
|
|
@@ -89,11 +102,8 @@ Generated by [`auto-changelog`](https://github.com/CookPete/auto-changelog).
|
|
|
89
102
|
|
|
90
103
|
#### :hammer_and_wrench: Others
|
|
91
104
|
|
|
92
|
-
- Add Sonarqube tag using advisory-board-frontend addons list [EEA Jenkins - [`f06f58c`](https://github.com/eea/volto-hero-block/commit/f06f58c7cd4cfc15a03208e9c7a4e31fe2eba2f6)]
|
|
93
|
-
- Add Sonarqube tag using climate-energy-frontend addons list [EEA Jenkins - [`20e5bcb`](https://github.com/eea/volto-hero-block/commit/20e5bcb3c4dd538595741928319c3204c5d18f8c)]
|
|
94
105
|
- Cosmetics [Alin Voinea - [`9dac70c`](https://github.com/eea/volto-hero-block/commit/9dac70c0a3bea8e188ede9123f4f99de8e0f6987)]
|
|
95
106
|
- test(Jenkins): Run tests and cypress with latest canary @plone/volto [Alin Voinea - [`2d4005f`](https://github.com/eea/volto-hero-block/commit/2d4005f0f31b121e1b7d2e94414f3dff92ec1a16)]
|
|
96
|
-
- Add Sonarqube tag using cca-frontend addons list [EEA Jenkins - [`2931fcc`](https://github.com/eea/volto-hero-block/commit/2931fccbee5f8e117e5ae9095ba57e63e465ddb3)]
|
|
97
107
|
### [2.1.0](https://github.com/eea/volto-hero-block/compare/2.0.0...2.1.0) - 12 December 2022
|
|
98
108
|
|
|
99
109
|
#### :bug: Bug Fixes
|
|
@@ -102,12 +112,6 @@ Generated by [`auto-changelog`](https://github.com/CookPete/auto-changelog).
|
|
|
102
112
|
|
|
103
113
|
#### :hammer_and_wrench: Others
|
|
104
114
|
|
|
105
|
-
- Add Sonarqube tag using bise-frontend addons list [EEA Jenkins - [`93be4f9`](https://github.com/eea/volto-hero-block/commit/93be4f96fb72cacfc25f9b058cb379d80060ee13)]
|
|
106
|
-
- yarn 3 [Alin Voinea - [`8e2dccd`](https://github.com/eea/volto-hero-block/commit/8e2dccd47cbef3c0871407baa376ce61c540c754)]
|
|
107
|
-
- Add Sonarqube tag using marine-frontend addons list [EEA Jenkins - [`6bc3af3`](https://github.com/eea/volto-hero-block/commit/6bc3af35b4edf07971d1b0ce1648965e8d6e3bc0)]
|
|
108
|
-
- Add Sonarqube tag using clms-frontend addons list [EEA Jenkins - [`d7dbbd2`](https://github.com/eea/volto-hero-block/commit/d7dbbd21277dd76bf59d91a4dc8e022b2a6ff99c)]
|
|
109
|
-
- Add Sonarqube tag using demo-kitkat-frontend addons list [EEA Jenkins - [`3c1f0d6`](https://github.com/eea/volto-hero-block/commit/3c1f0d6e7f8e5318aee3413ec3687d8492376f9d)]
|
|
110
|
-
- Add Sonarqube tag using forests-frontend addons list [EEA Jenkins - [`843017a`](https://github.com/eea/volto-hero-block/commit/843017aa7dbea71cc7888663496e352d287440b4)]
|
|
111
115
|
## [2.0.0](https://github.com/eea/volto-hero-block/compare/1.0.0...2.0.0) - 16 November 2022
|
|
112
116
|
|
|
113
117
|
#### :nail_care: Enhancements
|
|
@@ -117,7 +121,6 @@ Generated by [`auto-changelog`](https://github.com/CookPete/auto-changelog).
|
|
|
117
121
|
#### :hammer_and_wrench: Others
|
|
118
122
|
|
|
119
123
|
- test(estlint): Fix .project.eslintrc.js [Alin Voinea - [`b8f0971`](https://github.com/eea/volto-hero-block/commit/b8f0971b21a5334d40c1b8f5103cea61d9ffe6f1)]
|
|
120
|
-
- Add Sonarqube tag using circularity-frontend addons list [EEA Jenkins - [`581dedf`](https://github.com/eea/volto-hero-block/commit/581dedf07410ef2ca09e6ddaa05fbf176400adbb)]
|
|
121
124
|
## [1.0.0](https://github.com/eea/volto-hero-block/compare/0.2.0...1.0.0) - 28 October 2022
|
|
122
125
|
|
|
123
126
|
#### :nail_care: Enhancements
|
|
@@ -129,7 +132,6 @@ Generated by [`auto-changelog`](https://github.com/CookPete/auto-changelog).
|
|
|
129
132
|
- Remove cypress.json [Alin Voinea - [`593bdf2`](https://github.com/eea/volto-hero-block/commit/593bdf207ca4fd3f2393117b6f64a44727881ad0)]
|
|
130
133
|
- test(cypress): Upgrade to Cypress 10 / Razzle 4 [Alin Voinea - [`edd48a5`](https://github.com/eea/volto-hero-block/commit/edd48a5c13824bce5e03e46790f1890656b340d8)]
|
|
131
134
|
- Cleanup [Alin Voinea - [`9d72ee7`](https://github.com/eea/volto-hero-block/commit/9d72ee7a06d1c6fed46586d30bb85eae39e670bf)]
|
|
132
|
-
- Add Sonarqube tag using eea-website-frontend addons list [EEA Jenkins - [`95986d0`](https://github.com/eea/volto-hero-block/commit/95986d0b8fd5c3cbb9e6da9059f71e066a8e171b)]
|
|
133
135
|
### [0.2.0](https://github.com/eea/volto-hero-block/compare/0.1.4...0.2.0) - 6 July 2022
|
|
134
136
|
|
|
135
137
|
#### :bug: Bug Fixes
|
|
@@ -168,7 +170,6 @@ Generated by [`auto-changelog`](https://github.com/CookPete/auto-changelog).
|
|
|
168
170
|
- Update slate footnote support [Miu Razvan - [`c1522b4`](https://github.com/eea/volto-hero-block/commit/c1522b4164dbe6de01771d211d7e0bf3009f44d4)]
|
|
169
171
|
- Use justify content for text and button as well [Miu Razvan - [`08599cc`](https://github.com/eea/volto-hero-block/commit/08599cc45546d9b349128c4f8ce9c01318385811)]
|
|
170
172
|
- Add dependencies [Miu Razvan - [`30e2881`](https://github.com/eea/volto-hero-block/commit/30e2881a2a97a899e7f4cc614a0405c300ac6fee)]
|
|
171
|
-
- Add Sonarqube tag using eea-website-frontend addons list [EEA Jenkins - [`b415422`](https://github.com/eea/volto-hero-block/commit/b41542285edd29440a324b101a4dbae9334830bf)]
|
|
172
173
|
### 0.1.0 - 10 June 2022
|
|
173
174
|
|
|
174
175
|
#### :hammer_and_wrench: Others
|
package/README.md
CHANGED
package/jest-addon.config.js
CHANGED
|
@@ -5,19 +5,19 @@ module.exports = {
|
|
|
5
5
|
'!src/**/*.d.ts',
|
|
6
6
|
],
|
|
7
7
|
moduleNameMapper: {
|
|
8
|
+
'\\.(css|less|scss|sass)$': 'identity-obj-proxy',
|
|
8
9
|
'@plone/volto/cypress': '<rootDir>/node_modules/@plone/volto/cypress',
|
|
9
10
|
'@plone/volto/babel': '<rootDir>/node_modules/@plone/volto/babel',
|
|
10
11
|
'@plone/volto/(.*)$': '<rootDir>/node_modules/@plone/volto/src/$1',
|
|
11
12
|
'@package/(.*)$': '<rootDir>/src/$1',
|
|
12
13
|
'@root/(.*)$': '<rootDir>/src/$1',
|
|
13
14
|
'@plone/volto-quanta/(.*)$': '<rootDir>/src/addons/volto-quanta/src/$1',
|
|
14
|
-
'@eeacms/(.*?)/(.*)$': '<rootDir>/
|
|
15
|
+
'@eeacms/(.*?)/(.*)$': '<rootDir>/node_modules/@eeacms/$1/src/$2',
|
|
15
16
|
'@plone/volto-slate':
|
|
16
17
|
'<rootDir>/node_modules/@plone/volto/packages/volto-slate/src',
|
|
17
18
|
'~/(.*)$': '<rootDir>/src/$1',
|
|
18
19
|
'load-volto-addons':
|
|
19
20
|
'<rootDir>/node_modules/@plone/volto/jest-addons-loader.js',
|
|
20
|
-
'\\.(css|less|scss|sass)$': 'identity-obj-proxy',
|
|
21
21
|
},
|
|
22
22
|
transform: {
|
|
23
23
|
'^.+\\.js(x)?$': 'babel-jest',
|
package/package.json
CHANGED
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import renderer from 'react-test-renderer';
|
|
3
|
+
import Copyright from './Copyright';
|
|
4
|
+
import { Icon } from 'semantic-ui-react';
|
|
5
|
+
import { Provider } from 'react-intl-redux';
|
|
6
|
+
import configureStore from 'redux-mock-store';
|
|
7
|
+
import config from '@plone/volto/registry';
|
|
8
|
+
|
|
9
|
+
const mockStore = configureStore();
|
|
10
|
+
|
|
11
|
+
test('renders copyright', () => {
|
|
12
|
+
const store = mockStore({
|
|
13
|
+
intl: {
|
|
14
|
+
locale: 'en',
|
|
15
|
+
messages: {},
|
|
16
|
+
},
|
|
17
|
+
});
|
|
18
|
+
const copyrightPrefix =
|
|
19
|
+
config.blocks.blocksConfig.hero?.copyrightPrefix || '';
|
|
20
|
+
|
|
21
|
+
const component = renderer.create(
|
|
22
|
+
<Provider store={store}>
|
|
23
|
+
<Copyright copyrightPosition={'left'}>
|
|
24
|
+
<Copyright.Prefix>{copyrightPrefix}</Copyright.Prefix>
|
|
25
|
+
<Copyright.Icon>
|
|
26
|
+
<Icon className={'copyright outline'} />
|
|
27
|
+
</Copyright.Icon>
|
|
28
|
+
<Copyright.Text>Copyright Text Test</Copyright.Text>
|
|
29
|
+
</Copyright>
|
|
30
|
+
</Provider>,
|
|
31
|
+
);
|
|
32
|
+
|
|
33
|
+
const json = component.toJSON();
|
|
34
|
+
expect(json).toMatchSnapshot();
|
|
35
|
+
});
|
|
@@ -18,11 +18,13 @@ import {
|
|
|
18
18
|
} from '@plone/volto-slate/actions';
|
|
19
19
|
|
|
20
20
|
import { createSlateHeader } from '@eeacms/volto-hero-block/helpers';
|
|
21
|
+
import { getFieldURL } from '@eeacms/volto-hero-block/helpers';
|
|
21
22
|
|
|
22
23
|
import Copyright from './Copyright';
|
|
23
24
|
import Hero from './Hero';
|
|
24
25
|
|
|
25
|
-
const Metadata = ({ buttonLabel,
|
|
26
|
+
const Metadata = ({ buttonLabel, inverted, styles, ...props }) => {
|
|
27
|
+
const buttonLink = getFieldURL(props.buttonLink);
|
|
26
28
|
const { buttonVariant } = styles || {};
|
|
27
29
|
|
|
28
30
|
return buttonLabel ? (
|
|
@@ -2,7 +2,7 @@ import React from 'react';
|
|
|
2
2
|
import cx from 'classnames';
|
|
3
3
|
import PropTypes from 'prop-types';
|
|
4
4
|
import { isInternalURL } from '@plone/volto/helpers/Url/Url';
|
|
5
|
-
import { isImageGif } from '@eeacms/volto-hero-block/helpers';
|
|
5
|
+
import { isImageGif, getFieldURL } from '@eeacms/volto-hero-block/helpers';
|
|
6
6
|
import { useFirstVisited } from '@eeacms/volto-hero-block/hooks';
|
|
7
7
|
|
|
8
8
|
Hero.propTypes = {
|
|
@@ -19,7 +19,6 @@ Hero.propTypes = {
|
|
|
19
19
|
};
|
|
20
20
|
|
|
21
21
|
function Hero({
|
|
22
|
-
image,
|
|
23
22
|
overlay = true,
|
|
24
23
|
fullWidth = true,
|
|
25
24
|
fullHeight = true,
|
|
@@ -27,7 +26,9 @@ function Hero({
|
|
|
27
26
|
spaced = false,
|
|
28
27
|
inverted = true,
|
|
29
28
|
styles,
|
|
29
|
+
...props
|
|
30
30
|
}) {
|
|
31
|
+
const image = getFieldURL(props.image);
|
|
31
32
|
const isExternal = !isInternalURL(image);
|
|
32
33
|
const { alignContent = 'center', backgroundVariant = 'primary' } =
|
|
33
34
|
styles || {};
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import renderer from 'react-test-renderer';
|
|
3
|
+
import Hero from './Hero';
|
|
4
|
+
import { Provider } from 'react-intl-redux';
|
|
5
|
+
import configureStore from 'redux-mock-store';
|
|
6
|
+
|
|
7
|
+
const mockStore = configureStore();
|
|
8
|
+
|
|
9
|
+
test('renders a hero component', () => {
|
|
10
|
+
const store = mockStore({
|
|
11
|
+
intl: {
|
|
12
|
+
locale: 'en',
|
|
13
|
+
messages: {},
|
|
14
|
+
},
|
|
15
|
+
});
|
|
16
|
+
const component = renderer.create(
|
|
17
|
+
<Provider store={store}>
|
|
18
|
+
<Hero
|
|
19
|
+
image=""
|
|
20
|
+
overlay={true}
|
|
21
|
+
fullWidth={true}
|
|
22
|
+
fullHeight={true}
|
|
23
|
+
spaced={false}
|
|
24
|
+
inverted={true}
|
|
25
|
+
styles={{ alignContent: 'center', backgroundVariant: 'primary' }}
|
|
26
|
+
>
|
|
27
|
+
<Hero.Text
|
|
28
|
+
quoted={false}
|
|
29
|
+
styles={{ textVariant: 'white', textAlign: 'left' }}
|
|
30
|
+
>
|
|
31
|
+
Text test
|
|
32
|
+
</Hero.Text>
|
|
33
|
+
<Hero.Meta styles={{ buttonAlign: 'left' }}>Test meta</Hero.Meta>
|
|
34
|
+
</Hero>
|
|
35
|
+
</Provider>,
|
|
36
|
+
);
|
|
37
|
+
|
|
38
|
+
const json = component.toJSON();
|
|
39
|
+
expect(json).toMatchSnapshot();
|
|
40
|
+
});
|
|
@@ -6,9 +6,11 @@ import { BodyClass } from '@plone/volto/helpers';
|
|
|
6
6
|
import Hero from './Hero';
|
|
7
7
|
import Copyright from './Copyright';
|
|
8
8
|
import { serializeText } from '@eeacms/volto-hero-block/helpers';
|
|
9
|
+
import { getFieldURL } from '@eeacms/volto-hero-block/helpers';
|
|
9
10
|
import config from '@plone/volto/registry';
|
|
10
11
|
|
|
11
|
-
const Metadata = ({ buttonLabel,
|
|
12
|
+
const Metadata = ({ buttonLabel, inverted, styles, ...props }) => {
|
|
13
|
+
const buttonLink = getFieldURL(props.buttonLink);
|
|
12
14
|
const { buttonVariant = 'white' } = styles || {};
|
|
13
15
|
|
|
14
16
|
return buttonLabel ? (
|
package/src/helpers.js
CHANGED
|
@@ -1,5 +1,23 @@
|
|
|
1
|
-
import { isArray } from 'lodash';
|
|
2
1
|
import { serializeNodes } from '@plone/volto-slate/editor/render';
|
|
2
|
+
import isArray from 'lodash/isArray';
|
|
3
|
+
import isObject from 'lodash/isObject';
|
|
4
|
+
import isString from 'lodash/isString';
|
|
5
|
+
import { isInternalURL, flattenToAppURL } from '@plone/volto/helpers';
|
|
6
|
+
|
|
7
|
+
export const getFieldURL = (data) => {
|
|
8
|
+
let url = data;
|
|
9
|
+
const _isObject = data && isObject(data) && !isArray(data);
|
|
10
|
+
if (_isObject && data['@type'] === 'URL') {
|
|
11
|
+
url = data['value'] ?? data['url'] ?? data['href'] ?? data;
|
|
12
|
+
} else if (_isObject) {
|
|
13
|
+
url = data['@id'] ?? data['url'] ?? data['href'] ?? data;
|
|
14
|
+
}
|
|
15
|
+
if (isArray(data)) {
|
|
16
|
+
url = data.map((item) => getFieldURL(item));
|
|
17
|
+
}
|
|
18
|
+
if (isString(url) && isInternalURL(url)) return flattenToAppURL(url);
|
|
19
|
+
return url;
|
|
20
|
+
};
|
|
3
21
|
|
|
4
22
|
const createEmptyHeader = () => {
|
|
5
23
|
return {
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
import { createSlateHeader, serializeText, isImageGif } from './helpers';
|
|
2
|
+
import { isArray } from 'lodash';
|
|
3
|
+
import { serializeNodes } from '@plone/volto-slate/editor/render';
|
|
4
|
+
|
|
5
|
+
jest.mock('@plone/volto-slate/editor/render', () => ({
|
|
6
|
+
serializeNodes: jest.fn(),
|
|
7
|
+
}));
|
|
8
|
+
|
|
9
|
+
describe('createSlateHeader', () => {
|
|
10
|
+
it('should return the text if it is an array', () => {
|
|
11
|
+
const text = ['some', 'text'];
|
|
12
|
+
expect(createSlateHeader(text)).toEqual(text);
|
|
13
|
+
});
|
|
14
|
+
|
|
15
|
+
it('should return an array with an empty header if the text is not an array', () => {
|
|
16
|
+
const text = 'some text';
|
|
17
|
+
expect(createSlateHeader(text)).toEqual([
|
|
18
|
+
{
|
|
19
|
+
type: 'h2',
|
|
20
|
+
children: [{ text: '' }],
|
|
21
|
+
},
|
|
22
|
+
]);
|
|
23
|
+
});
|
|
24
|
+
});
|
|
25
|
+
|
|
26
|
+
describe('serializeText', () => {
|
|
27
|
+
it('should return the text when it is not an array', () => {
|
|
28
|
+
const text = 'Hello, World!';
|
|
29
|
+
|
|
30
|
+
expect(serializeText(text)).toEqual(text);
|
|
31
|
+
expect(isArray(text)).toBe(false);
|
|
32
|
+
expect(serializeNodes).not.toHaveBeenCalled();
|
|
33
|
+
});
|
|
34
|
+
|
|
35
|
+
it('should call serializeNodes when text is an array', () => {
|
|
36
|
+
const text = ['Hello', 'World!'];
|
|
37
|
+
|
|
38
|
+
serializeText(text);
|
|
39
|
+
expect(isArray(text)).toBe(true);
|
|
40
|
+
expect(serializeNodes).toHaveBeenCalledWith(text);
|
|
41
|
+
});
|
|
42
|
+
});
|
|
43
|
+
|
|
44
|
+
describe('isImageGif', () => {
|
|
45
|
+
it('should return true when input is a gif image', () => {
|
|
46
|
+
const input = 'image.gif';
|
|
47
|
+
const result = isImageGif(input);
|
|
48
|
+
expect(result).toBeTruthy();
|
|
49
|
+
});
|
|
50
|
+
|
|
51
|
+
it('should return false when input is not a gif image', () => {
|
|
52
|
+
const input = 'image.jpg';
|
|
53
|
+
const result = isImageGif(input);
|
|
54
|
+
expect(result).toBeFalsy();
|
|
55
|
+
});
|
|
56
|
+
|
|
57
|
+
it('should return false when input is null or undefined', () => {
|
|
58
|
+
let input;
|
|
59
|
+
let result = isImageGif(input);
|
|
60
|
+
expect(result).toBeFalsy();
|
|
61
|
+
|
|
62
|
+
input = null;
|
|
63
|
+
result = isImageGif(input);
|
|
64
|
+
expect(result).toBeFalsy();
|
|
65
|
+
});
|
|
66
|
+
});
|