@blaze-cms/react-page-builder 0.130.0-admin-updates.4 → 0.130.0-admin-updates.8
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 +28 -0
- package/lib/components/Code/Code.js +7 -3
- package/lib/components/Code/Code.js.map +1 -1
- package/lib/components/DataSummary/helpers/build-loop-props-content.js +3 -1
- package/lib/components/DataSummary/helpers/build-loop-props-content.js.map +1 -1
- package/lib/components/DataSummary/helpers/build-props-to-display-with-content.js +3 -2
- package/lib/components/DataSummary/helpers/build-props-to-display-with-content.js.map +1 -1
- package/lib/components/SearchContent/SearchContent.js +8 -6
- package/lib/components/SearchContent/SearchContent.js.map +1 -1
- package/lib/components/SearchContent/SearchContentItems.js +1 -1
- package/lib/components/SearchContent/SearchContentItems.js.map +1 -1
- package/lib/components/SearchFilter/SearchFilterContainer.js +2 -1
- package/lib/components/SearchFilter/SearchFilterContainer.js.map +1 -1
- package/lib/components/SearchFilter/helpers/build-new-query.js +3 -2
- package/lib/components/SearchFilter/helpers/build-new-query.js.map +1 -1
- package/lib/components/SearchFilterSort/helpers/handle-sort-update.js +5 -2
- package/lib/components/SearchFilterSort/helpers/handle-sort-update.js.map +1 -1
- package/lib/components/SearchFilterSort/helpers/update-sort.js +2 -1
- package/lib/components/SearchFilterSort/helpers/update-sort.js.map +1 -1
- package/lib/helpers/build-props-query.js +5 -2
- package/lib/helpers/build-props-query.js.map +1 -1
- package/lib/helpers/get-wrapped-value-with-link.js +2 -3
- package/lib/helpers/get-wrapped-value-with-link.js.map +1 -1
- package/lib/helpers/index.js +7 -0
- package/lib/helpers/index.js.map +1 -1
- package/lib/helpers/parse-props-to-display.js +13 -8
- package/lib/helpers/parse-props-to-display.js.map +1 -1
- package/lib/helpers/process-data-summary-value.js +56 -0
- package/lib/helpers/process-data-summary-value.js.map +1 -0
- package/lib-es/components/Code/Code.js +8 -4
- package/lib-es/components/Code/Code.js.map +1 -1
- package/lib-es/components/DataSummary/helpers/build-loop-props-content.js +3 -1
- package/lib-es/components/DataSummary/helpers/build-loop-props-content.js.map +1 -1
- package/lib-es/components/DataSummary/helpers/build-props-to-display-with-content.js +4 -3
- package/lib-es/components/DataSummary/helpers/build-props-to-display-with-content.js.map +1 -1
- package/lib-es/components/SearchContent/SearchContent.js +8 -6
- package/lib-es/components/SearchContent/SearchContent.js.map +1 -1
- package/lib-es/components/SearchContent/SearchContentItems.js +1 -1
- package/lib-es/components/SearchContent/SearchContentItems.js.map +1 -1
- package/lib-es/components/SearchFilter/SearchFilterContainer.js +2 -1
- package/lib-es/components/SearchFilter/SearchFilterContainer.js.map +1 -1
- package/lib-es/components/SearchFilter/helpers/build-new-query.js +3 -2
- package/lib-es/components/SearchFilter/helpers/build-new-query.js.map +1 -1
- package/lib-es/components/SearchFilterSort/helpers/handle-sort-update.js +7 -2
- package/lib-es/components/SearchFilterSort/helpers/handle-sort-update.js.map +1 -1
- package/lib-es/components/SearchFilterSort/helpers/update-sort.js +2 -2
- package/lib-es/components/SearchFilterSort/helpers/update-sort.js.map +1 -1
- package/lib-es/helpers/build-props-query.js +4 -2
- package/lib-es/helpers/build-props-query.js.map +1 -1
- package/lib-es/helpers/get-wrapped-value-with-link.js +2 -2
- package/lib-es/helpers/get-wrapped-value-with-link.js.map +1 -1
- package/lib-es/helpers/index.js +1 -0
- package/lib-es/helpers/index.js.map +1 -1
- package/lib-es/helpers/parse-props-to-display.js +12 -9
- package/lib-es/helpers/parse-props-to-display.js.map +1 -1
- package/lib-es/helpers/process-data-summary-value.js +36 -0
- package/lib-es/helpers/process-data-summary-value.js.map +1 -0
- package/package.json +2 -2
- package/src/components/Code/Code.js +7 -3
- package/src/components/DataSummary/helpers/build-loop-props-content.js +4 -1
- package/src/components/DataSummary/helpers/build-props-to-display-with-content.js +6 -3
- package/src/components/SearchContent/SearchContent.js +8 -6
- package/src/components/SearchFilter/SearchFilterContainer.js +2 -1
- package/src/components/SearchFilter/helpers/build-new-query.js +3 -2
- package/src/components/SearchFilterSort/helpers/handle-sort-update.js +7 -3
- package/src/components/SearchFilterSort/helpers/update-sort.js +2 -2
- package/src/helpers/build-props-query.js +4 -2
- package/src/helpers/get-wrapped-value-with-link.js +6 -3
- package/src/helpers/index.js +1 -0
- package/src/helpers/parse-props-to-display.js +25 -21
- package/src/helpers/process-data-summary-value.js +22 -0
- package/tests/unit/src/components/Code/Code.test.js +5 -0
- package/tests/unit/src/components/Code/__snapshots__/Code.test.js.snap +8 -0
- package/tests/unit/src/components/DataSummary/helpers/build-loop-props-content.test.js +9 -0
- package/tests/unit/src/components/SearchFilter/helpers/build-new-query.test.js +15 -1
- package/tests/unit/src/components/SearchFilterSort/helpers/handle-sort-update.test.js +9 -3
- package/tests/unit/src/components/SearchFilterSort/helpers/update-sort.test.js +10 -1
- package/tests/unit/src/helpers/__snapshots__/get-wrapped-value-with-link.test.js.snap +18 -0
- package/tests/unit/src/helpers/build-props-query.test.js +25 -0
- package/tests/unit/src/helpers/get-wrapped-value-with-link.test.js +2 -2
- package/tests/unit/src/helpers/parse-props-to-display.test.js +4 -0
- package/tests/unit/src/helpers/prcoess-data-summary-value.test.js +52 -0
|
@@ -5,6 +5,10 @@ import updateSort from './update-sort';
|
|
|
5
5
|
const handleSortUpdate = (router, value, query, url, selectLabel) => {
|
|
6
6
|
const queryWithoutSort = {};
|
|
7
7
|
const routerOptions = { shallow: true, scroll: false };
|
|
8
|
+
|
|
9
|
+
const { asPath } = router;
|
|
10
|
+
const hashBit = asPath.split('#')[1];
|
|
11
|
+
const parsedHash = hashBit ? `#${hashBit}` : '';
|
|
8
12
|
Object.keys(query).forEach(key => {
|
|
9
13
|
if (key.indexOf(PAGINATION_QUERY) !== -1) return;
|
|
10
14
|
if (key !== SORTBY && key !== SORT) queryWithoutSort[key] = query[key];
|
|
@@ -13,10 +17,10 @@ const handleSortUpdate = (router, value, query, url, selectLabel) => {
|
|
|
13
17
|
const stringifiedQuery = stringify(queryWithoutSort);
|
|
14
18
|
|
|
15
19
|
return stringifiedQuery
|
|
16
|
-
? router.push(`/Resolver`, `${url}?${stringifiedQuery}`, routerOptions)
|
|
17
|
-
: router.push(`/Resolver`, url
|
|
20
|
+
? router.push(`/Resolver`, `${url}?${stringifiedQuery}${parsedHash}`, routerOptions)
|
|
21
|
+
: router.push(`/Resolver`, `${url}${parsedHash}`, routerOptions);
|
|
18
22
|
}
|
|
19
|
-
const updatedSortUrl = updateSort(value, queryWithoutSort, url);
|
|
23
|
+
const updatedSortUrl = updateSort(value, queryWithoutSort, url, parsedHash);
|
|
20
24
|
return router.push('/Resolver', updatedSortUrl, routerOptions);
|
|
21
25
|
};
|
|
22
26
|
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import { stringify } from 'query-string';
|
|
2
2
|
|
|
3
|
-
const updateSort = (value, query, url) => {
|
|
3
|
+
const updateSort = (value, query, url, hashBit = '') => {
|
|
4
4
|
const [newSortBy, newSort] = value.split(':');
|
|
5
5
|
const updatedQuery = { ...query, sortby: newSortBy, sort: newSort };
|
|
6
6
|
const parsedQuery = stringify(updatedQuery);
|
|
7
|
-
return `${url}?${parsedQuery}`;
|
|
7
|
+
return `${url}?${parsedQuery}${hashBit}`;
|
|
8
8
|
};
|
|
9
9
|
|
|
10
10
|
export default updateSort;
|
|
@@ -44,19 +44,21 @@ const buildPropsQuery = (entitySchema, extraProps = [], cardOptions = null, link
|
|
|
44
44
|
const buildComplexProps = (
|
|
45
45
|
shouldAddCategoryProps,
|
|
46
46
|
props,
|
|
47
|
-
{ relations = [], dynamicProperties = {} },
|
|
47
|
+
{ relations = [], dynamicProperties = {}, properties = {} },
|
|
48
48
|
linkProps
|
|
49
49
|
) =>
|
|
50
50
|
Object.keys(props).map(base => {
|
|
51
51
|
const nestedProps = props[base];
|
|
52
52
|
const hasLink = !!linkProps.find(linkProp => linkProp.includes(base));
|
|
53
|
+
const matchingProperty = !!properties[base];
|
|
53
54
|
const matchingRelation = relations.find(({ localField }) => localField === base);
|
|
54
55
|
const matchingDynamicProp = Object.keys(dynamicProperties).find(
|
|
55
56
|
dynamicKey => dynamicKey === base
|
|
56
57
|
);
|
|
57
58
|
|
|
58
59
|
if (matchingRelation && !nestedProps.includes('id')) nestedProps.push('id');
|
|
59
|
-
if (hasLink && (!!matchingRelation || !!matchingDynamicProp))
|
|
60
|
+
if (hasLink && (!!matchingProperty || !!matchingRelation || !!matchingDynamicProp))
|
|
61
|
+
nestedProps.push('url');
|
|
60
62
|
const jointNestedProps = nestedProps.join(',');
|
|
61
63
|
if (base === 'category' && shouldAddCategoryProps)
|
|
62
64
|
return `${base}{${jointNestedProps}, ${categoryProps}}`;
|
|
@@ -6,13 +6,16 @@ const getWrappedValueWithLink = (value, link, keyPrefix = '') => {
|
|
|
6
6
|
const arrayResults = value.map((arrValue, index) => {
|
|
7
7
|
const { keyField, url } = arrValue;
|
|
8
8
|
const keyValue = arrValue[keyField];
|
|
9
|
+
|
|
9
10
|
const isLastItem = index === value.length - 1;
|
|
10
|
-
const keyFieldValue = isLastItem ? keyValue : keyValue
|
|
11
|
+
const keyFieldValue = isLastItem ? keyValue : <>{keyValue}, </>;
|
|
11
12
|
|
|
12
13
|
return url ? (
|
|
13
|
-
<BlazeLink key={[keyPrefix, index].join('-')} href={url}>
|
|
14
|
+
<BlazeLink key={[keyPrefix, index].join('-')} href={url}>
|
|
15
|
+
{<>{keyFieldValue} </>}
|
|
16
|
+
</BlazeLink>
|
|
14
17
|
) : (
|
|
15
|
-
|
|
18
|
+
<>{keyFieldValue} </>
|
|
16
19
|
);
|
|
17
20
|
});
|
|
18
21
|
|
package/src/helpers/index.js
CHANGED
|
@@ -51,3 +51,4 @@ export { default as getParsedPropValues } from './get-parsed-prop-values';
|
|
|
51
51
|
export { default as getSanitizedPropValues } from './get-sanitized-prop-values';
|
|
52
52
|
export { default as appendImages } from './append-images';
|
|
53
53
|
export { default as parseTextBlock } from './parse-TextBlock';
|
|
54
|
+
export { default as processDataSummaryValue } from './process-data-summary-value';
|
|
@@ -4,35 +4,39 @@ import isObject from './is-object';
|
|
|
4
4
|
import getParsedPropValues from './get-parsed-prop-values';
|
|
5
5
|
import getSanitizedPropValues from './get-sanitized-prop-values';
|
|
6
6
|
import { BOLD_TAG, BLANK_SPACE_UNICODE_STRING } from '../constants';
|
|
7
|
+
import processDataSummaryValue from './process-data-summary-value';
|
|
7
8
|
|
|
8
9
|
// TODO this helper should be removed if database is wiped clean and all elements change to new props struc
|
|
9
10
|
const parsePropsToDisplay = (props = {}, propsToDisplay = []) => {
|
|
10
11
|
if (!isObject(propsToDisplay[0])) return at(props, propsToDisplay).filter(Boolean);
|
|
11
12
|
|
|
12
|
-
return propsToDisplay.map(
|
|
13
|
-
|
|
14
|
-
|
|
13
|
+
return propsToDisplay.map((options, currentIndex) => {
|
|
14
|
+
const { bold, propertiesToDisplay, prefix, suffix, shouldStrip, enableLink } = options;
|
|
15
|
+
const Wrapper = bold ? BOLD_TAG : Fragment;
|
|
15
16
|
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
17
|
+
const parsedPropValues = getParsedPropValues({
|
|
18
|
+
propertiesToDisplay,
|
|
19
|
+
props,
|
|
20
|
+
enableLink,
|
|
21
|
+
shouldStrip
|
|
22
|
+
});
|
|
22
23
|
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
24
|
+
const sanitizedPropValues = getSanitizedPropValues(parsedPropValues);
|
|
25
|
+
if (!sanitizedPropValues || !sanitizedPropValues.length) return null;
|
|
26
|
+
const stringEndBlank =
|
|
27
|
+
currentIndex + 1 === propsToDisplay.length ? '' : BLANK_SPACE_UNICODE_STRING;
|
|
27
28
|
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
29
|
+
const processedValue = Array.isArray(sanitizedPropValues)
|
|
30
|
+
? sanitizedPropValues.map(value => processDataSummaryValue(value, options))
|
|
31
|
+
: processDataSummaryValue(sanitizedPropValues, options);
|
|
32
|
+
|
|
33
|
+
return (
|
|
34
|
+
<Wrapper>
|
|
35
|
+
{prefix} {processedValue} {suffix}
|
|
36
|
+
{stringEndBlank}
|
|
37
|
+
</Wrapper>
|
|
38
|
+
);
|
|
39
|
+
});
|
|
36
40
|
};
|
|
37
41
|
|
|
38
42
|
export default parsePropsToDisplay;
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import components from '../components';
|
|
3
|
+
|
|
4
|
+
const { code: Code } = components;
|
|
5
|
+
|
|
6
|
+
const renderCode = value => <Code code={value} disableWrapper />;
|
|
7
|
+
|
|
8
|
+
const processDataSummaryValue = (objPropValue, { isHtml }) => {
|
|
9
|
+
let pValue = objPropValue;
|
|
10
|
+
if (isHtml) {
|
|
11
|
+
pValue = Array.isArray(objPropValue)
|
|
12
|
+
? objPropValue.map(({ keyField, [keyField]: value, ...otherProps }) => ({
|
|
13
|
+
[keyField]: renderCode(value),
|
|
14
|
+
keyField,
|
|
15
|
+
...otherProps
|
|
16
|
+
}))
|
|
17
|
+
: renderCode(objPropValue);
|
|
18
|
+
}
|
|
19
|
+
return pValue;
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
export default processDataSummaryValue;
|
|
@@ -23,6 +23,11 @@ describe('Code component', () => {
|
|
|
23
23
|
expect(asFragment()).toMatchSnapshot();
|
|
24
24
|
});
|
|
25
25
|
|
|
26
|
+
it('should not render wrapper', () => {
|
|
27
|
+
const { asFragment } = render(Code, { ...props, disableWrapper: true });
|
|
28
|
+
expect(asFragment()).toMatchSnapshot();
|
|
29
|
+
});
|
|
30
|
+
|
|
26
31
|
it('should return null if there is not embed code', () => {
|
|
27
32
|
const { container } = render(Code, {});
|
|
28
33
|
expect(container.innerHTML).toBe('');
|
|
@@ -1,6 +1,11 @@
|
|
|
1
1
|
import '@testing-library/jest-dom/extend-expect';
|
|
2
2
|
import buildLoopPropsContent from '../../../../../../src/components/DataSummary/helpers/build-loop-props-content';
|
|
3
3
|
import { mockedLoopProps, mockedPropsToDisplay, mockedData, mockedResults } from './mocks';
|
|
4
|
+
import processDataSummaryValue from '../../../../../../src/helpers/process-data-summary-value';
|
|
5
|
+
|
|
6
|
+
jest.mock('../../../../../../src/helpers/process-data-summary-value', () =>
|
|
7
|
+
jest.fn(value => value)
|
|
8
|
+
);
|
|
4
9
|
|
|
5
10
|
describe('buildLoopPropsContent helper function', () => {
|
|
6
11
|
const noParamsPassed = buildLoopPropsContent();
|
|
@@ -41,6 +46,10 @@ describe('buildLoopPropsContent helper function', () => {
|
|
|
41
46
|
expect(noDataPassed).toEqual([]);
|
|
42
47
|
});
|
|
43
48
|
|
|
49
|
+
it('should call processDataSummaryValue', () => {
|
|
50
|
+
expect(processDataSummaryValue).toHaveBeenCalledWith('pre data name', mockedPropsToDisplay[0]);
|
|
51
|
+
});
|
|
52
|
+
|
|
44
53
|
it('should return regular dataSummary content if no loopable values are found', () => {
|
|
45
54
|
expect(withNoLoopValues).toEqual(mockedResults[0]);
|
|
46
55
|
expect(withNoLoopableValues).toEqual(mockedResults[1]);
|
|
@@ -3,13 +3,21 @@ import buildNewQuery from '../../../../../../src/components/SearchFilter/helpers
|
|
|
3
3
|
const mockedProps = [
|
|
4
4
|
['', 'current-as-path', 'some=query¶ms=value'],
|
|
5
5
|
['urlFromProps', '', 'other=query&with=value'],
|
|
6
|
-
['urlFromProps', 'not=used', 'another=query&withthis=value', 'sort=asc&sortby=name']
|
|
6
|
+
['urlFromProps', 'not=used', 'another=query&withthis=value', 'sort=asc&sortby=name'],
|
|
7
|
+
[
|
|
8
|
+
'urlFromProps',
|
|
9
|
+
'not=used',
|
|
10
|
+
'another=query&withthis=value',
|
|
11
|
+
'sort=asc&sortby=name',
|
|
12
|
+
'this-is-content'
|
|
13
|
+
]
|
|
7
14
|
];
|
|
8
15
|
|
|
9
16
|
describe('buildNewQuery helper function', () => {
|
|
10
17
|
const simpleExample = buildNewQuery(...mockedProps[0]);
|
|
11
18
|
const withPropsUrl = buildNewQuery(...mockedProps[1]);
|
|
12
19
|
const withSort = buildNewQuery(...mockedProps[2]);
|
|
20
|
+
const withHash = buildNewQuery(...mockedProps[3]);
|
|
13
21
|
|
|
14
22
|
it('should always return a string', () => {
|
|
15
23
|
expect(typeof simpleExample).toBe('string');
|
|
@@ -28,4 +36,10 @@ describe('buildNewQuery helper function', () => {
|
|
|
28
36
|
it('should return new url with sort if passed', () => {
|
|
29
37
|
expect(withSort).toEqual('urlFromProps?another=query&withthis=value&sort=asc&sortby=name');
|
|
30
38
|
});
|
|
39
|
+
|
|
40
|
+
it('should return new url with hash if passed', () => {
|
|
41
|
+
expect(withHash).toEqual(
|
|
42
|
+
'urlFromProps?another=query&withthis=value&sort=asc&sortby=name#this-is-content'
|
|
43
|
+
);
|
|
44
|
+
});
|
|
31
45
|
});
|
|
@@ -2,16 +2,22 @@ import handleSortUpdate from '../../../../../../src/components/SearchFilterSort/
|
|
|
2
2
|
|
|
3
3
|
const routerPushResultMock = () => ({ then: jest.fn() });
|
|
4
4
|
const mockedProps = [
|
|
5
|
-
[{ push: jest.fn(routerPushResultMock) }, 'defaultOption', {}, 'url', 'defaultOption'],
|
|
6
5
|
[
|
|
7
|
-
{ push: jest.fn(routerPushResultMock) },
|
|
6
|
+
{ asPath: 'asPath', push: jest.fn(routerPushResultMock) },
|
|
7
|
+
'defaultOption',
|
|
8
|
+
{},
|
|
9
|
+
'url',
|
|
10
|
+
'defaultOption'
|
|
11
|
+
],
|
|
12
|
+
[
|
|
13
|
+
{ push: jest.fn(routerPushResultMock), asPath: 'asPath' },
|
|
8
14
|
'defaultOption',
|
|
9
15
|
{ sort: 'asc', sortby: 'name', type: 'big' },
|
|
10
16
|
'baseurl',
|
|
11
17
|
'defaultOption'
|
|
12
18
|
],
|
|
13
19
|
[
|
|
14
|
-
{ push: jest.fn(routerPushResultMock) },
|
|
20
|
+
{ push: jest.fn(routerPushResultMock), asPath: 'asPath' },
|
|
15
21
|
'name:desc',
|
|
16
22
|
{ someOther: 'ott' },
|
|
17
23
|
'url',
|
|
@@ -1,10 +1,15 @@
|
|
|
1
1
|
import updateSort from '../../../../../../src/components/SearchFilterSort/helpers/update-sort';
|
|
2
2
|
|
|
3
|
-
const mockedProps = [
|
|
3
|
+
const mockedProps = [
|
|
4
|
+
['name:asc', {}, 'aurl'],
|
|
5
|
+
['name:asc', { other: '12', query2: 'an' }, 'aurl'],
|
|
6
|
+
['name:desc', { query1: 'aquery' }, 'theUrl', '#hashBit']
|
|
7
|
+
];
|
|
4
8
|
|
|
5
9
|
describe('updateSort helper function', () => {
|
|
6
10
|
const basicSort = updateSort(...mockedProps[0]);
|
|
7
11
|
const sortWithOtherQuerys = updateSort(...mockedProps[1]);
|
|
12
|
+
const sortWithhash = updateSort(...mockedProps[2]);
|
|
8
13
|
|
|
9
14
|
it('should return a parsed url based on the parameters passed', () => {
|
|
10
15
|
expect(basicSort).toEqual('aurl?sort=asc&sortby=name');
|
|
@@ -13,4 +18,8 @@ describe('updateSort helper function', () => {
|
|
|
13
18
|
it('should return a parsed url with extra query params if passed', () => {
|
|
14
19
|
expect(sortWithOtherQuerys).toEqual('aurl?other=12&query2=an&sort=asc&sortby=name');
|
|
15
20
|
});
|
|
21
|
+
|
|
22
|
+
it('should return a parsed url with extra query params and hash if passed', () => {
|
|
23
|
+
expect(sortWithhash).toEqual('theUrl?query1=aquery&sort=desc&sortby=name#hashBit');
|
|
24
|
+
});
|
|
16
25
|
});
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
// Jest Snapshot v1, https://goo.gl/fbAQLP
|
|
2
|
+
|
|
3
|
+
exports[`get wrapped value with link func should return array with correponding value and link 1`] = `
|
|
4
|
+
<React.Fragment>
|
|
5
|
+
<React.Fragment>
|
|
6
|
+
test-name
|
|
7
|
+
,
|
|
8
|
+
</React.Fragment>
|
|
9
|
+
|
|
10
|
+
</React.Fragment>
|
|
11
|
+
`;
|
|
12
|
+
|
|
13
|
+
exports[`get wrapped value with link func should return array with correponding value and link 2`] = `
|
|
14
|
+
<React.Fragment>
|
|
15
|
+
test-name2
|
|
16
|
+
|
|
17
|
+
</React.Fragment>
|
|
18
|
+
`;
|
|
@@ -182,6 +182,31 @@ describe('get card render props', () => {
|
|
|
182
182
|
'id,name,url,sponsored,featured,category{name,listingPageId,listingPageEntity, id publishedListingPage{id, url}},address{country,id}'
|
|
183
183
|
);
|
|
184
184
|
});
|
|
185
|
+
|
|
186
|
+
it('should url props where enableLink is set', () => {
|
|
187
|
+
const _data = {
|
|
188
|
+
getEntitySchema: {
|
|
189
|
+
interfaces: [CONTENT_INTERFACE],
|
|
190
|
+
properties: {
|
|
191
|
+
id: 'id',
|
|
192
|
+
nestedProperty: {
|
|
193
|
+
type: 'object'
|
|
194
|
+
}
|
|
195
|
+
},
|
|
196
|
+
relations: [{ localField: 'address' }],
|
|
197
|
+
dynamicProperties: {
|
|
198
|
+
nestedDynamicProperty: {
|
|
199
|
+
type: 'object'
|
|
200
|
+
}
|
|
201
|
+
}
|
|
202
|
+
}
|
|
203
|
+
};
|
|
204
|
+
const linkProps = ['nestedProperty.title', 'nestedDynamicProperty.title', 'address.title'];
|
|
205
|
+
const query = buildPropsQuery(_data, linkProps, {}, linkProps);
|
|
206
|
+
expect(query).toEqual(
|
|
207
|
+
'id,name,url,sponsored,featured,nestedProperty{title,url},nestedDynamicProperty{title,url},address{title,id,url}'
|
|
208
|
+
);
|
|
209
|
+
});
|
|
185
210
|
});
|
|
186
211
|
|
|
187
212
|
function testUrlProperty({ extraProperties = {}, dynamicProperties = {}, cardProps }) {
|
|
@@ -33,7 +33,7 @@ describe('get wrapped value with link func', () => {
|
|
|
33
33
|
expect(resultWithArray).toHaveLength(2);
|
|
34
34
|
expect(resultWithArray[0].props.href).toEqual(link);
|
|
35
35
|
expect(resultWithArray[0].key).toEqual(`${keyPrefix}-0`);
|
|
36
|
-
expect(resultWithArray[0].props.children).
|
|
37
|
-
expect(resultWithArray[1]).
|
|
36
|
+
expect(resultWithArray[0].props.children).toMatchSnapshot();
|
|
37
|
+
expect(resultWithArray[1]).toMatchSnapshot();
|
|
38
38
|
});
|
|
39
39
|
});
|
|
@@ -1,5 +1,8 @@
|
|
|
1
1
|
import '@testing-library/jest-dom/extend-expect';
|
|
2
2
|
import parsePropsToDisplay from '../../../../src/helpers/parse-props-to-display';
|
|
3
|
+
import processDataSummaryValue from '../../../../src/helpers/process-data-summary-value';
|
|
4
|
+
|
|
5
|
+
jest.mock('../../../../src/helpers/process-data-summary-value', () => jest.fn(value => value));
|
|
3
6
|
|
|
4
7
|
const mockedPropsToDisplayStringArr = ['name', 'other', 'cat.name', 'tag.name'];
|
|
5
8
|
const mockedPropsToDisplayObjectArr = [
|
|
@@ -34,6 +37,7 @@ describe('parsePropsToDisplay func', () => {
|
|
|
34
37
|
it('should return an array of react elements if an array of objects is passed', () => {
|
|
35
38
|
const nonElement = !!withObjArr.find(({ type }) => typeof type !== 'symbol');
|
|
36
39
|
expect(nonElement).toEqual(false);
|
|
40
|
+
expect(processDataSummaryValue).toHaveBeenCalled();
|
|
37
41
|
});
|
|
38
42
|
|
|
39
43
|
it('should display bold tag wrapper when props to display has bold property', () => {
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @jest-environment jsdom
|
|
3
|
+
*/
|
|
4
|
+
import React from 'react';
|
|
5
|
+
import processDataSummaryValue from '../../../../src/helpers/process-data-summary-value';
|
|
6
|
+
import components from '../../../../src/components';
|
|
7
|
+
|
|
8
|
+
const { code: Code } = components;
|
|
9
|
+
|
|
10
|
+
const keyField = 'name';
|
|
11
|
+
const john = { keyField, name: 'John', age: 30 };
|
|
12
|
+
const jane = { keyField, name: 'Jane', age: 25 };
|
|
13
|
+
|
|
14
|
+
describe('processDataSummaryValue', () => {
|
|
15
|
+
test('should return the same value when isHtml is false', () => {
|
|
16
|
+
const value = 'Hello, world!';
|
|
17
|
+
const result = processDataSummaryValue(value, { isHtml: false });
|
|
18
|
+
expect(result).toBe(value);
|
|
19
|
+
});
|
|
20
|
+
|
|
21
|
+
test('should render code when isHtml is true and objPropValue is a string', () => {
|
|
22
|
+
const value = 'value';
|
|
23
|
+
const result = processDataSummaryValue(value, { isHtml: true });
|
|
24
|
+
const expectedResult = <Code code={value} disableWrapper />;
|
|
25
|
+
expect(result).toEqual(expectedResult);
|
|
26
|
+
});
|
|
27
|
+
|
|
28
|
+
test('should render code for each object property when isHtml is true and objPropValue is an array of objects', () => {
|
|
29
|
+
const value = [john, jane];
|
|
30
|
+
const result = processDataSummaryValue(value, { isHtml: true });
|
|
31
|
+
const expectedResult = [
|
|
32
|
+
{
|
|
33
|
+
keyField,
|
|
34
|
+
name: <Code code={john.name} disableWrapper />,
|
|
35
|
+
age: 30
|
|
36
|
+
},
|
|
37
|
+
{
|
|
38
|
+
keyField,
|
|
39
|
+
name: <Code code={jane.name} disableWrapper />,
|
|
40
|
+
age: 25
|
|
41
|
+
}
|
|
42
|
+
];
|
|
43
|
+
expect(result).toEqual(expectedResult);
|
|
44
|
+
});
|
|
45
|
+
|
|
46
|
+
test('should not render code for the only property when isHtml is false and objPropValue is an object', () => {
|
|
47
|
+
const value = [john];
|
|
48
|
+
const result = processDataSummaryValue(value, { isHtml: false });
|
|
49
|
+
const expectedResult = [john];
|
|
50
|
+
expect(result).toEqual(expectedResult);
|
|
51
|
+
});
|
|
52
|
+
});
|