-
Notifications
You must be signed in to change notification settings - Fork 516
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(connector): add tests for connectClearAll and connectHierarchica…
…lMenu Also straighten up the API on connectClearAll, to make it more consistent between the initial rendering and the other renders
- Loading branch information
Alexandre Stanislawski
committed
Feb 20, 2017
1 parent
5409157
commit 0eb29ec
Showing
6 changed files
with
338 additions
and
50 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
111 changes: 111 additions & 0 deletions
111
src/connectors/current-refined-values/__tests__/connectCurrentRefinedValues-test.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,111 @@ | ||
/* eslint-env mocha */ | ||
|
||
import expect from 'expect'; | ||
import sinon from 'sinon'; | ||
|
||
import jsHelper from 'algoliasearch-helper'; | ||
const SearchResults = jsHelper.SearchResults; | ||
|
||
import connectCurrentRefinedValues from '../connectCurrentRefinedValues.js'; | ||
|
||
describe('connectCurrentRefinedValues', () => { | ||
it('Renders during init and render', () => { | ||
const helper = jsHelper({}); | ||
helper.search = sinon.stub(); | ||
const container = document.createElement('div'); | ||
// test that the dummyRendering is called with the isFirstRendering | ||
// flag set accordingly | ||
const rendering = sinon.stub(); | ||
const makeWidget = connectCurrentRefinedValues(rendering); | ||
const widget = makeWidget({ | ||
container, | ||
}); | ||
|
||
expect(widget.getConfiguration).toBe(undefined); | ||
// test if widget is not rendered yet at this point | ||
expect(rendering.callCount).toBe(0); | ||
|
||
widget.init({ | ||
helper, | ||
state: helper.state, | ||
createURL: () => '#', | ||
onHistoryChange: () => {}, | ||
}); | ||
|
||
// test that rendering has been called during init with isFirstRendering = true | ||
expect(rendering.callCount).toBe(1); | ||
expect(rendering.lastCall.args[1]).toBe(true); | ||
|
||
const firstRenderingOptions = rendering.lastCall.args[0]; | ||
expect(firstRenderingOptions.containerNode).toBe(container); | ||
expect(firstRenderingOptions.refinements).toEqual([]); | ||
expect(firstRenderingOptions.collapsible).toBe(false); | ||
expect(firstRenderingOptions.shouldAutoHideContainer).toBe(true); | ||
|
||
widget.render({ | ||
results: new SearchResults(helper.state, [{}]), | ||
state: helper.state, | ||
helper, | ||
createURL: () => '#', | ||
}); | ||
|
||
// test that rendering has been called during init with isFirstRendering = false | ||
expect(rendering.callCount).toBe(2); | ||
expect(rendering.lastCall.args[1]).toBe(false); | ||
|
||
const secondRenderingOptions = rendering.lastCall.args[0]; | ||
expect(secondRenderingOptions.containerNode).toBe(container); | ||
expect(secondRenderingOptions.refinements).toEqual([]); | ||
expect(secondRenderingOptions.collapsible).toBe(false); | ||
expect(secondRenderingOptions.shouldAutoHideContainer).toBe(true); | ||
}); | ||
|
||
it('Provide a function to clear the refinements at each step', () => { | ||
// For each refinements we get a function that we can call | ||
// for removing a single refinement | ||
const helper = jsHelper({}, '', { | ||
facets: ['myFacet'], | ||
}); | ||
helper.search = sinon.stub(); | ||
const container = document.createElement('div'); | ||
const rendering = sinon.stub(); | ||
const makeWidget = connectCurrentRefinedValues(rendering); | ||
const widget = makeWidget({ | ||
container, | ||
}); | ||
|
||
helper.addFacetRefinement('myFacet', 'value'); | ||
|
||
widget.init({ | ||
helper, | ||
state: helper.state, | ||
createURL: () => '#', | ||
onHistoryChange: () => {}, | ||
}); | ||
|
||
const firstRenderingOptions = rendering.lastCall.args[0]; | ||
const clearFunctions = firstRenderingOptions.clearRefinementClicks; | ||
const refinements = firstRenderingOptions.refinements; | ||
expect(clearFunctions.length).toBe(1); | ||
expect(refinements.length).toBe(1); | ||
clearFunctions[0](); | ||
expect(helper.hasRefinements('myFacet')).toBe(false); | ||
|
||
helper.addFacetRefinement('myFacet', 'value'); | ||
|
||
widget.render({ | ||
results: new SearchResults(helper.state, [{}]), | ||
state: helper.state, | ||
helper, | ||
createURL: () => '#', | ||
}); | ||
|
||
const secondRenderingOptions = rendering.lastCall.args[0]; | ||
const otherClearFunctions = secondRenderingOptions.clearRefinementClicks; | ||
const otherRefinements = secondRenderingOptions.refinements; | ||
expect(otherClearFunctions.length).toBe(1); | ||
expect(otherRefinements.length).toBe(1); | ||
otherClearFunctions[0](); | ||
expect(helper.hasRefinements('myFacet')).toBe(false); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.