2019-01-03 16:00:55 +03:00
|
|
|
import React from 'react';
|
2021-10-22 07:18:03 +03:00
|
|
|
import { fireEvent, render, screen } from '@testing-library/react';
|
2019-01-03 16:00:55 +03:00
|
|
|
import { Slider } from '../src';
|
|
|
|
|
2020-08-08 23:26:39 +03:00
|
|
|
describe('Slider', function () {
|
2019-01-03 16:00:55 +03:00
|
|
|
it('renders correctly', () => {
|
2021-10-22 07:18:03 +03:00
|
|
|
const { container } = render(
|
2020-09-09 17:35:22 +03:00
|
|
|
<Slider
|
|
|
|
onChange={() => {
|
|
|
|
// noop
|
|
|
|
}}
|
|
|
|
/>
|
|
|
|
);
|
2021-10-22 07:18:03 +03:00
|
|
|
expect(container.firstChild).toMatchSnapshot();
|
2019-01-03 16:00:55 +03:00
|
|
|
});
|
|
|
|
|
|
|
|
it('renders with props', () => {
|
2021-10-22 07:18:03 +03:00
|
|
|
const { container } = render(
|
2019-01-03 16:00:55 +03:00
|
|
|
<Slider
|
|
|
|
label="Hi"
|
|
|
|
min={1}
|
|
|
|
max={10}
|
|
|
|
value={5}
|
|
|
|
disabled
|
2020-09-09 17:35:22 +03:00
|
|
|
onChange={() => {
|
|
|
|
// noop
|
|
|
|
}}
|
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
|
|
|
});
|
|
|
|
|
|
|
|
it('should handle the change event', () => {
|
|
|
|
const onChange = jest.fn();
|
2021-10-22 07:18:03 +03:00
|
|
|
render(<Slider value={1} onChange={onChange} />);
|
2019-01-03 16:00:55 +03:00
|
|
|
|
2021-10-22 07:18:03 +03:00
|
|
|
fireEvent.change(screen.getByRole('slider'), { target: { value: '2' } });
|
|
|
|
expect(onChange).toHaveBeenCalled();
|
|
|
|
expect(onChange).toHaveBeenCalledWith(2);
|
2019-01-03 16:00:55 +03:00
|
|
|
});
|
|
|
|
});
|