2019-01-03 16:00:55 +03:00
|
|
|
import React from 'react';
|
2021-10-22 07:18:03 +03:00
|
|
|
import { render, screen } from '@testing-library/react';
|
|
|
|
import userEvent from '@testing-library/user-event';
|
2019-01-03 16:00:55 +03:00
|
|
|
import { SegmentedControl } from '../src';
|
|
|
|
|
2020-08-08 23:26:39 +03:00
|
|
|
describe('SegmentedControl', function () {
|
2019-01-03 16:00:55 +03:00
|
|
|
it('renders correctly', () => {
|
2021-10-22 07:18:03 +03:00
|
|
|
const { container } = render(
|
2019-01-03 16:00:55 +03:00
|
|
|
<SegmentedControl
|
|
|
|
values={['Button1', 'Button2', 'Button3']}
|
|
|
|
selected="Button1"
|
|
|
|
disabled={false}
|
2020-09-09 17:35:22 +03:00
|
|
|
onClick={() => {
|
|
|
|
// noop
|
|
|
|
}}
|
2023-07-12 21:03:20 +03:00
|
|
|
/>,
|
2019-01-03 16:00:55 +03:00
|
|
|
);
|
2021-10-22 07:18:03 +03:00
|
|
|
expect(container.firstChild).toMatchSnapshot();
|
2019-01-03 16:00:55 +03:00
|
|
|
});
|
2022-06-06 19:22:05 +03:00
|
|
|
it('should handle the click event', async () => {
|
2019-01-03 16:00:55 +03:00
|
|
|
const onClick = jest.fn();
|
2021-10-22 07:18:03 +03:00
|
|
|
render(
|
2019-01-10 21:51:14 +03:00
|
|
|
<SegmentedControl
|
|
|
|
values={['Button1', 'Button2', 'Button3']}
|
|
|
|
selected="Button1"
|
|
|
|
disabled={false}
|
|
|
|
onClick={onClick}
|
2023-07-12 21:03:20 +03:00
|
|
|
/>,
|
2019-01-03 16:00:55 +03:00
|
|
|
);
|
|
|
|
|
2022-06-06 19:22:05 +03:00
|
|
|
await userEvent.click(screen.getByRole('button', { name: 'Button1' }));
|
2021-10-22 07:18:03 +03:00
|
|
|
expect(onClick).toHaveBeenCalled();
|
2019-01-03 16:00:55 +03:00
|
|
|
});
|
|
|
|
});
|