Skip to content

Commit

Permalink
Improve tests to ensure callOnChange isn't called multiple times
Browse files Browse the repository at this point in the history
  • Loading branch information
trodi authored and ValentinH committed Feb 15, 2017
1 parent 8d7ea4d commit 8f51bb2
Show file tree
Hide file tree
Showing 7 changed files with 164 additions and 171 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,8 @@
var expectedValue = 50;
helper.moveMouseToValue(expectedValue);
expect(helper.scope.slider.min).to.equal(expectedValue);
helper.slider.positionTrackingHandle.called.should.be.true;
helper.slider.callOnChange.called.should.be.true;
expect(helper.slider.positionTrackingHandle.callCount).to.equal(1);
expect(helper.slider.callOnChange.callCount).to.equal(1);
});

it('should handle click and drag on maxH correctly when mouse is on the middle', function() {
Expand All @@ -55,8 +55,8 @@
var expectedValue = 50;
helper.moveMouseToValue(expectedValue);
expect(helper.scope.slider.max).to.equal(expectedValue);
helper.slider.positionTrackingHandle.called.should.be.true;
helper.slider.callOnChange.called.should.be.true;
expect(helper.slider.positionTrackingHandle.callCount).to.equal(1);
expect(helper.slider.callOnChange.callCount).to.equal(1);
});

it('should handle click and drag on minH and switch min/max if needed', function() {
Expand Down Expand Up @@ -91,9 +91,9 @@
expect(helper.scope.slider.min).to.equal(expectedValue);
expect(helper.slider.tracking).to.equal('lowValue');
helper.slider.focusElement.calledWith(helper.slider.minH).should.be.true;
helper.slider.positionTrackingHandle.called.should.be.true;
helper.slider.callOnStart.called.should.be.true;
helper.slider.callOnChange.called.should.be.true;
expect(helper.slider.positionTrackingHandle.callCount).to.equal(1);
expect(helper.slider.callOnStart.callCount).to.equal(1);
expect(helper.slider.callOnChange.callCount).to.equal(1);
});

it('should handle click on fullbar and move maxH when click pos is nearer to maxH', function() {
Expand All @@ -110,9 +110,9 @@
expect(helper.scope.slider.max).to.equal(expectedValue);
expect(helper.slider.tracking).to.equal('highValue');
helper.slider.focusElement.calledWith(helper.slider.maxH).should.be.true;
helper.slider.positionTrackingHandle.called.should.be.true;
helper.slider.callOnStart.called.should.be.true;
helper.slider.callOnChange.called.should.be.true;
expect(helper.slider.positionTrackingHandle.callCount).to.equal(1);
expect(helper.slider.callOnStart.callCount).to.equal(1);
expect(helper.slider.callOnChange.callCount).to.equal(1);
});

it('should handle click on selbar and move whole range when moved within slider range', function() {
Expand All @@ -131,9 +131,9 @@
expect(helper.scope.slider.max).to.equal(70);
expect(helper.slider.tracking).to.equal('lowValue');
helper.slider.focusElement.calledWith(helper.slider.minH).should.be.true;
helper.slider.positionTrackingBar.called.should.be.true;
helper.slider.callOnStart.called.should.be.true;
helper.slider.callOnChange.called.should.be.true;
expect(helper.slider.positionTrackingBar.callCount).to.equal(2);
expect(helper.slider.callOnStart.callCount).to.equal(1);
expect(helper.slider.callOnChange.callCount).to.equal(2);
});

it('should handle click on selbar and move move range when near 0 and moved left', function() {
Expand Down Expand Up @@ -265,8 +265,8 @@
position = helper.getMousePosition(expectedValue);
helper.fireMousemove(position);
expect(helper.scope.slider.min).to.equal(expectedValue);
helper.slider.positionTrackingHandle.called.should.be.true;
helper.slider.callOnChange.called.should.be.true;
expect(helper.slider.positionTrackingHandle.callCount).to.equal(1);
expect(helper.slider.callOnChange.callCount).to.equal(1);
});

it('should handle click and drag on maxH correctly when mouse is on the middle', function() {
Expand All @@ -277,8 +277,8 @@
position = helper.getMousePosition(expectedValue);
helper.fireMousemove(position);
expect(helper.scope.slider.max).to.equal(expectedValue);
helper.slider.positionTrackingHandle.called.should.be.true;
helper.slider.callOnChange.called.should.be.true;
expect(helper.slider.positionTrackingHandle.callCount).to.equal(1);
expect(helper.slider.callOnChange.callCount).to.equal(1);
});

it('should handle click and drag on minH and switch min/max if needed', function() {
Expand Down Expand Up @@ -315,9 +315,9 @@
expect(helper.scope.slider.min).to.equal(expectedValue);
expect(helper.slider.tracking).to.equal('lowValue');
helper.slider.focusElement.calledWith(helper.slider.minH).should.be.true;
helper.slider.positionTrackingHandle.called.should.be.true;
helper.slider.callOnStart.called.should.be.true;
helper.slider.callOnChange.called.should.be.true;
expect(helper.slider.positionTrackingHandle.callCount).to.equal(1);
expect(helper.slider.callOnStart.callCount).to.equal(1);
expect(helper.slider.callOnChange.callCount).to.equal(1);
});

it('should handle click on fullbar and move maxH when click pos is nearer to maxH', function() {
Expand All @@ -334,9 +334,9 @@
expect(helper.scope.slider.max).to.equal(expectedValue);
expect(helper.slider.tracking).to.equal('highValue');
helper.slider.focusElement.calledWith(helper.slider.maxH).should.be.true;
helper.slider.positionTrackingHandle.called.should.be.true;
helper.slider.callOnStart.called.should.be.true;
helper.slider.callOnChange.called.should.be.true;
expect(helper.slider.positionTrackingHandle.callCount).to.equal(1);
expect(helper.slider.callOnStart.callCount).to.equal(1);
expect(helper.slider.callOnChange.callCount).to.equal(1);
});

it('should handle click on selbar and move whole range when moved within slider range', function() {
Expand All @@ -355,9 +355,9 @@
expect(helper.scope.slider.max).to.equal(50);
expect(helper.slider.tracking).to.equal('highValue');
helper.slider.focusElement.calledWith(helper.slider.maxH).should.be.true;
helper.slider.positionTrackingBar.called.should.be.true;
helper.slider.callOnStart.called.should.be.true;
helper.slider.callOnChange.called.should.be.true;
expect(helper.slider.positionTrackingBar.callCount).to.equal(2);
expect(helper.slider.callOnStart.callCount).to.equal(1);
expect(helper.slider.callOnChange.callCount).to.equal(2);
});

it('should handle click on selbar and move move range when near 0 and moved right', function() {
Expand Down Expand Up @@ -422,4 +422,3 @@
});
});
}());

Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,8 @@

expect(helper.scope.slider.min).to.equal(50);
expect(helper.scope.slider.max).to.equal(70);
helper.slider.positionTrackingBar.called.should.be.true;
helper.slider.callOnChange.called.should.be.true;
expect(helper.slider.positionTrackingBar.callCount).to.equal(1);
expect(helper.slider.callOnChange.callCount).to.equal(1);
});

it('should handle click and drag on maxH correctly', function() {
Expand All @@ -61,8 +61,8 @@
helper.fireMousemove(position);
expect(helper.scope.slider.min).to.equal(50);
expect(helper.scope.slider.max).to.equal(70);
helper.slider.positionTrackingBar.called.should.be.true;
helper.slider.callOnChange.called.should.be.true;
expect(helper.slider.positionTrackingBar.callCount).to.equal(1);
expect(helper.slider.callOnChange.callCount).to.equal(1);
});

it('should not handle click on fullbar', function() {
Expand Down Expand Up @@ -95,9 +95,9 @@
expect(helper.scope.slider.max).to.equal(70);
expect(helper.slider.tracking).to.equal('lowValue');
helper.slider.focusElement.calledWith(helper.slider.minH).should.be.true;
helper.slider.positionTrackingBar.called.should.be.true;
helper.slider.callOnStart.called.should.be.true;
helper.slider.callOnChange.called.should.be.true;
expect(helper.slider.positionTrackingBar.callCount).to.equal(2);
expect(helper.slider.callOnStart.callCount).to.equal(1);
expect(helper.slider.callOnChange.callCount).to.equal(2);
});

it('should handle click on selbar and move range when near 0 and moved left', function() {
Expand Down Expand Up @@ -212,8 +212,8 @@

expect(helper.scope.slider.min).to.equal(50);
expect(helper.scope.slider.max).to.equal(70);
helper.slider.positionTrackingBar.called.should.be.true;
helper.slider.callOnChange.called.should.be.true;
expect(helper.slider.positionTrackingBar.callCount).to.equal(1);
expect(helper.slider.callOnChange.callCount).to.equal(1);
});

it('should handle click and drag on maxH correctly', function() {
Expand All @@ -225,8 +225,8 @@
helper.fireMousemove(position);
expect(helper.scope.slider.min).to.equal(50);
expect(helper.scope.slider.max).to.equal(70);
helper.slider.positionTrackingBar.called.should.be.true;
helper.slider.callOnChange.called.should.be.true;
expect(helper.slider.positionTrackingBar.callCount).to.equal(1);
expect(helper.slider.callOnChange.callCount).to.equal(1);
});

it('should not handle click on fullbar', function() {
Expand Down Expand Up @@ -259,9 +259,9 @@
expect(helper.scope.slider.max).to.equal(70);
expect(helper.slider.tracking).to.equal('lowValue');
helper.slider.focusElement.calledWith(helper.slider.minH).should.be.true;
helper.slider.positionTrackingBar.called.should.be.true;
helper.slider.callOnStart.called.should.be.true;
helper.slider.callOnChange.called.should.be.true;
expect(helper.slider.positionTrackingBar.callCount).to.equal(2);
expect(helper.slider.callOnStart.callCount).to.equal(1);
expect(helper.slider.callOnChange.callCount).to.equal(2);
});

it('should handle click on selbar and move range when near 0 and moved left', function() {
Expand Down Expand Up @@ -328,4 +328,3 @@
});
});
}());

Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,8 @@
var expectedValue = 50;
helper.moveMouseToValue(expectedValue);
expect(helper.scope.slider.value).to.equal(expectedValue);
helper.slider.positionTrackingHandle.called.should.be.true;
helper.slider.callOnChange.called.should.be.true;
expect(helper.slider.positionTrackingHandle.callCount).to.equal(1);
expect(helper.slider.callOnChange.callCount).to.equal(1);
});

it('should do nothing when a click happen on another element than the handle', function() {
Expand Down Expand Up @@ -106,8 +106,8 @@
var expectedValue = 50;
helper.moveMouseToValue(expectedValue);
expect(helper.scope.slider.value).to.equal(expectedValue);
helper.slider.positionTrackingHandle.called.should.be.true;
helper.slider.callOnChange.called.should.be.true;
expect(helper.slider.positionTrackingHandle.callCount).to.equal(1);
expect(helper.slider.callOnChange.callCount).to.equal(1);
});

it('should do nothing when a click happen on another element than the handle', function() {
Expand All @@ -124,4 +124,3 @@
});
});
}());

65 changes: 32 additions & 33 deletions tests/specs/mouse-controls/range-slider-horizontal-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -113,8 +113,8 @@
var expectedValue = 50;
helper.moveMouseToValue(expectedValue);
expect(helper.scope.slider.min).to.equal(expectedValue);
helper.slider.positionTrackingHandle.called.should.be.true;
helper.slider.callOnChange.called.should.be.true;
expect(helper.slider.positionTrackingHandle.callCount).to.equal(1);
expect(helper.slider.callOnChange.callCount).to.equal(1);
});

it('should handle click and drag on maxH correctly when mouse is on the middle', function() {
Expand All @@ -124,8 +124,8 @@
var expectedValue = 50;
helper.moveMouseToValue(expectedValue);
expect(helper.scope.slider.max).to.equal(expectedValue);
helper.slider.positionTrackingHandle.called.should.be.true;
helper.slider.callOnChange.called.should.be.true;
expect(helper.slider.positionTrackingHandle.callCount).to.equal(1);
expect(helper.slider.callOnChange.callCount).to.equal(1);
});

it('should handle click and drag on minH and switch min/max if needed', function() {
Expand Down Expand Up @@ -204,9 +204,9 @@
expect(helper.scope.slider.min).to.equal(expectedValue);
expect(helper.slider.tracking).to.equal('lowValue');
helper.slider.focusElement.calledWith(helper.slider.minH).should.be.true;
helper.slider.positionTrackingHandle.called.should.be.true;
helper.slider.callOnStart.called.should.be.true;
helper.slider.callOnChange.called.should.be.true;
expect(helper.slider.positionTrackingHandle.callCount).to.equal(1);
expect(helper.slider.callOnStart.callCount).to.equal(1);
expect(helper.slider.callOnChange.callCount).to.equal(1);
});

it('should handle click on fullbar and move maxH when click pos is nearer to maxH', function() {
Expand All @@ -223,9 +223,9 @@
expect(helper.scope.slider.max).to.equal(expectedValue);
expect(helper.slider.tracking).to.equal('highValue');
helper.slider.focusElement.calledWith(helper.slider.maxH).should.be.true;
helper.slider.positionTrackingHandle.called.should.be.true;
helper.slider.callOnStart.called.should.be.true;
helper.slider.callOnChange.called.should.be.true;
expect(helper.slider.positionTrackingHandle.callCount).to.equal(1);
expect(helper.slider.callOnStart.callCount).to.equal(1);
expect(helper.slider.callOnChange.callCount).to.equal(1);
});

it('should handle click on selbar and move minH when click pos is nearer to minH', function() {
Expand All @@ -242,9 +242,9 @@
expect(helper.scope.slider.min).to.equal(expectedValue);
expect(helper.slider.tracking).to.equal('lowValue');
helper.slider.focusElement.calledWith(helper.slider.minH).should.be.true;
helper.slider.positionTrackingHandle.called.should.be.true;
helper.slider.callOnStart.called.should.be.true;
helper.slider.callOnChange.called.should.be.true;
expect(helper.slider.positionTrackingHandle.callCount).to.equal(1);
expect(helper.slider.callOnStart.callCount).to.equal(1);
expect(helper.slider.callOnChange.callCount).to.equal(1);
});

it('should handle click on selbar and move maxH when click pos is nearer to maxH', function() {
Expand All @@ -261,9 +261,9 @@
expect(helper.scope.slider.max).to.equal(expectedValue);
expect(helper.slider.tracking).to.equal('highValue');
helper.slider.focusElement.calledWith(helper.slider.maxH).should.be.true;
helper.slider.positionTrackingHandle.called.should.be.true;
helper.slider.callOnStart.called.should.be.true;
helper.slider.callOnChange.called.should.be.true;
expect(helper.slider.positionTrackingHandle.callCount).to.equal(1);
expect(helper.slider.callOnStart.callCount).to.equal(1);
expect(helper.slider.callOnChange.callCount).to.equal(1);
});
});

Expand Down Expand Up @@ -380,8 +380,8 @@
var expectedValue = 50;
helper.moveMouseToValue(expectedValue);
expect(helper.scope.slider.min).to.equal(expectedValue);
helper.slider.positionTrackingHandle.called.should.be.true;
helper.slider.callOnChange.called.should.be.true;
expect(helper.slider.positionTrackingHandle.callCount).to.equal(1);
expect(helper.slider.callOnChange.callCount).to.equal(1);
});

it('should handle click and drag on maxH correctly when mouse is on the middle', function() {
Expand All @@ -391,8 +391,8 @@
var expectedValue = 50;
helper.moveMouseToValue(expectedValue);
expect(helper.scope.slider.max).to.equal(expectedValue);
helper.slider.positionTrackingHandle.called.should.be.true;
helper.slider.callOnChange.called.should.be.true;
expect(helper.slider.positionTrackingHandle.callCount).to.equal(1);
expect(helper.slider.callOnChange.callCount).to.equal(1);
});

it('should handle click and drag on minH and switch min/max if needed', function() {
Expand Down Expand Up @@ -471,9 +471,9 @@
expect(helper.scope.slider.min).to.equal(expectedValue);
expect(helper.slider.tracking).to.equal('lowValue');
helper.slider.focusElement.calledWith(helper.slider.minH).should.be.true;
helper.slider.positionTrackingHandle.called.should.be.true;
helper.slider.callOnStart.called.should.be.true;
helper.slider.callOnChange.called.should.be.true;
expect(helper.slider.positionTrackingHandle.callCount).to.equal(1);
expect(helper.slider.callOnStart.callCount).to.equal(1);
expect(helper.slider.callOnChange.callCount).to.equal(1);
});

it('should handle click on fullbar and move maxH when click pos is nearer to maxH', function() {
Expand All @@ -490,9 +490,9 @@
expect(helper.scope.slider.max).to.equal(expectedValue);
expect(helper.slider.tracking).to.equal('highValue');
helper.slider.focusElement.calledWith(helper.slider.maxH).should.be.true;
helper.slider.positionTrackingHandle.called.should.be.true;
helper.slider.callOnStart.called.should.be.true;
helper.slider.callOnChange.called.should.be.true;
expect(helper.slider.positionTrackingHandle.callCount).to.equal(1);
expect(helper.slider.callOnStart.callCount).to.equal(1);
expect(helper.slider.callOnChange.callCount).to.equal(1);
});

it('should handle click on selbar and move minH when click pos is nearer to minH', function() {
Expand All @@ -509,9 +509,9 @@
expect(helper.scope.slider.min).to.equal(expectedValue);
expect(helper.slider.tracking).to.equal('lowValue');
helper.slider.focusElement.calledWith(helper.slider.minH).should.be.true;
helper.slider.positionTrackingHandle.called.should.be.true;
helper.slider.callOnStart.called.should.be.true;
helper.slider.callOnChange.called.should.be.true;
expect(helper.slider.positionTrackingHandle.callCount).to.equal(1);
expect(helper.slider.callOnStart.callCount).to.equal(1);
expect(helper.slider.callOnChange.callCount).to.equal(1);
});

it('should handle click on selbar and move maxH when click pos is nearer to maxH', function() {
Expand All @@ -528,10 +528,9 @@
expect(helper.scope.slider.max).to.equal(expectedValue);
expect(helper.slider.tracking).to.equal('highValue');
helper.slider.focusElement.calledWith(helper.slider.maxH).should.be.true;
helper.slider.positionTrackingHandle.called.should.be.true;
helper.slider.callOnStart.called.should.be.true;
helper.slider.callOnChange.called.should.be.true;
expect(helper.slider.positionTrackingHandle.callCount).to.equal(1);
expect(helper.slider.callOnStart.callCount).to.equal(1);
expect(helper.slider.callOnChange.callCount).to.equal(1);
});
});
}());

Loading

0 comments on commit 8f51bb2

Please sign in to comment.