Skip to content

Commit c023b4b

Browse files
committed
test: add test cases for activeOptionFilter
1 parent 3147942 commit c023b4b

File tree

1 file changed

+47
-0
lines changed

1 file changed

+47
-0
lines changed

tests/Combobox.test.tsx

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,53 @@ describe('Select.Combobox', () => {
117117
expect(container.querySelector('input').value).toEqual('1');
118118
});
119119

120+
it('activeOptionFilter should work', async () => {
121+
const { container } = render(
122+
<Select
123+
mode="combobox"
124+
showSearch
125+
activeOptionFilter={(searchValue, option) => {
126+
return String(option.value).includes(searchValue);
127+
}}
128+
>
129+
<Option value="apple">apple</Option>
130+
<Option value="banana">banana</Option>
131+
<Option value="orange">orange</Option>
132+
</Select>,
133+
);
134+
135+
const input = container.querySelector('input')!;
136+
fireEvent.change(input, { target: { value: 'an' } });
137+
await delay();
138+
139+
expect(
140+
container.querySelector('.rc-select-item-option-active .rc-select-item-option-content'),
141+
).toHaveTextContent('banana');
142+
143+
fireEvent.change(input, { target: { value: 'ora' } });
144+
await delay();
145+
146+
expect(
147+
container.querySelector('.rc-select-item-option-active .rc-select-item-option-content'),
148+
).toHaveTextContent('orange');
149+
});
150+
151+
it('activeOptionFilter with empty function should not activate any option', async () => {
152+
const { container } = render(
153+
<Select mode="combobox" showSearch activeOptionFilter={() => false}>
154+
<Option value="apple">apple</Option>
155+
<Option value="banana">banana</Option>
156+
<Option value="orange">orange</Option>
157+
</Select>,
158+
);
159+
160+
const input = container.querySelector('input')!;
161+
fireEvent.change(input, { target: { value: 'an' } });
162+
await delay();
163+
164+
expect(container.querySelector('.rc-select-item-option-active')).toBeNull();
165+
});
166+
120167
describe('input value', () => {
121168
const createSelect = (props?: Partial<SelectProps>) => (
122169
<Select mode="combobox" {...props}>

0 commit comments

Comments
 (0)