Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
I
i20rzslider
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
jedife
i20rzslider
Commits
840eb79c
Commit
840eb79c
authored
Dec 24, 2015
by
Valentin Hervieu
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
test: Add more tests for slider init, RzSliderOptions handling, and start to test ticks
parent
ab2afaa1
Changes
4
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
188 additions
and
24 deletions
+188
-24
karma.conf.js
karma.conf.js
+2
-2
package.json
package.json
+2
-3
rzslider.js
src/rzslider.js
+32
-18
rz-slider-service-test.js
tests/spec/rz-slider-service-test.js
+152
-1
No files found.
karma.conf.js
View file @
840eb79c
...
@@ -6,7 +6,7 @@ module.exports = function (config) {
...
@@ -6,7 +6,7 @@ module.exports = function (config) {
basePath
:
''
,
basePath
:
''
,
// testing framework to use (jasmine/mocha/qunit/...)
// testing framework to use (jasmine/mocha/qunit/...)
frameworks
:
[
'mocha'
,
'
chai'
,
'chai-things'
,
'chai-as-promised
'
],
frameworks
:
[
'mocha'
,
'
sinon'
,
'chai
'
],
reporters
:
[
'dots'
,
'coverage'
],
reporters
:
[
'dots'
,
'coverage'
],
...
@@ -16,6 +16,7 @@ module.exports = function (config) {
...
@@ -16,6 +16,7 @@ module.exports = function (config) {
'node_modules/angular-mocks/angular-mocks.js'
,
'node_modules/angular-mocks/angular-mocks.js'
,
'src/*.js'
,
'src/*.js'
,
'tests/spec/*.js'
,
'tests/spec/*.js'
,
'dist/rzslider.css'
,
'src/*.html'
'src/*.html'
],
],
...
@@ -51,7 +52,6 @@ module.exports = function (config) {
...
@@ -51,7 +52,6 @@ module.exports = function (config) {
subdir
:
'.'
subdir
:
'.'
},
},
// Start these browsers, currently available:
// Start these browsers, currently available:
// - Chrome
// - Chrome
// - ChromeCanary
// - ChromeCanary
...
...
package.json
View file @
840eb79c
...
@@ -24,8 +24,6 @@
...
@@ -24,8 +24,6 @@
"
angular
"
:
"
1.4.7
"
,
"
angular
"
:
"
1.4.7
"
,
"
angular-mocks
"
:
"
^1.4.8
"
,
"
angular-mocks
"
:
"
^1.4.8
"
,
"
chai
"
:
"
^3.4.1
"
,
"
chai
"
:
"
^3.4.1
"
,
"
chai-as-promised
"
:
"
^5.1.0
"
,
"
chai-things
"
:
"
^0.2.0
"
,
"
codecov.io
"
:
"
^0.1.6
"
,
"
codecov.io
"
:
"
^0.1.6
"
,
"
commitizen
"
:
"
^2.4.6
"
,
"
commitizen
"
:
"
^2.4.6
"
,
"
cz-conventional-changelog
"
:
"
^1.1.5
"
,
"
cz-conventional-changelog
"
:
"
^1.1.5
"
,
...
@@ -41,12 +39,13 @@
...
@@ -41,12 +39,13 @@
"
grunt-replace
"
:
"
^0.11.0
"
,
"
grunt-replace
"
:
"
^0.11.0
"
,
"
grunt-serve
"
:
"
^0.1.6
"
,
"
grunt-serve
"
:
"
^0.1.6
"
,
"
karma
"
:
"
^0.13.15
"
,
"
karma
"
:
"
^0.13.15
"
,
"
karma-chai
-plugins
"
:
"
^0.6.1
"
,
"
karma-chai
"
:
"
^0.1.0
"
,
"
karma-chrome-launcher
"
:
"
^0.2.2
"
,
"
karma-chrome-launcher
"
:
"
^0.2.2
"
,
"
karma-coverage
"
:
"
^0.5.3
"
,
"
karma-coverage
"
:
"
^0.5.3
"
,
"
karma-mocha
"
:
"
^0.2.1
"
,
"
karma-mocha
"
:
"
^0.2.1
"
,
"
karma-ng-html2js-preprocessor
"
:
"
^0.2.0
"
,
"
karma-ng-html2js-preprocessor
"
:
"
^0.2.0
"
,
"
karma-phantomjs-launcher
"
:
"
^0.2.1
"
,
"
karma-phantomjs-launcher
"
:
"
^0.2.1
"
,
"
karma-sinon
"
:
"
^1.0.4
"
,
"
mocha
"
:
"
^2.3.4
"
,
"
mocha
"
:
"
^2.3.4
"
,
"
phantomjs
"
:
"
^1.9.19
"
,
"
phantomjs
"
:
"
^1.9.19
"
,
"
recess
"
:
"
~1.1.9
"
"
recess
"
:
"
~1.1.9
"
...
...
src/rzslider.js
View file @
840eb79c
...
@@ -282,9 +282,12 @@
...
@@ -282,9 +282,12 @@
*/
*/
init
:
function
()
{
init
:
function
()
{
var
thrLow
,
thrHigh
,
var
thrLow
,
thrHigh
,
calcDimFn
=
angular
.
bind
(
this
,
this
.
calcViewDimensions
),
self
=
this
;
self
=
this
;
var
calcDimFn
=
function
()
{
self
.
calcViewDimensions
();
};
this
.
applyOptions
();
this
.
applyOptions
();
this
.
initElemHandles
();
this
.
initElemHandles
();
this
.
manageElementsStyle
();
this
.
manageElementsStyle
();
...
@@ -309,27 +312,12 @@
...
@@ -309,27 +312,12 @@
this
.
initHasRun
=
true
;
this
.
initHasRun
=
true
;
// Watch for changes to the model
// Watch for changes to the model
thrLow
=
rzThrottle
(
function
()
{
thrLow
=
rzThrottle
(
function
()
{
self
.
setMinAndMax
();
self
.
onLowHandleChange
();
self
.
updateLowHandle
(
self
.
valueToOffset
(
self
.
scope
.
rzSliderModel
));
self
.
updateSelectionBar
();
self
.
updateTicksScale
();
self
.
updateAriaAttributes
();
if
(
self
.
range
)
{
self
.
updateCmbLabel
();
}
},
self
.
options
.
interval
);
},
self
.
options
.
interval
);
thrHigh
=
rzThrottle
(
function
()
{
thrHigh
=
rzThrottle
(
function
()
{
self
.
setMinAndMax
();
self
.
onHighHandleChange
();
self
.
updateHighHandle
(
self
.
valueToOffset
(
self
.
scope
.
rzSliderHigh
));
self
.
updateSelectionBar
();
self
.
updateTicksScale
();
self
.
updateCmbLabel
();
self
.
updateAriaAttributes
();
},
self
.
options
.
interval
);
},
self
.
options
.
interval
);
this
.
scope
.
$on
(
'rzSliderForceRender'
,
function
()
{
this
.
scope
.
$on
(
'rzSliderForceRender'
,
function
()
{
...
@@ -377,6 +365,32 @@
...
@@ -377,6 +365,32 @@
});
});
},
},
/*
* Reflow the slider when the low handle changes (called with throttle)
*/
onLowHandleChange
:
function
()
{
this
.
setMinAndMax
();
this
.
updateLowHandle
(
this
.
valueToOffset
(
this
.
scope
.
rzSliderModel
));
this
.
updateSelectionBar
();
this
.
updateTicksScale
();
this
.
updateAriaAttributes
();
if
(
this
.
range
)
{
this
.
updateCmbLabel
();
}
},
/*
* Reflow the slider when the high handle changes (called with throttle)
*/
onHighHandleChange
:
function
()
{
this
.
setMinAndMax
();
this
.
updateHighHandle
(
this
.
valueToOffset
(
this
.
scope
.
rzSliderHigh
));
this
.
updateSelectionBar
();
this
.
updateTicksScale
();
this
.
updateCmbLabel
();
this
.
updateAriaAttributes
();
},
/**
/**
* Read the user options and apply them to the slider model
* Read the user options and apply them to the slider model
*/
*/
...
...
tests/spec/rz-slider-service-test.js
View file @
840eb79c
...
@@ -2,20 +2,24 @@
...
@@ -2,20 +2,24 @@
describe
(
'rzslider - '
,
function
()
{
describe
(
'rzslider - '
,
function
()
{
var
RzSlider
,
var
RzSlider
,
RzSliderOptions
,
$rootScope
,
$rootScope
,
scope
,
scope
,
$compile
,
$compile
,
$timeout
,
$timeout
,
$window
,
element
,
element
,
slider
;
slider
;
beforeEach
(
module
(
'rzModule'
));
beforeEach
(
module
(
'rzModule'
));
beforeEach
(
module
(
'appTemplates'
));
beforeEach
(
module
(
'appTemplates'
));
beforeEach
(
inject
(
function
(
_RzSlider_
,
_
$rootScope_
,
_$compile_
,
_$timeout
_
)
{
beforeEach
(
inject
(
function
(
_RzSlider_
,
_
RzSliderOptions_
,
_$rootScope_
,
_$compile_
,
_$timeout_
,
_$window
_
)
{
RzSlider
=
_RzSlider_
;
RzSlider
=
_RzSlider_
;
RzSliderOptions
=
_RzSliderOptions_
;
$rootScope
=
_$rootScope_
;
$rootScope
=
_$rootScope_
;
$compile
=
_$compile_
;
$compile
=
_$compile_
;
$timeout
=
_$timeout_
;
$timeout
=
_$timeout_
;
$window
=
_$window_
;
}));
}));
/*
/*
...
@@ -50,7 +54,151 @@ describe('rzslider - ', function() {
...
@@ -50,7 +54,151 @@ describe('rzslider - ', function() {
$timeout
.
flush
();
//to flush the throttle function
$timeout
.
flush
();
//to flush the throttle function
expect
(
scope
.
slider
.
value
).
to
.
equal
(
60
);
expect
(
scope
.
slider
.
value
).
to
.
equal
(
60
);
});
});
it
(
'should call calcViewDimensions() on reCalcViewDimensions'
,
function
()
{
sinon
.
spy
(
slider
,
'calcViewDimensions'
);
scope
.
$broadcast
(
'reCalcViewDimensions'
);
slider
.
calcViewDimensions
.
called
.
should
.
be
.
true
;
});
it
(
'should reset everything on rzSliderForceRender'
,
function
()
{
sinon
.
spy
(
slider
,
'resetLabelsValue'
);
sinon
.
spy
(
slider
,
'resetSlider'
);
sinon
.
spy
(
slider
,
'onLowHandleChange'
);
scope
.
$broadcast
(
'rzSliderForceRender'
);
slider
.
resetLabelsValue
.
called
.
should
.
be
.
true
;
slider
.
resetSlider
.
called
.
should
.
be
.
true
;
slider
.
onLowHandleChange
.
called
.
should
.
be
.
true
;
});
it
(
'should call calcViewDimensions() on window resize event'
,
function
()
{
sinon
.
spy
(
slider
,
'calcViewDimensions'
);
angular
.
element
(
$window
).
triggerHandler
(
'resize'
);
slider
.
calcViewDimensions
.
called
.
should
.
be
.
true
;
});
it
(
'should unregister all dom events on $destroy'
,
function
()
{
sinon
.
spy
(
slider
,
'calcViewDimensions'
);
sinon
.
spy
(
slider
,
'unbindEvents'
);
scope
.
$broadcast
(
'$destroy'
);
angular
.
element
(
$window
).
triggerHandler
(
'resize'
);
slider
.
calcViewDimensions
.
called
.
should
.
be
.
false
;
slider
.
unbindEvents
.
called
.
should
.
be
.
true
;
});
});
});
/*
******************************************************************************
RANGE SLIDER INIT
******************************************************************************
*/
describe
(
'range slider initialisation'
,
function
()
{
beforeEach
(
function
()
{
var
sliderConf
=
{
min
:
10
,
max
:
90
,
options
:
{
floor
:
0
,
ceil
:
100
,
step
:
10
}
};
createRangeSlider
(
sliderConf
);
});
it
(
'should exist compiled'
,
function
()
{
expect
(
element
.
find
(
'span'
)).
to
.
have
.
length
(
11
);
});
it
(
'should round the model value to the step'
,
function
()
{
scope
.
slider
.
min
=
13
;
scope
.
slider
.
max
=
94
;
scope
.
$digest
();
expect
(
scope
.
slider
.
min
).
to
.
equal
(
10
);
expect
(
scope
.
slider
.
max
).
to
.
equal
(
90
);
scope
.
slider
.
min
=
15
;
scope
.
slider
.
max
=
95
;
scope
.
$digest
();
$timeout
.
flush
();
//to flush the throttle function
expect
(
scope
.
slider
.
min
).
to
.
equal
(
20
);
expect
(
scope
.
slider
.
max
).
to
.
equal
(
100
);
});
it
(
'should reset everything on rzSliderForceRender'
,
function
()
{
sinon
.
spy
(
slider
,
'resetLabelsValue'
);
sinon
.
spy
(
slider
,
'resetSlider'
);
sinon
.
spy
(
slider
,
'onLowHandleChange'
);
sinon
.
spy
(
slider
,
'onHighHandleChange'
);
scope
.
$broadcast
(
'rzSliderForceRender'
);
slider
.
resetLabelsValue
.
called
.
should
.
be
.
true
;
slider
.
resetSlider
.
called
.
should
.
be
.
true
;
slider
.
onLowHandleChange
.
called
.
should
.
be
.
true
;
slider
.
onHighHandleChange
.
called
.
should
.
be
.
true
;
});
});
/*
******************************************************************************
RzSliderOptions
******************************************************************************
*/
describe
(
'RzSliderOptions'
,
function
()
{
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
);
});
});
/*
******************************************************************************
Slider with ticks
******************************************************************************
*/
describe
(
'slider with ticks'
,
function
()
{
beforeEach
(
function
()
{
var
sliderConf
=
{
value
:
50
,
options
:
{
floor
:
0
,
ceil
:
100
,
step
:
10
,
showTicks
:
true
}
};
createSlider
(
sliderConf
);
});
it
(
'should create the correct number of ticks'
,
function
()
{
expect
(
element
[
0
].
querySelectorAll
(
'.tick'
)).
to
.
have
.
length
(
11
);
});
});
/*
/*
******************************************************************************
******************************************************************************
KEYBOARD CONTROLS
KEYBOARD CONTROLS
...
@@ -530,7 +678,10 @@ describe('rzslider - ', function() {
...
@@ -530,7 +678,10 @@ describe('rzslider - ', function() {
function
initSlider
(
sliderObj
,
template
)
{
function
initSlider
(
sliderObj
,
template
)
{
scope
=
$rootScope
.
$new
();
scope
=
$rootScope
.
$new
();
scope
.
slider
=
sliderObj
;
scope
.
slider
=
sliderObj
;
var
parent
=
angular
.
element
(
'<div style="width: 1000px"></div>'
);
element
=
$compile
(
template
)(
scope
);
element
=
$compile
(
template
)(
scope
);
parent
.
append
(
element
);
angular
.
element
(
document
).
find
(
'body'
).
append
(
parent
);
scope
.
$apply
();
scope
.
$apply
();
slider
=
element
.
isolateScope
().
slider
;
slider
=
element
.
isolateScope
().
slider
;
$timeout
.
flush
();
$timeout
.
flush
();
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment