Skip to content

Commit

Permalink
fix(hierarchicalMenu): configure maxValuesPerFacet using the limit op…
Browse files Browse the repository at this point in the history
…tion

this is a hotfix

fixes #66
  • Loading branch information
vvo committed Mar 2, 2016
1 parent 039bb5e commit 4868717
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 10 deletions.
46 changes: 38 additions & 8 deletions src/widgets/hierarchical-menu/__tests__/hierarchical-menu-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -77,59 +77,89 @@ describe('hierarchicalMenu()', () => {

it('has defaults', () => {
expect(
hierarchicalMenu(options).getConfiguration()
hierarchicalMenu(options).getConfiguration({})
).toEqual({
hierarchicalFacets: [{
name: 'hello',
rootPath: null,
attributes: ['hello', 'world'],
separator: ' > ',
showParentLevel: true
}]
}],
maxValuesPerFacet: 10
});
});

it('understand the separator option', () => {
expect(
hierarchicalMenu({separator: ' ? ', ...options}).getConfiguration()
hierarchicalMenu({separator: ' ? ', ...options}).getConfiguration({})
).toEqual({
hierarchicalFacets: [{
name: 'hello',
rootPath: null,
attributes: ['hello', 'world'],
separator: ' ? ',
showParentLevel: true
}]
}],
maxValuesPerFacet: 10
});
});

it('understand the showParentLevel option', () => {
expect(
hierarchicalMenu({showParentLevel: false, ...options}).getConfiguration()
hierarchicalMenu({showParentLevel: false, ...options}).getConfiguration({})
).toEqual({
hierarchicalFacets: [{
name: 'hello',
rootPath: null,
attributes: ['hello', 'world'],
separator: ' > ',
showParentLevel: false
}]
}],
maxValuesPerFacet: 10
});
});

it('understand the rootPath option', () => {
expect(
hierarchicalMenu({rootPath: 'Beer', ...options}).getConfiguration()
hierarchicalMenu({rootPath: 'Beer', ...options}).getConfiguration({})
).toEqual({
hierarchicalFacets: [{
name: 'hello',
rootPath: 'Beer',
attributes: ['hello', 'world'],
separator: ' > ',
showParentLevel: true
}]
}],
maxValuesPerFacet: 10
});
});

context('limit option', () => {
it('configures maxValuesPerFacet', () =>
expect(
hierarchicalMenu({limit: 20, ...options})
.getConfiguration({})
.maxValuesPerFacet
).toBe(20)
);

it('uses provided maxValuesPerFacet when higher', () =>
expect(
hierarchicalMenu({limit: 20, ...options})
.getConfiguration({maxValuesPerFacet: 30})
.maxValuesPerFacet
).toBe(30)
);

it('ignores provided maxValuesPerFacet when lower', () =>
expect(
hierarchicalMenu({limit: 10, ...options})
.getConfiguration({maxValuesPerFacet: 3})
.maxValuesPerFacet
).toBe(10)
);
});
});

context('render', () => {
Expand Down
7 changes: 5 additions & 2 deletions src/widgets/hierarchical-menu/hierarchical-menu.js
Original file line number Diff line number Diff line change
Expand Up @@ -83,14 +83,17 @@ function hierarchicalMenu({
let hierarchicalFacetName = attributes[0];

return {
getConfiguration: () => ({
getConfiguration: (currentConfiguration) => ({
hierarchicalFacets: [{
name: hierarchicalFacetName,
attributes,
separator,
rootPath,
showParentLevel
}]
}],
maxValuesPerFacet: currentConfiguration.maxValuesPerFacet !== undefined ?
Math.max(currentConfiguration.maxValuesPerFacet, limit) :
limit
}),
render: function({results, helper, templatesConfig, createURL, state}) {
let facetValues = getFacetValues(results, hierarchicalFacetName, sortBy, limit);
Expand Down

0 comments on commit 4868717

Please sign in to comment.