@blaze-cms/react-page-builder 0.122.1 → 0.123.0-alpha.4
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 +30 -0
- package/lib/application/query/index.js +7 -1
- package/lib/application/query/index.js.map +1 -1
- package/lib/components/Card/CardRender.js +1 -0
- package/lib/components/Card/CardRender.js.map +1 -1
- package/lib/components/DataSummary/helpers/build-props-to-display-with-content.js +20 -3
- package/lib/components/DataSummary/helpers/build-props-to-display-with-content.js.map +1 -1
- package/lib/components/DataSummary/helpers/get-link-based-on-value.js +28 -0
- package/lib/components/DataSummary/helpers/get-link-based-on-value.js.map +1 -0
- package/lib/components/DataSummary/helpers/index.js +8 -0
- package/lib/components/DataSummary/helpers/index.js.map +1 -1
- package/lib/components/Menu/Menu.js +46 -4
- package/lib/components/Menu/Menu.js.map +1 -1
- package/lib/components/SearchContent/index.js +227 -0
- package/lib/components/SearchContent/index.js.map +1 -0
- package/lib/components/index.js +5 -5
- package/lib/components/index.js.map +1 -1
- package/lib/constants/index.js +6 -2
- package/lib/constants/index.js.map +1 -1
- package/lib-es/application/query/index.js +29 -1
- package/lib-es/application/query/index.js.map +1 -1
- package/lib-es/components/Card/CardRender.js +1 -0
- package/lib-es/components/Card/CardRender.js.map +1 -1
- package/lib-es/components/DataSummary/helpers/build-props-to-display-with-content.js +19 -3
- package/lib-es/components/DataSummary/helpers/build-props-to-display-with-content.js.map +1 -1
- package/lib-es/components/DataSummary/helpers/get-link-based-on-value.js +16 -0
- package/lib-es/components/DataSummary/helpers/get-link-based-on-value.js.map +1 -0
- package/lib-es/components/DataSummary/helpers/index.js +2 -1
- package/lib-es/components/DataSummary/helpers/index.js.map +1 -1
- package/lib-es/components/Menu/Menu.js +46 -5
- package/lib-es/components/Menu/Menu.js.map +1 -1
- package/lib-es/components/SearchContent/index.js +155 -0
- package/lib-es/components/SearchContent/index.js.map +1 -0
- package/lib-es/components/index.js +4 -4
- package/lib-es/components/index.js.map +1 -1
- package/lib-es/constants/index.js +3 -1
- package/lib-es/constants/index.js.map +1 -1
- package/package.json +2 -2
- package/src/application/query/index.js +29 -0
- package/src/components/Card/CardRender.js +4 -0
- package/src/components/DataSummary/helpers/build-props-to-display-with-content.js +15 -3
- package/src/components/DataSummary/helpers/get-link-based-on-value.js +14 -0
- package/src/components/DataSummary/helpers/index.js +3 -1
- package/src/components/Menu/Menu.js +44 -2
- package/src/components/SearchContent/index.js +153 -0
- package/src/components/index.js +4 -2
- package/src/constants/index.js +6 -1
- package/tests/helpers/mocks.js +33 -10
- package/tests/unit/src/components/Card/CardRender.test.js +20 -6
- package/tests/unit/src/components/Card/__snapshots__/CardRender.test.js.snap +50 -1
- package/tests/unit/src/components/DataSummary/helpers/build-props-to-display-with-content.test.js +22 -0
- package/tests/unit/src/components/DataSummary/helpers/get-link-based-on-value.test.js +29 -0
- package/tests/unit/src/components/Menu/__snapshots__/Menu.test.js.snap +11 -7
- package/tests/unit/src/components/__snapshots__/index.test.js.snap +4 -4
|
@@ -3,6 +3,7 @@ import flatten from 'lodash.flatten';
|
|
|
3
3
|
import { isObject } from '../../../helpers';
|
|
4
4
|
import getLinkToPublishedContent from './get-link-to-published-content';
|
|
5
5
|
import getPropValue from './get-prop-value';
|
|
6
|
+
import getLinkBasedOnValue from './get-link-based-on-value';
|
|
6
7
|
|
|
7
8
|
const buildPropsToDisplayWithContent = (props, propsToDisplay = []) => {
|
|
8
9
|
if (!isObject(propsToDisplay[0])) {
|
|
@@ -19,18 +20,29 @@ const buildPropsToDisplayWithContent = (props, propsToDisplay = []) => {
|
|
|
19
20
|
|
|
20
21
|
return flatten(
|
|
21
22
|
propsToDisplay.map(options => {
|
|
22
|
-
const { propertiesToDisplay, label, modifier = '' } = options;
|
|
23
|
+
const { propertiesToDisplay, label, modifier = '', enableLink } = options;
|
|
23
24
|
return propertiesToDisplay.map(key => {
|
|
24
25
|
if (!key) return null;
|
|
25
26
|
|
|
26
27
|
const objPropValue = getPropValue(key, props, options);
|
|
27
28
|
if (!objPropValue) return null;
|
|
28
|
-
const linkToPublishedContent = getLinkToPublishedContent(key, props);
|
|
29
29
|
|
|
30
|
-
|
|
30
|
+
const link = getLink(enableLink, key, props, objPropValue);
|
|
31
|
+
|
|
32
|
+
return [upperFirst(label), objPropValue, link, modifier];
|
|
31
33
|
});
|
|
32
34
|
})
|
|
33
35
|
).filter(Boolean);
|
|
34
36
|
};
|
|
35
37
|
|
|
36
38
|
export default buildPropsToDisplayWithContent;
|
|
39
|
+
function getLink(enableLink, key, props, objPropValue) {
|
|
40
|
+
let link = '';
|
|
41
|
+
if (enableLink) {
|
|
42
|
+
link = getLinkToPublishedContent(key, props);
|
|
43
|
+
if (!link) {
|
|
44
|
+
link = getLinkBasedOnValue(objPropValue);
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
return link;
|
|
48
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { DATA_SUMMARY_EMAIL_REGEX, DATA_SUMMARY_URL_REGEX } from '../../../constants';
|
|
2
|
+
|
|
3
|
+
function getLinkBasedOnValue(value) {
|
|
4
|
+
if (DATA_SUMMARY_EMAIL_REGEX.test(value)) {
|
|
5
|
+
return `mailto:${value}`;
|
|
6
|
+
}
|
|
7
|
+
if (DATA_SUMMARY_URL_REGEX.test(value)) {
|
|
8
|
+
return value;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
return '';
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export default getLinkBasedOnValue;
|
|
@@ -4,6 +4,7 @@ import getLinkToPublishedContent from './get-link-to-published-content';
|
|
|
4
4
|
import stripSummaryPropsContent from './strip-summary-props-content';
|
|
5
5
|
import buildLoopPropsContent from './build-loop-props-content';
|
|
6
6
|
import parseBooleanValues from './parse-boolean-values';
|
|
7
|
+
import getLinkBasedOnValue from './get-link-based-on-value';
|
|
7
8
|
|
|
8
9
|
export {
|
|
9
10
|
getDataSummaryQuery,
|
|
@@ -11,5 +12,6 @@ export {
|
|
|
11
12
|
getLinkToPublishedContent,
|
|
12
13
|
stripSummaryPropsContent,
|
|
13
14
|
buildLoopPropsContent,
|
|
14
|
-
parseBooleanValues
|
|
15
|
+
parseBooleanValues,
|
|
16
|
+
getLinkBasedOnValue
|
|
15
17
|
};
|
|
@@ -4,6 +4,7 @@ import BlazeButton from '@blaze-react/button';
|
|
|
4
4
|
import { MdMenu, MdClose } from 'react-icons/md';
|
|
5
5
|
import { useCheckMobileScreen } from '../../hooks';
|
|
6
6
|
import { HIDDEN } from '../../constants';
|
|
7
|
+
import SearchContent from '../SearchContent';
|
|
7
8
|
|
|
8
9
|
const Menu = ({
|
|
9
10
|
children,
|
|
@@ -14,7 +15,15 @@ const Menu = ({
|
|
|
14
15
|
mobileIconAlignment,
|
|
15
16
|
mobileButtonModifier,
|
|
16
17
|
hamburgerIconModifier,
|
|
18
|
+
searchInputAlignment,
|
|
19
|
+
logoOnMobile,
|
|
20
|
+
logoOnDesktop,
|
|
21
|
+
logoOnMobileUrl,
|
|
22
|
+
logoOnMobileAlt,
|
|
23
|
+
logoOnMobileModifier,
|
|
24
|
+
logoOnDesktopModifier,
|
|
17
25
|
closeIconModifier,
|
|
26
|
+
entity,
|
|
18
27
|
...rest
|
|
19
28
|
}) => {
|
|
20
29
|
const isMobile = useCheckMobileScreen();
|
|
@@ -34,7 +43,7 @@ const Menu = ({
|
|
|
34
43
|
return (
|
|
35
44
|
<>
|
|
36
45
|
{collapse && (
|
|
37
|
-
<div className="
|
|
46
|
+
<div className="menu--mobile-wrapper">
|
|
38
47
|
<div
|
|
39
48
|
className={`flex w-screen z-50 justify-${mobileIconAlignment} ${isMobileMenuExpanded}`}>
|
|
40
49
|
<BlazeButton
|
|
@@ -48,16 +57,41 @@ const Menu = ({
|
|
|
48
57
|
)}
|
|
49
58
|
</i>
|
|
50
59
|
</BlazeButton>
|
|
60
|
+
{showMobileMenu && (
|
|
61
|
+
<SearchContent searchInputAlignment={searchInputAlignment} entity={entity} />
|
|
62
|
+
)}
|
|
51
63
|
</div>
|
|
52
64
|
</div>
|
|
53
65
|
)}
|
|
54
|
-
|
|
66
|
+
{logoOnMobile &&
|
|
67
|
+
!showMobileMenu && (
|
|
68
|
+
<a href="/">
|
|
69
|
+
<img src={logoOnMobileUrl} alt={logoOnMobileAlt} className={logoOnMobileModifier} />
|
|
70
|
+
</a>
|
|
71
|
+
)}
|
|
72
|
+
|
|
73
|
+
<div className="menu--desktop-wrapper">
|
|
74
|
+
<ul className={isMobile ? childrenMobileModifier : childrenDesktopModifier}>
|
|
75
|
+
{logoOnDesktop && (
|
|
76
|
+
<a href="/" className="">
|
|
77
|
+
<img src={logoOnMobileUrl} alt={logoOnMobileAlt} className={logoOnDesktopModifier} />
|
|
78
|
+
</a>
|
|
79
|
+
)}
|
|
80
|
+
{children}
|
|
81
|
+
</ul>
|
|
82
|
+
</div>
|
|
55
83
|
</>
|
|
56
84
|
);
|
|
57
85
|
};
|
|
58
86
|
|
|
59
87
|
Menu.propTypes = {
|
|
60
88
|
collapse: PropTypes.bool.isRequired,
|
|
89
|
+
logoOnMobile: PropTypes.bool.isRequired,
|
|
90
|
+
logoOnDesktop: PropTypes.bool.isRequired,
|
|
91
|
+
logoOnMobileUrl: PropTypes.string,
|
|
92
|
+
logoOnMobileAlt: PropTypes.string,
|
|
93
|
+
logoOnMobileModifier: PropTypes.string,
|
|
94
|
+
logoOnDesktopModifier: PropTypes.string,
|
|
61
95
|
hamburgerIconModifier: PropTypes.string,
|
|
62
96
|
closeIconModifier: PropTypes.string,
|
|
63
97
|
mobileButtonModifier: PropTypes.string,
|
|
@@ -65,17 +99,25 @@ Menu.propTypes = {
|
|
|
65
99
|
mobileMenuChildrenModifier: PropTypes.string,
|
|
66
100
|
modifier: PropTypes.string,
|
|
67
101
|
mobileIconAlignment: PropTypes.string,
|
|
102
|
+
searchInputAlignment: PropTypes.string,
|
|
103
|
+
entity: PropTypes.string,
|
|
68
104
|
children: PropTypes.oneOfType([PropTypes.arrayOf(PropTypes.node), PropTypes.node])
|
|
69
105
|
};
|
|
70
106
|
|
|
71
107
|
Menu.defaultProps = {
|
|
108
|
+
logoOnMobileUrl: '',
|
|
109
|
+
logoOnMobileAlt: '',
|
|
110
|
+
logoOnMobileModifier: '',
|
|
111
|
+
logoOnDesktopModifier: '',
|
|
72
112
|
hamburgerIconModifier: '',
|
|
73
113
|
closeIconModifier: '',
|
|
74
114
|
mobileButtonModifier: '',
|
|
75
115
|
mobileIconAlignment: '',
|
|
76
116
|
mobileMenuModifier: '',
|
|
77
117
|
mobileMenuChildrenModifier: '',
|
|
118
|
+
searchInputAlignment: '',
|
|
78
119
|
modifier: '',
|
|
120
|
+
entity: 'PublishedPage',
|
|
79
121
|
children: []
|
|
80
122
|
};
|
|
81
123
|
|
|
@@ -0,0 +1,153 @@
|
|
|
1
|
+
import React, { useState } from 'react';
|
|
2
|
+
import PropTypes from 'prop-types';
|
|
3
|
+
import { gql, useQuery } from '@apollo/client';
|
|
4
|
+
import { useRouter } from 'next/router';
|
|
5
|
+
import { getPublishedContent } from '../../application/query';
|
|
6
|
+
|
|
7
|
+
const SearchContent = ({ searchInputAlignment, entity }) => {
|
|
8
|
+
const [collapsed, setCollapsed] = useState(true);
|
|
9
|
+
const [searchTerm, setSearchTerm] = useState(null);
|
|
10
|
+
const router = useRouter();
|
|
11
|
+
|
|
12
|
+
let alignmentModifier = '';
|
|
13
|
+
|
|
14
|
+
if (searchInputAlignment && searchInputAlignment !== '') {
|
|
15
|
+
alignmentModifier = searchInputAlignment === 'left' ? 'left-6' : 'right-16';
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
const capitalize = s => {
|
|
19
|
+
if (typeof s !== 'string') return '';
|
|
20
|
+
return s.charAt(0).toUpperCase() + s.slice(1);
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
const [a, b] = entity.split('_');
|
|
24
|
+
|
|
25
|
+
const entityName = capitalize(a) + capitalize(b);
|
|
26
|
+
|
|
27
|
+
const rawQueryStringified = JSON.stringify({
|
|
28
|
+
size: 0,
|
|
29
|
+
query: {
|
|
30
|
+
bool: {
|
|
31
|
+
should: [
|
|
32
|
+
{
|
|
33
|
+
match: {
|
|
34
|
+
docType: entity
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
],
|
|
38
|
+
minimum_should_match: 1
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
const query = gql`
|
|
44
|
+
${getPublishedContent(entityName)}
|
|
45
|
+
`;
|
|
46
|
+
|
|
47
|
+
const { loading, error, data } = useQuery(query, {
|
|
48
|
+
variables: { rawQueryStringified, offset: 0, limit: 5 }
|
|
49
|
+
});
|
|
50
|
+
|
|
51
|
+
if (loading) return null;
|
|
52
|
+
if (error) return `Error! ${error}`;
|
|
53
|
+
|
|
54
|
+
const renderResults = () => {
|
|
55
|
+
// eslint-disable-next-line no-undef
|
|
56
|
+
const { results } = data?.searchPublishedContent;
|
|
57
|
+
|
|
58
|
+
const handleClick = (e, url) => {
|
|
59
|
+
e.preventDefault();
|
|
60
|
+
router.push(url);
|
|
61
|
+
};
|
|
62
|
+
|
|
63
|
+
if (results && searchTerm && searchTerm !== '') {
|
|
64
|
+
return results.map(({ name, url }) => {
|
|
65
|
+
if (name.match(searchTerm)) {
|
|
66
|
+
return (
|
|
67
|
+
<a href={url} onClick={e => handleClick(e, url)}>
|
|
68
|
+
{name}
|
|
69
|
+
</a>
|
|
70
|
+
);
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
return null;
|
|
74
|
+
});
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
return [];
|
|
78
|
+
};
|
|
79
|
+
|
|
80
|
+
const searchResultsMessage = searchTerm ? `Search results for: ${searchTerm}` : '';
|
|
81
|
+
|
|
82
|
+
return collapsed ? (
|
|
83
|
+
<div className={`absolute rounded-3xl overflow-clip top-3 ${alignmentModifier}`}>
|
|
84
|
+
<div className="w-11 mx-auto">
|
|
85
|
+
<label className="relative block">
|
|
86
|
+
<span className="absolute inset-y-0 right-3 flex items-center pl-2 cursor-pointer">
|
|
87
|
+
<svg className="h-5 w-5 fill-slate-300" viewBox="0 0 20 20">
|
|
88
|
+
<path
|
|
89
|
+
fillRule="evenodd"
|
|
90
|
+
d="M8 4a4 4 0 100 8 4 4 0 000-8zM2 8a6 6 0 1110.89 3.476l4.817 4.817a1 1 0 01-1.414 1.414l-4.816-4.816A6 6 0 012 8z"
|
|
91
|
+
clipRule="evenodd"
|
|
92
|
+
/>
|
|
93
|
+
</svg>
|
|
94
|
+
</span>
|
|
95
|
+
<span className="sr-only">Search</span>
|
|
96
|
+
<input
|
|
97
|
+
onFocus={() => setCollapsed(false)}
|
|
98
|
+
onChange={e => setSearchTerm(e.target.value)}
|
|
99
|
+
type="text"
|
|
100
|
+
name="search"
|
|
101
|
+
value=""
|
|
102
|
+
className="disabled:bg-white block bg-white w-full rounded-full py-2 pl-5 pr-3 placeholder:italic placeholder:text-gray-400 focus:outline-none sm:text-sm"
|
|
103
|
+
/>
|
|
104
|
+
</label>
|
|
105
|
+
</div>
|
|
106
|
+
</div>
|
|
107
|
+
) : (
|
|
108
|
+
<>
|
|
109
|
+
<div className={`absolute overflow-clip top-3 ${alignmentModifier}`}>
|
|
110
|
+
<div className="w-96 mx-auto rounded-3xl">
|
|
111
|
+
<label className="relative block">
|
|
112
|
+
<span className="absolute inset-y-0 right-3 flex items-center pl-2">
|
|
113
|
+
<svg className="h-5 w-5 fill-slate-300" viewBox="0 0 20 20">
|
|
114
|
+
<path
|
|
115
|
+
fillRule="evenodd"
|
|
116
|
+
d="M8 4a4 4 0 100 8 4 4 0 000-8zM2 8a6 6 0 1110.89 3.476l4.817 4.817a1 1 0 01-1.414 1.414l-4.816-4.816A6 6 0 012 8z"
|
|
117
|
+
clipRule="evenodd"
|
|
118
|
+
/>
|
|
119
|
+
</svg>
|
|
120
|
+
</span>
|
|
121
|
+
<span className="sr-only">Search</span>
|
|
122
|
+
<input
|
|
123
|
+
type="text"
|
|
124
|
+
name="search"
|
|
125
|
+
onChange={e => setSearchTerm(e.target.value)}
|
|
126
|
+
className="block bg-white w-full rounded-full py-2 pl-3 pr-3 placeholder:italic placeholder:text-slate-400 focus:outline-none sm:text-sm"
|
|
127
|
+
placeholder="Search for anything..."
|
|
128
|
+
onBlur={() => setCollapsed(true)}
|
|
129
|
+
/>
|
|
130
|
+
</label>
|
|
131
|
+
</div>
|
|
132
|
+
<div className="bg-white ml-1 mr-1 rounded rounded-lg relative top-0 flex flex-col">
|
|
133
|
+
<div className="text-sm pt-2">{searchResultsMessage}</div>
|
|
134
|
+
|
|
135
|
+
<div className="text-left px-4 py-2">
|
|
136
|
+
<div className="text-bold">{data && renderResults()}</div>
|
|
137
|
+
</div>
|
|
138
|
+
</div>
|
|
139
|
+
</div>
|
|
140
|
+
</>
|
|
141
|
+
);
|
|
142
|
+
};
|
|
143
|
+
|
|
144
|
+
SearchContent.propTypes = {
|
|
145
|
+
searchInputAlignment: PropTypes.string,
|
|
146
|
+
entity: PropTypes.string.isRequired
|
|
147
|
+
};
|
|
148
|
+
|
|
149
|
+
SearchContent.defaultProps = {
|
|
150
|
+
searchInputAlignment: ''
|
|
151
|
+
};
|
|
152
|
+
|
|
153
|
+
export default SearchContent;
|
package/src/components/index.js
CHANGED
|
@@ -17,6 +17,9 @@ export default {
|
|
|
17
17
|
textblock: dynamic(() => import(/* webpackChunkName: "blazePbTextBlock" */ './TextBlock')),
|
|
18
18
|
video: dynamic(() => import(/* webpackChunkName: "blazePbVideo" */ './Video')),
|
|
19
19
|
wrapper: dynamic(() => import(/* webpackChunkName: "blazePbWrapper" */ './Wrapper')),
|
|
20
|
+
searchcontent: dynamic(() =>
|
|
21
|
+
import(/* webpackChunkName: "blazePbSearchFilter" */ './SearchContent')
|
|
22
|
+
),
|
|
20
23
|
searchfilter: dynamic(() =>
|
|
21
24
|
import(/* webpackChunkName: "blazePbSearchFilter" */ './SearchFilter')
|
|
22
25
|
),
|
|
@@ -37,6 +40,5 @@ export default {
|
|
|
37
40
|
),
|
|
38
41
|
passwordresetrequest: dynamic(() =>
|
|
39
42
|
import(/* webpackChunkName: "blazePbPasswordResetRequest" */ './PasswordResetRequest')
|
|
40
|
-
)
|
|
41
|
-
breadcrumb: dynamic(() => import(/* webpackChunkName: "blazePbBreadcrumb" */ './Breadcrumb'))
|
|
43
|
+
)
|
|
42
44
|
};
|
package/src/constants/index.js
CHANGED
|
@@ -205,6 +205,9 @@ const BANNER_LOADED = 'loaded';
|
|
|
205
205
|
const ANCHOR_TAG = 'a';
|
|
206
206
|
const TARGET_BLANK = '_blank';
|
|
207
207
|
|
|
208
|
+
const DATA_SUMMARY_EMAIL_REGEX = /^([a-z0-9_\.\+-]+)@([\da-z\.-]+)\.([a-z\.]{2,6})$/;
|
|
209
|
+
const DATA_SUMMARY_URL_REGEX = /(https?:\/\/)?(www\.)?[-a-zA-Z0-9@:%._\+~#=]{2,256}\.[a-z]{2,6}\b([-a-zA-Z0-9@:%_\+.~#?&//=]*)/;
|
|
210
|
+
|
|
208
211
|
export {
|
|
209
212
|
BANNER_LOADING,
|
|
210
213
|
BANNER_EMPTY,
|
|
@@ -313,5 +316,7 @@ export {
|
|
|
313
316
|
AZ,
|
|
314
317
|
SCROLL_OFFSET,
|
|
315
318
|
ANCHOR_TAG,
|
|
316
|
-
TARGET_BLANK
|
|
319
|
+
TARGET_BLANK,
|
|
320
|
+
DATA_SUMMARY_EMAIL_REGEX,
|
|
321
|
+
DATA_SUMMARY_URL_REGEX
|
|
317
322
|
};
|
package/tests/helpers/mocks.js
CHANGED
|
@@ -606,14 +606,11 @@ const ENTITY_SCHEMA_AS_OBJECT = [
|
|
|
606
606
|
const CARD_RENDER_ENTITY_DATA_MOCK = [
|
|
607
607
|
{
|
|
608
608
|
request: {
|
|
609
|
-
query:
|
|
610
|
-
variables: {
|
|
611
|
-
id: 'page'
|
|
612
|
-
}
|
|
609
|
+
query: getMultipleSchema(['page'])
|
|
613
610
|
},
|
|
614
611
|
result: {
|
|
615
612
|
data: {
|
|
616
|
-
|
|
613
|
+
page: {
|
|
617
614
|
id: 'page',
|
|
618
615
|
identifier: 'page',
|
|
619
616
|
properties: {
|
|
@@ -797,7 +794,7 @@ const CARD_RENDER_ENTITY_DATA_MOCK = [
|
|
|
797
794
|
'content-base/has-authors'
|
|
798
795
|
],
|
|
799
796
|
relations: [],
|
|
800
|
-
|
|
797
|
+
__typename: ''
|
|
801
798
|
}
|
|
802
799
|
}
|
|
803
800
|
}
|
|
@@ -844,22 +841,47 @@ const QUERY_PROPS = `results {
|
|
|
844
841
|
}
|
|
845
842
|
total`;
|
|
846
843
|
|
|
844
|
+
const CARD_RECORD = {
|
|
845
|
+
id: 'CARD PAGE ID',
|
|
846
|
+
name: 'Card page',
|
|
847
|
+
url: '/card-page',
|
|
848
|
+
metaDescription: 'Card page meta',
|
|
849
|
+
category: {
|
|
850
|
+
name: 'Card page cat',
|
|
851
|
+
listingPageId: 'Card page Listing ID',
|
|
852
|
+
listingPageEntity: 'page',
|
|
853
|
+
publishedListingPage: {
|
|
854
|
+
url: '/listing-page',
|
|
855
|
+
__typename: 'PublishedPage'
|
|
856
|
+
},
|
|
857
|
+
__typename: 'Category'
|
|
858
|
+
},
|
|
859
|
+
image: {
|
|
860
|
+
url: '/card-image.jpg',
|
|
861
|
+
data: { alt: 'card image alt' },
|
|
862
|
+
__typename: 'File'
|
|
863
|
+
},
|
|
864
|
+
__typename: 'PublishedPage'
|
|
865
|
+
};
|
|
866
|
+
|
|
847
867
|
const CARD_RENDER_SEARCH_PUBLISHED_MOCK = [
|
|
848
868
|
{
|
|
849
869
|
request: {
|
|
850
870
|
query: getSearchPublishedContent(QUERY_PROPS),
|
|
851
871
|
variables: {
|
|
852
|
-
limit:
|
|
872
|
+
limit: 51,
|
|
853
873
|
offset: 0,
|
|
874
|
+
sort: '',
|
|
854
875
|
rawQueryStringified:
|
|
855
|
-
'{"bool":{"filter":{"bool":{"must":[{"term":{"docType":"published_page"}}]}}
|
|
876
|
+
'{"bool":{"filter":{"bool":{"must":[{"term":{"docType":"published_page"}}]}}}}'
|
|
856
877
|
}
|
|
857
878
|
},
|
|
858
879
|
result: {
|
|
859
880
|
data: {
|
|
860
881
|
searchPublishedContent: {
|
|
861
|
-
results: [],
|
|
862
|
-
total:
|
|
882
|
+
results: [CARD_RECORD],
|
|
883
|
+
total: 1,
|
|
884
|
+
__typename: 'SearchPublishedContentReponse'
|
|
863
885
|
}
|
|
864
886
|
}
|
|
865
887
|
}
|
|
@@ -2494,6 +2516,7 @@ const GET_IMAGE_ID_FROM_RELATION_MOCK = [
|
|
|
2494
2516
|
export {
|
|
2495
2517
|
PAGE_BUILDER_MOCK,
|
|
2496
2518
|
DATA_SUMMARY_MOCK,
|
|
2519
|
+
CARD_RECORD,
|
|
2497
2520
|
CARD_RENDER_ENTITY_DATA_MOCK,
|
|
2498
2521
|
CARD_RENDER_EMPTY_ENTITY_DATA_MOCK,
|
|
2499
2522
|
CARD_RENDER_SEARCH_PUBLISHED_MOCK,
|
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
2
|
import '@testing-library/jest-dom/extend-expect';
|
|
3
3
|
import { MockedProvider } from '@apollo/client/testing';
|
|
4
|
-
import { render, act } from '@testing-library/react';
|
|
4
|
+
import { render, act, waitFor } from '@testing-library/react';
|
|
5
5
|
import {
|
|
6
6
|
CARD_RENDER_ENTITY_DATA_MOCK,
|
|
7
|
-
CARD_RENDER_SEARCH_PUBLISHED_MOCK
|
|
7
|
+
CARD_RENDER_SEARCH_PUBLISHED_MOCK,
|
|
8
|
+
CARD_RECORD
|
|
8
9
|
} from '../../../../helpers/mocks';
|
|
9
10
|
import CardRender from '../../../../../src/components/Card/CardRender';
|
|
10
11
|
|
|
@@ -39,8 +40,8 @@ const renderComponent = async component => {
|
|
|
39
40
|
};
|
|
40
41
|
};
|
|
41
42
|
|
|
42
|
-
const setupTest = async mocks => {
|
|
43
|
-
const componentMock = await setup(mockedProps, mocks);
|
|
43
|
+
const setupTest = async (mocks, overrides = {}) => {
|
|
44
|
+
const componentMock = await setup({ ...mockedProps, ...overrides }, mocks);
|
|
44
45
|
const renderResults = await renderComponent(componentMock);
|
|
45
46
|
|
|
46
47
|
return {
|
|
@@ -50,11 +51,24 @@ const setupTest = async mocks => {
|
|
|
50
51
|
|
|
51
52
|
describe('CardRender component', () => {
|
|
52
53
|
it('should render without throwing an error and match snapshot', async () => {
|
|
53
|
-
const { asFragment } = await setupTest([
|
|
54
|
+
const { asFragment, getByText } = await setupTest([
|
|
54
55
|
...CARD_RENDER_ENTITY_DATA_MOCK,
|
|
55
56
|
...CARD_RENDER_SEARCH_PUBLISHED_MOCK
|
|
56
57
|
]);
|
|
57
|
-
|
|
58
|
+
await waitFor(() => getByText(CARD_RECORD.name));
|
|
58
59
|
expect(asFragment()).toMatchSnapshot();
|
|
59
60
|
});
|
|
61
|
+
|
|
62
|
+
it('should render empty string if parent matches result record and there is only one results', async () => {
|
|
63
|
+
const parent = {
|
|
64
|
+
itemId: CARD_RECORD.id,
|
|
65
|
+
itemEntity: 'published_page'
|
|
66
|
+
};
|
|
67
|
+
const { asFragment } = await setupTest(
|
|
68
|
+
[...CARD_RENDER_ENTITY_DATA_MOCK, ...CARD_RENDER_SEARCH_PUBLISHED_MOCK],
|
|
69
|
+
{ parent }
|
|
70
|
+
);
|
|
71
|
+
|
|
72
|
+
expect(asFragment()).toMatchSnapshot(); // will be empty string
|
|
73
|
+
});
|
|
60
74
|
});
|
|
@@ -1,3 +1,52 @@
|
|
|
1
1
|
// Jest Snapshot v1, https://goo.gl/fbAQLP
|
|
2
2
|
|
|
3
|
-
exports[`CardRender component should render
|
|
3
|
+
exports[`CardRender component should render empty string if parent matches result record and there is only one results 1`] = `<DocumentFragment />`;
|
|
4
|
+
|
|
5
|
+
exports[`CardRender component should render without throwing an error and match snapshot 1`] = `
|
|
6
|
+
<DocumentFragment>
|
|
7
|
+
<div
|
|
8
|
+
class="grid grid-cols-1 grid--one"
|
|
9
|
+
>
|
|
10
|
+
<div
|
|
11
|
+
class="card card--portrait"
|
|
12
|
+
>
|
|
13
|
+
<div
|
|
14
|
+
class="card__image card__image--portrait"
|
|
15
|
+
>
|
|
16
|
+
<a
|
|
17
|
+
class="card__image-link"
|
|
18
|
+
href="/card-page"
|
|
19
|
+
>
|
|
20
|
+
<span />
|
|
21
|
+
</a>
|
|
22
|
+
</div>
|
|
23
|
+
<div
|
|
24
|
+
class="card__content-wrapper card__content-wrapper--portrait"
|
|
25
|
+
>
|
|
26
|
+
<div
|
|
27
|
+
class="card__content card__content--portrait"
|
|
28
|
+
>
|
|
29
|
+
<a
|
|
30
|
+
class="badge badge--label"
|
|
31
|
+
href="/listing-page"
|
|
32
|
+
>
|
|
33
|
+
Card page cat
|
|
34
|
+
</a>
|
|
35
|
+
<h2
|
|
36
|
+
class="card__title card__title--portrait"
|
|
37
|
+
>
|
|
38
|
+
<a
|
|
39
|
+
href="/card-page"
|
|
40
|
+
>
|
|
41
|
+
Card page
|
|
42
|
+
</a>
|
|
43
|
+
</h2>
|
|
44
|
+
</div>
|
|
45
|
+
<div
|
|
46
|
+
class="card__child-content"
|
|
47
|
+
/>
|
|
48
|
+
</div>
|
|
49
|
+
</div>
|
|
50
|
+
</div>
|
|
51
|
+
</DocumentFragment>
|
|
52
|
+
`;
|
package/tests/unit/src/components/DataSummary/helpers/build-props-to-display-with-content.test.js
CHANGED
|
@@ -27,4 +27,26 @@ describe('build props to display func', () => {
|
|
|
27
27
|
it('should return an empty array if no values are passed', () => {
|
|
28
28
|
expect(emptyPropsToDisplay.length).toEqual(0);
|
|
29
29
|
});
|
|
30
|
+
|
|
31
|
+
it('should add link if enableLink=true', () => {
|
|
32
|
+
const obj = {
|
|
33
|
+
name: 'Item name',
|
|
34
|
+
url: '/url',
|
|
35
|
+
email: 'email@blazecms.app'
|
|
36
|
+
};
|
|
37
|
+
const propsTorDisplay = [
|
|
38
|
+
{
|
|
39
|
+
propertiesToDisplay: ['name'],
|
|
40
|
+
enableLink: false
|
|
41
|
+
},
|
|
42
|
+
{
|
|
43
|
+
propertiesToDisplay: ['email'],
|
|
44
|
+
enableLink: true
|
|
45
|
+
}
|
|
46
|
+
];
|
|
47
|
+
const [nameProp, emailProp] = buildPropsToDisplayWithContent(obj, propsTorDisplay);
|
|
48
|
+
|
|
49
|
+
expect(nameProp[2]).toEqual('');
|
|
50
|
+
expect(emailProp[2]).toEqual('mailto:email@blazecms.app');
|
|
51
|
+
});
|
|
30
52
|
});
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @testEnvironment node
|
|
3
|
+
*/
|
|
4
|
+
import { getLinkBasedOnValue } from '../../../../../../src/components/DataSummary/helpers';
|
|
5
|
+
|
|
6
|
+
describe('Get link based on value', () => {
|
|
7
|
+
it('should be a function', () => {
|
|
8
|
+
expect(typeof getLinkBasedOnValue).toEqual('function');
|
|
9
|
+
});
|
|
10
|
+
|
|
11
|
+
it('should not return link if value does not match values', () => {
|
|
12
|
+
const result = getLinkBasedOnValue('not matched');
|
|
13
|
+
expect(result).toEqual('');
|
|
14
|
+
});
|
|
15
|
+
|
|
16
|
+
it('should return mailto: link for email string', () => {
|
|
17
|
+
const email = 'email@blazecms.app';
|
|
18
|
+
const result = getLinkBasedOnValue(email);
|
|
19
|
+
expect(result).toEqual(`mailto:${email}`);
|
|
20
|
+
});
|
|
21
|
+
|
|
22
|
+
it('should return url link with or without scheme', () => {
|
|
23
|
+
const urls = ['https://www.blazecms.app/path?query=string', 'blazecms.app/page'];
|
|
24
|
+
urls.forEach(url => {
|
|
25
|
+
expect(getLinkBasedOnValue(url)).toEqual(url);
|
|
26
|
+
});
|
|
27
|
+
expect.hasAssertions();
|
|
28
|
+
});
|
|
29
|
+
});
|
|
@@ -2,14 +2,18 @@
|
|
|
2
2
|
|
|
3
3
|
exports[`Menu component should render without throwing an error and match snapshot 1`] = `
|
|
4
4
|
<DocumentFragment>
|
|
5
|
-
<
|
|
6
|
-
class="menu-
|
|
5
|
+
<div
|
|
6
|
+
class="menu--desktop-wrapper"
|
|
7
7
|
>
|
|
8
|
-
<
|
|
9
|
-
class="
|
|
8
|
+
<ul
|
|
9
|
+
class="menu-mod"
|
|
10
10
|
>
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
11
|
+
<div
|
|
12
|
+
class="child_1"
|
|
13
|
+
>
|
|
14
|
+
only child
|
|
15
|
+
</div>
|
|
16
|
+
</ul>
|
|
17
|
+
</div>
|
|
14
18
|
</DocumentFragment>
|
|
15
19
|
`;
|
|
@@ -6,10 +6,6 @@ Object {
|
|
|
6
6
|
"$$typeof": Symbol(react.forward_ref),
|
|
7
7
|
"render": [Function],
|
|
8
8
|
},
|
|
9
|
-
"breadcrumb": Object {
|
|
10
|
-
"$$typeof": Symbol(react.forward_ref),
|
|
11
|
-
"render": [Function],
|
|
12
|
-
},
|
|
13
9
|
"button": Object {
|
|
14
10
|
"$$typeof": Symbol(react.forward_ref),
|
|
15
11
|
"render": [Function],
|
|
@@ -74,6 +70,10 @@ Object {
|
|
|
74
70
|
"$$typeof": Symbol(react.forward_ref),
|
|
75
71
|
"render": [Function],
|
|
76
72
|
},
|
|
73
|
+
"searchcontent": Object {
|
|
74
|
+
"$$typeof": Symbol(react.forward_ref),
|
|
75
|
+
"render": [Function],
|
|
76
|
+
},
|
|
77
77
|
"searchfilter": Object {
|
|
78
78
|
"$$typeof": Symbol(react.forward_ref),
|
|
79
79
|
"render": [Function],
|