Skip to content

Commit

Permalink
chore(tests): Add a moveMouseToValue helper to simplofy many tests
Browse files Browse the repository at this point in the history
  • Loading branch information
ValentinH committed Jul 2, 2016
1 parent 12f3e01 commit 3a6b103
Show file tree
Hide file tree
Showing 11 changed files with 175 additions and 235 deletions.
9 changes: 6 additions & 3 deletions tests/specs/helper.js
Original file line number Diff line number Diff line change
Expand Up @@ -108,9 +108,12 @@
$timeout.flush();
};

h.mouseMoveToValue = function(value) {
var offset = h.slider.valueToOffset(value) + h.slider.handleHalfDim + h.slider.sliderElem.rzsp;
h.fireMousemove(offset);
h.getMousePosition = function(value) {
return h.slider.valueToOffset(value) + h.slider.handleHalfDim + h.slider.sliderElem.rzsp;
};

h.moveMouseToValue = function(value) {
h.fireMousemove(h.getMousePosition(value));
};

return h;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,8 @@
sinon.spy(helper.slider, 'positionTrackingHandle');
sinon.spy(helper.slider, 'callOnChange');
var event = helper.fireMousedown(helper.slider.minH, 0);
var expectedValue = 50,
offset = helper.slider.valueToOffset(expectedValue) + helper.slider.handleHalfDim + helper.slider.sliderElem.rzsp;
helper.fireMousemove(offset);
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;
Expand All @@ -53,29 +52,26 @@
sinon.spy(helper.slider, 'positionTrackingHandle');
sinon.spy(helper.slider, 'callOnChange');
var event = helper.fireMousedown(helper.slider.maxH, 0);
var expectedValue = 50,
offset = helper.slider.valueToOffset(expectedValue) + helper.slider.handleHalfDim + helper.slider.sliderElem.rzsp;
helper.fireMousemove(offset);
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;
});

it('should handle click and drag on minH and switch min/max if needed', function() {
var event = helper.fireMousedown(helper.slider.minH, 0);
var expectedValue = 80,
offset = helper.slider.valueToOffset(expectedValue) + helper.slider.handleHalfDim + helper.slider.sliderElem.rzsp;
helper.fireMousemove(offset);
var expectedValue = 80;
helper.moveMouseToValue(expectedValue);

expect(helper.scope.slider.min).to.equal(60);
expect(helper.scope.slider.max).to.equal(80);
});

it('should handle click and drag on maxH and switch min/max if needed', function() {
var event = helper.fireMousedown(helper.slider.maxH, 0);
var expectedValue = 20,
offset = helper.slider.valueToOffset(expectedValue) + helper.slider.handleHalfDim + helper.slider.sliderElem.rzsp;
helper.fireMousemove(offset);
var expectedValue = 20;
helper.moveMouseToValue(expectedValue);

expect(helper.scope.slider.min).to.equal(20);
expect(helper.scope.slider.max).to.equal(40);
Expand All @@ -88,7 +84,7 @@
sinon.spy(helper.slider, 'focusElement');

var expectedValue = 10,
offset = helper.slider.valueToOffset(expectedValue) + helper.slider.handleHalfDim + helper.slider.sliderElem.rzsp;
offset = helper.getMousePosition(expectedValue);

var event = helper.fireMousedown(helper.slider.fullBar, offset);

Expand All @@ -107,7 +103,7 @@
sinon.spy(helper.slider, 'focusElement');

var expectedValue = 90,
offset = helper.slider.valueToOffset(expectedValue) + helper.slider.handleHalfDim + helper.slider.sliderElem.rzsp;
offset = helper.getMousePosition(expectedValue);

var event = helper.fireMousedown(helper.slider.fullBar, offset);

Expand Down Expand Up @@ -244,7 +240,7 @@
sinon.spy(helper.slider, 'callOnChange');
var event = helper.fireMousedown(helper.slider.minH, 0);
var expectedValue = 50,
offset = helper.slider.valueToOffset(expectedValue) + helper.slider.handleHalfDim + helper.slider.sliderElem.rzsp;
offset = helper.getMousePosition(expectedValue);
helper.fireMousemove(offset);
expect(helper.scope.slider.min).to.equal(expectedValue);
helper.slider.positionTrackingHandle.called.should.be.true;
Expand All @@ -256,7 +252,7 @@
sinon.spy(helper.slider, 'callOnChange');
var event = helper.fireMousedown(helper.slider.maxH, 0);
var expectedValue = 50,
offset = helper.slider.valueToOffset(expectedValue) + helper.slider.handleHalfDim + helper.slider.sliderElem.rzsp;
offset = helper.getMousePosition(expectedValue);
helper.fireMousemove(offset);
expect(helper.scope.slider.max).to.equal(expectedValue);
helper.slider.positionTrackingHandle.called.should.be.true;
Expand All @@ -266,7 +262,7 @@
it('should handle click and drag on minH and switch min/max if needed', function() {
var event = helper.fireMousedown(helper.slider.minH, 0);
var expectedValue = 80,
offset = helper.slider.valueToOffset(expectedValue) + helper.slider.handleHalfDim + helper.slider.sliderElem.rzsp;
offset = helper.getMousePosition(expectedValue);
helper.fireMousemove(offset);

expect(helper.scope.slider.min).to.equal(60);
Expand All @@ -276,7 +272,7 @@
it('should handle click and drag on maxH and switch min/max if needed', function() {
var event = helper.fireMousedown(helper.slider.maxH, 0);
var expectedValue = 20,
offset = helper.slider.valueToOffset(expectedValue) + helper.slider.handleHalfDim + helper.slider.sliderElem.rzsp;
offset = helper.getMousePosition(expectedValue);
helper.fireMousemove(offset);

expect(helper.scope.slider.min).to.equal(20);
Expand All @@ -290,7 +286,7 @@
sinon.spy(helper.slider, 'focusElement');

var expectedValue = 10,
offset = helper.slider.valueToOffset(expectedValue) + helper.slider.handleHalfDim + helper.slider.sliderElem.rzsp;
offset = helper.getMousePosition(expectedValue);

var event = helper.fireMousedown(helper.slider.fullBar, offset);

Expand All @@ -309,7 +305,7 @@
sinon.spy(helper.slider, 'focusElement');

var expectedValue = 90,
offset = helper.slider.valueToOffset(expectedValue) + helper.slider.handleHalfDim + helper.slider.sliderElem.rzsp;
offset = helper.getMousePosition(expectedValue);

var event = helper.fireMousedown(helper.slider.fullBar, offset);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,33 +40,29 @@

it('should be able to modify minH above minLimit', function() {
helper.fireMousedown(helper.slider.minH, 0);
var expectedValue = 42,
offset = helper.slider.valueToOffset(expectedValue) + helper.slider.handleHalfDim + helper.slider.sliderElem.rzsp;
helper.fireMousemove(offset);
var expectedValue = 42;
helper.moveMouseToValue(expectedValue);
expect(helper.scope.slider.min).to.equal(42);
});

it('should not be able to modify minH below minLimit', function() {
helper.fireMousedown(helper.slider.minH, 0);
var expectedValue = 30,
offset = helper.slider.valueToOffset(expectedValue) + helper.slider.handleHalfDim + helper.slider.sliderElem.rzsp;
helper.fireMousemove(offset);
var expectedValue = 30;
helper.moveMouseToValue(expectedValue);
expect(helper.scope.slider.min).to.equal(40);
});

it('should be able to modify maxH below maxLimit', function() {
helper.fireMousedown(helper.slider.maxH, 0);
var expectedValue = 58,
offset = helper.slider.valueToOffset(expectedValue) + helper.slider.handleHalfDim + helper.slider.sliderElem.rzsp;
helper.fireMousemove(offset);
var expectedValue = 58;
helper.moveMouseToValue(expectedValue);
expect(helper.scope.slider.max).to.equal(58);
});

it('should not be able to modify maxH above maxLimit', function() {
helper.fireMousedown(helper.slider.maxH, 0);
var expectedValue = 70,
offset = helper.slider.valueToOffset(expectedValue) + helper.slider.handleHalfDim + helper.slider.sliderElem.rzsp;
helper.fireMousemove(offset);
var expectedValue = 70;
helper.moveMouseToValue(expectedValue);
expect(helper.scope.slider.max).to.equal(60);
});
});
Expand Down Expand Up @@ -111,33 +107,29 @@

it('should be able to modify minH above minLimit', function() {
helper.fireMousedown(helper.slider.minH, 0);
var expectedValue = 42,
offset = helper.slider.valueToOffset(expectedValue) + helper.slider.handleHalfDim + helper.slider.sliderElem.rzsp;
helper.fireMousemove(offset);
var expectedValue = 42;
helper.moveMouseToValue(expectedValue);
expect(helper.scope.slider.min).to.equal(42);
});

it('should not be able to modify minH below minLimit', function() {
helper.fireMousedown(helper.slider.minH, 0);
var expectedValue = 30,
offset = helper.slider.valueToOffset(expectedValue) + helper.slider.handleHalfDim + helper.slider.sliderElem.rzsp;
helper.fireMousemove(offset);
var expectedValue = 30;
helper.moveMouseToValue(expectedValue);
expect(helper.scope.slider.min).to.equal(40);
});

it('should be able to modify maxH below maxLimit', function() {
helper.fireMousedown(helper.slider.maxH, 0);
var expectedValue = 58,
offset = helper.slider.valueToOffset(expectedValue) + helper.slider.handleHalfDim + helper.slider.sliderElem.rzsp;
helper.fireMousemove(offset);
var expectedValue = 58;
helper.moveMouseToValue(expectedValue);
expect(helper.scope.slider.max).to.equal(58);
});

it('should not be able to modify maxH above maxLimit', function() {
helper.fireMousedown(helper.slider.maxH, 0);
var expectedValue = 70,
offset = helper.slider.valueToOffset(expectedValue) + helper.slider.handleHalfDim + helper.slider.sliderElem.rzsp;
helper.fireMousemove(offset);
var expectedValue = 70;
helper.moveMouseToValue(expectedValue);
expect(helper.scope.slider.max).to.equal(60);
});
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,33 +39,29 @@

it('should be able to modify minH above minLimit', function() {
helper.fireMousedown(helper.slider.minH, 0);
var expectedValue = 42,
offset = helper.slider.valueToOffset(expectedValue) + helper.slider.handleHalfDim + helper.slider.sliderElem.rzsp;
helper.fireMousemove(offset);
var expectedValue = 42;
helper.moveMouseToValue(expectedValue);
expect(helper.scope.slider.value).to.equal(42);
});

it('should not be able to modify minH below minLimit', function() {
helper.fireMousedown(helper.slider.minH, 0);
var expectedValue = 30,
offset = helper.slider.valueToOffset(expectedValue) + helper.slider.handleHalfDim + helper.slider.sliderElem.rzsp;
helper.fireMousemove(offset);
var expectedValue = 30;
helper.moveMouseToValue(expectedValue);
expect(helper.scope.slider.value).to.equal(40);
});

it('should be able to modify minH below maxLimit', function() {
helper.fireMousedown(helper.slider.minH, 0);
var expectedValue = 58,
offset = helper.slider.valueToOffset(expectedValue) + helper.slider.handleHalfDim + helper.slider.sliderElem.rzsp;
helper.fireMousemove(offset);
var expectedValue = 58;
helper.moveMouseToValue(expectedValue);
expect(helper.scope.slider.value).to.equal(58);
});

it('should not be able to modify minH above maxLimit', function() {
helper.fireMousedown(helper.slider.minH, 0);
var expectedValue = 70,
offset = helper.slider.valueToOffset(expectedValue) + helper.slider.handleHalfDim + helper.slider.sliderElem.rzsp;
helper.fireMousemove(offset);
var expectedValue = 70;
helper.moveMouseToValue(expectedValue);
expect(helper.scope.slider.value).to.equal(60);
});
});
Expand Down Expand Up @@ -109,33 +105,29 @@

it('should be able to modify minH above minLimit', function() {
helper.fireMousedown(helper.slider.minH, 0);
var expectedValue = 42,
offset = helper.slider.valueToOffset(expectedValue) + helper.slider.handleHalfDim + helper.slider.sliderElem.rzsp;
helper.fireMousemove(offset);
var expectedValue = 42;
helper.moveMouseToValue(expectedValue);
expect(helper.scope.slider.value).to.equal(42);
});

it('should not be able to modify minH below minLimit', function() {
helper.fireMousedown(helper.slider.minH, 0);
var expectedValue = 30,
offset = helper.slider.valueToOffset(expectedValue) + helper.slider.handleHalfDim + helper.slider.sliderElem.rzsp;
helper.fireMousemove(offset);
var expectedValue = 30;
helper.moveMouseToValue(expectedValue);
expect(helper.scope.slider.value).to.equal(40);
});

it('should be able to modify minH below maxLimit', function() {
helper.fireMousedown(helper.slider.minH, 0);
var expectedValue = 58,
offset = helper.slider.valueToOffset(expectedValue) + helper.slider.handleHalfDim + helper.slider.sliderElem.rzsp;
helper.fireMousemove(offset);
var expectedValue = 58;
helper.moveMouseToValue(expectedValue);
expect(helper.scope.slider.value).to.equal(58);
});

it('should not be able to modify minH above maxLimit', function() {
helper.fireMousedown(helper.slider.minH, 0);
var expectedValue = 70,
offset = helper.slider.valueToOffset(expectedValue) + helper.slider.handleHalfDim + helper.slider.sliderElem.rzsp;
helper.fireMousemove(offset);
var expectedValue = 70;
helper.moveMouseToValue(expectedValue);
expect(helper.scope.slider.value).to.equal(60);
});
});
Expand Down
Loading

0 comments on commit 3a6b103

Please sign in to comment.