Skip to content

Commit 26e99fb

Browse files
Maxime Jantonbobylito
authored andcommitted
fix(connectHierarchicalMenu): do not return if facet not set (#2521)
* fix(connectHierarchicalMenu): dont return if facet not set * test(connectHierarchicalMenu): add `getConfiguration` complex use cases * test(connectBreadcrumb): add `getConfiguration()` complex use cases
1 parent 07d1998 commit 26e99fb

File tree

3 files changed

+107
-1
lines changed

3 files changed

+107
-1
lines changed

src/connectors/breadcrumb/__tests__/connectBreadcrumb-test.js

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,57 @@ const SearchResults = jsHelper.SearchResults;
44
import connectBreadcrumb from '../connectBreadcrumb.js';
55

66
describe('connectBreadcrumb', () => {
7+
it('It should compute getConfiguration() correctly', () => {
8+
const rendering = jest.fn();
9+
const makeWidget = connectBreadcrumb(rendering);
10+
11+
const widget = makeWidget({ attributes: ['category', 'sub_category'] });
12+
13+
// when there is no hierarchicalFacets into current configuration
14+
{
15+
const config = widget.getConfiguration({});
16+
expect(config).toEqual({
17+
hierarchicalFacets: [
18+
{
19+
attributes: ['category', 'sub_category'],
20+
name: 'category',
21+
rootPath: null,
22+
separator: ' > ',
23+
},
24+
],
25+
});
26+
}
27+
28+
// when there is an identical hierarchicalFacets into current configuration
29+
{
30+
const spy = jest.spyOn(global.console, 'warn');
31+
const config = widget.getConfiguration({
32+
hierarchicalFacets: [{ name: 'category' }],
33+
});
34+
expect(config).toEqual({});
35+
expect(spy).toHaveBeenCalled();
36+
spy.mockReset();
37+
spy.mockRestore();
38+
}
39+
40+
// when there is already a different hierarchicalFacets into current configuration
41+
{
42+
const config = widget.getConfiguration({
43+
hierarchicalFacets: [{ name: 'foo' }],
44+
});
45+
expect(config).toEqual({
46+
hierarchicalFacets: [
47+
{
48+
attributes: ['category', 'sub_category'],
49+
name: 'category',
50+
rootPath: null,
51+
separator: ' > ',
52+
},
53+
],
54+
});
55+
}
56+
});
57+
758
it('Renders during init and render', () => {
859
const rendering = jest.fn();
960
const makeWidget = connectBreadcrumb(rendering);

src/connectors/hierarchical-menu/__tests__/connectHierarchicalMenu-test.js

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,61 @@ const SearchResults = jsHelper.SearchResults;
66
import connectHierarchicalMenu from '../connectHierarchicalMenu.js';
77

88
describe('connectHierarchicalMenu', () => {
9+
it('It should compute getConfiguration() correctly', () => {
10+
const rendering = jest.fn();
11+
const makeWidget = connectHierarchicalMenu(rendering);
12+
13+
const widget = makeWidget({ attributes: ['category', 'sub_category'] });
14+
15+
// when there is no hierarchicalFacets into current configuration
16+
{
17+
const config = widget.getConfiguration({});
18+
expect(config).toEqual({
19+
hierarchicalFacets: [
20+
{
21+
attributes: ['category', 'sub_category'],
22+
name: 'category',
23+
rootPath: null,
24+
separator: ' > ',
25+
showParentLevel: true,
26+
},
27+
],
28+
maxValuesPerFacet: 10,
29+
});
30+
}
31+
32+
// when there is an identical hierarchicalFacets into current configuration
33+
{
34+
const spy = jest.spyOn(global.console, 'warn');
35+
const config = widget.getConfiguration({
36+
hierarchicalFacets: [{ name: 'category' }],
37+
});
38+
expect(config).toEqual({});
39+
expect(spy).toHaveBeenCalled();
40+
spy.mockReset();
41+
spy.mockRestore();
42+
}
43+
44+
// when there is already a different hierarchicalFacets into current configuration
45+
{
46+
const config = widget.getConfiguration({
47+
hierarchicalFacets: [{ name: 'foo' }],
48+
});
49+
expect(config).toEqual({
50+
hierarchicalFacets: [
51+
{
52+
attributes: ['category', 'sub_category'],
53+
name: 'category',
54+
rootPath: null,
55+
separator: ' > ',
56+
showParentLevel: true,
57+
},
58+
],
59+
maxValuesPerFacet: 10,
60+
});
61+
}
62+
});
63+
964
it('Renders during init and render', () => {
1065
// test that the dummyRendering is called with the isFirstRendering
1166
// flag set accordingly

src/connectors/hierarchical-menu/connectHierarchicalMenu.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,8 +109,8 @@ export default function connectHierarchicalMenu(renderFn) {
109109
console.warn(
110110
'using Breadcrumb & HierarchicalMenu on the same facet with different options'
111111
);
112+
return {};
112113
}
113-
return {};
114114
}
115115

116116
return {

0 commit comments

Comments
 (0)