Skip to content

Commit

Permalink
add test cases
Browse files Browse the repository at this point in the history
  • Loading branch information
oliviertassinari committed Mar 31, 2021
1 parent ec50405 commit 9c0eb6f
Showing 1 changed file with 43 additions and 0 deletions.
43 changes: 43 additions & 0 deletions packages/material-ui/src/Slider/Slider.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -1123,4 +1123,47 @@ describe('<Slider />', () => {
render(<SliderUnstyled tabIndex={-1} value={30} />);
expect(screen.getByRole('slider')).to.have.property('tabIndex', -1);
});

describe('prop: disableSwap', () => {
it('should bound the value when using the keyboard', () => {
const handleChange = spy();
const { getAllByRole } = render(
<Slider defaultValue={[20, 30]} disableSwap onChange={handleChange} />,
);
const [slider1, slider2] = getAllByRole('slider');

act(() => {
slider1.focus();
fireEvent.change(slider2, { target: { value: '19' } });
});
expect(handleChange.args[0][1]).to.deep.equal([20, 20]);
expect(document.activeElement).to.have.attribute('data-index', '1');
});

it('should bound the value when using the mouse', () => {
const handleChange = spy();
const { container } = render(
<Slider defaultValue={[20, 30]} disableSwap onChange={handleChange} />,
);

stub(container.firstChild, 'getBoundingClientRect').callsFake(() => ({
width: 100,
height: 10,
bottom: 10,
left: 0,
}));

fireEvent.touchStart(
container.firstChild,
createTouches([{ identifier: 1, clientX: 35, clientY: 0 }]),
);
fireEvent.touchMove(
document.body,
createTouches([{ identifier: 1, clientX: 19, clientY: 0 }]),
);
expect(handleChange.args[0][1]).to.deep.equal([20, 35]);
expect(handleChange.args[1][1]).to.deep.equal([20, 20]);
expect(document.activeElement).to.have.attribute('data-index', '1');
});
});
});

0 comments on commit 9c0eb6f

Please sign in to comment.