-
Notifications
You must be signed in to change notification settings - Fork 531
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(configure): pass the latest state to onStateChange (#4555)
* fix(configure): pass the latest state to onStateChange * chore: rename tests
- Loading branch information
Eunjae Lee
authored
Oct 30, 2020
1 parent
f2d8087
commit 6ab76e8
Showing
2 changed files
with
49 additions
and
3 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
import { getByText, fireEvent } from '@testing-library/dom'; | ||
import instantsearch from '../../index.es'; | ||
import { configure } from '../../widgets'; | ||
import { connectConfigure } from '../../connectors'; | ||
import { createSearchClient } from '../../../test/mock/createSearchClient'; | ||
|
||
describe('configure', () => { | ||
it('provides up-to-date uiState to onStateChange', () => { | ||
const container = document.createElement('div'); | ||
const onStateChange = jest.fn(); | ||
const search = instantsearch({ | ||
indexName: 'instant_search', | ||
searchClient: createSearchClient(), | ||
onStateChange({ uiState, setUiState }) { | ||
onStateChange(uiState); | ||
setUiState(uiState); | ||
}, | ||
}); | ||
const customComp = connectConfigure(({ refine }, isFirstRendering) => { | ||
if (isFirstRendering) { | ||
const button = document.createElement('button'); | ||
button.setAttribute('type', 'button'); | ||
button.textContent = 'click me'; | ||
container.appendChild(button); | ||
container.querySelector('button')!.addEventListener('click', () => { | ||
refine({ hitsPerPage: 4 }); | ||
}); | ||
} | ||
}); | ||
search.addWidgets([ | ||
configure({ | ||
hitsPerPage: 10, | ||
}), | ||
customComp({ searchParameters: {} }), | ||
]); | ||
|
||
search.start(); | ||
expect(onStateChange).not.toHaveBeenCalled(); | ||
|
||
fireEvent.click(getByText(container, 'click me')); | ||
expect(onStateChange).toHaveBeenCalledTimes(1); | ||
expect(onStateChange).toHaveBeenCalledWith({ | ||
instant_search: { configure: { hitsPerPage: 4 } }, | ||
}); | ||
}); | ||
}); |