Skip to content

Commit 46ad839

Browse files
committed
Add test for nested PF4 options with searchable
1 parent d8a2d9d commit 46ad839

File tree

1 file changed

+68
-0
lines changed

1 file changed

+68
-0
lines changed

packages/pf4-component-mapper/src/tests/select/select.test.js

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,74 @@ describe('<Select />', () => {
179179
expect(onSubmit).toHaveBeenCalledWith({ 'select-with-categories': '111' });
180180
});
181181

182+
it('filters with nested options', async () => {
183+
const wrapper = mount(
184+
<FormRenderer
185+
onSubmit={jest.fn()}
186+
FormTemplate={FormTemplate}
187+
componentMapper={componentMapper}
188+
schema={{
189+
fields: [
190+
{
191+
component: 'select',
192+
name: 'select-with-categories',
193+
label: 'With categories',
194+
isSearchable: true,
195+
options: [
196+
{
197+
label: 'Category 1',
198+
options: [
199+
{ label: 'value 1', value: '111' },
200+
{ label: 'value 2', value: '222' },
201+
],
202+
},
203+
{ divider: true },
204+
{ label: 'independent 1', value: '1112333' },
205+
{ divider: true },
206+
{
207+
label: 'Category 2',
208+
options: [
209+
{ label: 'value 3', value: '333' },
210+
{ label: 'value 4', value: '444' },
211+
],
212+
},
213+
{ divider: true },
214+
{ label: 'independent 2', value: '11111' },
215+
],
216+
},
217+
],
218+
}}
219+
/>
220+
);
221+
222+
wrapper.find('.pf-c-select__toggle').simulate('click');
223+
224+
await act(async () => {
225+
const search = wrapper.find('input');
226+
search.instance().value = 'value';
227+
search.simulate('change');
228+
});
229+
wrapper.update();
230+
231+
expect(wrapper.find('.pf-c-select__menu-group-title')).toHaveLength(2);
232+
expect(wrapper.find('.pf-c-divider')).toHaveLength(0);
233+
234+
expect(wrapper.find('.pf-c-select__menu-item')).toHaveLength(4);
235+
expect(wrapper.find('.pf-c-select__menu-item').map((opt) => opt.text())).toEqual(['value 1', 'value 2', 'value 3', 'value 4']);
236+
237+
await act(async () => {
238+
const search = wrapper.find('input');
239+
search.instance().value = 'independent';
240+
search.simulate('change');
241+
});
242+
wrapper.update();
243+
244+
expect(wrapper.find('.pf-c-select__menu-group-title')).toHaveLength(0);
245+
expect(wrapper.find('.pf-c-divider')).toHaveLength(0);
246+
247+
expect(wrapper.find('.pf-c-select__menu-item')).toHaveLength(2);
248+
expect(wrapper.find('.pf-c-select__menu-item').map((opt) => opt.text())).toEqual(['independent 1', 'independent 2']);
249+
});
182250
it('should return single simple value', async () => {
183251
const wrapper = mount(<Select {...initialProps} />);
184252
wrapper.find('.pf-c-select__toggle').simulate('click');

0 commit comments

Comments
 (0)