[test] add test for pogrammatically filter

This commit is contained in:
Chun-MingChen
2018-04-04 17:43:39 +08:00
parent c64951fd6f
commit a82e611358
3 changed files with 95 additions and 0 deletions

View File

@@ -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(
<NumberFilter onFilter={ onFilter } column={ column } getFilter={ getFilter } />
);
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;

View File

@@ -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(
<SelectFilter
onFilter={ onFilter }
column={ column }
options={ options }
getFilter={ getFilter }
/>
);
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(() => {

View File

@@ -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(
<TextFilter onFilter={ onFilter } column={ column } getFilter={ getFilter } />
);
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(() => {