mirror of
https://github.com/gosticks/react-bootstrap-table2.git
synced 2025-10-16 11:55:39 +00:00
[test] correct tests for filter components
* <Text />, <Select /> and <Numbner />
This commit is contained in:
parent
a35701fabf
commit
c64951fd6f
@ -64,7 +64,7 @@ class TextFilter extends Component {
|
||||
cleanFiltered() {
|
||||
const value = this.props.defaultValue;
|
||||
this.setState(() => ({ value }));
|
||||
this.props.onFilter(this.props.column, value, FILTER_TYPE.TEXT)();
|
||||
this.props.onFilter(this.props.column, FILTER_TYPE.TEXT)(value);
|
||||
}
|
||||
|
||||
applyFilter(filterText) {
|
||||
|
||||
@ -9,7 +9,11 @@ import * as Comparator from '../../src/comparison';
|
||||
|
||||
describe('Number Filter', () => {
|
||||
let wrapper;
|
||||
|
||||
// onFilter(x)(y) = filter result
|
||||
const onFilter = sinon.stub();
|
||||
const onFilterFirstReturn = sinon.stub();
|
||||
|
||||
const column = {
|
||||
dataField: 'price',
|
||||
text: 'Product Price'
|
||||
@ -17,6 +21,9 @@ describe('Number Filter', () => {
|
||||
|
||||
afterEach(() => {
|
||||
onFilter.reset();
|
||||
onFilterFirstReturn.reset();
|
||||
|
||||
onFilter.returns(onFilterFirstReturn);
|
||||
});
|
||||
|
||||
describe('initialization', () => {
|
||||
@ -110,8 +117,9 @@ describe('Number Filter', () => {
|
||||
|
||||
it('should calling onFilter on componentDidMount', () => {
|
||||
expect(onFilter.calledOnce).toBeTruthy();
|
||||
expect(onFilter.calledWith(
|
||||
column, { number: `${number}`, comparator }, FILTER_TYPE.NUMBER)).toBeTruthy();
|
||||
expect(onFilter.calledWith(column, FILTER_TYPE.NUMBER)).toBeTruthy();
|
||||
expect(onFilterFirstReturn.calledOnce).toBeTruthy();
|
||||
expect(onFilterFirstReturn.calledWith({ number: `${number}`, comparator })).toBeTruthy();
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
@ -9,19 +9,27 @@ import { FILTER_TYPE } from '../../src/const';
|
||||
describe('Select Filter', () => {
|
||||
let wrapper;
|
||||
let instance;
|
||||
|
||||
// onFilter(x)(y) = filter result
|
||||
const onFilter = sinon.stub();
|
||||
const onFilterFirstReturn = sinon.stub();
|
||||
|
||||
const column = {
|
||||
dataField: 'quality',
|
||||
text: 'Product Quality'
|
||||
};
|
||||
|
||||
const options = {
|
||||
0: 'Bad',
|
||||
1: 'Good',
|
||||
2: 'Unknow'
|
||||
2: 'Unknown'
|
||||
};
|
||||
|
||||
afterEach(() => {
|
||||
onFilter.reset();
|
||||
onFilterFirstReturn.reset();
|
||||
|
||||
onFilter.returns(onFilterFirstReturn);
|
||||
});
|
||||
|
||||
describe('initialization', () => {
|
||||
@ -83,7 +91,9 @@ describe('Select Filter', () => {
|
||||
|
||||
it('should calling onFilter on componentDidMount', () => {
|
||||
expect(onFilter.calledOnce).toBeTruthy();
|
||||
expect(onFilter.calledWith(column, defaultValue, FILTER_TYPE.SELECT)).toBeTruthy();
|
||||
expect(onFilter.calledWith(column, FILTER_TYPE.SELECT)).toBeTruthy();
|
||||
expect(onFilterFirstReturn.calledOnce).toBeTruthy();
|
||||
expect(onFilterFirstReturn.calledWith(defaultValue)).toBeTruthy();
|
||||
});
|
||||
});
|
||||
});
|
||||
@ -170,8 +180,9 @@ describe('Select Filter', () => {
|
||||
|
||||
it('should update', () => {
|
||||
expect(onFilter.callCount).toBe(2);
|
||||
expect(onFilter.calledWith(
|
||||
column, instance.props.defaultValue, FILTER_TYPE.SELECT)).toBeTruthy();
|
||||
expect(onFilter.calledWith(column, FILTER_TYPE.SELECT)).toBeTruthy();
|
||||
expect(onFilterFirstReturn.callCount).toBe(2);
|
||||
expect(onFilterFirstReturn.calledWith(instance.props.defaultValue)).toBeTruthy();
|
||||
});
|
||||
});
|
||||
|
||||
@ -198,8 +209,9 @@ describe('Select Filter', () => {
|
||||
|
||||
it('should update', () => {
|
||||
expect(onFilter.callCount).toBe(2);
|
||||
expect(onFilter.calledWith(
|
||||
column, instance.props.defaultValue, FILTER_TYPE.SELECT)).toBeTruthy();
|
||||
expect(onFilter.calledWith(column, FILTER_TYPE.SELECT)).toBeTruthy();
|
||||
expect(onFilterFirstReturn.callCount).toBe(2);
|
||||
expect(onFilterFirstReturn.calledWith(instance.props.defaultValue)).toBeTruthy();
|
||||
});
|
||||
});
|
||||
});
|
||||
@ -226,7 +238,9 @@ describe('Select Filter', () => {
|
||||
|
||||
it('should calling onFilter correctly', () => {
|
||||
expect(onFilter.callCount).toBe(2);
|
||||
expect(onFilter.calledWith(column, defaultValue, FILTER_TYPE.SELECT)).toBeTruthy();
|
||||
expect(onFilter.calledWith(column, FILTER_TYPE.SELECT)).toBeTruthy();
|
||||
expect(onFilterFirstReturn.callCount).toBe(2);
|
||||
expect(onFilterFirstReturn.calledWith(defaultValue)).toBeTruthy();
|
||||
});
|
||||
});
|
||||
|
||||
@ -249,6 +263,7 @@ describe('Select Filter', () => {
|
||||
|
||||
it('should calling onFilter correctly', () => {
|
||||
expect(onFilter.callCount).toBe(1);
|
||||
expect(onFilterFirstReturn.callCount).toBe(1);
|
||||
});
|
||||
});
|
||||
});
|
||||
@ -268,8 +283,10 @@ describe('Select Filter', () => {
|
||||
});
|
||||
|
||||
it('should calling onFilter correctly', () => {
|
||||
expect(onFilter.callCount).toBe(1);
|
||||
expect(onFilter.calledWith(column, value, FILTER_TYPE.SELECT)).toBeTruthy();
|
||||
expect(onFilter.calledOnce).toBeTruthy();
|
||||
expect(onFilter.calledWith(column, FILTER_TYPE.SELECT)).toBeTruthy();
|
||||
expect(onFilterFirstReturn.calledOnce).toBeTruthy();
|
||||
expect(onFilterFirstReturn.calledWith(value)).toBeTruthy();
|
||||
});
|
||||
});
|
||||
|
||||
@ -289,8 +306,10 @@ describe('Select Filter', () => {
|
||||
});
|
||||
|
||||
it('should calling onFilter correctly', () => {
|
||||
expect(onFilter.callCount).toBe(1);
|
||||
expect(onFilter.calledWith(column, event.target.value, FILTER_TYPE.SELECT)).toBeTruthy();
|
||||
expect(onFilter.calledOnce).toBeTruthy();
|
||||
expect(onFilter.calledWith(column, FILTER_TYPE.SELECT)).toBeTruthy();
|
||||
expect(onFilterFirstReturn.calledOnce).toBeTruthy();
|
||||
expect(onFilterFirstReturn.calledWith(event.target.value)).toBeTruthy();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@ -9,7 +9,11 @@ jest.useFakeTimers();
|
||||
describe('Text Filter', () => {
|
||||
let wrapper;
|
||||
let instance;
|
||||
|
||||
// onFilter(x)(y) = filter result
|
||||
const onFilter = sinon.stub();
|
||||
const onFilterFirstReturn = sinon.stub();
|
||||
|
||||
const column = {
|
||||
dataField: 'price',
|
||||
text: 'Price'
|
||||
@ -17,6 +21,9 @@ describe('Text Filter', () => {
|
||||
|
||||
afterEach(() => {
|
||||
onFilter.reset();
|
||||
onFilterFirstReturn.reset();
|
||||
|
||||
onFilter.returns(onFilterFirstReturn);
|
||||
});
|
||||
|
||||
describe('initialization', () => {
|
||||
@ -58,7 +65,9 @@ describe('Text Filter', () => {
|
||||
|
||||
it('should calling onFilter on componentDidMount', () => {
|
||||
expect(onFilter.calledOnce).toBeTruthy();
|
||||
expect(onFilter.calledWith(column, defaultValue, FILTER_TYPE.TEXT)).toBeTruthy();
|
||||
expect(onFilter.calledWith(column, FILTER_TYPE.TEXT)).toBeTruthy();
|
||||
expect(onFilterFirstReturn.calledOnce).toBeTruthy();
|
||||
expect(onFilterFirstReturn.calledWith(defaultValue)).toBeTruthy();
|
||||
});
|
||||
});
|
||||
|
||||
@ -114,7 +123,9 @@ describe('Text Filter', () => {
|
||||
|
||||
it('should calling onFilter correctly when props.defaultValue is changed', () => {
|
||||
expect(onFilter.calledOnce).toBeTruthy();
|
||||
expect(onFilter.calledWith(column, nextDefaultValue, FILTER_TYPE.TEXT)).toBeTruthy();
|
||||
expect(onFilter.calledWith(column, FILTER_TYPE.TEXT)).toBeTruthy();
|
||||
expect(onFilterFirstReturn.calledOnce).toBeTruthy();
|
||||
expect(onFilterFirstReturn.calledWith(nextDefaultValue)).toBeTruthy();
|
||||
});
|
||||
});
|
||||
|
||||
@ -133,8 +144,9 @@ describe('Text Filter', () => {
|
||||
|
||||
it('should calling onFilter correctly', () => {
|
||||
expect(onFilter.calledOnce).toBeTruthy();
|
||||
expect(onFilter.calledWith(
|
||||
column, instance.props.defaultValue, FILTER_TYPE.TEXT)).toBeTruthy();
|
||||
expect(onFilter.calledWith(column, FILTER_TYPE.TEXT)).toBeTruthy();
|
||||
expect(onFilterFirstReturn.calledOnce).toBeTruthy();
|
||||
expect(onFilterFirstReturn.calledWith(instance.props.defaultValue)).toBeTruthy();
|
||||
});
|
||||
});
|
||||
|
||||
@ -154,7 +166,9 @@ describe('Text Filter', () => {
|
||||
|
||||
it('should calling onFilter correctly', () => {
|
||||
expect(onFilter.calledOnce).toBeTruthy();
|
||||
expect(onFilter.calledWith(column, filterText, FILTER_TYPE.TEXT)).toBeTruthy();
|
||||
expect(onFilter.calledWith(column, FILTER_TYPE.TEXT)).toBeTruthy();
|
||||
expect(onFilterFirstReturn.calledOnce).toBeTruthy();
|
||||
expect(onFilterFirstReturn.calledWith(filterText)).toBeTruthy();
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user