Skip to content

Commit 75ce131

Browse files
committed
add tests
1 parent 7f0be0d commit 75ce131

File tree

7 files changed

+105
-5
lines changed

7 files changed

+105
-5
lines changed

dist/rzslider.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -816,7 +816,7 @@
816816
}
817817
}
818818
if (this.getLegend) {
819-
var legend = this.getLegend(i, this.options.id);
819+
var legend = this.getLegend(value, this.options.id);
820820
if (legend)
821821
tick.legend = legend;
822822
}

dist/rzslider.min.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/rzslider.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -820,7 +820,7 @@
820820
}
821821
}
822822
if (this.getLegend) {
823-
var legend = this.getLegend(i, this.options.id);
823+
var legend = this.getLegend(value, this.options.id);
824824
if (legend)
825825
tick.legend = legend;
826826
}

src/rzslider.less

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ rzslider {
2121
user-select: none;
2222

2323
&.with-legend {
24-
margin-bottom: 40px;
24+
margin-bottom: @withLegendMargin;
2525
}
2626

2727
&[disabled] {

src/variables.less

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,3 +26,5 @@
2626
@handlePointerSize: 8px;
2727
@bubblePadding: 1px 3px;
2828
@barDimension: 4px;
29+
30+
@withLegendMargin: 40px;

tests/specs/options-handling-test.js

Lines changed: 55 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,8 +104,20 @@
104104
expect(helper.slider.options.draggableRangeOnly).to.be.false;
105105
});
106106

107-
it('should set correct step/floor/ceil and translate function when stepsArray is used', function() {
107+
it('should set correct step/floor/ceil and translate function when stepsArray is used with values', function() {
108+
helper.scope.slider.options.stepsArray = ['A', 'B', 'C', 'D', 'E'];
109+
helper.scope.$digest();
110+
expect(helper.slider.options.step).to.equal(1);
111+
expect(helper.slider.options.floor).to.equal(0);
112+
expect(helper.slider.options.ceil).to.equal(4);
113+
114+
expect(helper.slider.customTrFn(0)).to.equal('A');
115+
expect(helper.slider.customTrFn(2)).to.equal('C');
116+
});
117+
118+
it('should set correct step/floor/ceil and translate function when stepsArray is used with values and ticks', function() {
108119
helper.scope.slider.options.stepsArray = ['A', 'B', 'C', 'D', 'E'];
120+
helper.scope.slider.options.showTicks = true;
109121
helper.scope.$digest();
110122
expect(helper.slider.options.step).to.equal(1);
111123
expect(helper.slider.options.floor).to.equal(0);
@@ -115,6 +127,48 @@
115127
expect(helper.slider.customTrFn(2)).to.equal('C');
116128
});
117129

130+
it('should set correct step/floor/ceil and translate function when stepsArray is used with objects', function() {
131+
helper.scope.slider.options.stepsArray = [
132+
{value: 'A'},
133+
{value: 'B'},
134+
{value: 'C'},
135+
{value: 'D'},
136+
{value: 'E'}
137+
];
138+
helper.scope.$digest();
139+
expect(helper.slider.options.step).to.equal(1);
140+
expect(helper.slider.options.floor).to.equal(0);
141+
expect(helper.slider.options.ceil).to.equal(4);
142+
143+
expect(helper.slider.customTrFn(0)).to.equal('A');
144+
expect(helper.slider.customTrFn(2)).to.equal('C');
145+
});
146+
147+
148+
it('should set correct step/floor/ceil and translate function when stepsArray is used with objects containing legends', function() {
149+
helper.scope.slider.options.stepsArray = [
150+
{value: 'A'},
151+
{value: 'B', legend: 'Legend B'},
152+
{value: 'C'},
153+
{value: 'D', legend: 'Legend D'},
154+
{value: 'E'}
155+
];
156+
helper.scope.slider.options.showTicks = true;
157+
helper.scope.$digest();
158+
159+
expect(helper.slider.options.step).to.equal(1);
160+
expect(helper.slider.options.floor).to.equal(0);
161+
expect(helper.slider.options.ceil).to.equal(4);
162+
163+
expect(helper.slider.customTrFn(0)).to.equal('A');
164+
expect(helper.slider.customTrFn(2)).to.equal('C');
165+
166+
expect(helper.slider.getLegend(1)).to.equal('Legend B');
167+
expect(helper.slider.getLegend(3)).to.equal('Legend D');
168+
169+
expect(helper.element[0].querySelectorAll('.rz-tick-legend')).to.have.length(2);
170+
});
171+
118172
it('should allow a custom translate function when stepsArray is used', function() {
119173
helper.scope.slider.options.stepsArray = [{'foo': 'barA'}, {'foo': 'barB'}, {'foo': 'barC'}];
120174
helper.scope.slider.options.translate = function(value, sliderId, label) {

tests/specs/ticks-test.js

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,50 @@
102102
expect(lastTick.text()).to.equal('100');
103103
});
104104

105+
it('should create the correct number of legend items when getLegend is defined', function() {
106+
var sliderConf = {
107+
value: 50,
108+
options: {
109+
floor: 0,
110+
ceil: 100,
111+
step: 10,
112+
showTicks: true,
113+
getLegend: function(value) {
114+
return 'Legend for ' + value;
115+
}
116+
}
117+
};
118+
helper.createSlider(sliderConf);
119+
expect(helper.element[0].querySelectorAll('.rz-tick-legend')).to.have.length(11);
120+
var firstLegend = angular.element(helper.element[0].querySelectorAll('.rz-tick-legend')[0]);
121+
expect(firstLegend.text()).to.equal('Legend for 0');
122+
var lastLegend = angular.element(helper.element[0].querySelectorAll('.rz-tick-legend')[10]);
123+
expect(lastLegend.text()).to.equal('Legend for 100');
124+
});
125+
126+
it('should create the correct number of legend items when getLegend is defined and only some legend are displayed', function() {
127+
var sliderConf = {
128+
value: 50,
129+
options: {
130+
floor: 0,
131+
ceil: 100,
132+
step: 10,
133+
showTicks: true,
134+
getLegend: function(value) {
135+
if(value % 20 === 0)
136+
return 'Legend for ' + value;
137+
return null;
138+
}
139+
}
140+
};
141+
helper.createSlider(sliderConf);
142+
expect(helper.element[0].querySelectorAll('.rz-tick-legend')).to.have.length(6);
143+
var firstLegend = angular.element(helper.element[0].querySelectorAll('.rz-tick-legend')[0]);
144+
expect(firstLegend.text()).to.equal('Legend for 0');
145+
var lastLegend = angular.element(helper.element[0].querySelectorAll('.rz-tick-legend')[5]);
146+
expect(lastLegend.text()).to.equal('Legend for 100');
147+
});
148+
105149
it('should set rz-selected class to ticks below the model value if showSelectionBar is true', function() {
106150
var sliderConf = {
107151
value: 50,

0 commit comments

Comments
 (0)