-
-
Notifications
You must be signed in to change notification settings - Fork 497
/
Copy pathsingle-slider-init-test.js
110 lines (92 loc) · 3.41 KB
/
single-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
106
107
108
109
110
;(function() {
'use strict'
describe('Single 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 = {
value: 10,
options: {
floor: 0,
ceil: 100,
step: 10,
},
}
helper.createSlider(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.false
expect(helper.slider.valueRange).to.equal(100)
expect(helper.slider.maxH.css('display')).to.equal('none')
})
it('should watch rzSliderModel and reflow the slider accordingly', function() {
sinon.spy(helper.slider, 'onLowHandleChange')
helper.scope.slider.value = 54
helper.scope.$digest()
helper.slider.onLowHandleChange.called.should.be.true
})
it('should watch rzSliderOptions and reset the slider accordingly', function() {
sinon.spy(helper.slider, 'applyOptions')
sinon.spy(helper.slider, 'resetSlider')
helper.scope.slider.options.showTicks = true
helper.scope.$digest()
helper.slider.applyOptions.called.should.be.true
helper.slider.resetSlider.called.should.be.true
})
it('should round the model value to the step by default', function() {
helper.scope.slider.value = 54
helper.scope.$digest()
expect(helper.scope.slider.value).to.equal(50)
helper.scope.slider.value = 55
helper.scope.$digest()
$timeout.flush() //to flush the throttle function since we modify twice in a row
expect(helper.scope.slider.value).to.equal(60)
})
it('should call calcViewDimensions() on reCalcViewDimensions', function() {
sinon.spy(helper.slider, 'calcViewDimensions')
helper.scope.$broadcast('reCalcViewDimensions')
helper.slider.calcViewDimensions.called.should.be.true
})
it('should reset everything on rzSliderForceRender', function() {
sinon.spy(helper.slider, 'resetLabelsValue')
sinon.spy(helper.slider, 'resetSlider')
sinon.spy(helper.slider, 'onLowHandleChange')
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
})
it('should call calcViewDimensions() on window resize event', inject(function(
$window
) {
sinon.spy(helper.slider, 'calcViewDimensions')
angular.element($window).triggerHandler('resize')
helper.slider.calcViewDimensions.called.should.be.true
}))
it('should unregister all dom events on $destroy', inject(function(
$window
) {
sinon.spy(helper.slider, 'calcViewDimensions')
sinon.spy(helper.slider, 'unbindEvents')
helper.scope.$broadcast('$destroy')
angular.element($window).triggerHandler('resize')
helper.slider.calcViewDimensions.called.should.be.false
helper.slider.unbindEvents.called.should.be.true
}))
})
})()