mirror of
https://github.com/gosticks/react-bootstrap-table2.git
synced 2025-10-16 11:55:39 +00:00
fix #445
This commit is contained in:
parent
4506a3dea2
commit
8b89b3de0e
@ -68,12 +68,13 @@ export default (
|
||||
return;
|
||||
}
|
||||
|
||||
let result;
|
||||
if (filter.props.onFilter) {
|
||||
filter.props.onFilter(filterVal);
|
||||
result = filter.props.onFilter(filterVal);
|
||||
}
|
||||
|
||||
const { listenerForPagination, data } = this.props;
|
||||
const result = filters(data, this.props.columns, _)(this.currFilters);
|
||||
result = result || filters(data, this.props.columns, _)(this.currFilters);
|
||||
if (listenerForPagination) {
|
||||
listenerForPagination.emit('filterChanged', result.length);
|
||||
}
|
||||
|
||||
@ -254,6 +254,41 @@ describe('FilterContext', () => {
|
||||
});
|
||||
});
|
||||
|
||||
describe('if filter.props.onFilter is defined and return an undefined data', () => {
|
||||
const mockReturn = [{
|
||||
id: 1,
|
||||
name: 'A'
|
||||
}];
|
||||
const filterVal = 'A';
|
||||
const onFilter = jest.fn().mockReturnValue(mockReturn);
|
||||
const customColumns = columns.map((column, i) => {
|
||||
if (i === 1) {
|
||||
return {
|
||||
...column,
|
||||
filter: textFilter({ onFilter })
|
||||
};
|
||||
}
|
||||
return column;
|
||||
});
|
||||
|
||||
beforeEach(() => {
|
||||
wrapper = shallow(shallowContext(false, customColumns));
|
||||
wrapper.render();
|
||||
instance = wrapper.instance();
|
||||
});
|
||||
|
||||
it('should call filter.props.onFilter correctly', () => {
|
||||
instance.onFilter(customColumns[1], FILTER_TYPE.TEXT)(filterVal);
|
||||
expect(onFilter).toHaveBeenCalledTimes(1);
|
||||
expect(onFilter).toHaveBeenCalledWith(filterVal);
|
||||
});
|
||||
|
||||
it('should set state.data correctly', () => {
|
||||
instance.onFilter(customColumns[1], FILTER_TYPE.TEXT)(filterVal);
|
||||
expect(instance.state.data).toEqual(mockReturn);
|
||||
});
|
||||
});
|
||||
|
||||
describe('when props.listenerForPagination is defined', () => {
|
||||
const filterVal = '3';
|
||||
const newDataLength = 0;
|
||||
|
||||
Loading…
Reference in New Issue
Block a user