@blaze-cms/react-page-builder 0.131.0-project-admin-customisations.2 → 0.132.0-admin-updates.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 +22 -11
- package/lib/HOC/recreateOnNavigation.js +29 -0
- package/lib/HOC/recreateOnNavigation.js.map +1 -0
- package/lib/components/CarouselWrapper/SmoothScrollCarousel.js +2 -2
- package/lib/components/CarouselWrapper/SmoothScrollCarousel.js.map +1 -1
- package/lib/components/ContentGroupSection/ContentGroupSection.js +4 -1
- package/lib/components/ContentGroupSection/ContentGroupSection.js.map +1 -1
- package/lib/components/DataSummary/helpers/build-loop-props-content.js +3 -2
- package/lib/components/DataSummary/helpers/build-loop-props-content.js.map +1 -1
- package/lib/components/DataSummary/helpers/get-link-to-published-content.js +2 -0
- package/lib/components/DataSummary/helpers/get-link-to-published-content.js.map +1 -1
- package/lib/components/Layout/Layout.js +3 -2
- package/lib/components/Layout/Layout.js.map +1 -1
- package/lib/components/Layout/LayoutFactory.js +35 -0
- package/lib/components/Layout/LayoutFactory.js.map +1 -0
- package/lib/components/Layout/LayoutWithStickyTimer.js +66 -0
- package/lib/components/Layout/LayoutWithStickyTimer.js.map +1 -0
- package/lib/components/Layout/index.js +2 -2
- package/lib/components/Layout/index.js.map +1 -1
- package/lib/components/SearchContent/SearchContent.js +0 -2
- package/lib/components/SearchContent/SearchContent.js.map +1 -1
- package/lib/components/SearchFilter/SearchFilter/SearchFilter.js +1 -3
- package/lib/components/SearchFilter/SearchFilter/SearchFilter.js.map +1 -1
- package/lib/components/SearchFilter/SearchFilterContainer.js +5 -2
- package/lib/components/SearchFilter/SearchFilterContainer.js.map +1 -1
- package/lib/components/SearchFilter/helpers/build-url-query.js +1 -0
- package/lib/components/SearchFilter/helpers/build-url-query.js.map +1 -1
- package/lib/components/SearchFilter/searchFilterReducer.js +1 -3
- package/lib/components/SearchFilter/searchFilterReducer.js.map +1 -1
- package/lib/helpers/get-entities-with-banner.js +8 -2
- package/lib/helpers/get-entities-with-banner.js.map +1 -1
- package/lib/utils/get-class-modifiers.js +1 -1
- package/lib/utils/get-class-modifiers.js.map +1 -1
- package/lib-es/HOC/recreateOnNavigation.js +20 -0
- package/lib-es/HOC/recreateOnNavigation.js.map +1 -0
- package/lib-es/components/CarouselWrapper/SmoothScrollCarousel.js +2 -2
- package/lib-es/components/CarouselWrapper/SmoothScrollCarousel.js.map +1 -1
- package/lib-es/components/ContentGroupSection/ContentGroupSection.js +8 -4
- package/lib-es/components/ContentGroupSection/ContentGroupSection.js.map +1 -1
- package/lib-es/components/DataSummary/helpers/build-loop-props-content.js +3 -2
- package/lib-es/components/DataSummary/helpers/build-loop-props-content.js.map +1 -1
- package/lib-es/components/DataSummary/helpers/get-link-to-published-content.js +2 -1
- package/lib-es/components/DataSummary/helpers/get-link-to-published-content.js.map +1 -1
- package/lib-es/components/Layout/Layout.js +3 -2
- package/lib-es/components/Layout/Layout.js.map +1 -1
- package/lib-es/components/Layout/LayoutFactory.js +14 -0
- package/lib-es/components/Layout/LayoutFactory.js.map +1 -0
- package/lib-es/components/Layout/LayoutWithStickyTimer.js +42 -0
- package/lib-es/components/Layout/LayoutWithStickyTimer.js.map +1 -0
- package/lib-es/components/Layout/index.js +2 -2
- package/lib-es/components/Layout/index.js.map +1 -1
- package/lib-es/components/SearchContent/SearchContent.js +0 -2
- package/lib-es/components/SearchContent/SearchContent.js.map +1 -1
- package/lib-es/components/SearchFilter/SearchFilter/SearchFilter.js +2 -4
- package/lib-es/components/SearchFilter/SearchFilter/SearchFilter.js.map +1 -1
- package/lib-es/components/SearchFilter/SearchFilterContainer.js +5 -2
- package/lib-es/components/SearchFilter/SearchFilterContainer.js.map +1 -1
- package/lib-es/components/SearchFilter/helpers/build-url-query.js +1 -0
- package/lib-es/components/SearchFilter/helpers/build-url-query.js.map +1 -1
- package/lib-es/components/SearchFilter/searchFilterReducer.js +1 -3
- package/lib-es/components/SearchFilter/searchFilterReducer.js.map +1 -1
- package/lib-es/helpers/get-entities-with-banner.js +9 -2
- package/lib-es/helpers/get-entities-with-banner.js.map +1 -1
- package/lib-es/utils/get-class-modifiers.js +1 -1
- package/lib-es/utils/get-class-modifiers.js.map +1 -1
- package/package.json +10 -10
- package/src/HOC/recreateOnNavigation.js +21 -0
- package/src/components/CarouselWrapper/SmoothScrollCarousel.js +2 -2
- package/src/components/ContentGroupSection/ContentGroupSection.js +1 -1
- package/src/components/DataSummary/helpers/build-loop-props-content.js +3 -2
- package/src/components/DataSummary/helpers/get-link-to-published-content.js +4 -1
- package/src/components/Layout/Layout.js +29 -32
- package/src/components/Layout/LayoutFactory.js +17 -0
- package/src/components/Layout/LayoutWithStickyTimer.js +40 -0
- package/src/components/Layout/index.js +2 -2
- package/src/components/SearchContent/SearchContent.js +0 -2
- package/src/components/SearchFilter/SearchFilter/SearchFilter.js +3 -9
- package/src/components/SearchFilter/SearchFilterContainer.js +6 -2
- package/src/components/SearchFilter/helpers/build-url-query.js +2 -0
- package/src/components/SearchFilter/searchFilterReducer.js +1 -1
- package/src/helpers/get-entities-with-banner.js +3 -2
- package/src/utils/get-class-modifiers.js +1 -1
- package/tests/unit/src/HOC/recreateOnNavigation.test.js +28 -0
- package/tests/unit/src/components/DataSummary/helpers/build-loop-props-content.test.js +41 -0
- package/tests/unit/src/components/DataSummary/helpers/get-link-to-published-content.test.js +21 -0
- package/tests/unit/src/components/Layout/Layout.test.js +1 -1
- package/tests/unit/src/components/Layout/LayoutFactory.test.js +53 -0
|
@@ -1,6 +1,9 @@
|
|
|
1
|
-
const getLinkToPublishedContent = (key = '', props = {}) => {
|
|
1
|
+
const getLinkToPublishedContent = (key = '', props = {}, currentValue = null) => {
|
|
2
2
|
const [baseKey] = key.split('.');
|
|
3
3
|
if (!props[baseKey]) return '';
|
|
4
|
+
|
|
5
|
+
if (currentValue && typeof currentValue.url !== 'undefined') return currentValue.url;
|
|
6
|
+
|
|
4
7
|
const content = Array.isArray(props[baseKey]) ? props[baseKey][0] : props[baseKey];
|
|
5
8
|
return content && content.url ? content.url : '';
|
|
6
9
|
};
|
|
@@ -7,43 +7,40 @@ import { getStylesToUpdate, checkIfRowHasColumns } from './helpers';
|
|
|
7
7
|
import { renderChildren, hasChildren } from '../../helpers';
|
|
8
8
|
import { COLUMN } from '../../constants';
|
|
9
9
|
|
|
10
|
-
const Layout = (
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
...otherProps
|
|
19
|
-
}) => {
|
|
20
|
-
const {
|
|
21
|
-
data: { getFile: { url = null } = {} }
|
|
22
|
-
} = useGetImages(backgroundImage);
|
|
10
|
+
const Layout = React.forwardRef(
|
|
11
|
+
(
|
|
12
|
+
{ type, children, settings, modifier, backgroundImage, tagType, dataNoSnippet, ...otherProps },
|
|
13
|
+
ref
|
|
14
|
+
) => {
|
|
15
|
+
const {
|
|
16
|
+
data: { getFile: { url = null } = {} }
|
|
17
|
+
} = useGetImages(backgroundImage);
|
|
23
18
|
|
|
24
|
-
|
|
25
|
-
|
|
19
|
+
const style = getStylesToUpdate({ backgroundImage: url });
|
|
20
|
+
const { title } = settings;
|
|
26
21
|
|
|
27
|
-
|
|
28
|
-
|
|
22
|
+
const classModifiers = getClassModifiers(type, { modifier, ...otherProps });
|
|
23
|
+
const additionalRowModifier = checkIfRowHasColumns(type, children) ? ' display-row' : '';
|
|
29
24
|
|
|
30
|
-
|
|
25
|
+
if (type === COLUMN && !hasChildren(children)) return null;
|
|
31
26
|
|
|
32
|
-
|
|
33
|
-
|
|
27
|
+
const otherWrapperProps = {};
|
|
28
|
+
if (dataNoSnippet) otherWrapperProps['data-nosnippet'] = true;
|
|
34
29
|
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
30
|
+
return (
|
|
31
|
+
<Wrapper
|
|
32
|
+
ref={ref}
|
|
33
|
+
tagType={tagType}
|
|
34
|
+
className={type}
|
|
35
|
+
modifiers={`${classModifiers}${additionalRowModifier}`}
|
|
36
|
+
style={style}
|
|
37
|
+
{...otherWrapperProps}>
|
|
38
|
+
{title && <h2 className="heading heading--section">{title}</h2>}
|
|
39
|
+
{renderChildren(children, otherProps)}
|
|
40
|
+
</Wrapper>
|
|
41
|
+
);
|
|
42
|
+
}
|
|
43
|
+
);
|
|
47
44
|
|
|
48
45
|
Layout.propTypes = {
|
|
49
46
|
type: PropTypes.string.isRequired,
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import dynamic from 'next/dynamic';
|
|
3
|
+
import Layout from './Layout';
|
|
4
|
+
|
|
5
|
+
const LayoutWithStickyTimer = dynamic(() =>
|
|
6
|
+
import(/* webpackChunkName: "blazePbLayoutWithStickyTimer" */ './LayoutWithStickyTimer')
|
|
7
|
+
);
|
|
8
|
+
|
|
9
|
+
const LayoutFactory = props => {
|
|
10
|
+
const { sticky, stickyTimer } = props;
|
|
11
|
+
|
|
12
|
+
if (sticky && stickyTimer) return <LayoutWithStickyTimer {...props} />;
|
|
13
|
+
|
|
14
|
+
return <Layout {...props} />;
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
export default LayoutFactory;
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import React, { useEffect, useState } from 'react';
|
|
2
|
+
import PropTypes from 'prop-types';
|
|
3
|
+
import { useInView } from '@blaze-react/utils/lib/customHooks';
|
|
4
|
+
import recreateOnNavigation from '../../HOC/recreateOnNavigation';
|
|
5
|
+
import Layout from './Layout';
|
|
6
|
+
|
|
7
|
+
const LayoutWithStickyTimer = ({ sticky, stickyTimer, ...otherProps }) => {
|
|
8
|
+
const [isIntersecting, outerRef] = useInView({});
|
|
9
|
+
const [isSticky, setIsSticky] = useState(sticky);
|
|
10
|
+
|
|
11
|
+
useEffect(
|
|
12
|
+
() => {
|
|
13
|
+
if (isIntersecting && sticky && !!stickyTimer) {
|
|
14
|
+
setIsSticky(true);
|
|
15
|
+
const timer = setTimeout(() => {
|
|
16
|
+
setIsSticky(false);
|
|
17
|
+
}, stickyTimer);
|
|
18
|
+
|
|
19
|
+
return () => {
|
|
20
|
+
clearTimeout(timer);
|
|
21
|
+
};
|
|
22
|
+
}
|
|
23
|
+
},
|
|
24
|
+
[isIntersecting, stickyTimer, sticky]
|
|
25
|
+
);
|
|
26
|
+
|
|
27
|
+
return <Layout {...otherProps} sticky={isSticky} ref={sticky ? outerRef : null} />;
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
LayoutWithStickyTimer.propTypes = {
|
|
31
|
+
sticky: PropTypes.bool,
|
|
32
|
+
stickyTimer: PropTypes.number
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
LayoutWithStickyTimer.defaultProps = {
|
|
36
|
+
sticky: false,
|
|
37
|
+
stickyTimer: 0
|
|
38
|
+
};
|
|
39
|
+
|
|
40
|
+
export default recreateOnNavigation(LayoutWithStickyTimer);
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import
|
|
1
|
+
import LayoutFactory from './LayoutFactory';
|
|
2
2
|
|
|
3
|
-
export default
|
|
3
|
+
export default LayoutFactory;
|
|
@@ -118,7 +118,6 @@ SearchContent.propTypes = {
|
|
|
118
118
|
searchInputWrapperDesktop: PropTypes.string,
|
|
119
119
|
placeholder: PropTypes.string,
|
|
120
120
|
isMobile: PropTypes.bool,
|
|
121
|
-
collapsible: PropTypes.bool,
|
|
122
121
|
entities: PropTypes.array.isRequired,
|
|
123
122
|
modifier: PropTypes.string,
|
|
124
123
|
collapsedSearch: PropTypes.bool
|
|
@@ -130,7 +129,6 @@ SearchContent.defaultProps = {
|
|
|
130
129
|
searchInputWrapperDesktop: '',
|
|
131
130
|
placeholder: '',
|
|
132
131
|
isMobile: false,
|
|
133
|
-
collapsible: false,
|
|
134
132
|
modifier: '',
|
|
135
133
|
collapsedSearch: false
|
|
136
134
|
};
|
|
@@ -3,12 +3,7 @@ import PropTypes from 'prop-types';
|
|
|
3
3
|
import classnames from 'classnames';
|
|
4
4
|
import debounce from 'lodash.debounce';
|
|
5
5
|
import FiltersList from './FiltersList';
|
|
6
|
-
import {
|
|
7
|
-
isDeviceDesktop,
|
|
8
|
-
buildUrlQuery,
|
|
9
|
-
getFilterValues,
|
|
10
|
-
getResponsiveFilterClassnames
|
|
11
|
-
} from '../helpers';
|
|
6
|
+
import { isDeviceDesktop, buildUrlQuery, getResponsiveFilterClassnames } from '../helpers';
|
|
12
7
|
import CloseMobileForm from './CloseMobileForm';
|
|
13
8
|
import ResetDesktopForm from './ResetDesktopForm';
|
|
14
9
|
import MobileFormToolbar from './MobileFormToolbar';
|
|
@@ -71,9 +66,8 @@ const SearchFilter = ({
|
|
|
71
66
|
const formId = `filter-${name}-form`;
|
|
72
67
|
|
|
73
68
|
const handleReset = () => {
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
doSubmit(newValues);
|
|
69
|
+
setAppliedFilters({ type: 'reset' });
|
|
70
|
+
doSubmit();
|
|
77
71
|
};
|
|
78
72
|
|
|
79
73
|
const updateFilterValues = (newValues, shouldSubmit) => {
|
|
@@ -98,9 +98,10 @@ const SearchFilterContainer = ({
|
|
|
98
98
|
const { searchPublishedContent: { rawResults: { aggregations: filterData } = {} } = {} } =
|
|
99
99
|
data || {};
|
|
100
100
|
|
|
101
|
-
if (!filterValues && !loading && filterData) {
|
|
101
|
+
if (!filterValues && !loading && (filterData || !rawQueryStringified)) {
|
|
102
102
|
const newValues = getFilterValues(filterData, filters, updatedQuery);
|
|
103
103
|
dispatch({ newValues, shouldSearch: false, type: 'update' });
|
|
104
|
+
return null;
|
|
104
105
|
}
|
|
105
106
|
|
|
106
107
|
const handleSearch = newQuery => {
|
|
@@ -110,11 +111,13 @@ const SearchFilterContainer = ({
|
|
|
110
111
|
scrollToFirstList();
|
|
111
112
|
if (!newQuery) {
|
|
112
113
|
const baseQuery = `${currentUrl}${parsedHashBit}`;
|
|
114
|
+
setUrlPath(baseQuery);
|
|
113
115
|
return router.push('/Resolver', baseQuery, { shallow: !url, scroll: false }).then(() => {
|
|
114
116
|
setKey(`filter-${name}:${Date.now()}`); // remove after range component update
|
|
115
117
|
});
|
|
116
118
|
}
|
|
117
119
|
const newUrl = buildNewUrl(url, currentUrl, newQuery, hashBit);
|
|
120
|
+
setUrlPath(newUrl);
|
|
118
121
|
return router.push('/Resolver', newUrl, { shallow: !url, scroll: false });
|
|
119
122
|
};
|
|
120
123
|
|
|
@@ -131,7 +134,8 @@ const SearchFilterContainer = ({
|
|
|
131
134
|
window.scrollTo(0, 0);
|
|
132
135
|
}
|
|
133
136
|
};
|
|
134
|
-
|
|
137
|
+
|
|
138
|
+
if (!filterValues) return null;
|
|
135
139
|
|
|
136
140
|
return (
|
|
137
141
|
<SearchFilter
|
|
@@ -3,6 +3,8 @@ import parseFilterValue from './parse-filter-value';
|
|
|
3
3
|
import { buildQueryKey } from '../../../helpers';
|
|
4
4
|
|
|
5
5
|
const buildUrlQuery = (filterValues, filters, listComponentName = '', query = {}) => {
|
|
6
|
+
if (!filterValues) return '';
|
|
7
|
+
|
|
6
8
|
const newQuery = [];
|
|
7
9
|
const queryKeys = [];
|
|
8
10
|
const searchValue = filterValues[SEARCH_TERM];
|
|
@@ -4,8 +4,9 @@ export default function getEntitiesWithBanner(entities, options, hasNewBannerSet
|
|
|
4
4
|
const { hasBanner } = options;
|
|
5
5
|
if (hasNewBannerSettings) {
|
|
6
6
|
return entities.map(currentEntity => {
|
|
7
|
-
const { parent, transform, limit } = options;
|
|
8
|
-
|
|
7
|
+
const { parent, transform, limit, banner } = options;
|
|
8
|
+
const { adunit, baseAdunit } = banner || {};
|
|
9
|
+
return { ...currentEntity, parent, limit, transform, adunit, baseAdunit };
|
|
9
10
|
});
|
|
10
11
|
}
|
|
11
12
|
if (!hasBanner) return entities;
|
|
@@ -25,7 +25,7 @@ const iconProps = [BUTTON_TYPE, ...commonProps];
|
|
|
25
25
|
const commonAttributes = { props: commonProps, prefix: null };
|
|
26
26
|
|
|
27
27
|
const supportedTypes = {
|
|
28
|
-
row: { props: [WIDTH, ...responsiveProps, ...commonProps] },
|
|
28
|
+
row: { props: [WIDTH, STICKY, ...responsiveProps, ...commonProps] },
|
|
29
29
|
column: { props: [WIDTH, STICKY, ...responsiveProps, ...commonProps] },
|
|
30
30
|
button: {
|
|
31
31
|
props: buttonProps,
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @jest-environment jsdom
|
|
3
|
+
*/
|
|
4
|
+
import React from 'react';
|
|
5
|
+
import '@testing-library/jest-dom/extend-expect';
|
|
6
|
+
import { render } from '@testing-library/react';
|
|
7
|
+
import recreateOnNavigation from '../../../../src/HOC/recreateOnNavigation';
|
|
8
|
+
|
|
9
|
+
jest.mock('next/router', () => {
|
|
10
|
+
const mockRouter = {
|
|
11
|
+
asPath: '/abc',
|
|
12
|
+
push: null
|
|
13
|
+
};
|
|
14
|
+
return {
|
|
15
|
+
router: mockRouter,
|
|
16
|
+
useRouter: () => mockRouter
|
|
17
|
+
};
|
|
18
|
+
});
|
|
19
|
+
|
|
20
|
+
describe('recreateOnNavigation HOC', () => {
|
|
21
|
+
const mockComponent = jest.fn(() => <div>Mock Component</div>);
|
|
22
|
+
it('should render component and change key on route change', async () => {
|
|
23
|
+
const WrapperComponent = recreateOnNavigation(mockComponent);
|
|
24
|
+
const name = 'test';
|
|
25
|
+
render(<WrapperComponent name={name} />);
|
|
26
|
+
expect(mockComponent).toHaveBeenCalledWith(expect.objectContaining({ name }), {});
|
|
27
|
+
});
|
|
28
|
+
});
|
|
@@ -90,4 +90,45 @@ describe('buildLoopPropsContent helper function', () => {
|
|
|
90
90
|
});
|
|
91
91
|
expect.hasAssertions();
|
|
92
92
|
});
|
|
93
|
+
|
|
94
|
+
it('should nested items with urls', () => {
|
|
95
|
+
const data = {
|
|
96
|
+
nestedLoopProp: [
|
|
97
|
+
{
|
|
98
|
+
nestedValue: 'abc',
|
|
99
|
+
url: 'http://blazecms.app/abc'
|
|
100
|
+
},
|
|
101
|
+
{
|
|
102
|
+
nestedValue: '123',
|
|
103
|
+
url: 'http://blazecms.app/123'
|
|
104
|
+
},
|
|
105
|
+
{
|
|
106
|
+
nestedValue: 'no url',
|
|
107
|
+
url: null
|
|
108
|
+
}
|
|
109
|
+
]
|
|
110
|
+
};
|
|
111
|
+
const withUrl = buildLoopPropsContent(
|
|
112
|
+
mockedLoopProps,
|
|
113
|
+
[
|
|
114
|
+
{
|
|
115
|
+
bold: false,
|
|
116
|
+
enableLink: true,
|
|
117
|
+
label: '',
|
|
118
|
+
modifier: '',
|
|
119
|
+
prefix: '',
|
|
120
|
+
propertiesToDisplay: ['nestedLoopProp.nestedValue'],
|
|
121
|
+
shouldStrip: true
|
|
122
|
+
}
|
|
123
|
+
],
|
|
124
|
+
0,
|
|
125
|
+
data
|
|
126
|
+
);
|
|
127
|
+
|
|
128
|
+
withUrl.forEach(([, value, url], index) => {
|
|
129
|
+
expect(value).toEqual(data.nestedLoopProp[index].nestedValue);
|
|
130
|
+
expect(url).toEqual(data.nestedLoopProp[index].url || '');
|
|
131
|
+
});
|
|
132
|
+
expect.hasAssertions();
|
|
133
|
+
});
|
|
93
134
|
});
|
|
@@ -38,4 +38,25 @@ describe('get link to published content', () => {
|
|
|
38
38
|
const result = getLinkToPublishedContent(publishedKey, props);
|
|
39
39
|
expect(result).toEqual('');
|
|
40
40
|
});
|
|
41
|
+
|
|
42
|
+
it('should return url from the currentValue', () => {
|
|
43
|
+
const currentValue = { url: 'currentValueUrl' };
|
|
44
|
+
const props = { content: [content] };
|
|
45
|
+
const result = getLinkToPublishedContent(publishedKey, props, currentValue);
|
|
46
|
+
expect(result).toEqual(currentValue.url);
|
|
47
|
+
});
|
|
48
|
+
|
|
49
|
+
it('should return url from the currentValue even if falsey', () => {
|
|
50
|
+
const currentValue = { url: null };
|
|
51
|
+
const props = { content: [content] };
|
|
52
|
+
const result = getLinkToPublishedContent(publishedKey, props, currentValue);
|
|
53
|
+
expect(result).toEqual(currentValue.url);
|
|
54
|
+
});
|
|
55
|
+
|
|
56
|
+
it('should not return url from the currentValue if not set', () => {
|
|
57
|
+
const currentValue = {};
|
|
58
|
+
const props = { content: [content] };
|
|
59
|
+
const result = getLinkToPublishedContent(publishedKey, props, currentValue);
|
|
60
|
+
expect(result).toEqual(content.url);
|
|
61
|
+
});
|
|
41
62
|
});
|
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
import React from 'react';
|
|
5
5
|
import '@testing-library/jest-dom/extend-expect';
|
|
6
6
|
import { render } from '@blaze-cms/tools/test-helpers/test-functions';
|
|
7
|
-
import Layout from '../../../../../src/components/Layout';
|
|
7
|
+
import Layout from '../../../../../src/components/Layout/Layout';
|
|
8
8
|
import { COLUMN, ROW } from '../../../../../src/constants';
|
|
9
9
|
import useGetImages from '../../../../../src/hooks/use-get-images';
|
|
10
10
|
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @jest-environment jsdom
|
|
3
|
+
*/
|
|
4
|
+
import React from 'react';
|
|
5
|
+
import '@testing-library/jest-dom/extend-expect';
|
|
6
|
+
import { render } from '@testing-library/react';
|
|
7
|
+
import Layout from '../../../../../src/components/Layout';
|
|
8
|
+
|
|
9
|
+
jest.mock('../../../../../src/components/Layout/Layout', () =>
|
|
10
|
+
jest.fn(({ children }) => <div data-testid="Layout">{children}</div>)
|
|
11
|
+
);
|
|
12
|
+
|
|
13
|
+
jest.mock('next/dynamic', () => {
|
|
14
|
+
const LayoutWithStickyTimer = ({ children }) => (
|
|
15
|
+
<div data-testid="LayoutWithStickyTimer">{children}</div>
|
|
16
|
+
);
|
|
17
|
+
return jest.fn(() => LayoutWithStickyTimer);
|
|
18
|
+
});
|
|
19
|
+
|
|
20
|
+
const defaultComponentTestId = 'Layout';
|
|
21
|
+
const testId = 'child-test-id';
|
|
22
|
+
|
|
23
|
+
describe('LayoutFactoriy component', () => {
|
|
24
|
+
const props = { someProps: true, children: <div data-testid={testId} /> };
|
|
25
|
+
|
|
26
|
+
it('should be defined', () => {
|
|
27
|
+
expect(Layout).toBeDefined();
|
|
28
|
+
});
|
|
29
|
+
|
|
30
|
+
it('should render Layout component', () => {
|
|
31
|
+
const { getByTestId } = render(<Layout {...props} />);
|
|
32
|
+
expect(getByTestId(defaultComponentTestId)).toBeDefined();
|
|
33
|
+
expect(getByTestId(testId)).toBeDefined();
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
it('should render LayoutWithStickyTimer component', () => {
|
|
37
|
+
const { getByTestId } = render(<Layout {...props} sticky stickyTimer={10} />);
|
|
38
|
+
expect(getByTestId('LayoutWithStickyTimer')).toBeDefined();
|
|
39
|
+
expect(getByTestId(testId)).toBeDefined();
|
|
40
|
+
});
|
|
41
|
+
|
|
42
|
+
it('should render if stickyTimer is not set', () => {
|
|
43
|
+
const { getByTestId } = render(<Layout {...props} sticky />);
|
|
44
|
+
expect(getByTestId(defaultComponentTestId)).toBeDefined();
|
|
45
|
+
expect(getByTestId(testId)).toBeDefined();
|
|
46
|
+
});
|
|
47
|
+
|
|
48
|
+
it('should render if sticky is not set', () => {
|
|
49
|
+
const { getByTestId } = render(<Layout {...props} stickyTimer={20} />);
|
|
50
|
+
expect(getByTestId(defaultComponentTestId)).toBeDefined();
|
|
51
|
+
expect(getByTestId(testId)).toBeDefined();
|
|
52
|
+
});
|
|
53
|
+
});
|