Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit a82e611

Browse files
[test] add test for pogrammatically filter
1 parent c64951f commit a82e611

File tree

3 files changed

+95
-0
lines changed

3 files changed

+95
-0
lines changed

‎packages/react-bootstrap-table2-filter/test/components/number.test.js‎

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,36 @@ describe('Number Filter', () => {
9797
});
9898
});
9999

100+
describe('when props.getFilter is defined', () => {
101+
let programmaticallyFilter;
102+
103+
const comparator = Comparator.EQ;
104+
const number = 123;
105+
106+
const getFilter = (filter) => {
107+
programmaticallyFilter = filter;
108+
};
109+
110+
beforeEach(() => {
111+
wrapper = mount(
112+
<NumberFilter onFilter={ onFilter } column={ column } getFilter={ getFilter } />
113+
);
114+
115+
programmaticallyFilter({ comparator, number });
116+
});
117+
118+
it('should do onFilter correctly when exported function was executed', () => {
119+
expect(onFilter.calledOnce).toBeTruthy();
120+
expect(onFilter.calledWith(column, FILTER_TYPE.NUMBER)).toBeTruthy();
121+
expect(onFilterFirstReturn.calledOnce).toBeTruthy();
122+
expect(onFilterFirstReturn.calledWith({ comparator, number })).toBeTruthy();
123+
});
124+
125+
it('should setState correctly when exported function was executed', () => {
126+
expect(wrapper.state().isSelected).toBeTruthy();
127+
});
128+
});
129+
100130
describe('when defaultValue.number and defaultValue.comparator props is defined', () => {
101131
const number = 203;
102132
const comparator = Comparator.EQ;

‎packages/react-bootstrap-table2-filter/test/components/select.test.js‎

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,41 @@ describe('Select Filter', () => {
9898
});
9999
});
100100

101+
describe('when props.getFilter is defined', () => {
102+
let programmaticallyFilter;
103+
104+
const filterValue = 'foo';
105+
106+
const getFilter = (filter) => {
107+
programmaticallyFilter = filter;
108+
};
109+
110+
beforeEach(() => {
111+
wrapper = mount(
112+
<SelectFilter
113+
onFilter={ onFilter }
114+
column={ column }
115+
options={ options }
116+
getFilter={ getFilter }
117+
/>
118+
);
119+
instance = wrapper.instance();
120+
121+
programmaticallyFilter(filterValue);
122+
});
123+
124+
it('should do onFilter correctly when exported function was executed', () => {
125+
expect(onFilter.calledOnce).toBeTruthy();
126+
expect(onFilter.calledWith(column, FILTER_TYPE.SELECT)).toBeTruthy();
127+
expect(onFilterFirstReturn.calledOnce).toBeTruthy();
128+
expect(onFilterFirstReturn.calledWith(filterValue)).toBeTruthy();
129+
});
130+
131+
it('should setState correctly when exported function was executed', () => {
132+
expect(instance.state.isSelected).toBeTruthy();
133+
});
134+
});
135+
101136
describe('when placeholder is defined', () => {
102137
const placeholder = 'test';
103138
beforeEach(() => {

‎packages/react-bootstrap-table2-filter/test/components/text.test.js‎

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,36 @@ describe('Text Filter', () => {
7171
});
7272
});
7373

74+
describe('when props.getFilter is defined', () => {
75+
let programmaticallyFilter;
76+
77+
const filterValue = 'foo';
78+
79+
const getFilter = (filter) => {
80+
programmaticallyFilter = filter;
81+
};
82+
83+
beforeEach(() => {
84+
wrapper = mount(
85+
<TextFilter onFilter={ onFilter } column={ column } getFilter={ getFilter } />
86+
);
87+
instance = wrapper.instance();
88+
89+
programmaticallyFilter(filterValue);
90+
});
91+
92+
it('should do onFilter correctly when exported function was executed', () => {
93+
expect(onFilter.calledOnce).toBeTruthy();
94+
expect(onFilter.calledWith(column, FILTER_TYPE.TEXT)).toBeTruthy();
95+
expect(onFilterFirstReturn.calledOnce).toBeTruthy();
96+
expect(onFilterFirstReturn.calledWith(filterValue)).toBeTruthy();
97+
});
98+
99+
it('should setState correctly when exported function was executed', () => {
100+
expect(instance.state.value).toEqual(filterValue);
101+
});
102+
});
103+
74104
describe('when placeholder is defined', () => {
75105
const placeholder = 'test';
76106
beforeEach(() => {

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /