Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 2f2a28b

Browse files
author
Valentin Hervieu
committed
test(helper functions): Add tests to event related helper functions
1 parent 069c77a commit 2f2a28b

File tree

2 files changed

+186
-1
lines changed

2 files changed

+186
-1
lines changed

src/rzslider.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1165,7 +1165,6 @@
11651165
* @returns {undefined}
11661166
*/
11671167
bindEvents: function() {
1168-
if (this.options.readOnly || this.options.disabled) return;
11691168
var barTracking, barStart, barMove;
11701169

11711170
if (this.options.draggableRange) {

tests/spec/rz-slider-service-test.js

Lines changed: 186 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1509,5 +1509,191 @@ describe('rzslider - ', function() {
15091509
expect(slider.sanitizeValue(101)).to.equal(100);
15101510
expect(slider.sanitizeValue(110)).to.equal(100);
15111511
});
1512+
1513+
it('should have a valid offsetToValue for positive sliders', function() {
1514+
slider.maxPos = 1000;
1515+
expect(slider.offsetToValue(0)).to.equal(0);
1516+
expect(slider.offsetToValue(1000)).to.equal(100);
1517+
expect(slider.offsetToValue(500)).to.equal(50);
1518+
});
1519+
1520+
it('should have a valid offsetToValue for for negative sliders', function() {
1521+
scope.slider.options.floor = -100;
1522+
scope.slider.options.ceil = 0;
1523+
scope.slider.value = -50;
1524+
scope.$digest();
1525+
slider.maxPos = 1000;
1526+
1527+
expect(slider.offsetToValue(0)).to.equal(-100);
1528+
expect(slider.offsetToValue(1000)).to.equal(0);
1529+
expect(slider.offsetToValue(500)).to.equal(-50);
1530+
});
1531+
1532+
it('should have a valid getEventXY for horizontal sliders on desktop browsers', function() {
1533+
var event = {
1534+
clientX: 12
1535+
};
1536+
expect(slider.getEventXY(event)).to.equal(12);
1537+
});
1538+
1539+
it('should have a valid getEventXY for vertical sliders on desktop browsers', function() {
1540+
scope.slider.options.vertical = true;
1541+
scope.$digest();
1542+
var event = {
1543+
clientY: 12
1544+
};
1545+
expect(slider.getEventXY(event)).to.equal(12);
1546+
});
1547+
1548+
it('should have a valid getEventXY for horizontal sliders on mobile browsers with no originalEvent', function() {
1549+
var event = {
1550+
touches: [{
1551+
clientX: 12
1552+
}]
1553+
};
1554+
expect(slider.getEventXY(event)).to.equal(12);
1555+
});
1556+
1557+
it('should have a valid getEventXY for horizontal sliders on mobile browsers with originalEvent', function() {
1558+
var event = {
1559+
originalEvent: {
1560+
touches: [{
1561+
clientX: 12
1562+
}]
1563+
}
1564+
};
1565+
expect(slider.getEventXY(event)).to.equal(12);
1566+
});
1567+
1568+
it('should have a valid getEventXY for vertical sliders on mobile browsers with no originalEvent', function() {
1569+
scope.slider.options.vertical = true;
1570+
scope.$digest();
1571+
var event = {
1572+
touches: [{
1573+
clientY: 12
1574+
}]
1575+
};
1576+
expect(slider.getEventXY(event)).to.equal(12);
1577+
});
1578+
1579+
it('should have a valid getEventXY for vertical sliders on mobile browsers with originalEvent', function() {
1580+
scope.slider.options.vertical = true;
1581+
scope.$digest();
1582+
var event = {
1583+
originalEvent: {
1584+
touches: [{
1585+
clientY: 12
1586+
}]
1587+
}
1588+
};
1589+
expect(slider.getEventXY(event)).to.equal(12);
1590+
});
1591+
1592+
it('should have a valid getEventPosition for horizontal sliders', function() {
1593+
sinon.stub(slider, 'getEventXY').returns(46);
1594+
var event = {};
1595+
1596+
//fake slider's dimension
1597+
slider.sliderElem.rzsp = 10;
1598+
slider.handleHalfDim = 16;
1599+
1600+
expect(slider.getEventPosition(event)).to.equal(20);
1601+
});
1602+
1603+
it('should have a valid getEventPosition for vertical sliders', function() {
1604+
scope.slider.options.vertical = true;
1605+
scope.$digest();
1606+
sinon.stub(slider, 'getEventXY').returns(46);
1607+
var event = {};
1608+
1609+
//fake slider's dimension
1610+
slider.sliderElem.rzsp = 10;
1611+
slider.handleHalfDim = 16;
1612+
1613+
expect(slider.getEventPosition(event)).to.equal(-52);
1614+
});
1615+
1616+
it('should have a valid getEventPosition for horizontal sliders with scale option', function() {
1617+
scope.slider.options.scale = 0.5;
1618+
scope.$digest();
1619+
sinon.stub(slider, 'getEventXY').returns(46);
1620+
var event = {};
1621+
1622+
//fake slider's dimension
1623+
slider.sliderElem.rzsp = 10;
1624+
slider.handleHalfDim = 16;
1625+
1626+
expect(slider.getEventPosition(event)).to.equal(10);
1627+
});
1628+
1629+
it('should have a valid getEventPosition for vertical sliders with scale option', function() {
1630+
scope.slider.options.scale = 0.5;
1631+
scope.slider.options.vertical = true;
1632+
scope.$digest();
1633+
sinon.stub(slider, 'getEventXY').returns(46);
1634+
var event = {};
1635+
1636+
//fake slider's dimension
1637+
slider.sliderElem.rzsp = 10;
1638+
slider.handleHalfDim = 16;
1639+
1640+
expect(slider.getEventPosition(event)).to.equal(-26);
1641+
});
1642+
1643+
it('should have a valid getNearestHandle for single sliders', function() {
1644+
sinon.stub(slider, 'getEventPosition').returns(46);
1645+
var event = {};
1646+
expect(slider.getNearestHandle(event)).to.equal(slider.minH);
1647+
});
1648+
1649+
it('should have a valid focusElement', function() {
1650+
var el = [{
1651+
focus: sinon.spy()
1652+
}];
1653+
slider.focusElement(el);
1654+
el[0].focus.called.should.be.true;
1655+
});
1656+
});
1657+
1658+
it('should have a valid getNearestHandle for range sliders when click is near minH', function() {
1659+
var sliderConf = {
1660+
min: 20,
1661+
max: 80,
1662+
options: {
1663+
floor: 0,
1664+
ceil: 100,
1665+
step: 10
1666+
}
1667+
};
1668+
createRangeSlider(sliderConf);
1669+
sinon.stub(slider, 'getEventPosition').returns(46);
1670+
1671+
//fake slider's dimension
1672+
slider.minH.rzsp = 0;
1673+
slider.maxH.rzsp = 100;
1674+
1675+
var event = {};
1676+
expect(slider.getNearestHandle(event)).to.equal(slider.minH);
1677+
});
1678+
1679+
it('should have a valid getNearestHandle for range sliders when click is near maxH', function() {
1680+
var sliderConf = {
1681+
min: 20,
1682+
max: 80,
1683+
options: {
1684+
floor: 0,
1685+
ceil: 100,
1686+
step: 10
1687+
}
1688+
};
1689+
createRangeSlider(sliderConf);
1690+
sinon.stub(slider, 'getEventPosition').returns(66);
1691+
1692+
//fake slider's dimension
1693+
slider.minH.rzsp = 0;
1694+
slider.maxH.rzsp = 100;
1695+
1696+
var event = {};
1697+
expect(slider.getNearestHandle(event)).to.equal(slider.maxH);
15121698
});
15131699
});

0 commit comments

Comments
 (0)