@blaze-cms/react-page-builder 0.146.0-node18-core-styles-tooltips.41 → 0.146.0-node18-tooltips.34
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 +46 -97
- package/lib/components/Menu/Menu.js +1 -4
- package/lib/components/Menu/Menu.js.map +1 -1
- package/lib/components/Menu/MenuContext.js +1 -2
- package/lib/components/Menu/MenuContext.js.map +1 -1
- package/lib/components/MenuItem/MenuItemRender.js +12 -27
- package/lib/components/MenuItem/MenuItemRender.js.map +1 -1
- package/lib/components/MenuItem/helpers/index.js +0 -14
- package/lib/components/MenuItem/helpers/index.js.map +1 -1
- package/lib/helpers/get-image-ids.js +3 -0
- package/lib/helpers/get-image-ids.js.map +1 -1
- package/lib/hooks/use-get-image-id-from-relation.js +9 -2
- package/lib/hooks/use-get-image-id-from-relation.js.map +1 -1
- package/lib-es/components/Menu/Menu.js +1 -4
- package/lib-es/components/Menu/Menu.js.map +1 -1
- package/lib-es/components/Menu/MenuContext.js +1 -2
- package/lib-es/components/Menu/MenuContext.js.map +1 -1
- package/lib-es/components/MenuItem/MenuItemRender.js +11 -25
- package/lib-es/components/MenuItem/MenuItemRender.js.map +1 -1
- package/lib-es/components/MenuItem/helpers/index.js +1 -3
- package/lib-es/components/MenuItem/helpers/index.js.map +1 -1
- package/lib-es/helpers/get-image-ids.js +2 -0
- package/lib-es/helpers/get-image-ids.js.map +1 -1
- package/lib-es/hooks/use-get-image-id-from-relation.js +9 -2
- package/lib-es/hooks/use-get-image-id-from-relation.js.map +1 -1
- package/package.json +10 -10
- package/src/components/Menu/Menu.js +1 -3
- package/src/components/Menu/MenuContext.js +1 -1
- package/src/components/MenuItem/MenuItemRender.js +12 -40
- package/src/components/MenuItem/helpers/index.js +1 -3
- package/src/helpers/get-image-ids.js +3 -0
- package/src/hooks/use-get-image-id-from-relation.js +9 -2
- package/tests/unit/src/components/MenuItem/MenuItem.test.js +0 -5
- package/tests/unit/src/components/MenuItem/MenuItemRender.test.js +3 -11
- package/tests/unit/src/helpers/get-image-ids.test.js +22 -10
- package/tests/unit/src/hooks/use-get-image-id-from-relation.test.js +73 -4
- package/lib/components/MenuItem/helpers/has-active-child.js +0 -19
- package/lib/components/MenuItem/helpers/has-active-child.js.map +0 -1
- package/lib/components/MenuItem/helpers/isUrlPathMatch.js +0 -18
- package/lib/components/MenuItem/helpers/isUrlPathMatch.js.map +0 -1
- package/lib-es/components/MenuItem/helpers/has-active-child.js +0 -5
- package/lib-es/components/MenuItem/helpers/has-active-child.js.map +0 -1
- package/lib-es/components/MenuItem/helpers/isUrlPathMatch.js +0 -8
- package/lib-es/components/MenuItem/helpers/isUrlPathMatch.js.map +0 -1
- package/src/components/MenuItem/helpers/has-active-child.js +0 -10
- package/src/components/MenuItem/helpers/isUrlPathMatch.js +0 -10
- package/tests/unit/src/components/MenuItem/helpers/constants.js +0 -73
- package/tests/unit/src/components/MenuItem/helpers/has-active-child.test.js +0 -35
- package/tests/unit/src/components/MenuItem/helpers/is-url-path-match.test.js +0 -53
|
@@ -1,5 +1,3 @@
|
|
|
1
1
|
import injectHelperIntoTemplate from './inject-helper-into-template';
|
|
2
|
-
import isUrlPathMatch from './isUrlPathMatch';
|
|
3
|
-
import hasActiveChild from './has-active-child';
|
|
4
2
|
|
|
5
|
-
export { injectHelperIntoTemplate
|
|
3
|
+
export { injectHelperIntoTemplate };
|
|
@@ -4,6 +4,7 @@ const getIdsFromArray = (relationImageData, relationProp, imageId) => {
|
|
|
4
4
|
if (!relationImageData.length) return [imageId];
|
|
5
5
|
return relationImageData
|
|
6
6
|
.map(image => {
|
|
7
|
+
if (typeof image !== 'object') return image;
|
|
7
8
|
if (!Object.keys(image).length) return '';
|
|
8
9
|
return image[relationProp];
|
|
9
10
|
})
|
|
@@ -27,6 +28,8 @@ const getImageIds = (imageRelation, relationData, imageId) => {
|
|
|
27
28
|
? relationImageData[relationProp]
|
|
28
29
|
: [relationImageData[relationProp]];
|
|
29
30
|
}
|
|
31
|
+
|
|
32
|
+
if (relationImageData) return [relationImageData];
|
|
30
33
|
}
|
|
31
34
|
|
|
32
35
|
return imageIdArray;
|
|
@@ -22,14 +22,21 @@ function useGetImageIdFromRelation(
|
|
|
22
22
|
const { getPublished, get } = actions || {};
|
|
23
23
|
const getAction = isPreview ? get : getPublished || get;
|
|
24
24
|
|
|
25
|
-
|
|
25
|
+
let props;
|
|
26
|
+
if (imageRelationData) {
|
|
27
|
+
if (relationProp) {
|
|
28
|
+
props = imageRelationData ? `${relationName} { ${relationProp} }` : 'id';
|
|
29
|
+
} else {
|
|
30
|
+
props = relationName;
|
|
31
|
+
}
|
|
32
|
+
}
|
|
26
33
|
const {
|
|
27
34
|
data = {},
|
|
28
35
|
loading,
|
|
29
36
|
error
|
|
30
37
|
} = useQuery(generateSingleItemQuery(getAction, props), {
|
|
31
38
|
variables: { id },
|
|
32
|
-
skip
|
|
39
|
+
skip: skip || !imageRelationData
|
|
33
40
|
});
|
|
34
41
|
return { data, loading, error };
|
|
35
42
|
}
|
|
@@ -19,11 +19,6 @@ jest.mock('next/router', () => ({
|
|
|
19
19
|
useRouter: () => ({ asPath: '/' })
|
|
20
20
|
}));
|
|
21
21
|
|
|
22
|
-
// todo: add extra tests to support this util
|
|
23
|
-
jest.mock('../../../../../src/components/MenuItem/helpers/has-active-child', () =>
|
|
24
|
-
jest.fn(() => false)
|
|
25
|
-
);
|
|
26
|
-
|
|
27
22
|
const componentProps = {
|
|
28
23
|
id: 'id',
|
|
29
24
|
name: 'mock name',
|
|
@@ -11,22 +11,14 @@ const MENU_ITEM_CHILDREN_CLASS = 'menu--item-children';
|
|
|
11
11
|
|
|
12
12
|
let mockAsPathValue = '/';
|
|
13
13
|
|
|
14
|
-
jest.mock('next/router', () => {
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
useRouter: () => router
|
|
18
|
-
};
|
|
19
|
-
});
|
|
14
|
+
jest.mock('next/router', () => ({
|
|
15
|
+
useRouter: () => ({ asPath: mockAsPathValue })
|
|
16
|
+
}));
|
|
20
17
|
|
|
21
18
|
jest.mock('@blaze-cms/utils-handlebars', () => ({
|
|
22
19
|
useStringTemplate: jest.fn((parent, [title]) => ({ loading: false, data: [title] }))
|
|
23
20
|
}));
|
|
24
21
|
|
|
25
|
-
// todo: add extra tests to support this util
|
|
26
|
-
jest.mock('../../../../../src/components/MenuItem/helpers/has-active-child', () =>
|
|
27
|
-
jest.fn(() => false)
|
|
28
|
-
);
|
|
29
|
-
|
|
30
22
|
describe('MenuRender component', () => {
|
|
31
23
|
it('renders menu item with link when URL is provided', () => {
|
|
32
24
|
const { getByText } = render(<MenuRender eventType="click" text="Home" url="/home" />);
|
|
@@ -42,10 +42,10 @@ describe('getImageIds helper', () => {
|
|
|
42
42
|
expect(getImageIds(relationNameProp, relationData, '')).toEqual(['test', 'test3']);
|
|
43
43
|
});
|
|
44
44
|
|
|
45
|
-
it('should return
|
|
45
|
+
it('should return the relation object itself when relationName is an empty object', () => {
|
|
46
46
|
expect(
|
|
47
47
|
getImageIds(relationNameProp, { entityData: { relationName: {} } }, 'test-id-not-array')
|
|
48
|
-
).toEqual([
|
|
48
|
+
).toEqual([{}]);
|
|
49
49
|
});
|
|
50
50
|
|
|
51
51
|
it('should return expected value if relationName is not an empty object', () => {
|
|
@@ -58,16 +58,10 @@ describe('getImageIds helper', () => {
|
|
|
58
58
|
).toEqual(['prop-value']);
|
|
59
59
|
});
|
|
60
60
|
|
|
61
|
-
it('should return
|
|
61
|
+
it('should return primitive relationName when it is not an object or array', () => {
|
|
62
62
|
expect(
|
|
63
63
|
getImageIds(relationNameProp, { entityData: { relationName: 'relationName' } }, imageId)
|
|
64
|
-
).toEqual([
|
|
65
|
-
});
|
|
66
|
-
|
|
67
|
-
it('should return empty array', () => {
|
|
68
|
-
expect(
|
|
69
|
-
getImageIds(relationNameProp, { entityData: { relationName: 'relationName' } }, '')
|
|
70
|
-
).toEqual([]);
|
|
64
|
+
).toEqual(['relationName']);
|
|
71
65
|
});
|
|
72
66
|
|
|
73
67
|
it('should return data from object with non array property', () => {
|
|
@@ -77,4 +71,22 @@ describe('getImageIds helper', () => {
|
|
|
77
71
|
it('should return data from object with array property', () => {
|
|
78
72
|
expect(getImageIds(['objectRelation.imageIds'], relationData, '')).toEqual(['test5']);
|
|
79
73
|
});
|
|
74
|
+
|
|
75
|
+
it('should return an empty array when no imageId and relation produces no ids', () => {
|
|
76
|
+
const dataWithNoMatches = {
|
|
77
|
+
entityData: {
|
|
78
|
+
relationName: [{ otherProp: 'x' }, { otherProp: 'y' }]
|
|
79
|
+
}
|
|
80
|
+
};
|
|
81
|
+
expect(getImageIds(['relationName.relationProp'], dataWithNoMatches, '')).toEqual([]);
|
|
82
|
+
});
|
|
83
|
+
|
|
84
|
+
it('should return multiple ids when relation property is an array', () => {
|
|
85
|
+
const dataWithPropArray = {
|
|
86
|
+
entityData: {
|
|
87
|
+
gallery: { imageIds: ['id1', 'id2'] }
|
|
88
|
+
}
|
|
89
|
+
};
|
|
90
|
+
expect(getImageIds(['gallery.imageIds'], dataWithPropArray, '')).toEqual(['id1', 'id2']);
|
|
91
|
+
});
|
|
80
92
|
});
|
|
@@ -41,11 +41,21 @@ describe('useGetImageIdFromRelation', () => {
|
|
|
41
41
|
it('should use `get` query when preview is true', async () => {
|
|
42
42
|
const spy = jest.spyOn(query, 'generateSingleItemQuery');
|
|
43
43
|
|
|
44
|
-
renderHook(
|
|
45
|
-
|
|
46
|
-
|
|
44
|
+
renderHook(
|
|
45
|
+
() =>
|
|
46
|
+
useGetImageIdFromRelation(
|
|
47
|
+
mockProps.id,
|
|
48
|
+
mockProps.imageRelation,
|
|
49
|
+
mockProps.actions,
|
|
50
|
+
true,
|
|
51
|
+
true
|
|
52
|
+
),
|
|
53
|
+
{
|
|
54
|
+
wrapper
|
|
55
|
+
}
|
|
56
|
+
);
|
|
47
57
|
|
|
48
|
-
expect(spy).toHaveBeenCalledWith('getPage', '
|
|
58
|
+
expect(spy).toHaveBeenCalledWith('getPage', 'publishedPages { imageId }');
|
|
49
59
|
});
|
|
50
60
|
|
|
51
61
|
it('should use `getPublished` query when preview is false', async () => {
|
|
@@ -73,6 +83,65 @@ describe('useGetImageIdFromRelation', () => {
|
|
|
73
83
|
expect(result.current.error).toBeUndefined();
|
|
74
84
|
expect(result.current.data).toEqual({});
|
|
75
85
|
});
|
|
86
|
+
|
|
87
|
+
it('should skip when hasImgSrc is true', async () => {
|
|
88
|
+
const { result } = renderHook(
|
|
89
|
+
() =>
|
|
90
|
+
useGetImageIdFromRelation(
|
|
91
|
+
mockProps.id,
|
|
92
|
+
mockProps.imageRelation,
|
|
93
|
+
mockProps.actions,
|
|
94
|
+
true,
|
|
95
|
+
false,
|
|
96
|
+
true
|
|
97
|
+
),
|
|
98
|
+
{ wrapper }
|
|
99
|
+
);
|
|
100
|
+
|
|
101
|
+
expect(result.current.loading).toBeFalsy();
|
|
102
|
+
expect(result.current.error).toBeUndefined();
|
|
103
|
+
expect(result.current.data).toEqual({});
|
|
104
|
+
});
|
|
105
|
+
|
|
106
|
+
it('should skip when id is not a string', async () => {
|
|
107
|
+
const { result } = renderHook(
|
|
108
|
+
() =>
|
|
109
|
+
useGetImageIdFromRelation(
|
|
110
|
+
12345,
|
|
111
|
+
mockProps.imageRelation,
|
|
112
|
+
mockProps.actions,
|
|
113
|
+
true,
|
|
114
|
+
false,
|
|
115
|
+
false
|
|
116
|
+
),
|
|
117
|
+
{ wrapper }
|
|
118
|
+
);
|
|
119
|
+
|
|
120
|
+
expect(result.current.loading).toBeFalsy();
|
|
121
|
+
expect(result.current.error).toBeUndefined();
|
|
122
|
+
expect(result.current.data).toEqual({});
|
|
123
|
+
});
|
|
124
|
+
|
|
125
|
+
it('should fallback to `get` when `getPublished` is missing', async () => {
|
|
126
|
+
const actionsWithoutPublished = { ...mockProps.actions };
|
|
127
|
+
delete actionsWithoutPublished.getPublished;
|
|
128
|
+
|
|
129
|
+
const spy = jest.spyOn(query, 'generateSingleItemQuery');
|
|
130
|
+
|
|
131
|
+
renderHook(
|
|
132
|
+
() =>
|
|
133
|
+
useGetImageIdFromRelation(
|
|
134
|
+
mockProps.id,
|
|
135
|
+
mockProps.imageRelation,
|
|
136
|
+
actionsWithoutPublished,
|
|
137
|
+
true,
|
|
138
|
+
false
|
|
139
|
+
),
|
|
140
|
+
{ wrapper }
|
|
141
|
+
);
|
|
142
|
+
|
|
143
|
+
expect(spy).toHaveBeenCalledWith('getPage', 'publishedPages { imageId }');
|
|
144
|
+
});
|
|
76
145
|
});
|
|
77
146
|
|
|
78
147
|
function renderCustomHook() {
|
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
require("core-js/modules/es.object.define-property.js");
|
|
4
|
-
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
5
|
-
Object.defineProperty(exports, "__esModule", {
|
|
6
|
-
value: true
|
|
7
|
-
});
|
|
8
|
-
exports["default"] = void 0;
|
|
9
|
-
require("core-js/modules/es.array.find.js");
|
|
10
|
-
require("core-js/modules/es.object.to-string.js");
|
|
11
|
-
var _isUrlPathMatch = _interopRequireDefault(require("./isUrlPathMatch"));
|
|
12
|
-
var _helpers = require("../../../helpers");
|
|
13
|
-
var hasActiveChild = function hasActiveChild(path, children) {
|
|
14
|
-
return (0, _helpers.hasChildren)(children) && children.props.children[1][0].props.component.items.find(function (menuItem) {
|
|
15
|
-
return (0, _isUrlPathMatch["default"])(path, menuItem.settings.url);
|
|
16
|
-
});
|
|
17
|
-
};
|
|
18
|
-
var _default = exports["default"] = hasActiveChild;
|
|
19
|
-
//# sourceMappingURL=has-active-child.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"has-active-child.js","names":["_isUrlPathMatch","_interopRequireDefault","require","_helpers","hasActiveChild","path","children","hasChildren","props","component","items","find","menuItem","isUrlPathMatch","settings","url","_default","exports"],"sources":["../../../../src/components/MenuItem/helpers/has-active-child.js"],"sourcesContent":["import isUrlPathMatch from './isUrlPathMatch';\nimport { hasChildren } from '../../../helpers';\n\nconst hasActiveChild = (path, children) =>\n hasChildren(children) &&\n children.props.children[1][0].props.component.items.find(menuItem =>\n isUrlPathMatch(path, menuItem.settings.url)\n );\n\nexport default hasActiveChild;\n"],"mappings":";;;;;;;;;;AAAA,IAAAA,eAAA,GAAAC,sBAAA,CAAAC,OAAA;AACA,IAAAC,QAAA,GAAAD,OAAA;AAEA,IAAME,cAAc,GAAG,SAAjBA,cAAcA,CAAIC,IAAI,EAAEC,QAAQ;EAAA,OACpC,IAAAC,oBAAW,EAACD,QAAQ,CAAC,IACrBA,QAAQ,CAACE,KAAK,CAACF,QAAQ,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAACE,KAAK,CAACC,SAAS,CAACC,KAAK,CAACC,IAAI,CAAC,UAAAC,QAAQ;IAAA,OAC/D,IAAAC,0BAAc,EAACR,IAAI,EAAEO,QAAQ,CAACE,QAAQ,CAACC,GAAG,CAAC;EAAA,CAC7C,CAAC;AAAA;AAAC,IAAAC,QAAA,GAAAC,OAAA,cAEWb,cAAc","ignoreList":[]}
|
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
require("core-js/modules/es.object.define-property.js");
|
|
4
|
-
Object.defineProperty(exports, "__esModule", {
|
|
5
|
-
value: true
|
|
6
|
-
});
|
|
7
|
-
exports["default"] = void 0;
|
|
8
|
-
require("core-js/modules/es.regexp.constructor.js");
|
|
9
|
-
require("core-js/modules/es.regexp.exec.js");
|
|
10
|
-
require("core-js/modules/es.regexp.to-string.js");
|
|
11
|
-
var isUrlPathMatch = function isUrlPathMatch(path, itemUrl) {
|
|
12
|
-
if (!itemUrl || !path) return false;
|
|
13
|
-
var reg = new RegExp(/^[^#?]+/);
|
|
14
|
-
var _path = reg.exec(path)[0];
|
|
15
|
-
return _path === itemUrl || _path === "/".concat(itemUrl);
|
|
16
|
-
};
|
|
17
|
-
var _default = exports["default"] = isUrlPathMatch;
|
|
18
|
-
//# sourceMappingURL=isUrlPathMatch.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"isUrlPathMatch.js","names":["isUrlPathMatch","path","itemUrl","reg","RegExp","_path","exec","concat","_default","exports"],"sources":["../../../../src/components/MenuItem/helpers/isUrlPathMatch.js"],"sourcesContent":["const isUrlPathMatch = (path, itemUrl) => {\n if (!itemUrl || !path) return false;\n\n const reg = new RegExp(/^[^#?]+/);\n const _path = reg.exec(path)[0];\n\n return _path === itemUrl || _path === `/${itemUrl}`;\n};\n\nexport default isUrlPathMatch;\n"],"mappings":";;;;;;;;;;AAAA,IAAMA,cAAc,GAAG,SAAjBA,cAAcA,CAAIC,IAAI,EAAEC,OAAO,EAAK;EACxC,IAAI,CAACA,OAAO,IAAI,CAACD,IAAI,EAAE,OAAO,KAAK;EAEnC,IAAME,GAAG,GAAG,IAAIC,MAAM,CAAC,SAAS,CAAC;EACjC,IAAMC,KAAK,GAAGF,GAAG,CAACG,IAAI,CAACL,IAAI,CAAC,CAAC,CAAC,CAAC;EAE/B,OAAOI,KAAK,KAAKH,OAAO,IAAIG,KAAK,SAAAE,MAAA,CAASL,OAAO,CAAE;AACrD,CAAC;AAAC,IAAAM,QAAA,GAAAC,OAAA,cAEaT,cAAc","ignoreList":[]}
|
|
@@ -1,5 +0,0 @@
|
|
|
1
|
-
import isUrlPathMatch from './isUrlPathMatch';
|
|
2
|
-
import { hasChildren } from '../../../helpers';
|
|
3
|
-
const hasActiveChild = (path, children) => hasChildren(children) && children.props.children[1][0].props.component.items.find(menuItem => isUrlPathMatch(path, menuItem.settings.url));
|
|
4
|
-
export default hasActiveChild;
|
|
5
|
-
//# sourceMappingURL=has-active-child.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"has-active-child.js","names":["isUrlPathMatch","hasChildren","hasActiveChild","path","children","props","component","items","find","menuItem","settings","url"],"sources":["../../../../src/components/MenuItem/helpers/has-active-child.js"],"sourcesContent":["import isUrlPathMatch from './isUrlPathMatch';\nimport { hasChildren } from '../../../helpers';\n\nconst hasActiveChild = (path, children) =>\n hasChildren(children) &&\n children.props.children[1][0].props.component.items.find(menuItem =>\n isUrlPathMatch(path, menuItem.settings.url)\n );\n\nexport default hasActiveChild;\n"],"mappings":"AAAA,OAAOA,cAAc,MAAM,kBAAkB;AAC7C,SAASC,WAAW,QAAQ,kBAAkB;AAE9C,MAAMC,cAAc,GAAGA,CAACC,IAAI,EAAEC,QAAQ,KACpCH,WAAW,CAACG,QAAQ,CAAC,IACrBA,QAAQ,CAACC,KAAK,CAACD,QAAQ,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAACC,KAAK,CAACC,SAAS,CAACC,KAAK,CAACC,IAAI,CAACC,QAAQ,IAC/DT,cAAc,CAACG,IAAI,EAAEM,QAAQ,CAACC,QAAQ,CAACC,GAAG,CAC5C,CAAC;AAEH,eAAeT,cAAc","ignoreList":[]}
|
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
const isUrlPathMatch = (path, itemUrl) => {
|
|
2
|
-
if (!itemUrl || !path) return false;
|
|
3
|
-
const reg = new RegExp(/^[^#?]+/);
|
|
4
|
-
const _path = reg.exec(path)[0];
|
|
5
|
-
return _path === itemUrl || _path === `/${itemUrl}`;
|
|
6
|
-
};
|
|
7
|
-
export default isUrlPathMatch;
|
|
8
|
-
//# sourceMappingURL=isUrlPathMatch.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"isUrlPathMatch.js","names":["isUrlPathMatch","path","itemUrl","reg","RegExp","_path","exec"],"sources":["../../../../src/components/MenuItem/helpers/isUrlPathMatch.js"],"sourcesContent":["const isUrlPathMatch = (path, itemUrl) => {\n if (!itemUrl || !path) return false;\n\n const reg = new RegExp(/^[^#?]+/);\n const _path = reg.exec(path)[0];\n\n return _path === itemUrl || _path === `/${itemUrl}`;\n};\n\nexport default isUrlPathMatch;\n"],"mappings":"AAAA,MAAMA,cAAc,GAAGA,CAACC,IAAI,EAAEC,OAAO,KAAK;EACxC,IAAI,CAACA,OAAO,IAAI,CAACD,IAAI,EAAE,OAAO,KAAK;EAEnC,MAAME,GAAG,GAAG,IAAIC,MAAM,CAAC,SAAS,CAAC;EACjC,MAAMC,KAAK,GAAGF,GAAG,CAACG,IAAI,CAACL,IAAI,CAAC,CAAC,CAAC,CAAC;EAE/B,OAAOI,KAAK,KAAKH,OAAO,IAAIG,KAAK,KAAK,IAAIH,OAAO,EAAE;AACrD,CAAC;AAED,eAAeF,cAAc","ignoreList":[]}
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
import isUrlPathMatch from './isUrlPathMatch';
|
|
2
|
-
import { hasChildren } from '../../../helpers';
|
|
3
|
-
|
|
4
|
-
const hasActiveChild = (path, children) =>
|
|
5
|
-
hasChildren(children) &&
|
|
6
|
-
children.props.children[1][0].props.component.items.find(menuItem =>
|
|
7
|
-
isUrlPathMatch(path, menuItem.settings.url)
|
|
8
|
-
);
|
|
9
|
-
|
|
10
|
-
export default hasActiveChild;
|
|
@@ -1,73 +0,0 @@
|
|
|
1
|
-
export const mockMenuProps = {
|
|
2
|
-
props: {
|
|
3
|
-
children: [
|
|
4
|
-
false,
|
|
5
|
-
[
|
|
6
|
-
{
|
|
7
|
-
props: {
|
|
8
|
-
component: {
|
|
9
|
-
items: [
|
|
10
|
-
{
|
|
11
|
-
type: 'menuitem',
|
|
12
|
-
settings: {
|
|
13
|
-
name: 'menuitem-card',
|
|
14
|
-
url: 'card',
|
|
15
|
-
text: 'Card'
|
|
16
|
-
},
|
|
17
|
-
id: 'menuitem-card-1',
|
|
18
|
-
items: [],
|
|
19
|
-
name: 'menuitem-card-1'
|
|
20
|
-
},
|
|
21
|
-
{
|
|
22
|
-
type: 'menuitem',
|
|
23
|
-
settings: {
|
|
24
|
-
name: 'menuitem-Card',
|
|
25
|
-
|
|
26
|
-
url: 'card',
|
|
27
|
-
text: 'Card'
|
|
28
|
-
},
|
|
29
|
-
id: 'menuitem-Card-1',
|
|
30
|
-
items: [],
|
|
31
|
-
name: 'menuitem-Card-1'
|
|
32
|
-
},
|
|
33
|
-
{
|
|
34
|
-
type: 'menuitem',
|
|
35
|
-
settings: {
|
|
36
|
-
name: 'menuitem-card-Carousel',
|
|
37
|
-
url: 'card-carousel',
|
|
38
|
-
text: 'Card Carousel'
|
|
39
|
-
},
|
|
40
|
-
id: 'menuitem-card-carousel-1',
|
|
41
|
-
items: [],
|
|
42
|
-
name: 'menuitem-card-carousel-1'
|
|
43
|
-
},
|
|
44
|
-
{
|
|
45
|
-
type: 'menuitem',
|
|
46
|
-
settings: {
|
|
47
|
-
eventType: 'hover',
|
|
48
|
-
name: 'menuitem-Content-Group',
|
|
49
|
-
modifier: null,
|
|
50
|
-
url: 'content-group',
|
|
51
|
-
text: 'Content Group',
|
|
52
|
-
variant: null,
|
|
53
|
-
gtmClassName: null,
|
|
54
|
-
entities: [],
|
|
55
|
-
filterByProperty: [],
|
|
56
|
-
filterByFeatured: 'off',
|
|
57
|
-
filterBySponsored: 'off',
|
|
58
|
-
operator: 'AND',
|
|
59
|
-
filterBy: [],
|
|
60
|
-
sortProperties: []
|
|
61
|
-
},
|
|
62
|
-
id: 'menuitem-Content-Group-1',
|
|
63
|
-
items: [],
|
|
64
|
-
name: 'menuitem-Content-Group-1'
|
|
65
|
-
}
|
|
66
|
-
]
|
|
67
|
-
}
|
|
68
|
-
}
|
|
69
|
-
}
|
|
70
|
-
]
|
|
71
|
-
]
|
|
72
|
-
}
|
|
73
|
-
};
|
|
@@ -1,35 +0,0 @@
|
|
|
1
|
-
/* eslint-disable no-unused-vars */
|
|
2
|
-
import '@testing-library/jest-dom/extend-expect';
|
|
3
|
-
import { hasActiveChild } from '../../../../../../src/components/MenuItem/helpers';
|
|
4
|
-
import { mockMenuProps } from './constants';
|
|
5
|
-
|
|
6
|
-
describe('hasActiveChild', () => {
|
|
7
|
-
const structuredClone = val => JSON.parse(JSON.stringify(val));
|
|
8
|
-
|
|
9
|
-
it('should return true for finding active menu-item child', () => {
|
|
10
|
-
const activePath = '/card';
|
|
11
|
-
const menuProps = mockMenuProps;
|
|
12
|
-
const result = !!hasActiveChild(activePath, menuProps);
|
|
13
|
-
expect(result).toBe(true);
|
|
14
|
-
});
|
|
15
|
-
|
|
16
|
-
it('shoul return false for findng no exact match', () => {
|
|
17
|
-
const activePath = '/carousel';
|
|
18
|
-
const menuProps = mockMenuProps;
|
|
19
|
-
|
|
20
|
-
const result = !!hasActiveChild(activePath, menuProps);
|
|
21
|
-
expect(result).toBe(false);
|
|
22
|
-
});
|
|
23
|
-
|
|
24
|
-
it('should return false for empty children-items', () => {
|
|
25
|
-
const activePath = '/carousel';
|
|
26
|
-
const menuWithNoChildrenProps = (() => {
|
|
27
|
-
const obj = structuredClone(mockMenuProps);
|
|
28
|
-
obj.props.children[1][0].props.component.items = [];
|
|
29
|
-
return obj;
|
|
30
|
-
}).call();
|
|
31
|
-
|
|
32
|
-
const result = !!hasActiveChild(activePath, menuWithNoChildrenProps);
|
|
33
|
-
expect(result).toBe(false);
|
|
34
|
-
});
|
|
35
|
-
});
|
|
@@ -1,53 +0,0 @@
|
|
|
1
|
-
import '@testing-library/jest-dom/extend-expect';
|
|
2
|
-
import { isUrlPathMatch } from '../../../../../../src/components/MenuItem/helpers';
|
|
3
|
-
|
|
4
|
-
describe('isUrlPathMatch', () => {
|
|
5
|
-
it('should return true since path and itemUrl match', () => {
|
|
6
|
-
const path = '/button';
|
|
7
|
-
const itemUrl = 'button';
|
|
8
|
-
const result = isUrlPathMatch(path, itemUrl);
|
|
9
|
-
expect(result).toBeTruthy();
|
|
10
|
-
});
|
|
11
|
-
|
|
12
|
-
it('should match since path and itemUrl do not match', () => {
|
|
13
|
-
const path = '/card';
|
|
14
|
-
const itemUrl = 'button';
|
|
15
|
-
const result = isUrlPathMatch(path, itemUrl);
|
|
16
|
-
expect(result).toBeFalsy();
|
|
17
|
-
});
|
|
18
|
-
|
|
19
|
-
it('should not match since path and itemUrl is a partial match', () => {
|
|
20
|
-
const path = '/button-card';
|
|
21
|
-
const itemUrl = 'button';
|
|
22
|
-
const result = isUrlPathMatch(path, itemUrl);
|
|
23
|
-
expect(result).toBeFalsy();
|
|
24
|
-
});
|
|
25
|
-
|
|
26
|
-
it('should not match since nested path and itemUrl is a partial match', () => {
|
|
27
|
-
const path = '/button/child';
|
|
28
|
-
const itemUrl = 'button';
|
|
29
|
-
const result = isUrlPathMatch(path, itemUrl);
|
|
30
|
-
expect(result).toBeFalsy();
|
|
31
|
-
});
|
|
32
|
-
|
|
33
|
-
it('should match with uri-with-fragment', () => {
|
|
34
|
-
const path = '/button#dark';
|
|
35
|
-
const itemUrl = 'button';
|
|
36
|
-
const result = isUrlPathMatch(path, itemUrl);
|
|
37
|
-
expect(result).toBeTruthy();
|
|
38
|
-
});
|
|
39
|
-
|
|
40
|
-
it('should match with uri-with-parameters', () => {
|
|
41
|
-
const path = '/button?paramater=value';
|
|
42
|
-
const itemUrl = 'button';
|
|
43
|
-
const result = isUrlPathMatch(path, itemUrl);
|
|
44
|
-
expect(result).toBeTruthy();
|
|
45
|
-
});
|
|
46
|
-
|
|
47
|
-
it('should not match with empty itemUrl', () => {
|
|
48
|
-
const path = '/';
|
|
49
|
-
const itemUrl = null;
|
|
50
|
-
const result = isUrlPathMatch(path, itemUrl);
|
|
51
|
-
expect(result).toBeFalsy();
|
|
52
|
-
});
|
|
53
|
-
});
|