Unverified Commit f9bf500c authored by Tamika Tannis's avatar Tamika Tannis Committed by GitHub

Filter Fixes (#399)

* Reset pageIndex to 0 on filter update

* Allow CheckBoxItem to handle checked = undefined
parent 29393825
......@@ -4,14 +4,14 @@ import { connect } from 'react-redux';
import 'components/common/Inputs/styles.scss';
export interface CheckBoxItemProps {
checked: boolean;
checked?: boolean;
disabled?: boolean
name: string;
onChange: (e: React.FormEvent<HTMLInputElement>) => any;
value: string;
}
const CheckBoxItem: React.SFC<CheckBoxItemProps> = ({ checked, disabled = false, name, onChange, value, children }) => {
const CheckBoxItem: React.SFC<CheckBoxItemProps> = ({ checked = false, disabled = false, name, onChange, value, children }) => {
return (
<div className="checkbox">
<label className="checkbox-label">
......
......@@ -53,6 +53,11 @@ describe('CheckBoxItem', () => {
});
});
it('renders input with default value for checked if not provided', () => {
const wrapper = setup({ checked: undefined }).wrapper;
expect(wrapper.find('input').props().checked).toEqual(false);
});
it('renders input with default value for disabled if not provided', () => {
const wrapper = setup({ disabled: undefined }).wrapper;
expect(wrapper.find('input').props().disabled).toEqual(false);
......
......@@ -67,7 +67,8 @@ export function* filterWatcher(): SagaIterator {
export function* filterWorker(): SagaIterator {
const state = yield select(getSearchState);
const { search_term, selectedTab, filters } = state;
const pageIndex = getPageIndex(state)
/* filters must reset pageIndex to 0 as the number of results is expected to change */
const pageIndex = 0;
yield put(searchResource(SearchType.FILTER, search_term, selectedTab, pageIndex));
updateSearchUrl({ filters, resource: selectedTab, term: search_term, index: pageIndex }, true);
};
......
......@@ -483,13 +483,9 @@ describe('search ducks', () => {
});
describe('filterWorker', () => {
let mockIndex;
let getPageIndexSpy;
let mockSearchState;
let saga;
beforeAll(() => {
mockIndex = 1;
getPageIndexSpy = jest.spyOn(Utils, 'getPageIndex').mockImplementationOnce(() => mockIndex);
mockSearchState = globalState.search;
saga = testSaga(Sagas.filterWorker);
})
......@@ -500,14 +496,14 @@ describe('search ducks', () => {
unsure if that's a good practice or what it means for writing robust unit tests
*/
updateSearchUrlSpy.mockClear();
saga = saga.next().select(SearchUtils.getSearchState).next(mockSearchState);
expect(getPageIndexSpy).toHaveBeenCalledWith(mockSearchState);
saga = saga.put(searchResource(SearchType.FILTER, mockSearchState.search_term, mockSearchState.selectedTab, mockIndex)).next();
saga = saga.next()
.select(SearchUtils.getSearchState).next(mockSearchState)
.put(searchResource(SearchType.FILTER, mockSearchState.search_term, mockSearchState.selectedTab, 0)).next();
expect(updateSearchUrlSpy).toHaveBeenCalledWith({
filters: mockSearchState.filters,
resource: mockSearchState.selectedTab,
term: mockSearchState.search_term,
index: mockIndex,
index: 0,
}, true);
saga.isDone();
});
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment