Skip to content

Commit 567a898

Browse files
committed
tests: add test case
1 parent f325565 commit 567a898

File tree

1 file changed

+49
-0
lines changed

1 file changed

+49
-0
lines changed

tests/BaseSelect.test.tsx

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,4 +123,53 @@ describe('BaseSelect', () => {
123123

124124
expect(container.querySelector('.rc-select-dropdown-placement-fallback')).toBeTruthy();
125125
});
126+
127+
describe("Testing BaseSelect component's onContainerBlur params", () => {
128+
it('mode with null, onContainerBlur params is blur', () => {
129+
const onSearch = jest.fn();
130+
const { container } = render(
131+
<BaseSelect
132+
prefixCls="rc-select"
133+
id="test"
134+
displayValues={[]}
135+
onDisplayValuesChange={() => {}}
136+
searchValue="1"
137+
showSearch
138+
open
139+
onSearch={onSearch}
140+
OptionList={OptionList}
141+
emptyOptions
142+
/>,
143+
);
144+
expect(container.querySelector('div.rc-select')).toBeTruthy();
145+
fireEvent.change(container.querySelector('input'), { target: { value: '2' } });
146+
expect(onSearch).toHaveBeenCalledWith('2', { source: 'typing' });
147+
fireEvent.blur(container.querySelector('div.rc-select'));
148+
expect(onSearch).toHaveBeenCalledWith('', { source: 'blur' });
149+
});
150+
151+
it('mode with multiple, onContainerBlur params is blur', () => {
152+
const onSearch = jest.fn();
153+
const { container } = render(
154+
<BaseSelect
155+
prefixCls="rc-select"
156+
mode="multiple"
157+
id="test"
158+
displayValues={[]}
159+
onDisplayValuesChange={() => {}}
160+
searchValue="1"
161+
showSearch={false}
162+
open
163+
onSearch={onSearch}
164+
OptionList={OptionList}
165+
emptyOptions
166+
/>,
167+
);
168+
expect(container.querySelector('div.rc-select')).toBeTruthy();
169+
fireEvent.change(container.querySelector('input'), { target: { value: '2' } });
170+
expect(onSearch).toHaveBeenCalledWith('2', { source: 'typing' });
171+
fireEvent.blur(container.querySelector('div.rc-select'));
172+
expect(onSearch).toHaveBeenCalledWith('', { source: 'blur' });
173+
});
174+
});
126175
});

0 commit comments

Comments
 (0)