Commit 5d751909 authored by Valentin Hervieu's avatar Valentin Hervieu

test(unit tests): Split all tests in dedicated files

parent 9a9df3d3
...@@ -8,7 +8,7 @@ To contribute to the project, please follow these steps: ...@@ -8,7 +8,7 @@ To contribute to the project, please follow these steps:
4. Run `npm install` 4. Run `npm install`
5. Run `npm run test` 5. Run `npm run test`
6. Make your changes 6. Make your changes
7. Test your changes 7. Test your changes (if you need a new test file, please copy the `test-template.js` file in the tests/specs folder.)
8. Run `npm run build` to generate the dist files 8. Run `npm run build` to generate the dist files
9. Run `git add -A` to add your changes 9. Run `git add -A` to add your changes
10. Run `npm run commit` (**Do not** use `git commit`) - follow the prompts to create your git message 10. Run `npm run commit` (**Do not** use `git commit`) - follow the prompts to create your git message
......
...@@ -133,7 +133,7 @@ module.exports = function(grunt) { ...@@ -133,7 +133,7 @@ module.exports = function(grunt) {
tasks: ['css'] tasks: ['css']
}, },
test: { test: {
files: ['src/*.js', 'tests/spec/*.js'], files: ['src/*.js', 'tests/specs/**/*.js'],
tasks: ['test'] tasks: ['test']
} }
}, },
......
...@@ -15,7 +15,8 @@ module.exports = function (config) { ...@@ -15,7 +15,8 @@ module.exports = function (config) {
'node_modules/angular/angular.js', 'node_modules/angular/angular.js',
'node_modules/angular-mocks/angular-mocks.js', 'node_modules/angular-mocks/angular-mocks.js',
'src/*.js', 'src/*.js',
'tests/spec/*.js', 'tests/specs/helper.js',
'tests/specs/**/*-test.js',
'dist/rzslider.css', 'dist/rzslider.css',
'src/*.html' 'src/*.html'
], ],
......
This source diff could not be displayed because it is too large. You can view the blob instead.
var module = angular.module('test-helper', ['rzModule', 'appTemplates']);
module.factory('TestHelper', function(RzSlider, RzSliderOptions, $rootScope, $compile, $timeout, $window, $document) {
var h = {
RzSlider: RzSlider,
RzSliderOptions: RzSliderOptions,
$rootScope: $rootScope,
$compile: $compile,
$timeout: $timeout,
$window: $window,
$document: $document
};
h.createSlider = function(sliderObj) {
var template = '';
if (sliderObj.options)
template = '<rzslider rz-slider-model="slider.value" rz-slider-options="slider.options"></rzslider>';
else
template = '<rzslider rz-slider-model="slider.value"></rzslider>';
h.initSlider(sliderObj, template);
};
h.createRangeSlider = function(sliderObj) {
var template = '';
if (sliderObj.options)
template = '<rzslider rz-slider-model="slider.min" rz-slider-high="slider.max"' +
'rz-slider-options="slider.options"></rzslider>';
else
template = '<rzslider rz-slider-model="slider.min" rz-slider-high="slider.max"></rzslider>';
h.initSlider(sliderObj, template);
};
h.initSlider = function(sliderObj, template) {
h.scope = $rootScope.$new();
h.scope.slider = sliderObj;
h.parent = angular.element('<div style="width: 1000px; height:1000px;"></div>');
h.element = $compile(template)(h.scope);
h.parent.append(h.element);
angular.element(document).find('body').append(h.parent);
h.scope.$digest();
h.slider = h.element.isolateScope().slider;
};
h.clean = function() {
//simulate to $destroy event to clean everything
if (h.scope)
h.scope.$broadcast('$destroy');
//clean the element we append at each test
if (h.parent)
h.parent.remove();
};
h.fireMousedown = function(element, position, vertical) {
var positionProp = vertical ? 'clientY' : 'clientX';
var event = {
type: 'mousedown',
preventDefault: sinon.stub(),
stopPropagation: sinon.stub()
};
event[positionProp] = position;
element.triggerHandler(event);
return event;
};
h.fireMousemove = function(position, vertical) {
var positionProp = vertical ? 'clientY' : 'clientX';
var event = {
type: 'mousemove'
};
event[positionProp] = position;
$document.triggerHandler(event);
};
h.fireMouseup = function() {
var event = {
type: 'mouseup'
};
$document.triggerHandler(event);
};
h.pressKeydown = function(element, key, oldAPI) {
key = key.toUpperCase();
var event = {
type: 'keydown'
};
var keys = {
'UP': 38,
'DOWN': 40,
'LEFT': 37,
'RIGHT': 39,
'PAGEUP': 33,
'PAGEDOWN': 34,
'HOME': 36,
'END': 35,
'SPACE': 32
};
var keyCode = keys[key];
if (oldAPI)
event.which = keyCode;
else event.keyCode = keyCode;
element.triggerHandler(event);
};
return h;
});
(function() {
"use strict";
describe('Accessibility - ', 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();
});
it('should have accessible horizontal single slider', function() {
var sliderConf = {
value: 10,
options: {
floor: 0,
ceil: 100,
step: 10
}
};
helper.createSlider(sliderConf);
expect(helper.slider.minH.attr('role')).to.equal('slider');
expect(helper.slider.minH.attr('tabindex')).to.equal('0');
expect(helper.slider.minH.attr('aria-valuenow')).to.equal('10');
expect(helper.slider.minH.attr('aria-valuetext')).to.equal('10');
expect(helper.slider.minH.attr('aria-valuemin')).to.equal('0');
expect(helper.slider.minH.attr('aria-valuemax')).to.equal('100');
helper.scope.slider.value = 20;
helper.scope.$digest();
expect(helper.slider.minH.attr('aria-valuenow')).to.equal('20');
expect(helper.slider.minH.attr('aria-valuetext')).to.equal('20');
});
it('should have accessible vertical single slider', function() {
var sliderConf = {
value: 10,
options: {
floor: 0,
ceil: 100,
step: 10,
vertical: true
}
};
helper.createSlider(sliderConf);
expect(helper.slider.minH.attr('role')).to.equal('slider');
expect(helper.slider.minH.attr('tabindex')).to.equal('0');
expect(helper.slider.minH.attr('aria-orientation')).to.equal('vertical');
expect(helper.slider.minH.attr('aria-valuenow')).to.equal('10');
expect(helper.slider.minH.attr('aria-valuetext')).to.equal('10');
expect(helper.slider.minH.attr('aria-valuemin')).to.equal('0');
expect(helper.slider.minH.attr('aria-valuemax')).to.equal('100');
helper.scope.slider.value = 20;
helper.scope.$digest();
expect(helper.slider.minH.attr('aria-valuenow')).to.equal('20');
expect(helper.slider.minH.attr('aria-valuetext')).to.equal('20');
});
it('should have accessible horizontal range slider', function() {
var sliderConf = {
min: 10,
max: 90,
options: {
floor: 0,
ceil: 100,
step: 10
}
};
helper.createRangeSlider(sliderConf);
expect(helper.slider.minH.attr('role')).to.equal('slider');
expect(helper.slider.minH.attr('tabindex')).to.equal('0');
expect(helper.slider.minH.attr('aria-valuenow')).to.equal('10');
expect(helper.slider.minH.attr('aria-valuetext')).to.equal('10');
expect(helper.slider.minH.attr('aria-valuemin')).to.equal('0');
expect(helper.slider.minH.attr('aria-valuemax')).to.equal('100');
expect(helper.slider.maxH.attr('role')).to.equal('slider');
expect(helper.slider.maxH.attr('tabindex')).to.equal('0');
expect(helper.slider.maxH.attr('aria-valuenow')).to.equal('90');
expect(helper.slider.maxH.attr('aria-valuetext')).to.equal('90');
expect(helper.slider.maxH.attr('aria-valuemin')).to.equal('0');
expect(helper.slider.maxH.attr('aria-valuemax')).to.equal('100');
helper.scope.slider.min = 20;
helper.scope.$digest();
expect(helper.slider.minH.attr('aria-valuenow')).to.equal('20');
expect(helper.slider.minH.attr('aria-valuetext')).to.equal('20');
helper.scope.slider.max = 80;
helper.scope.$digest();
expect(helper.slider.maxH.attr('aria-valuenow')).to.equal('80');
expect(helper.slider.maxH.attr('aria-valuetext')).to.equal('80');
});
it('should have accessible vertical range slider', function() {
var sliderConf = {
min: 10,
max: 90,
options: {
floor: 0,
ceil: 100,
step: 10,
vertical: true
}
};
helper.createRangeSlider(sliderConf);
expect(helper.slider.minH.attr('role')).to.equal('slider');
expect(helper.slider.minH.attr('tabindex')).to.equal('0');
expect(helper.slider.minH.attr('aria-orientation')).to.equal('vertical');
expect(helper.slider.minH.attr('aria-valuenow')).to.equal('10');
expect(helper.slider.minH.attr('aria-valuetext')).to.equal('10');
expect(helper.slider.minH.attr('aria-valuemin')).to.equal('0');
expect(helper.slider.minH.attr('aria-valuemax')).to.equal('100');
expect(helper.slider.maxH.attr('role')).to.equal('slider');
expect(helper.slider.maxH.attr('tabindex')).to.equal('0');
expect(helper.slider.maxH.attr('aria-orientation')).to.equal('vertical');
expect(helper.slider.maxH.attr('aria-valuenow')).to.equal('90');
expect(helper.slider.maxH.attr('aria-valuetext')).to.equal('90');
expect(helper.slider.maxH.attr('aria-valuemin')).to.equal('0');
expect(helper.slider.maxH.attr('aria-valuemax')).to.equal('100');
helper.scope.slider.min = 20;
helper.scope.$digest();
expect(helper.slider.minH.attr('aria-valuenow')).to.equal('20');
expect(helper.slider.minH.attr('aria-valuetext')).to.equal('20');
helper.scope.slider.max = 80;
helper.scope.$digest();
expect(helper.slider.maxH.attr('aria-valuenow')).to.equal('80');
expect(helper.slider.maxH.attr('aria-valuetext')).to.equal('80');
});
it('should have accessible horizontal single slider when keyboardSupport is false', function() {
var sliderConf = {
value: 10,
options: {
floor: 0,
ceil: 100,
step: 10,
keyboardSupport: false
}
};
helper.createSlider(sliderConf);
expect(helper.slider.minH.attr('role')).to.equal('slider');
expect(helper.slider.minH.attr('tabindex')).to.equal('');
expect(helper.slider.minH.attr('aria-valuenow')).to.equal('10');
expect(helper.slider.minH.attr('aria-valuetext')).to.equal('10');
expect(helper.slider.minH.attr('aria-valuemin')).to.equal('0');
expect(helper.slider.minH.attr('aria-valuemax')).to.equal('100');
helper.scope.slider.value = 20;
helper.scope.$digest();
expect(helper.slider.minH.attr('aria-valuenow')).to.equal('20');
expect(helper.slider.minH.attr('aria-valuetext')).to.equal('20');
});
it('should have accessible horizontal range slider when keyboardSupport is false', function() {
var sliderConf = {
min: 10,
max: 90,
options: {
floor: 0,
ceil: 100,
step: 10,
keyboardSupport: false
}
};
helper.createRangeSlider(sliderConf);
expect(helper.slider.minH.attr('role')).to.equal('slider');
expect(helper.slider.minH.attr('tabindex')).to.equal('');
expect(helper.slider.minH.attr('aria-valuenow')).to.equal('10');
expect(helper.slider.minH.attr('aria-valuetext')).to.equal('10');
expect(helper.slider.minH.attr('aria-valuemin')).to.equal('0');
expect(helper.slider.minH.attr('aria-valuemax')).to.equal('100');
expect(helper.slider.maxH.attr('role')).to.equal('slider');
expect(helper.slider.maxH.attr('tabindex')).to.equal('');
expect(helper.slider.maxH.attr('aria-valuenow')).to.equal('90');
expect(helper.slider.maxH.attr('aria-valuetext')).to.equal('90');
expect(helper.slider.maxH.attr('aria-valuemin')).to.equal('0');
expect(helper.slider.maxH.attr('aria-valuemax')).to.equal('100');
helper.scope.slider.min = 20;
helper.scope.$digest();
expect(helper.slider.minH.attr('aria-valuenow')).to.equal('20');
expect(helper.slider.minH.attr('aria-valuetext')).to.equal('20');
helper.scope.slider.max = 80;
helper.scope.$digest();
expect(helper.slider.maxH.attr('aria-valuenow')).to.equal('80');
expect(helper.slider.maxH.attr('aria-valuetext')).to.equal('80');
});
it('should have accessible slider when values are text', function() {
var sliderConf = {
value: 1,
options: {
stepsArray: ['A', 'B', 'C']
}
};
helper.createSlider(sliderConf);
expect(helper.slider.minH.attr('role')).to.equal('slider');
expect(helper.slider.minH.attr('tabindex')).to.equal('0');
expect(helper.slider.minH.attr('aria-valuenow')).to.equal('1');
expect(helper.slider.minH.attr('aria-valuetext')).to.equal('B');
expect(helper.slider.minH.attr('aria-valuemin')).to.equal('0');
expect(helper.slider.minH.attr('aria-valuemax')).to.equal('2');
helper.scope.slider.value = 2;
helper.scope.$digest();
expect(helper.slider.minH.attr('aria-valuenow')).to.equal('2');
expect(helper.slider.minH.attr('aria-valuetext')).to.equal('C');
});
});
}());
This diff is collapsed.
(function() {
"use strict";
var helperModule = angular.module('test-helper', ['rzModule', 'appTemplates']);
helperModule.factory('TestHelper', function(RzSlider, RzSliderOptions, $rootScope, $compile, $timeout, $window, $document) {
var h = {
element: null,
scope: null,
parent: null
};
h.createSlider = function(sliderObj) {
var template = '';
if (sliderObj.options)
template = '<rzslider rz-slider-model="slider.value" rz-slider-options="slider.options"></rzslider>';
else
template = '<rzslider rz-slider-model="slider.value"></rzslider>';
h.initSlider(sliderObj, template);
};
h.createRangeSlider = function(sliderObj) {
var template = '';
if (sliderObj.options)
template = '<rzslider rz-slider-model="slider.min" rz-slider-high="slider.max"' +
'rz-slider-options="slider.options"></rzslider>';
else
template = '<rzslider rz-slider-model="slider.min" rz-slider-high="slider.max"></rzslider>';
h.initSlider(sliderObj, template);
};
h.initSlider = function(sliderObj, template) {
h.scope = $rootScope.$new();
h.scope.slider = sliderObj;
h.parent = angular.element('<div style="width: 1000px; height:1000px;"></div>');
h.element = $compile(template)(h.scope);
h.parent.append(h.element);
angular.element(document).find('body').append(h.parent);
h.scope.$digest();
h.slider = h.element.isolateScope().slider;
};
h.clean = function() {
//simulate to $destroy event to clean everything
if (h.scope)
h.scope.$broadcast('$destroy');
//clean the element we append at each test
if (h.parent)
h.parent.remove();
};
h.fireMousedown = function(element, position, vertical) {
var positionProp = vertical ? 'clientY' : 'clientX';
var event = {
type: 'mousedown',
preventDefault: sinon.stub(),
stopPropagation: sinon.stub()
};
event[positionProp] = position;
element.triggerHandler(event);
return event;
};
h.fireMousemove = function(position, vertical) {
var positionProp = vertical ? 'clientY' : 'clientX';
var event = {
type: 'mousemove'
};
event[positionProp] = position;
$document.triggerHandler(event);
};
h.fireMouseup = function() {
var event = {
type: 'mouseup'
};
$document.triggerHandler(event);
};
h.pressKeydown = function(element, key, oldAPI) {
key = key.toUpperCase();
var event = {
type: 'keydown'
};
var keys = {
'UP': 38,
'DOWN': 40,
'LEFT': 37,
'RIGHT': 39,
'PAGEUP': 33,
'PAGEDOWN': 34,
'HOME': 36,
'END': 35,
'SPACE': 32
};
var keyCode = keys[key];
if (oldAPI)
event.which = keyCode;
else event.keyCode = keyCode;
element.triggerHandler(event);
};
return h;
});
}());
(function() {
"use strict";
describe('Keyboard controls - draggableRangeOnly range slider', 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: 90,
max: 110,
options: {
floor: 0,
ceil: 200,
draggableRangeOnly: true
}
};
helper.createRangeSlider(sliderConf);
});
it('should increment minH/maxH by 1 when RIGHT is pressed on minH', function() {
helper.slider.minH.triggerHandler('focus');
helper.pressKeydown(helper.slider.minH, 'RIGHT');
expect(helper.scope.slider.min).to.equal(91);
expect(helper.scope.slider.max).to.equal(111);
});
it('should increment minH/maxH by 1 when RIGHT is pressed on maxH', function() {
helper.slider.maxH.triggerHandler('focus');
helper.pressKeydown(helper.slider.maxH, 'RIGHT');
expect(helper.scope.slider.min).to.equal(91);
expect(helper.scope.slider.max).to.equal(111);
});
it('should increment minH/maxH by 1 when LEFT is pressed on minH', function() {
helper.slider.minH.triggerHandler('focus');
helper.pressKeydown(helper.slider.minH, 'LEFT');
expect(helper.scope.slider.min).to.equal(89);
expect(helper.scope.slider.max).to.equal(109);
});
it('should increment minH/maxH by 1 when LEFT is pressed on maxH', function() {
helper.slider.maxH.triggerHandler('focus');
helper.pressKeydown(helper.slider.maxH, 'LEFT');
expect(helper.scope.slider.min).to.equal(89);
expect(helper.scope.slider.max).to.equal(109);
});
it('should increment minH/maxH by 10% when PAGEUP is pressed on minH', function() {
helper.slider.minH.triggerHandler('focus');
helper.pressKeydown(helper.slider.minH, 'PAGEUP');
expect(helper.scope.slider.min).to.equal(110);
expect(helper.scope.slider.max).to.equal(130);
});
it('should increment minH/maxH by 10% when PAGEUP is pressed on maxH', function() {
helper.slider.maxH.triggerHandler('focus');
helper.pressKeydown(helper.slider.maxH, 'PAGEUP');
expect(helper.scope.slider.min).to.equal(110);
expect(helper.scope.slider.max).to.equal(130);
});
it('should decrement minH/maxH by 10% when PAGEDOWN is pressed on minH', function() {
helper.slider.minH.triggerHandler('focus');
helper.pressKeydown(helper.slider.minH, 'PAGEDOWN');
expect(helper.scope.slider.min).to.equal(70);
expect(helper.scope.slider.max).to.equal(90);
});
it('should decrement minH/maxH by 10% when PAGEDOWN is pressed on maxH', function() {
helper.slider.maxH.triggerHandler('focus');
helper.pressKeydown(helper.slider.maxH, 'PAGEDOWN');
expect(helper.scope.slider.min).to.equal(70);
expect(helper.scope.slider.max).to.equal(90);
});
it('should set minH to min when HOME is pressed on minH', function() {
helper.slider.minH.triggerHandler('focus');
helper.pressKeydown(helper.slider.minH, 'HOME');
expect(helper.scope.slider.min).to.equal(0);
expect(helper.scope.slider.max).to.equal(20);
});
it('should set minH to min when HOME is pressed on maxH', function() {
helper.slider.maxH.triggerHandler('focus');
helper.pressKeydown(helper.slider.maxH, 'HOME');
expect(helper.scope.slider.min).to.equal(0);
expect(helper.scope.slider.max).to.equal(20);
});
it('should set minH to min when END is pressed on minH', function() {
helper.slider.minH.triggerHandler('focus');
helper.pressKeydown(helper.slider.minH, 'END');
expect(helper.scope.slider.min).to.equal(180);
expect(helper.scope.slider.max).to.equal(200);
});
it('should set minH to min when END is pressed on maxH', function() {
helper.slider.maxH.triggerHandler('focus');
helper.pressKeydown(helper.slider.maxH, 'END');
expect(helper.scope.slider.min).to.equal(180);
expect(helper.scope.slider.max).to.equal(200);
});
});
}());
(function() {
"use strict";
describe('Keyboard controls - range slider', 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: 50,
max: 100,
options: {
floor: 0,
ceil: 200
}
};
helper.createRangeSlider(sliderConf);
});
it('should toggle active style when handle focused/blured', function() {
helper.slider.minH.triggerHandler('focus');
expect(helper.slider.minH.hasClass('rz-active')).to.be.true;
expect(helper.slider.maxH.hasClass('rz-active')).to.be.false;
helper.slider.minH.triggerHandler('blur');
helper.slider.maxH.triggerHandler('focus');
expect(helper.slider.minH.hasClass('rz-active')).to.be.false;
expect(helper.slider.maxH.hasClass('rz-active')).to.be.true;
helper.slider.maxH.triggerHandler('blur');
expect(helper.slider.minH.hasClass('rz-active')).to.be.false;
expect(helper.slider.maxH.hasClass('rz-active')).to.be.false;
});
it('should increment minH by 1 when RIGHT is pressed', function() {
helper.slider.minH.triggerHandler('focus');
helper.pressKeydown(helper.slider.minH, 'RIGHT');
expect(helper.scope.slider.min).to.equal(51);
});
it('should increment maxH by 1 when RIGHT is pressed', function() {
helper.slider.maxH.triggerHandler('focus');
helper.pressKeydown(helper.slider.maxH, 'RIGHT');
expect(helper.scope.slider.max).to.equal(101);
});
it('should decrement minH by 1 when LEFT is pressed', function() {
helper.slider.minH.triggerHandler('focus');
helper.pressKeydown(helper.slider.minH, 'LEFT');
expect(helper.scope.slider.min).to.equal(49);
});
it('should decrement maxH by 1 when LEFT is pressed', function() {
helper.slider.maxH.triggerHandler('focus');
helper.pressKeydown(helper.slider.maxH, 'LEFT');
expect(helper.scope.slider.max).to.equal(99);
});
it('should increment minH by 10% when PAGEUP is pressed', function() {
helper.slider.minH.triggerHandler('focus');
helper.pressKeydown(helper.slider.minH, 'PAGEUP');
expect(helper.scope.slider.min).to.equal(70);
});
it('should increment maxH by 10% when PAGEUP is pressed', function() {
helper.slider.maxH.triggerHandler('focus');
helper.pressKeydown(helper.slider.maxH, 'PAGEUP');
expect(helper.scope.slider.max).to.equal(120);
});
it('should decrement minH by 10% when PAGEDOWN is pressed', function() {
helper.slider.minH.triggerHandler('focus');
helper.pressKeydown(helper.slider.minH, 'PAGEDOWN');
expect(helper.scope.slider.min).to.equal(30);
});
it('should decrement maxH by 10% when PAGEDOWN is pressed', function() {
helper.slider.maxH.triggerHandler('focus');
helper.pressKeydown(helper.slider.maxH, 'PAGEDOWN');
expect(helper.scope.slider.max).to.equal(80);
});
it('should set minH to min when HOME is pressed on minH', function() {
helper.slider.minH.triggerHandler('focus');
helper.pressKeydown(helper.slider.minH, 'HOME');
expect(helper.scope.slider.min).to.equal(0);
});
it('should set minH value to previous min and switch min/max when HOME is pressed on maxH', function() {
helper.slider.maxH.triggerHandler('focus');
helper.pressKeydown(helper.slider.maxH, 'HOME');
expect(helper.scope.slider.min).to.equal(0);
expect(helper.scope.slider.max).to.equal(50);
});
it('should set minH value to previous max and switch min/max when END is pressed on minH', function() {
helper.slider.minH.triggerHandler('focus');
helper.pressKeydown(helper.slider.minH, 'END');
expect(helper.scope.slider.min).to.equal(100);
expect(helper.scope.slider.max).to.equal(200);
});
it('should set maxH value to max when END is pressed on maxH', function() {
helper.slider.maxH.triggerHandler('focus');
helper.pressKeydown(helper.slider.maxH, 'END');
expect(helper.scope.slider.max).to.equal(200);
});
it('should do nothing when SPACE is pressed on minH', function() {
helper.slider.minH.triggerHandler('focus');
helper.pressKeydown(helper.slider.minH, 'SPACE');
expect(helper.scope.slider.min).to.equal(50);
});
it('should do nothing when SPACE is pressed on maxH', function() {
helper.slider.maxH.triggerHandler('focus');
helper.pressKeydown(helper.slider.maxH, 'SPACE');
expect(helper.scope.slider.max).to.equal(100);
});
it('should not modify minH when keypress but not focused', function() {
helper.slider.minH.triggerHandler('focus');
helper.pressKeydown(helper.slider.minH, 'RIGHT');
expect(helper.scope.slider.min).to.equal(51);
helper.slider.minH.triggerHandler('blur');
helper.pressKeydown(helper.slider.minH, 'RIGHT');
expect(helper.scope.slider.min).to.equal(51);
});
it('should not modify maxH when keypress but not focused', function() {
helper.slider.maxH.triggerHandler('focus');
helper.pressKeydown(helper.slider.maxH, 'RIGHT');
expect(helper.scope.slider.max).to.equal(101);
helper.slider.maxH.triggerHandler('blur');
helper.pressKeydown(helper.slider.maxH, 'RIGHT');
expect(helper.scope.slider.max).to.equal(101);
});
});
}());
(function() {
"use strict";
describe('Keyboard controls - single slider', 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: 100,
options: {
floor: 0,
ceil: 200
}
};
helper.createSlider(sliderConf);
});
it('should toggle active style when handle focused/blured', function() {
helper.slider.minH.triggerHandler('focus');
expect(helper.slider.minH.hasClass('rz-active')).to.be.true;
helper.slider.minH.triggerHandler('blur');
expect(helper.slider.minH.hasClass('rz-active')).to.be.false;
});
it('should increment by 1 when RIGHT is pressed', function() {
helper.slider.minH.triggerHandler('focus');
helper.pressKeydown(helper.slider.minH, 'RIGHT');
expect(helper.scope.slider.value).to.equal(101);
});
it('should increment by 1 when RIGHT is pressed with oldAPI', function() {
helper.slider.minH.triggerHandler('focus');
helper.pressKeydown(helper.slider.minH, 'RIGHT', true);
expect(helper.scope.slider.value).to.equal(101);
});
it('should decrement by 1 when LEFT is pressed', function() {
helper.slider.minH.triggerHandler('focus');
helper.pressKeydown(helper.slider.minH, 'LEFT');
expect(helper.scope.slider.value).to.equal(99);
});
it('should increment by 1 when UP is pressed', function() {
helper.slider.minH.triggerHandler('focus');
helper.pressKeydown(helper.slider.minH, 'UP');
expect(helper.scope.slider.value).to.equal(101);
});
it('should decrement by 1 when DOWN is pressed', function() {
helper.slider.minH.triggerHandler('focus');
helper.pressKeydown(helper.slider.minH, 'DOWN');
expect(helper.scope.slider.value).to.equal(99);
});
it('should increment by 10% when PAGEUP is pressed', function() {
helper.slider.minH.triggerHandler('focus');
helper.pressKeydown(helper.slider.minH, 'PAGEUP');
expect(helper.scope.slider.value).to.equal(120);
});
it('should decrement by 10% when PAGEDOWN is pressed', function() {
helper.slider.minH.triggerHandler('focus');
helper.pressKeydown(helper.slider.minH, 'PAGEDOWN');
expect(helper.scope.slider.value).to.equal(80);
});
it('should set value to min when HOME is pressed', function() {
helper.slider.minH.triggerHandler('focus');
helper.pressKeydown(helper.slider.minH, 'HOME');
expect(helper.scope.slider.value).to.equal(0);
});
it('should set value to max when END is pressed', function() {
helper.slider.minH.triggerHandler('focus');
helper.pressKeydown(helper.slider.minH, 'END');
expect(helper.scope.slider.value).to.equal(200);
});
it('should do nothing when SPACE is pressed', function() {
helper.slider.minH.triggerHandler('focus');
helper.pressKeydown(helper.slider.minH, 'SPACE');
expect(helper.scope.slider.value).to.equal(100);
});
it('should not modify when keypress but not focused', function() {
helper.slider.minH.triggerHandler('focus');
helper.pressKeydown(helper.slider.minH, 'RIGHT');
expect(helper.scope.slider.value).to.equal(101);
helper.slider.minH.triggerHandler('blur');
helper.pressKeydown(helper.slider.minH, 'RIGHT');
expect(helper.scope.slider.value).to.equal(101);
});
});
}());
(function() {
"use strict";
describe('Keyboard controls - specific tests', 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();
});
it('should not go below floor', function() {
var sliderConf = {
value: 10,
options: {
floor: 0,
ceil: 1000,
step: 10
}
};
helper.createSlider(sliderConf);
helper.slider.minH.triggerHandler('focus');
helper.pressKeydown(helper.slider.minH, 'PAGEDOWN');
expect(helper.scope.slider.value).to.equal(0);
});
it('should not go above ceil', function() {
var sliderConf = {
value: 990,
options: {
floor: 0,
ceil: 1000,
step: 10
}
};
helper.createSlider(sliderConf);
helper.slider.minH.triggerHandler('focus');
helper.pressKeydown(helper.slider.minH, 'PAGEUP');
expect(helper.scope.slider.value).to.equal(1000);
});
it('should not be modified by keyboard if disabled=true', function() {
var sliderConf = {
value: 10,
options: {
floor: 0,
ceil: 100,
disabled: true
}
};
helper.createSlider(sliderConf);
helper.slider.minH.triggerHandler('focus');
helper.pressKeydown(helper.slider.minH, 'LEFT');
expect(helper.scope.slider.value).to.equal(10);
});
it('should not be modified by keyboard if readOnly=true', function() {
var sliderConf = {
value: 10,
options: {
floor: 0,
ceil: 100,
readOnly: true
}
};
helper.createSlider(sliderConf);
helper.slider.minH.triggerHandler('focus');
helper.pressKeydown(helper.slider.minH, 'LEFT');
expect(helper.scope.slider.value).to.equal(10);
});
it('should not be modified by keyboard if new range is below minRange', function() {
var sliderConf = {
min: 45,
max: 55,
options: {
floor: 0,
ceil: 100,
step: 1,
minRange: 10
}
};
helper.createRangeSlider(sliderConf);
//try to move minH right
helper.slider.minH.triggerHandler('focus');
helper.pressKeydown(helper.slider.minH, 'RIGHT');
expect(helper.scope.slider.min).to.equal(45);
//try to move maxH left
helper.slider.maxH.triggerHandler('focus');
helper.pressKeydown(helper.slider.maxH, 'LEFT');
expect(helper.scope.slider.max).to.equal(55);
});
it('should be modified by keyboard if new range is above minRange', function() {
var sliderConf = {
min: 45,
max: 55,
options: {
floor: 0,
ceil: 100,
step: 1,
minRange: 10
}
};
helper.createRangeSlider(sliderConf);
//try to move minH left
helper.slider.minH.triggerHandler('focus');
helper.pressKeydown(helper.slider.minH, 'LEFT');
expect(helper.scope.slider.min).to.equal(44);
//try to move maxH right
helper.slider.maxH.triggerHandler('focus');
helper.pressKeydown(helper.slider.maxH, 'RIGHT');
expect(helper.scope.slider.max).to.equal(56);
});
});
}());
(function() {
"use strict";
describe('Keyboard controls - vertical slider', 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: 100,
options: {
floor: 0,
ceil: 200,
vertical: true
}
};
helper.createSlider(sliderConf);
});
it('should increment by 1 when RIGHT is pressed', function() {
helper.slider.minH.triggerHandler('focus');
helper.pressKeydown(helper.slider.minH, 'RIGHT');
expect(helper.scope.slider.value).to.equal(101);
});
it('should increment by 1 when UP is pressed', function() {
helper.slider.minH.triggerHandler('focus');
helper.pressKeydown(helper.slider.minH, 'UP');
expect(helper.scope.slider.value).to.equal(101);
});
it('should decrement by 1 when DOWN is pressed', function() {
helper.slider.minH.triggerHandler('focus');
helper.pressKeydown(helper.slider.minH, 'DOWN');
expect(helper.scope.slider.value).to.equal(99);
});
it('should decrement by 1 when LEFT is pressed', function() {
helper.slider.minH.triggerHandler('focus');
helper.pressKeydown(helper.slider.minH, 'LEFT');
expect(helper.scope.slider.value).to.equal(99);
});
});
}());
(function() {
"use strict";
describe('Mouse controls - draggableRange Horizontal', 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: 40,
max: 60,
options: {
floor: 0,
ceil: 100,
draggableRange: true
}
};
helper.createRangeSlider(sliderConf);
});
afterEach(function() {
// to clean document listener
helper.fireMouseup();
});
it('should handle click and drag on minH correctly when mouse is on the middle', function() {
sinon.spy(helper.slider, 'positionTrackingHandle');
sinon.spy(helper.slider, 'callOnChange');
var event = helper.fireMousedown(helper.slider.minH, 0);
var expectedValue = 50,
offset = helper.slider.valueToOffset(expectedValue) + helper.slider.handleHalfDim + helper.slider.sliderElem.rzsp;
helper.fireMousemove(offset);
expect(helper.scope.slider.min).to.equal(expectedValue);
helper.slider.positionTrackingHandle.called.should.be.true;
helper.slider.callOnChange.called.should.be.true;
});
it('should handle click and drag on maxH correctly when mouse is on the middle', function() {
sinon.spy(helper.slider, 'positionTrackingHandle');
sinon.spy(helper.slider, 'callOnChange');
var event = helper.fireMousedown(helper.slider.maxH, 0);
var expectedValue = 50,
offset = helper.slider.valueToOffset(expectedValue) + helper.slider.handleHalfDim + helper.slider.sliderElem.rzsp;
helper.fireMousemove(offset);
expect(helper.scope.slider.max).to.equal(expectedValue);
helper.slider.positionTrackingHandle.called.should.be.true;
helper.slider.callOnChange.called.should.be.true;
});
it('should handle click and drag on minH and switch min/max if needed', function() {
var event = helper.fireMousedown(helper.slider.minH, 0);
var expectedValue = 80,
offset = helper.slider.valueToOffset(expectedValue) + helper.slider.handleHalfDim + helper.slider.sliderElem.rzsp;
helper.fireMousemove(offset);
expect(helper.scope.slider.min).to.equal(60);
expect(helper.scope.slider.max).to.equal(80);
});
it('should handle click and drag on maxH and switch min/max if needed', function() {
var event = helper.fireMousedown(helper.slider.maxH, 0);
var expectedValue = 20,
offset = helper.slider.valueToOffset(expectedValue) + helper.slider.handleHalfDim + helper.slider.sliderElem.rzsp;
helper.fireMousemove(offset);
expect(helper.scope.slider.min).to.equal(20);
expect(helper.scope.slider.max).to.equal(40);
});
it('should handle click on fullbar and move minH when click pos is nearer to minH', function() {
sinon.spy(helper.slider, 'positionTrackingHandle');
sinon.spy(helper.slider, 'callOnStart');
sinon.spy(helper.slider, 'callOnChange');
sinon.spy(helper.slider, 'focusElement');
var expectedValue = 10,
offset = helper.slider.valueToOffset(expectedValue) + helper.slider.handleHalfDim + helper.slider.sliderElem.rzsp;
var event = helper.fireMousedown(helper.slider.fullBar, offset);
expect(helper.scope.slider.min).to.equal(expectedValue);
expect(helper.slider.tracking).to.equal('rzSliderModel');
helper.slider.focusElement.calledWith(helper.slider.minH).should.be.true;
helper.slider.positionTrackingHandle.called.should.be.true;
helper.slider.callOnStart.called.should.be.true;
helper.slider.callOnChange.called.should.be.true;
});
it('should handle click on fullbar and move maxH when click pos is nearer to maxH', function() {
sinon.spy(helper.slider, 'positionTrackingHandle');
sinon.spy(helper.slider, 'callOnStart');
sinon.spy(helper.slider, 'callOnChange');
sinon.spy(helper.slider, 'focusElement');
var expectedValue = 90,
offset = helper.slider.valueToOffset(expectedValue) + helper.slider.handleHalfDim + helper.slider.sliderElem.rzsp;
var event = helper.fireMousedown(helper.slider.fullBar, offset);
expect(helper.scope.slider.max).to.equal(expectedValue);
expect(helper.slider.tracking).to.equal('rzSliderHigh');
helper.slider.focusElement.calledWith(helper.slider.maxH).should.be.true;
helper.slider.positionTrackingHandle.called.should.be.true;
helper.slider.callOnStart.called.should.be.true;
helper.slider.callOnChange.called.should.be.true;
});
it('should handle click on selbar and move whole range when moved within slider range', function() {
sinon.spy(helper.slider, 'positionTrackingBar');
sinon.spy(helper.slider, 'callOnStart');
sinon.spy(helper.slider, 'callOnChange');
sinon.spy(helper.slider, 'focusElement');
helper.fireMousedown(helper.slider.selBar, 0);
var moveValue = 10,
offset = helper.slider.valueToOffset(moveValue);
helper.fireMousemove(offset);
expect(helper.scope.slider.min).to.equal(50);
expect(helper.scope.slider.max).to.equal(70);
expect(helper.slider.tracking).to.equal('rzSliderModel');
helper.slider.focusElement.calledWith(helper.slider.minH).should.be.true;
helper.slider.positionTrackingBar.called.should.be.true;
helper.slider.callOnStart.called.should.be.true;
helper.slider.callOnChange.called.should.be.true;
});
it('should handle click on selbar and move move range when near 0 and moved left', function() {
helper.scope.slider.min = 10;
helper.scope.$digest();
helper.fireMousedown(helper.slider.selBar, 0);
helper.fireMousemove(-1000);
expect(helper.scope.slider.min).to.equal(0);
expect(helper.scope.slider.max).to.equal(50);
expect(helper.slider.tracking).to.equal('rzSliderModel');
});
it('should handle click on selbar and don\'t move range when already at 0 and moved left', function() {
helper.scope.slider.min = 0;
helper.scope.$digest();
helper.fireMousedown(helper.slider.selBar, 0);
helper.fireMousemove(-100);
expect(helper.scope.slider.min).to.equal(0);
expect(helper.scope.slider.max).to.equal(60);
expect(helper.slider.tracking).to.equal('rzSliderModel');
});
it('should handle click on selbar and move move range when near max and moved right', function() {
helper.scope.slider.max = 90;
helper.scope.$digest();
helper.fireMousedown(helper.slider.selBar, 0);
helper.fireMousemove(helper.slider.maxPos);
expect(helper.scope.slider.min).to.equal(50);
expect(helper.scope.slider.max).to.equal(100);
expect(helper.slider.tracking).to.equal('rzSliderModel');
});
it('should handle click on selbar and don\'t move range when already at max and moved right', function() {
helper.scope.slider.max = 100;
helper.scope.$digest();
helper.fireMousedown(helper.slider.selBar, 0);
helper.fireMousemove(helper.slider.maxPos);
expect(helper.scope.slider.min).to.equal(40);
expect(helper.scope.slider.max).to.equal(100);
expect(helper.slider.tracking).to.equal('rzSliderModel');
});
it('should a working positionTrackingBar', function() {
var newMin = 50,
newMax = 90,
minOffset = helper.slider.valueToOffset(newMin),
maxOffset = helper.slider.valueToOffset(newMax);
helper.slider.positionTrackingBar(newMin, newMax, minOffset, maxOffset);
expect(helper.scope.slider.min).to.equal(50);
expect(helper.scope.slider.max).to.equal(90);
expect(helper.slider.minH.css('left')).to.equal(minOffset + 'px');
expect(helper.slider.maxH.css('left')).to.equal(maxOffset + 'px');
});
});
}());
(function() {
"use strict";
describe('Mouse controls - draggableRangeOnly Horizontal', 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: 40,
max: 60,
options: {
floor: 0,
ceil: 100,
draggableRangeOnly: true
}
};
helper.createRangeSlider(sliderConf);
});
afterEach(function() {
// to clean document listener
helper.fireMouseup();
});
it('should handle click and drag on minH correctly', function() {
sinon.spy(helper.slider, 'positionTrackingBar');
sinon.spy(helper.slider, 'callOnChange');
var event = helper.fireMousedown(helper.slider.minH, 0);
var moveValue = 10,
offset = helper.slider.valueToOffset(moveValue);
helper.fireMousemove(offset);
expect(helper.scope.slider.min).to.equal(50);
expect(helper.scope.slider.max).to.equal(70);
helper.slider.positionTrackingBar.called.should.be.true;
helper.slider.callOnChange.called.should.be.true;
});
it('should handle click and drag on maxH correctly', function() {
sinon.spy(helper.slider, 'positionTrackingBar');
sinon.spy(helper.slider, 'callOnChange');
var event = helper.fireMousedown(helper.slider.maxH, 0);
var moveValue = 10,
offset = helper.slider.valueToOffset(moveValue);
helper.fireMousemove(offset);
expect(helper.scope.slider.min).to.equal(50);
expect(helper.scope.slider.max).to.equal(70);
helper.slider.positionTrackingBar.called.should.be.true;
helper.slider.callOnChange.called.should.be.true;
});
it('should not handle click on fullbar', function() {
sinon.spy(helper.slider, 'callOnStart');
var moveValue = 10,
offset = helper.slider.valueToOffset(moveValue);
var event = helper.fireMousedown(helper.slider.fullBar, offset);
expect(helper.scope.slider.min).to.equal(40);
expect(helper.scope.slider.max).to.equal(60);
expect(helper.slider.tracking).to.equal('');
helper.slider.callOnStart.called.should.be.false;
});
it('should handle click on selbar and move whole range when moved within slider range', function() {
sinon.spy(helper.slider, 'positionTrackingBar');
sinon.spy(helper.slider, 'callOnStart');
sinon.spy(helper.slider, 'callOnChange');
sinon.spy(helper.slider, 'focusElement');
helper.fireMousedown(helper.slider.selBar, 0);
var moveValue = 10,
offset = helper.slider.valueToOffset(moveValue);
helper.fireMousemove(offset);
expect(helper.scope.slider.min).to.equal(50);
expect(helper.scope.slider.max).to.equal(70);
expect(helper.slider.tracking).to.equal('rzSliderModel');
helper.slider.focusElement.calledWith(helper.slider.minH).should.be.true;
helper.slider.positionTrackingBar.called.should.be.true;
helper.slider.callOnStart.called.should.be.true;
helper.slider.callOnChange.called.should.be.true;
});
it('should handle click on selbar and move move range when near 0 and moved left', function() {
helper.scope.slider.min = 10;
helper.scope.$digest();
helper.fireMousedown(helper.slider.selBar, 0);
helper.fireMousemove(-1000);
expect(helper.scope.slider.min).to.equal(0);
expect(helper.scope.slider.max).to.equal(50);
expect(helper.slider.tracking).to.equal('rzSliderModel');
});
it('should handle click on selbar and don\'t move range when already at 0 and moved left', function() {
helper.scope.slider.min = 0;
helper.scope.$digest();
helper.fireMousedown(helper.slider.selBar, 0);
helper.fireMousemove(-100);
expect(helper.scope.slider.min).to.equal(0);
expect(helper.scope.slider.max).to.equal(60);
expect(helper.slider.tracking).to.equal('rzSliderModel');
});
it('should handle click on selbar and move move range when near max and moved right', function() {
helper.scope.slider.max = 90;
helper.scope.$digest();
helper.fireMousedown(helper.slider.selBar, 0);
helper.fireMousemove(helper.slider.maxPos);
expect(helper.scope.slider.min).to.equal(50);
expect(helper.scope.slider.max).to.equal(100);
expect(helper.slider.tracking).to.equal('rzSliderModel');
});
it('should handle click on selbar and don\'t move range when already at max and moved right', function() {
helper.scope.slider.max = 100;
helper.scope.$digest();
helper.fireMousedown(helper.slider.selBar, 0);
helper.fireMousemove(helper.slider.maxPos);
expect(helper.scope.slider.min).to.equal(40);
expect(helper.scope.slider.max).to.equal(100);
expect(helper.slider.tracking).to.equal('rzSliderModel');
});
});
}());
(function() {
"use strict";
describe('Mouse controls - minRange and noSwitching Range Horizontal', 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: 45,
max: 55,
options: {
floor: 0,
ceil: 100,
minRange: 10,
noSwitching: true
}
};
helper.createRangeSlider(sliderConf);
});
afterEach(function() {
// to clean document listener
helper.fireMouseup();
});
it('should not modify any value if new range would be smaller than minRange when moving minH', function() {
helper.fireMousedown(helper.slider.minH, 0);
var expectedValue = 50,
offset = helper.slider.valueToOffset(expectedValue) + helper.slider.handleHalfDim + helper.slider.sliderElem.rzsp;
helper.fireMousemove(offset);
expect(helper.scope.slider.min).to.equal(45);
});
it('should not modify any value if new range would be smaller than minRange when moving maxH', function() {
helper.fireMousedown(helper.slider.maxH, 0);
var expectedValue = 50,
offset = helper.slider.valueToOffset(expectedValue) + helper.slider.handleHalfDim + helper.slider.sliderElem.rzsp;
helper.fireMousemove(offset);
expect(helper.scope.slider.max).to.equal(55);
});
it('should modify the min value if new range is larger than minRange when moving minH', function() {
helper.fireMousedown(helper.slider.minH, 0);
var expectedValue = 30,
offset = helper.slider.valueToOffset(expectedValue) + helper.slider.handleHalfDim + helper.slider.sliderElem.rzsp;
helper.fireMousemove(offset);
expect(helper.scope.slider.min).to.equal(expectedValue);
});
it('should modify the max value if new range is larger than than minRange when moving maxH', function() {
helper.fireMousedown(helper.slider.maxH, 0);
var expectedValue = 70,
offset = helper.slider.valueToOffset(expectedValue) + helper.slider.handleHalfDim + helper.slider.sliderElem.rzsp;
helper.fireMousemove(offset);
expect(helper.scope.slider.max).to.equal(expectedValue);
});
it('should not switch min/max when moving minH even if the range is large enough', function() {
helper.fireMousedown(helper.slider.minH, 0);
var expectedValue = 80,
offset = helper.slider.valueToOffset(expectedValue) + helper.slider.handleHalfDim + helper.slider.sliderElem.rzsp;
helper.fireMousemove(offset);
expect(helper.scope.slider.min).to.equal(45);
expect(helper.scope.slider.max).to.equal(55);
});
it('should not switch min/max when moving maxH even if the range is large enough', function() {
helper.fireMousedown(helper.slider.maxH, 0);
var expectedValue = 20,
offset = helper.slider.valueToOffset(expectedValue) + helper.slider.handleHalfDim + helper.slider.sliderElem.rzsp;
helper.fireMousemove(offset);
expect(helper.scope.slider.min).to.equal(45);
expect(helper.scope.slider.max).to.equal(55);
});
});
}());
(function() {
"use strict";
describe('Mouse controls - minRange!=0 Range Horizontal', 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: 45,
max: 55,
options: {
floor: 0,
ceil: 100,
minRange: 10
}
};
helper.createRangeSlider(sliderConf);
});
afterEach(function() {
// to clean document listener
helper.fireMouseup();
});
it('should not modify any value if new range would be smaller than minRange when moving minH', function() {
helper.fireMousedown(helper.slider.minH, 0);
var expectedValue = 50,
offset = helper.slider.valueToOffset(expectedValue) + helper.slider.handleHalfDim + helper.slider.sliderElem.rzsp;
helper.fireMousemove(offset);
expect(helper.scope.slider.min).to.equal(45);
});
it('should not modify any value if new range would be smaller than minRange when moving maxH', function() {
helper.fireMousedown(helper.slider.maxH, 0);
var expectedValue = 50,
offset = helper.slider.valueToOffset(expectedValue) + helper.slider.handleHalfDim + helper.slider.sliderElem.rzsp;
helper.fireMousemove(offset);
expect(helper.scope.slider.max).to.equal(55);
});
it('should modify the min value if new range is larger than minRange when moving minH', function() {
helper.fireMousedown(helper.slider.minH, 0);
var expectedValue = 30,
offset = helper.slider.valueToOffset(expectedValue) + helper.slider.handleHalfDim + helper.slider.sliderElem.rzsp;
helper.fireMousemove(offset);
expect(helper.scope.slider.min).to.equal(expectedValue);
});
it('should modify the max value if new range is larger than than minRange when moving maxH', function() {
helper.fireMousedown(helper.slider.maxH, 0);
var expectedValue = 70,
offset = helper.slider.valueToOffset(expectedValue) + helper.slider.handleHalfDim + helper.slider.sliderElem.rzsp;
helper.fireMousemove(offset);
expect(helper.scope.slider.max).to.equal(expectedValue);
});
it('should modify the min value if switch min/max with a value large enough', function() {
helper.fireMousedown(helper.slider.minH, 0);
var expectedValue = 80,
offset = helper.slider.valueToOffset(expectedValue) + helper.slider.handleHalfDim + helper.slider.sliderElem.rzsp;
helper.fireMousemove(offset);
expect(helper.scope.slider.min).to.equal(55);
expect(helper.scope.slider.max).to.equal(expectedValue);
});
it('should modify the max value if switch min/max with a value large enough', function() {
helper.fireMousedown(helper.slider.maxH, 0);
var expectedValue = 20,
offset = helper.slider.valueToOffset(expectedValue) + helper.slider.handleHalfDim + helper.slider.sliderElem.rzsp;
helper.fireMousemove(offset);
expect(helper.scope.slider.min).to.equal(expectedValue);
expect(helper.scope.slider.max).to.equal(45);
});
});
}());
(function() {
"use strict";
describe('Mouse controls - noSwitching Range Horizontal', 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: 45,
max: 55,
options: {
floor: 0,
ceil: 100,
noSwitching: true
}
};
helper.createRangeSlider(sliderConf);
});
afterEach(function() {
// to clean document listener
helper.fireMouseup();
});
it('should not switch min and max handles if minH is dragged after maxH', function() {
helper.fireMousedown(helper.slider.minH, 0);
var expectedValue = 60,
offset = helper.slider.valueToOffset(expectedValue) + helper.slider.handleHalfDim + helper.slider.sliderElem.rzsp;
helper.fireMousemove(offset);
expect(helper.scope.slider.min).to.equal(55);
});
it('should not switch min and max handles if maxH is dragged before minH', function() {
helper.fireMousedown(helper.slider.maxH, 0);
var expectedValue = 20,
offset = helper.slider.valueToOffset(expectedValue) + helper.slider.handleHalfDim + helper.slider.sliderElem.rzsp;
helper.fireMousemove(offset);
expect(helper.scope.slider.max).to.equal(45);
});
it('should move minH if minH==maxH and click is on the left side of the bar', function() {
helper.scope.slider.min = helper.scope.slider.max = 50;
helper.scope.$digest();
var expectedValue = 30,
offset = helper.slider.valueToOffset(expectedValue) + helper.slider.handleHalfDim + helper.slider.sliderElem.rzsp;
helper.fireMousedown(helper.slider.fullBar, offset);
expect(helper.scope.slider.min).to.equal(30);
expect(helper.scope.slider.max).to.equal(50);
});
it('should move maxH if minH==maxH and click is on the right side of the bar', function() {
helper.scope.slider.min = helper.scope.slider.max = 50;
helper.scope.$digest();
var expectedValue = 70,
offset = helper.slider.valueToOffset(expectedValue) + helper.slider.handleHalfDim + helper.slider.sliderElem.rzsp;
helper.fireMousedown(helper.slider.fullBar, offset);
expect(helper.scope.slider.min).to.equal(50);
expect(helper.scope.slider.max).to.equal(70);
});
});
}());
(function() {
"use strict";
describe('Mouse controls - onlyBindHandles Single Horizontal', 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: 0,
options: {
floor: 0,
ceil: 100,
showTicks: true,
onlyBindHandles: true
}
};
helper.createSlider(sliderConf);
});
afterEach(function() {
// to clean document listener
helper.fireMouseup();
});
it('should handle click and drag on minH correctly when mouse is on the middle', function() {
sinon.spy(helper.slider, 'positionTrackingHandle');
sinon.spy(helper.slider, 'callOnChange');
helper.fireMousedown(helper.slider.minH, 0);
var expectedValue = 50,
offset = helper.slider.valueToOffset(expectedValue) + helper.slider.handleHalfDim + helper.slider.sliderElem.rzsp;
helper.fireMousemove(offset);
expect(helper.scope.slider.value).to.equal(expectedValue);
helper.slider.positionTrackingHandle.called.should.be.true;
helper.slider.callOnChange.called.should.be.true;
});
it('should do nothing when a click happen on another element than the handle', function() {
helper.scope.slider.value = 100;
helper.scope.$digest();
sinon.spy(helper.slider, 'positionTrackingHandle');
helper.fireMousedown(helper.slider.selBar, 0);
helper.fireMousedown(helper.slider.fullBar, 0);
helper.fireMousedown(helper.slider.ticks, 0);
expect(helper.scope.slider.value).to.equal(100);
helper.slider.positionTrackingHandle.called.should.be.false;
});
});
}());
This diff is collapsed.
This diff is collapsed.
(function() {
"use strict";
describe('Mouse controls - Single Horizontal', 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: 0,
options: {
floor: 0,
ceil: 100
}
};
helper.createSlider(sliderConf);
});
afterEach(function() {
// to clean document listener
helper.fireMouseup();
});
it('should handle mousedown on minH correctly when keyboardSupport is true', function() {
sinon.spy(helper.slider, 'calcViewDimensions');
sinon.spy(helper.slider, 'callOnStart');
sinon.spy(helper.slider, 'focusElement');
var event = helper.fireMousedown(helper.slider.minH, 0);
helper.slider.calcViewDimensions.called.should.be.true;
helper.slider.callOnStart.called.should.be.true;
helper.slider.focusElement.calledWith(helper.slider.minH).should.be.true;
event.preventDefault.called.should.be.true;
event.stopPropagation.called.should.be.true;
expect(helper.slider.tracking).to.equal('rzSliderModel');
expect(helper.slider.minH.hasClass('rz-active')).to.be.true;
});
it('should handle mousedown on minH correctly when keyboardSupport is false', function() {
helper.scope.slider.options.keyboardSupport = false;
helper.scope.$digest();
sinon.spy(helper.slider, 'calcViewDimensions');
sinon.spy(helper.slider, 'callOnStart');
sinon.spy(helper.slider, 'focusElement');
var event = helper.fireMousedown(helper.slider.minH, 0);
helper.slider.calcViewDimensions.called.should.be.true;
helper.slider.callOnStart.called.should.be.true;
helper.slider.focusElement.called.should.be.false;
event.preventDefault.called.should.be.true;
event.stopPropagation.called.should.be.true;
expect(helper.slider.tracking).to.equal('rzSliderModel');
expect(helper.slider.minH.hasClass('rz-active')).to.be.true;
});
it('should handle click and drag on minH correctly when mouse is on the middle', function() {
sinon.spy(helper.slider, 'positionTrackingHandle');
sinon.spy(helper.slider, 'callOnChange');
var event = helper.fireMousedown(helper.slider.minH, 0);
var expectedValue = 50,
offset = helper.slider.valueToOffset(expectedValue) + helper.slider.handleHalfDim + helper.slider.sliderElem.rzsp;
helper.fireMousemove(offset);
expect(helper.scope.slider.value).to.equal(expectedValue);
helper.slider.positionTrackingHandle.called.should.be.true;
helper.slider.callOnChange.called.should.be.true;
});
it('should handle click and drag on minH correctly when mouse is before the slider and previous value was different than 0', function() {
helper.scope.slider.value = 50;
helper.scope.$digest();
sinon.spy(helper.slider, 'positionTrackingHandle');
var event = helper.fireMousedown(helper.slider.minH, 0);
helper.fireMousemove(-100);
expect(helper.scope.slider.value).to.equal(0);
helper.slider.positionTrackingHandle.called.should.be.true;
});
it('should handle click and drag on minH correctly when mouse is after the slider and previous value was different than 100', function() {
sinon.spy(helper.slider, 'positionTrackingHandle');
var event = helper.fireMousedown(helper.slider.minH, 0);
helper.fireMousemove(helper.slider.maxPos + 100);
expect(helper.scope.slider.value).to.equal(100);
helper.slider.positionTrackingHandle.called.should.be.true;
});
it('should call correct callbacks on slider end and keep handle focused when keyboardSupport is true', function() {
var event = helper.fireMousedown(helper.slider.minH, 0);
sinon.spy(helper.slider, 'callOnEnd');
sinon.spy(helper.slider.scope, '$emit');
helper.fireMouseup();
expect(helper.slider.tracking).to.equal('rzSliderModel');
expect(helper.slider.minH.hasClass('rz-active')).to.be.true;
helper.slider.callOnEnd.called.should.be.true;
helper.slider.scope.$emit.calledWith('slideEnded').should.be.true;
});
it('should call correct callbacks on slider end and not keep handle focused when keyboardSupport is false', function() {
helper.scope.slider.options.keyboardSupport = false;
helper.scope.$digest();
var event = helper.fireMousedown(helper.slider.minH, 0);
sinon.spy(helper.slider, 'callOnEnd');
sinon.spy(helper.slider.scope, '$emit');
helper.fireMouseup();
expect(helper.slider.tracking).to.equal('');
expect(helper.slider.minH.hasClass('rz-active')).to.be.false;
helper.slider.callOnEnd.called.should.be.true;
helper.slider.scope.$emit.calledWith('slideEnded').should.be.true;
});
it('should handle click on fullbar and move minH', function() {
sinon.spy(helper.slider, 'positionTrackingHandle');
sinon.spy(helper.slider, 'callOnStart');
sinon.spy(helper.slider, 'callOnChange');
var expectedValue = 12,
offset = helper.slider.valueToOffset(expectedValue) + helper.slider.handleHalfDim + helper.slider.sliderElem.rzsp;
helper.fireMousedown(helper.slider.fullBar, offset);
expect(helper.scope.slider.value).to.equal(expectedValue);
expect(helper.slider.tracking).to.equal('rzSliderModel');
helper.slider.positionTrackingHandle.called.should.be.true;
helper.slider.callOnStart.called.should.be.true;
helper.slider.callOnChange.called.should.be.true;
});
it('should handle click on selbar and move minH', function() {
sinon.spy(helper.slider, 'positionTrackingHandle');
sinon.spy(helper.slider, 'callOnStart');
sinon.spy(helper.slider, 'callOnChange');
var expectedValue = 12,
offset = helper.slider.valueToOffset(expectedValue) + helper.slider.handleHalfDim + helper.slider.sliderElem.rzsp;
var event = helper.fireMousedown(helper.slider.selBar, offset);
expect(helper.scope.slider.value).to.equal(expectedValue);
expect(helper.slider.tracking).to.equal('rzSliderModel');
helper.slider.positionTrackingHandle.called.should.be.true;
helper.slider.callOnStart.called.should.be.true;
helper.slider.callOnChange.called.should.be.true;
});
it('should handle click on ticks and move minH', function() {
helper.scope.slider.options.step = 10;
helper.scope.slider.options.showTicks = true;
helper.scope.$digest();
sinon.spy(helper.slider, 'positionTrackingHandle');
sinon.spy(helper.slider, 'callOnStart');
sinon.spy(helper.slider, 'callOnChange');
var expectedValue = 10,
offset = helper.slider.valueToOffset(expectedValue) + helper.slider.handleHalfDim + helper.slider.sliderElem.rzsp;
helper.fireMousedown(helper.slider.ticks, offset);
expect(helper.scope.slider.value).to.equal(expectedValue);
expect(helper.slider.tracking).to.equal('rzSliderModel');
helper.slider.positionTrackingHandle.called.should.be.true;
helper.slider.callOnStart.called.should.be.true;
helper.slider.callOnChange.called.should.be.true;
});
});
}());
(function() {
"use strict";
describe('Mouse controls - Single Vertical', 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: 0,
options: {
floor: 0,
ceil: 100,
vertical: true
}
};
helper.createSlider(sliderConf);
});
afterEach(function() {
// to clean document listener
helper.fireMouseup();
});
it('should handle mousedown on minH correctly when keyboardSupport is true', function() {
sinon.spy(helper.slider, 'calcViewDimensions');
sinon.spy(helper.slider, 'callOnStart');
sinon.spy(helper.slider, 'focusElement');
var event = helper.fireMousedown(helper.slider.minH, 0, true);
helper.slider.calcViewDimensions.called.should.be.true;
helper.slider.callOnStart.called.should.be.true;
helper.slider.focusElement.calledWith(helper.slider.minH).should.be.true;
event.preventDefault.called.should.be.true;
event.stopPropagation.called.should.be.true;
expect(helper.slider.tracking).to.equal('rzSliderModel');
expect(helper.slider.minH.hasClass('rz-active')).to.be.true;
});
it('should handle mousedown on minH correctly when keyboardSupport is false', function() {
helper.scope.slider.options.keyboardSupport = false;
helper.scope.$digest();
sinon.spy(helper.slider, 'calcViewDimensions');
sinon.spy(helper.slider, 'callOnStart');
sinon.spy(helper.slider, 'focusElement');
var event = helper.fireMousedown(helper.slider.minH, 0, true);
helper.slider.calcViewDimensions.called.should.be.true;
helper.slider.callOnStart.called.should.be.true;
helper.slider.focusElement.called.should.be.false;
event.preventDefault.called.should.be.true;
event.stopPropagation.called.should.be.true;
expect(helper.slider.tracking).to.equal('rzSliderModel');
expect(helper.slider.minH.hasClass('rz-active')).to.be.true;
});
it('should handle click and drag on minH correctly when mouse is on the middle', function() {
sinon.spy(helper.slider, 'positionTrackingHandle');
sinon.spy(helper.slider, 'callOnChange');
helper.fireMousedown(helper.slider.minH, 0, true);
var expectedValue = 50,
offset = helper.slider.sliderElem.rzsp - helper.slider.valueToOffset(expectedValue) - helper.slider.handleHalfDim;
helper.fireMousemove(offset, true);
expect(helper.scope.slider.value).to.equal(expectedValue);
helper.slider.positionTrackingHandle.called.should.be.true;
helper.slider.callOnChange.called.should.be.true;
});
it('should handle click and drag on minH correctly when mouse is before the slider and previous value was different than 0', function() {
helper.scope.slider.value = 50;
helper.scope.$digest();
sinon.spy(helper.slider, 'positionTrackingHandle');
var event = helper.fireMousedown(helper.slider.minH, 0, true);
helper.fireMousemove(helper.slider.maxPos + 100, true);
expect(helper.scope.slider.value).to.equal(0);
helper.slider.positionTrackingHandle.called.should.be.true;
});
it('should handle click and drag on minH correctly when mouse is after the slider and previous value was different than 100', function() {
sinon.spy(helper.slider, 'positionTrackingHandle');
var event = helper.fireMousedown(helper.slider.minH, 0, true);
helper.fireMousemove(-100, true);
expect(helper.scope.slider.value).to.equal(100);
helper.slider.positionTrackingHandle.called.should.be.true;
});
it('should call correct callbacks on slider end and keep handle focused when keyboardSupport is true', function() {
var event = helper.fireMousedown(helper.slider.minH, 0, true);
sinon.spy(helper.slider, 'callOnEnd');
sinon.spy(helper.slider.scope, '$emit');
helper.fireMouseup();
expect(helper.slider.tracking).to.equal('rzSliderModel');
expect(helper.slider.minH.hasClass('rz-active')).to.be.true;
helper.slider.callOnEnd.called.should.be.true;
helper.slider.scope.$emit.calledWith('slideEnded').should.be.true;
});
it('should call correct callbacks on slider end and not keep handle focused when keyboardSupport is false', function() {
helper.scope.slider.options.keyboardSupport = false;
helper.scope.$digest();
var event = helper.fireMousedown(helper.slider.minH, 0, true);
sinon.spy(helper.slider, 'callOnEnd');
sinon.spy(helper.slider.scope, '$emit');
helper.fireMouseup();
expect(helper.slider.tracking).to.equal('');
expect(helper.slider.minH.hasClass('rz-active')).to.be.false;
helper.slider.callOnEnd.called.should.be.true;
helper.slider.scope.$emit.calledWith('slideEnded').should.be.true;
});
it('should handle click on fullbar and move minH', function() {
sinon.spy(helper.slider, 'positionTrackingHandle');
sinon.spy(helper.slider, 'callOnStart');
sinon.spy(helper.slider, 'callOnChange');
var expectedValue = 50,
offset = helper.slider.sliderElem.rzsp - helper.slider.valueToOffset(expectedValue) - helper.slider.handleHalfDim;
var event = helper.fireMousedown(helper.slider.fullBar, offset, true);
expect(helper.scope.slider.value).to.equal(expectedValue);
expect(helper.slider.tracking).to.equal('rzSliderModel');
helper.slider.positionTrackingHandle.called.should.be.true;
helper.slider.callOnStart.called.should.be.true;
helper.slider.callOnChange.called.should.be.true;
});
it('should handle click on selbar and move minH', function() {
sinon.spy(helper.slider, 'positionTrackingHandle');
sinon.spy(helper.slider, 'callOnStart');
sinon.spy(helper.slider, 'callOnChange');
var expectedValue = 12,
offset = helper.slider.sliderElem.rzsp - helper.slider.valueToOffset(expectedValue) - helper.slider.handleHalfDim;
helper.fireMousedown(helper.slider.selBar, offset, true);
expect(helper.scope.slider.value).to.equal(expectedValue);
expect(helper.slider.tracking).to.equal('rzSliderModel');
helper.slider.positionTrackingHandle.called.should.be.true;
helper.slider.callOnStart.called.should.be.true;
helper.slider.callOnChange.called.should.be.true;
});
it('should handle click on ticks and move minH', function() {
helper.scope.slider.options.step = 10;
helper.scope.slider.options.showTicks = true;
helper.scope.$digest();
sinon.spy(helper.slider, 'positionTrackingHandle');
sinon.spy(helper.slider, 'callOnStart');
sinon.spy(helper.slider, 'callOnChange');
var expectedValue = 10,
offset = helper.slider.sliderElem.rzsp - helper.slider.valueToOffset(expectedValue) - helper.slider.handleHalfDim;
helper.fireMousedown(helper.slider.ticks, offset, true);
expect(helper.scope.slider.value).to.equal(expectedValue);
expect(helper.slider.tracking).to.equal('rzSliderModel');
helper.slider.positionTrackingHandle.called.should.be.true;
helper.slider.callOnStart.called.should.be.true;
helper.slider.callOnChange.called.should.be.true;
});
});
}());
This diff is collapsed.
(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(11);
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 = 13;
helper.scope.slider.max = 94;
helper.scope.$digest();
expect(helper.scope.slider.min).to.equal(10);
expect(helper.scope.slider.max).to.equal(90);
helper.scope.slider.min = 15;
helper.scope.slider.max = 95;
helper.scope.$digest();
$timeout.flush(); //to flush the throttle function
expect(helper.scope.slider.min).to.equal(20);
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;
});
});
}());
(function() {
"use strict";
describe('RzSliderOptions - ', 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();
});
it('should have a correct getOptions method that apply custom options', function() {
var defaultOpts = RzSliderOptions.getOptions();
var customOpts = {
showTicks: true
};
var expectedOpts = angular.extend({}, defaultOpts, customOpts);
var options = RzSliderOptions.getOptions(customOpts);
expect(options).to.deep.equal(expectedOpts);
});
it('should have a correct options method to update the global options', function() {
var defaultOpts = RzSliderOptions.getOptions();
var globalOpts = {
showTicks: true
};
RzSliderOptions.options(globalOpts);
var expectedOpts = angular.extend({}, defaultOpts, globalOpts);
var options = RzSliderOptions.getOptions();
expect(options).to.deep.equal(expectedOpts);
});
});
}());
(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(11);
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;
}));
});
}());
(function() {
"use strict";
/**
* Your test file should end with "-test.js" to be executed.
* Don't modify this file but copy it to create a new test group
*/
describe('Test group description - ', 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();
});
/*
The slider that will be used for each test.
If you want to create a specific one for each test, then create it directly in the "it" blocks
*/
beforeEach(function() {
var sliderConf = {
value: 10,
options: {
floor: 0,
ceil: 100,
step: 10
}
};
helper.createSlider(sliderConf);
});
it('should be true', function() {
});
});
}());
This diff is collapsed.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment