diff --git a/packages/react-bootstrap-table2-filter/test/components/number.test.js b/packages/react-bootstrap-table2-filter/test/components/number.test.js index e08573d..3586ec4 100644 --- a/packages/react-bootstrap-table2-filter/test/components/number.test.js +++ b/packages/react-bootstrap-table2-filter/test/components/number.test.js @@ -97,6 +97,36 @@ describe('Number Filter', () => { }); }); + describe('when props.getFilter is defined', () => { + let programmaticallyFilter; + + const comparator = Comparator.EQ; + const number = 123; + + const getFilter = (filter) => { + programmaticallyFilter = filter; + }; + + beforeEach(() => { + wrapper = mount( + + ); + + programmaticallyFilter({ comparator, number }); + }); + + it('should do onFilter correctly when exported function was executed', () => { + expect(onFilter.calledOnce).toBeTruthy(); + expect(onFilter.calledWith(column, FILTER_TYPE.NUMBER)).toBeTruthy(); + expect(onFilterFirstReturn.calledOnce).toBeTruthy(); + expect(onFilterFirstReturn.calledWith({ comparator, number })).toBeTruthy(); + }); + + it('should setState correctly when exported function was executed', () => { + expect(wrapper.state().isSelected).toBeTruthy(); + }); + }); + describe('when defaultValue.number and defaultValue.comparator props is defined', () => { const number = 203; const comparator = Comparator.EQ; diff --git a/packages/react-bootstrap-table2-filter/test/components/select.test.js b/packages/react-bootstrap-table2-filter/test/components/select.test.js index 0c4c80a..85f9686 100644 --- a/packages/react-bootstrap-table2-filter/test/components/select.test.js +++ b/packages/react-bootstrap-table2-filter/test/components/select.test.js @@ -98,6 +98,41 @@ describe('Select Filter', () => { }); }); + describe('when props.getFilter is defined', () => { + let programmaticallyFilter; + + const filterValue = 'foo'; + + const getFilter = (filter) => { + programmaticallyFilter = filter; + }; + + beforeEach(() => { + wrapper = mount( + + ); + instance = wrapper.instance(); + + programmaticallyFilter(filterValue); + }); + + it('should do onFilter correctly when exported function was executed', () => { + expect(onFilter.calledOnce).toBeTruthy(); + expect(onFilter.calledWith(column, FILTER_TYPE.SELECT)).toBeTruthy(); + expect(onFilterFirstReturn.calledOnce).toBeTruthy(); + expect(onFilterFirstReturn.calledWith(filterValue)).toBeTruthy(); + }); + + it('should setState correctly when exported function was executed', () => { + expect(instance.state.isSelected).toBeTruthy(); + }); + }); + describe('when placeholder is defined', () => { const placeholder = 'test'; beforeEach(() => { diff --git a/packages/react-bootstrap-table2-filter/test/components/text.test.js b/packages/react-bootstrap-table2-filter/test/components/text.test.js index 0885824..5a8d297 100644 --- a/packages/react-bootstrap-table2-filter/test/components/text.test.js +++ b/packages/react-bootstrap-table2-filter/test/components/text.test.js @@ -71,6 +71,36 @@ describe('Text Filter', () => { }); }); + describe('when props.getFilter is defined', () => { + let programmaticallyFilter; + + const filterValue = 'foo'; + + const getFilter = (filter) => { + programmaticallyFilter = filter; + }; + + beforeEach(() => { + wrapper = mount( + + ); + instance = wrapper.instance(); + + programmaticallyFilter(filterValue); + }); + + it('should do onFilter correctly when exported function was executed', () => { + expect(onFilter.calledOnce).toBeTruthy(); + expect(onFilter.calledWith(column, FILTER_TYPE.TEXT)).toBeTruthy(); + expect(onFilterFirstReturn.calledOnce).toBeTruthy(); + expect(onFilterFirstReturn.calledWith(filterValue)).toBeTruthy(); + }); + + it('should setState correctly when exported function was executed', () => { + expect(instance.state.value).toEqual(filterValue); + }); + }); + describe('when placeholder is defined', () => { const placeholder = 'test'; beforeEach(() => {