Skip to content

Commit

Permalink
[PickerInput]: add tests about setting selected value as a search
Browse files Browse the repository at this point in the history
  • Loading branch information
AlekseyManetov committed Feb 5, 2025
1 parent b1cf2f0 commit 822d4f7
Showing 1 changed file with 34 additions and 0 deletions.
34 changes: 34 additions & 0 deletions uui/components/pickers/__tests__/PickerInput.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -627,6 +627,40 @@ describe('PickerInput', () => {

expect(apiMock).toBeCalledTimes(1);
});

it.each(['id', 'entity'])('should use selected value as a search value for single select and search in input', async (valueType) => {
const { dom } = await setupPickerInputForTest({
value: undefined,
selectionMode: 'single',
searchPosition: 'input',
valueType: valueType as PickerInputProps<any, any>['valueType'],
});

expect(PickerInputTestObject.getPlaceholderText(dom.input)).toEqual('Please select');
fireEvent.click(dom.input);
expect(screen.getByRole('dialog')).toBeInTheDocument();

const optionC2 = await screen.findByText('C2');
fireEvent.click(optionC2);
await waitFor(() => {
expect(dom.input.getAttribute('value')?.trim()).toEqual('C2');
});

await userEvent.type(dom.input, '{backspace}'); // remove 1 char to apply value to search

await waitFor(() => {
expect(dom.input.getAttribute('value')?.trim()).toEqual('C');
});

expect(screen.getByRole('dialog')).toBeInTheDocument();
await PickerInputTestObject.waitForOptionsToBeReady();

expect(await PickerInputTestObject.findOptionsText({ busy: false })).toEqual([
'C1',
'C1+',
'C2',
]);
});
});

describe('Selection', () => {
Expand Down

0 comments on commit 822d4f7

Please sign in to comment.