mirror of
https://github.com/Hopiu/jquery-mobile.git
synced 2026-04-30 19:04:43 +00:00
61 lines
No EOL
1.6 KiB
JavaScript
61 lines
No EOL
1.6 KiB
JavaScript
/*
|
|
* mobile slider unit tests
|
|
*/
|
|
|
|
(function($){
|
|
module('jquery.mobile.slider.js');
|
|
|
|
var keypressTest = function(opts){
|
|
var slider = $(opts.selector),
|
|
val = window.parseFloat(slider.val()),
|
|
handle = slider.siblings('.ui-slider').find('.ui-slider-handle');
|
|
|
|
expect( opts.keyCodes.length );
|
|
|
|
$.each(opts.keyCodes, function(i, elem){
|
|
$.Event.prototype.keyCode = $.mobile.keyCode[elem];
|
|
handle.trigger('keydown');
|
|
val = val + opts.increment;
|
|
same(val, window.parseFloat(slider.val(), 10), "new value is one larger");
|
|
});
|
|
};
|
|
|
|
test( "slider should move right with up, right, and page up keypress", function(){
|
|
keypressTest({
|
|
selector: '#range-slider-up',
|
|
keyCodes: ['UP', 'RIGHT', 'PAGE_UP'],
|
|
increment: 1
|
|
});
|
|
});
|
|
|
|
test( "slider should move right with down, left, and page down keypress", function(){
|
|
keypressTest({
|
|
selector: '#range-slider-down',
|
|
keyCodes: ['DOWN', 'LEFT', 'PAGE_DOWN'],
|
|
increment: -1
|
|
});
|
|
});
|
|
|
|
test( "slider should move to range minimum on end keypress", function(){
|
|
var selector = "#range-slider-end",
|
|
initialVal = window.parseFloat($(selector).val(), 10),
|
|
max = window.parseFloat($(selector).attr('max'), 10);
|
|
|
|
keypressTest({
|
|
selector: selector,
|
|
keyCodes: ['END'],
|
|
increment: max - initialVal
|
|
});
|
|
});
|
|
|
|
test( "slider should move to range minimum on end keypress", function(){
|
|
var selector = "#range-slider-home",
|
|
initialVal = window.parseFloat($(selector).val(), 10);
|
|
|
|
keypressTest({
|
|
selector: selector,
|
|
keyCodes: ['HOME'],
|
|
increment: 0 - initialVal
|
|
});
|
|
});
|
|
})(jQuery); |