Skip to content

Commit

Permalink
Updated tests to get full coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
Christoffer Palm committed Apr 6, 2018
1 parent 37b44ba commit b817455
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/Slider/Slider.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ const Slider = class Slider extends React.Component {
handleOnMouseClick(ev) {
if (!this.props.dragEnabled || !this.state.isBeingMouseDragged) return;

if (this.state.isBeingMouseDragged && this.state.mouseIsMoving) {
if (this.state.mouseIsMoving) {
ev.preventDefault();
}

Expand Down
17 changes: 15 additions & 2 deletions src/Slider/__tests__/Slider.test.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -413,7 +413,7 @@ describe('<Slider />', () => {
expect(wrapper.state('mouseIsMoving')).toBe(true);
});

it('should prevent default action on clicks when being dragged and mouse is moving', () => {
it('should prevent default action on clicks when mouse is moving', () => {
const wrapper = shallow(<Slider {...props} />);
const instance = wrapper.instance();

Expand All @@ -427,19 +427,32 @@ describe('<Slider />', () => {
wrapper.find('.sliderTray').simulate('mousemove', drag100);
wrapper.update();

expect(wrapper.state('mouseIsMoving')).toBe(true);
drag100.preventDefault.mockReset();

wrapper.find('.sliderTray').simulate('click', drag100);
wrapper.update();

expect(drag100.preventDefault).toHaveBeenCalled();
expect(wrapper.state('mouseIsMoving')).toBe(false);
});

it('should not prevent default action on clicks when not dragging or mouse moving', () => {
const wrapper = shallow(<Slider {...props} />);
const wrapper = shallow(<Slider {...props} dragEnabled />);
const instance = wrapper.instance();

instance.sliderTrayElement = {
clientWidth: 100,
clientHeight: 100,
};

drag100.preventDefault.mockReset();

wrapper.setState({
isBeingMouseDragged: true,
mouseIsMoving: false,
});

wrapper.find('.sliderTray').simulate('click', drag100);
wrapper.update();

Expand Down

0 comments on commit b817455

Please sign in to comment.