|
2 | 2 |
|
3 | 3 | describe('rzslider - ', function() {
|
4 | 4 | var RzSlider,
|
| 5 | + RzSliderOptions, |
5 | 6 | $rootScope,
|
6 | 7 | scope,
|
7 | 8 | $compile,
|
8 | 9 | $timeout,
|
| 10 | + $window, |
9 | 11 | element,
|
10 | 12 | slider;
|
11 | 13 | beforeEach(module('rzModule'));
|
12 | 14 | beforeEach(module('appTemplates'));
|
13 | 15 |
|
14 |
| - beforeEach(inject(function(_RzSlider_, _$rootScope_, _$compile_, _$timeout_) { |
| 16 | + beforeEach(inject(function(_RzSlider_, _RzSliderOptions_, _$rootScope_, _$compile_, _$timeout_, _$window_) { |
15 | 17 | RzSlider = _RzSlider_;
|
| 18 | + RzSliderOptions = _RzSliderOptions_; |
16 | 19 | $rootScope = _$rootScope_;
|
17 | 20 | $compile = _$compile_;
|
18 | 21 | $timeout = _$timeout_;
|
| 22 | + $window = _$window_; |
19 | 23 | }));
|
20 | 24 |
|
21 | 25 | /*
|
@@ -50,7 +54,151 @@ describe('rzslider - ', function() {
|
50 | 54 | $timeout.flush(); //to flush the throttle function
|
51 | 55 | expect(scope.slider.value).to.equal(60);
|
52 | 56 | });
|
| 57 | + |
| 58 | + it('should call calcViewDimensions() on reCalcViewDimensions', function() { |
| 59 | + sinon.spy(slider, 'calcViewDimensions'); |
| 60 | + scope.$broadcast('reCalcViewDimensions'); |
| 61 | + slider.calcViewDimensions.called.should.be.true; |
| 62 | + }); |
| 63 | + |
| 64 | + it('should reset everything on rzSliderForceRender', function() { |
| 65 | + sinon.spy(slider, 'resetLabelsValue'); |
| 66 | + sinon.spy(slider, 'resetSlider'); |
| 67 | + sinon.spy(slider, 'onLowHandleChange'); |
| 68 | + |
| 69 | + scope.$broadcast('rzSliderForceRender'); |
| 70 | + |
| 71 | + slider.resetLabelsValue.called.should.be.true; |
| 72 | + slider.resetSlider.called.should.be.true; |
| 73 | + slider.onLowHandleChange.called.should.be.true; |
| 74 | + }); |
| 75 | + |
| 76 | + it('should call calcViewDimensions() on window resize event', function() { |
| 77 | + sinon.spy(slider, 'calcViewDimensions'); |
| 78 | + angular.element($window).triggerHandler('resize'); |
| 79 | + slider.calcViewDimensions.called.should.be.true; |
| 80 | + }); |
| 81 | + |
| 82 | + it('should unregister all dom events on $destroy', function() { |
| 83 | + sinon.spy(slider, 'calcViewDimensions'); |
| 84 | + sinon.spy(slider, 'unbindEvents'); |
| 85 | + |
| 86 | + scope.$broadcast('$destroy'); |
| 87 | + angular.element($window).triggerHandler('resize'); |
| 88 | + |
| 89 | + slider.calcViewDimensions.called.should.be.false; |
| 90 | + slider.unbindEvents.called.should.be.true; |
| 91 | + }); |
| 92 | + }); |
| 93 | + |
| 94 | + /* |
| 95 | + ****************************************************************************** |
| 96 | + RANGE SLIDER INIT |
| 97 | + ****************************************************************************** |
| 98 | + */ |
| 99 | + describe('range slider initialisation', function() { |
| 100 | + beforeEach(function() { |
| 101 | + var sliderConf = { |
| 102 | + min: 10, |
| 103 | + max: 90, |
| 104 | + options: { |
| 105 | + floor: 0, |
| 106 | + ceil: 100, |
| 107 | + step: 10 |
| 108 | + } |
| 109 | + }; |
| 110 | + createRangeSlider(sliderConf); |
| 111 | + }); |
| 112 | + |
| 113 | + it('should exist compiled', function() { |
| 114 | + expect(element.find('span')).to.have.length(11); |
| 115 | + }); |
| 116 | + |
| 117 | + it('should round the model value to the step', function() { |
| 118 | + scope.slider.min = 13; |
| 119 | + scope.slider.max = 94; |
| 120 | + scope.$digest(); |
| 121 | + expect(scope.slider.min).to.equal(10); |
| 122 | + expect(scope.slider.max).to.equal(90); |
| 123 | + |
| 124 | + scope.slider.min = 15; |
| 125 | + scope.slider.max = 95; |
| 126 | + scope.$digest(); |
| 127 | + $timeout.flush(); //to flush the throttle function |
| 128 | + expect(scope.slider.min).to.equal(20); |
| 129 | + expect(scope.slider.max).to.equal(100); |
| 130 | + }); |
| 131 | + |
| 132 | + it('should reset everything on rzSliderForceRender', function() { |
| 133 | + sinon.spy(slider, 'resetLabelsValue'); |
| 134 | + sinon.spy(slider, 'resetSlider'); |
| 135 | + sinon.spy(slider, 'onLowHandleChange'); |
| 136 | + sinon.spy(slider, 'onHighHandleChange'); |
| 137 | + |
| 138 | + scope.$broadcast('rzSliderForceRender'); |
| 139 | + |
| 140 | + slider.resetLabelsValue.called.should.be.true; |
| 141 | + slider.resetSlider.called.should.be.true; |
| 142 | + slider.onLowHandleChange.called.should.be.true; |
| 143 | + slider.onHighHandleChange.called.should.be.true; |
| 144 | + }); |
| 145 | + }); |
| 146 | + |
| 147 | + /* |
| 148 | + ****************************************************************************** |
| 149 | + RzSliderOptions |
| 150 | + ****************************************************************************** |
| 151 | + */ |
| 152 | + describe('RzSliderOptions', function() { |
| 153 | + |
| 154 | + it('should have a correct getOptions method that apply custom options', function() { |
| 155 | + var defaultOpts = RzSliderOptions.getOptions(); |
| 156 | + var customOpts = { |
| 157 | + showTicks: true |
| 158 | + }; |
| 159 | + |
| 160 | + var expectedOpts = angular.extend({}, defaultOpts, customOpts); |
| 161 | + var options = RzSliderOptions.getOptions(customOpts); |
| 162 | + expect(options).to.deep.equal(expectedOpts); |
| 163 | + }); |
| 164 | + |
| 165 | + it('should have a correct options method to update the global options', function() { |
| 166 | + var defaultOpts = RzSliderOptions.getOptions(); |
| 167 | + var globalOpts = { |
| 168 | + showTicks: true |
| 169 | + }; |
| 170 | + RzSliderOptions.options(globalOpts); |
| 171 | + |
| 172 | + var expectedOpts = angular.extend({}, defaultOpts, globalOpts); |
| 173 | + var options = RzSliderOptions.getOptions(); |
| 174 | + expect(options).to.deep.equal(expectedOpts); |
| 175 | + }); |
53 | 176 | });
|
| 177 | + |
| 178 | + /* |
| 179 | + ****************************************************************************** |
| 180 | + Slider with ticks |
| 181 | + ****************************************************************************** |
| 182 | + */ |
| 183 | + describe('slider with ticks', function() { |
| 184 | + beforeEach(function() { |
| 185 | + var sliderConf = { |
| 186 | + value: 50, |
| 187 | + options: { |
| 188 | + floor: 0, |
| 189 | + ceil: 100, |
| 190 | + step: 10, |
| 191 | + showTicks: true |
| 192 | + } |
| 193 | + }; |
| 194 | + createSlider(sliderConf); |
| 195 | + }); |
| 196 | + |
| 197 | + it('should create the correct number of ticks', function() { |
| 198 | + expect(element[0].querySelectorAll('.tick')).to.have.length(11); |
| 199 | + }); |
| 200 | + }); |
| 201 | + |
54 | 202 | /*
|
55 | 203 | ******************************************************************************
|
56 | 204 | KEYBOARD CONTROLS
|
@@ -530,7 +678,10 @@ describe('rzslider - ', function() {
|
530 | 678 | function initSlider(sliderObj, template) {
|
531 | 679 | scope = $rootScope.$new();
|
532 | 680 | scope.slider = sliderObj;
|
| 681 | + var parent = angular.element('<div style="width: 1000px"></div>'); |
533 | 682 | element = $compile(template)(scope);
|
| 683 | + parent.append(element); |
| 684 | + angular.element(document).find('body').append(parent); |
534 | 685 | scope.$apply();
|
535 | 686 | slider = element.isolateScope().slider;
|
536 | 687 | $timeout.flush();
|
|
0 commit comments