-
-
Notifications
You must be signed in to change notification settings - Fork 497
/
Copy pathrange-slider-init-test.js
105 lines (91 loc) · 3.37 KB
/
range-slider-init-test.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
;(function() {
'use strict'
describe('Range slider initialisation - ', function() {
var helper, RzSliderOptions, $rootScope, $timeout
beforeEach(module('test-helper'))
beforeEach(inject(function(
TestHelper,
_RzSliderOptions_,
_$rootScope_,
_$timeout_
) {
helper = TestHelper
RzSliderOptions = _RzSliderOptions_
$rootScope = _$rootScope_
$timeout = _$timeout_
}))
afterEach(function() {
helper.clean()
})
beforeEach(function() {
var sliderConf = {
min: 10,
max: 90,
options: {
floor: 0,
ceil: 100,
step: 10,
},
}
helper.createRangeSlider(sliderConf)
})
it('should exist compiled and with correct config', function() {
expect(helper.element.find('span')).to.have.length(17)
expect(helper.slider.range).to.be.true
expect(helper.slider.valueRange).to.equal(100)
expect(helper.slider.maxH.css('display')).to.equal('')
})
it('should watch rzSliderHigh and reflow the slider accordingly', function() {
sinon.spy(helper.slider, 'onHighHandleChange')
helper.scope.slider.max = 95
helper.scope.$digest()
helper.slider.onHighHandleChange.called.should.be.true
})
it('should switch to a single slider when rzSliderHigh is unset after init', function() {
sinon.spy(helper.slider, 'onHighHandleChange')
sinon.spy(helper.slider, 'applyOptions')
sinon.spy(helper.slider, 'resetSlider')
helper.scope.slider.max = undefined
helper.scope.$digest()
helper.slider.onHighHandleChange.called.should.be.false
helper.slider.applyOptions.called.should.be.true
helper.slider.resetSlider.called.should.be.true
})
it('should switch to a range slider when rzSliderHigh is set after init', function() {
helper.scope.slider.max = undefined
helper.scope.$digest()
sinon.spy(helper.slider, 'onHighHandleChange')
sinon.spy(helper.slider, 'applyOptions')
sinon.spy(helper.slider, 'resetSlider')
helper.scope.slider.max = 100
helper.scope.$digest()
helper.slider.onHighHandleChange.called.should.be.true
helper.slider.applyOptions.called.should.be.true
helper.slider.resetSlider.called.should.be.true
})
it('should round the model value to the step', function() {
helper.scope.slider.min = 23
helper.scope.slider.max = 84
helper.scope.$digest()
expect(helper.scope.slider.min).to.equal(20)
expect(helper.scope.slider.max).to.equal(80)
helper.scope.slider.min = 25
helper.scope.slider.max = 95
helper.scope.$digest()
$timeout.flush() //to flush the throttle function
expect(helper.scope.slider.min).to.equal(30)
expect(helper.scope.slider.max).to.equal(100)
})
it('should reset everything on rzSliderForceRender', function() {
sinon.spy(helper.slider, 'resetLabelsValue')
sinon.spy(helper.slider, 'resetSlider')
sinon.spy(helper.slider, 'onLowHandleChange')
sinon.spy(helper.slider, 'onHighHandleChange')
helper.scope.$broadcast('rzSliderForceRender')
helper.slider.resetLabelsValue.called.should.be.true
helper.slider.resetSlider.called.should.be.true
helper.slider.onLowHandleChange.called.should.be.true
helper.slider.onHighHandleChange.called.should.be.true
})
})
})()