Skip to content

Commit b202243

Browse files
committed
Fix unit tests
1 parent 73308a1 commit b202243

13 files changed

+186
-120
lines changed

dist/rzslider.js

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/*! angularjs-slider - v2.14.0 -
22
(c) Rafal Zajac <[email protected]>, Valentin Hervieu <[email protected]>, Jussi Saarivirta <[email protected]>, Angelin Sirbu <[email protected]> -
33
https://github.com/angular-slider/angularjs-slider -
4-
2016-05-25 */
4+
2016-06-04 */
55
/*jslint unparam: true */
66
/*global angular: false, console: false, define, module */
77
(function(root, factory) {
@@ -370,7 +370,10 @@
370370
this.scope.$watch('rzSliderOptions()', function(newValue, oldValue) {
371371
if (newValue === oldValue)
372372
return;
373-
self.applyOptions();
373+
self.applyOptions(); // need to be called before synchronizing the values
374+
self.syncLowValue();
375+
if (self.range)
376+
self.syncHighValue();
374377
self.resetSlider();
375378
}, true);
376379

@@ -457,6 +460,8 @@
457460
*/
458461
onLowHandleChange: function() {
459462
this.syncLowValue();
463+
if (this.range)
464+
this.syncHighValue();
460465
this.setMinAndMax();
461466
this.updateLowHandle(this.valueToOffset(this.lowValue));
462467
this.updateSelectionBar();
@@ -471,6 +476,7 @@
471476
* Reflow the slider when the high handle changes (called with throttle)
472477
*/
473478
onHighHandleChange: function() {
479+
this.syncLowValue();
474480
this.syncHighValue();
475481
this.setMinAndMax();
476482
this.updateHighHandle(this.valueToOffset(this.highValue));
@@ -1702,8 +1708,9 @@
17021708
var newValue = self.roundStep(self.sanitizeValue(action));
17031709
if (!self.options.draggableRangeOnly) {
17041710
self.positionTrackingHandle(newValue);
1705-
} else {
1706-
var difference = this.highValue - this.lowValue,
1711+
}
1712+
else {
1713+
var difference = self.highValue - self.lowValue,
17071714
newMinValue, newMaxValue;
17081715
if (self.tracking === 'lowValue') {
17091716
newMinValue = newValue;
@@ -1851,6 +1858,7 @@
18511858
this.applyLowValue();
18521859
if (this.range)
18531860
this.applyHighValue();
1861+
this.applyModel();
18541862
this.updateHandles('lowValue', this.valueToOffset(newMinValue));
18551863
this.updateHandles('highValue', this.valueToOffset(newMaxValue));
18561864
},

dist/rzslider.min.js

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

karma.conf.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ module.exports = function (config) {
88
// testing framework to use (jasmine/mocha/qunit/...)
99
frameworks: ['mocha', 'sinon', 'chai'],
1010

11-
reporters: ['dots', /*'coverage'*/],
11+
reporters: ['dots', 'coverage'],
1212

1313
// list of files / patterns to load in the browser
1414
files: [
@@ -26,7 +26,7 @@ module.exports = function (config) {
2626

2727
// preprocess matching files before serving them to the browser
2828
preprocessors: {
29-
//"src/*.js": ['coverage'],
29+
"src/*.js": ['coverage'],
3030
"src/*Tpl.html": 'ng-html2js'
3131
},
3232

src/rzslider.js

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -374,10 +374,10 @@
374374
this.scope.$watch('rzSliderOptions()', function(newValue, oldValue) {
375375
if (newValue === oldValue)
376376
return;
377+
self.applyOptions(); // need to be called before synchronizing the values
377378
self.syncLowValue();
378379
if (self.range)
379380
self.syncHighValue();
380-
self.applyOptions();
381381
self.resetSlider();
382382
}, true);
383383

@@ -1712,8 +1712,9 @@
17121712
var newValue = self.roundStep(self.sanitizeValue(action));
17131713
if (!self.options.draggableRangeOnly) {
17141714
self.positionTrackingHandle(newValue);
1715-
} else {
1716-
var difference = this.highValue - this.lowValue,
1715+
}
1716+
else {
1717+
var difference = self.highValue - self.lowValue,
17171718
newMinValue, newMaxValue;
17181719
if (self.tracking === 'lowValue') {
17191720
newMinValue = newValue;
@@ -1861,6 +1862,7 @@
18611862
this.applyLowValue();
18621863
if (this.range)
18631864
this.applyHighValue();
1865+
this.applyModel();
18641866
this.updateHandles('lowValue', this.valueToOffset(newMinValue));
18651867
this.updateHandles('highValue', this.valueToOffset(newMaxValue));
18661868
},

tests/specs/accessibility-test.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -203,22 +203,22 @@
203203

204204
it('should have accessible slider when values are text', function() {
205205
var sliderConf = {
206-
value: 1,
206+
value: 'B',
207207
options: {
208208
stepsArray: ['A', 'B', 'C']
209209
}
210210
};
211211
helper.createSlider(sliderConf);
212212
expect(helper.slider.minH.attr('role')).to.equal('slider');
213213
expect(helper.slider.minH.attr('tabindex')).to.equal('0');
214-
expect(helper.slider.minH.attr('aria-valuenow')).to.equal('1');
214+
expect(helper.slider.minH.attr('aria-valuenow')).to.equal('B');
215215
expect(helper.slider.minH.attr('aria-valuetext')).to.equal('B');
216216
expect(helper.slider.minH.attr('aria-valuemin')).to.equal('0');
217217
expect(helper.slider.minH.attr('aria-valuemax')).to.equal('2');
218218

219-
helper.scope.slider.value = 2;
219+
helper.scope.slider.value = 'C';
220220
helper.scope.$digest();
221-
expect(helper.slider.minH.attr('aria-valuenow')).to.equal('2');
221+
expect(helper.slider.minH.attr('aria-valuenow')).to.equal('C');
222222
expect(helper.slider.minH.attr('aria-valuetext')).to.equal('C');
223223
});
224224
});

tests/specs/mouse-controls/draggable-range-slider-horizontal-test.js

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@
9393
var event = helper.fireMousedown(helper.slider.fullBar, offset);
9494

9595
expect(helper.scope.slider.min).to.equal(expectedValue);
96-
expect(helper.slider.tracking).to.equal('rzSliderModel');
96+
expect(helper.slider.tracking).to.equal('lowValue');
9797
helper.slider.focusElement.calledWith(helper.slider.minH).should.be.true;
9898
helper.slider.positionTrackingHandle.called.should.be.true;
9999
helper.slider.callOnStart.called.should.be.true;
@@ -112,7 +112,7 @@
112112
var event = helper.fireMousedown(helper.slider.fullBar, offset);
113113

114114
expect(helper.scope.slider.max).to.equal(expectedValue);
115-
expect(helper.slider.tracking).to.equal('rzSliderHigh');
115+
expect(helper.slider.tracking).to.equal('highValue');
116116
helper.slider.focusElement.calledWith(helper.slider.maxH).should.be.true;
117117
helper.slider.positionTrackingHandle.called.should.be.true;
118118
helper.slider.callOnStart.called.should.be.true;
@@ -133,7 +133,7 @@
133133

134134
expect(helper.scope.slider.min).to.equal(50);
135135
expect(helper.scope.slider.max).to.equal(70);
136-
expect(helper.slider.tracking).to.equal('rzSliderModel');
136+
expect(helper.slider.tracking).to.equal('lowValue');
137137
helper.slider.focusElement.calledWith(helper.slider.minH).should.be.true;
138138
helper.slider.positionTrackingBar.called.should.be.true;
139139
helper.slider.callOnStart.called.should.be.true;
@@ -149,7 +149,7 @@
149149

150150
expect(helper.scope.slider.min).to.equal(0);
151151
expect(helper.scope.slider.max).to.equal(50);
152-
expect(helper.slider.tracking).to.equal('rzSliderModel');
152+
expect(helper.slider.tracking).to.equal('lowValue');
153153
});
154154

155155
it('should handle click on selbar and don\'t move range when already at 0 and moved left', function() {
@@ -161,7 +161,7 @@
161161

162162
expect(helper.scope.slider.min).to.equal(0);
163163
expect(helper.scope.slider.max).to.equal(60);
164-
expect(helper.slider.tracking).to.equal('rzSliderModel');
164+
expect(helper.slider.tracking).to.equal('lowValue');
165165
});
166166

167167
it('should handle click on selbar and move move range when near max and moved right', function() {
@@ -173,7 +173,7 @@
173173

174174
expect(helper.scope.slider.min).to.equal(50);
175175
expect(helper.scope.slider.max).to.equal(100);
176-
expect(helper.slider.tracking).to.equal('rzSliderModel');
176+
expect(helper.slider.tracking).to.equal('lowValue');
177177
});
178178

179179
it('should handle click on selbar and don\'t move range when already at max and moved right', function() {
@@ -185,7 +185,7 @@
185185

186186
expect(helper.scope.slider.min).to.equal(40);
187187
expect(helper.scope.slider.max).to.equal(100);
188-
expect(helper.slider.tracking).to.equal('rzSliderModel');
188+
expect(helper.slider.tracking).to.equal('lowValue');
189189
});
190190

191191
it('should a working positionTrackingBar', function() {
@@ -295,7 +295,7 @@
295295
var event = helper.fireMousedown(helper.slider.fullBar, offset);
296296

297297
expect(helper.scope.slider.min).to.equal(expectedValue);
298-
expect(helper.slider.tracking).to.equal('rzSliderModel');
298+
expect(helper.slider.tracking).to.equal('lowValue');
299299
helper.slider.focusElement.calledWith(helper.slider.minH).should.be.true;
300300
helper.slider.positionTrackingHandle.called.should.be.true;
301301
helper.slider.callOnStart.called.should.be.true;
@@ -314,7 +314,7 @@
314314
var event = helper.fireMousedown(helper.slider.fullBar, offset);
315315

316316
expect(helper.scope.slider.max).to.equal(expectedValue);
317-
expect(helper.slider.tracking).to.equal('rzSliderHigh');
317+
expect(helper.slider.tracking).to.equal('highValue');
318318
helper.slider.focusElement.calledWith(helper.slider.maxH).should.be.true;
319319
helper.slider.positionTrackingHandle.called.should.be.true;
320320
helper.slider.callOnStart.called.should.be.true;
@@ -335,7 +335,7 @@
335335

336336
expect(helper.scope.slider.min).to.equal(30);
337337
expect(helper.scope.slider.max).to.equal(50);
338-
expect(helper.slider.tracking).to.equal('rzSliderHigh');
338+
expect(helper.slider.tracking).to.equal('highValue');
339339
helper.slider.focusElement.calledWith(helper.slider.maxH).should.be.true;
340340
helper.slider.positionTrackingBar.called.should.be.true;
341341
helper.slider.callOnStart.called.should.be.true;
@@ -351,7 +351,7 @@
351351

352352
expect(helper.scope.slider.min).to.equal(0);
353353
expect(helper.scope.slider.max).to.equal(50);
354-
expect(helper.slider.tracking).to.equal('rzSliderHigh');
354+
expect(helper.slider.tracking).to.equal('highValue');
355355
});
356356

357357
it('should handle click on selbar and don\'t move range when already at 0 and moved right', function() {
@@ -363,7 +363,7 @@
363363

364364
expect(helper.scope.slider.min).to.equal(0);
365365
expect(helper.scope.slider.max).to.equal(60);
366-
expect(helper.slider.tracking).to.equal('rzSliderHigh');
366+
expect(helper.slider.tracking).to.equal('highValue');
367367
});
368368

369369
it('should handle click on selbar and move range when near max and moved left', function() {
@@ -375,7 +375,7 @@
375375

376376
expect(helper.scope.slider.min).to.equal(50);
377377
expect(helper.scope.slider.max).to.equal(100);
378-
expect(helper.slider.tracking).to.equal('rzSliderHigh');
378+
expect(helper.slider.tracking).to.equal('highValue');
379379
});
380380

381381
it('should handle click on selbar and don\'t move range when already at max and moved left', function() {
@@ -387,7 +387,7 @@
387387

388388
expect(helper.scope.slider.min).to.equal(40);
389389
expect(helper.scope.slider.max).to.equal(100);
390-
expect(helper.slider.tracking).to.equal('rzSliderHigh');
390+
expect(helper.slider.tracking).to.equal('highValue');
391391
});
392392

393393
it('should a working positionTrackingBar', function() {

tests/specs/mouse-controls/draggableOnly-range-slider-horizontal-test.js

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@
9393

9494
expect(helper.scope.slider.min).to.equal(50);
9595
expect(helper.scope.slider.max).to.equal(70);
96-
expect(helper.slider.tracking).to.equal('rzSliderModel');
96+
expect(helper.slider.tracking).to.equal('lowValue');
9797
helper.slider.focusElement.calledWith(helper.slider.minH).should.be.true;
9898
helper.slider.positionTrackingBar.called.should.be.true;
9999
helper.slider.callOnStart.called.should.be.true;
@@ -109,7 +109,7 @@
109109

110110
expect(helper.scope.slider.min).to.equal(0);
111111
expect(helper.scope.slider.max).to.equal(50);
112-
expect(helper.slider.tracking).to.equal('rzSliderModel');
112+
expect(helper.slider.tracking).to.equal('lowValue');
113113
});
114114

115115
it('should handle click on selbar and don\'t move range when already at 0 and moved left', function() {
@@ -121,7 +121,7 @@
121121

122122
expect(helper.scope.slider.min).to.equal(0);
123123
expect(helper.scope.slider.max).to.equal(60);
124-
expect(helper.slider.tracking).to.equal('rzSliderModel');
124+
expect(helper.slider.tracking).to.equal('lowValue');
125125
});
126126

127127
it('should handle click on selbar and move range when near max and moved right', function() {
@@ -133,7 +133,7 @@
133133

134134
expect(helper.scope.slider.min).to.equal(50);
135135
expect(helper.scope.slider.max).to.equal(100);
136-
expect(helper.slider.tracking).to.equal('rzSliderModel');
136+
expect(helper.slider.tracking).to.equal('lowValue');
137137
});
138138

139139
it('should handle click on selbar and don\'t move range when already at max and moved right', function() {
@@ -145,7 +145,7 @@
145145

146146
expect(helper.scope.slider.min).to.equal(40);
147147
expect(helper.scope.slider.max).to.equal(100);
148-
expect(helper.slider.tracking).to.equal('rzSliderModel');
148+
expect(helper.slider.tracking).to.equal('lowValue');
149149
});
150150

151151
it('should handle click on selbar and move range when floor is not 0 and handle is dragged below limit', function() {
@@ -160,7 +160,7 @@
160160

161161
expect(helper.scope.slider.min).to.equal(1000);
162162
expect(helper.scope.slider.max).to.equal(1500);
163-
expect(helper.slider.tracking).to.equal('rzSliderModel');
163+
expect(helper.slider.tracking).to.equal('lowValue');
164164
});
165165
});
166166

@@ -257,7 +257,7 @@
257257

258258
expect(helper.scope.slider.min).to.equal(50);
259259
expect(helper.scope.slider.max).to.equal(70);
260-
expect(helper.slider.tracking).to.equal('rzSliderModel');
260+
expect(helper.slider.tracking).to.equal('lowValue');
261261
helper.slider.focusElement.calledWith(helper.slider.minH).should.be.true;
262262
helper.slider.positionTrackingBar.called.should.be.true;
263263
helper.slider.callOnStart.called.should.be.true;
@@ -273,7 +273,7 @@
273273

274274
expect(helper.scope.slider.min).to.equal(0);
275275
expect(helper.scope.slider.max).to.equal(50);
276-
expect(helper.slider.tracking).to.equal('rzSliderModel');
276+
expect(helper.slider.tracking).to.equal('lowValue');
277277
});
278278

279279
it('should handle click on selbar and don\'t move range when already at 0 and moved left', function() {
@@ -285,7 +285,7 @@
285285

286286
expect(helper.scope.slider.min).to.equal(0);
287287
expect(helper.scope.slider.max).to.equal(60);
288-
expect(helper.slider.tracking).to.equal('rzSliderModel');
288+
expect(helper.slider.tracking).to.equal('lowValue');
289289
});
290290

291291
it('should handle click on selbar and move range when near max and moved right', function() {
@@ -297,7 +297,7 @@
297297

298298
expect(helper.scope.slider.min).to.equal(50);
299299
expect(helper.scope.slider.max).to.equal(100);
300-
expect(helper.slider.tracking).to.equal('rzSliderModel');
300+
expect(helper.slider.tracking).to.equal('lowValue');
301301
});
302302

303303
it('should handle click on selbar and don\'t move range when already at max and moved right', function() {
@@ -309,7 +309,7 @@
309309

310310
expect(helper.scope.slider.min).to.equal(40);
311311
expect(helper.scope.slider.max).to.equal(100);
312-
expect(helper.slider.tracking).to.equal('rzSliderModel');
312+
expect(helper.slider.tracking).to.equal('lowValue');
313313
});
314314

315315
it('should handle click on selbar and move range when floor is not 0 and handle is dragged below limit', function() {
@@ -324,7 +324,7 @@
324324

325325
expect(helper.scope.slider.min).to.equal(1000);
326326
expect(helper.scope.slider.max).to.equal(1500);
327-
expect(helper.slider.tracking).to.equal('rzSliderModel');
327+
expect(helper.slider.tracking).to.equal('lowValue');
328328
});
329329
});
330330
}());

0 commit comments

Comments
 (0)