Skip to content

Commit

Permalink
test(Search): improve unit-tests coverage (#7356)
Browse files Browse the repository at this point in the history
  • Loading branch information
EldarMuhamethanov authored Aug 12, 2024
1 parent dd636bb commit 7d400a7
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions packages/vkui/src/components/Search/Search.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,14 @@ const getInput = () => screen.getByRole('searchbox');
const getClearIcon = () => document.querySelector(`.${styles.Search__icon}`)!;
const getFindButton = () => document.querySelector(`.${styles.Search__findButton}`)!;

jest.mock('../../lib/touch', () => {
const originalModule = jest.requireActual('../../lib/touch');
return {
...originalModule,
touchEnabled: () => true,
};
});

describe(Search, () => {
baselineComponent(Search);

Expand Down Expand Up @@ -162,4 +170,17 @@ describe(Search, () => {
act(jest.runAllTimers);
expect(cb).toHaveBeenCalled();
});

it.each([fireEvent.click, fireEvent.pointerDown])(
'should clear value by click clear button',
async (clickFn) => {
let value = '';
const { container } = render(<Search onChange={(e) => (value = e.target.value)} />);
await userEvent.type(getInput(), 'user');
expect(value).toEqual('user');
const clearButton = container.getElementsByClassName(styles['Search__icon'])[0];
clickFn(clearButton);
expect(value).toEqual('');
},
);
});

0 comments on commit 7d400a7

Please sign in to comment.