jquery-ui/tests/unit/slider/slider_core.js

298 lines
6.7 KiB
JavaScript
Raw Normal View History

2013-02-07 14:33:26 +00:00
(function( $ ) {
//
// Slider Test Helper Functions
//
2013-02-07 14:33:26 +00:00
var element, options;
2008-06-04 02:34:33 +00:00
function handle() {
2013-02-07 14:33:26 +00:00
return element.find( ".ui-slider-handle" );
2008-06-04 02:34:33 +00:00
}
// Slider Tests
2013-02-07 14:33:26 +00:00
module( "slider: core" );
2013-02-07 14:33:26 +00:00
test( "keydown HOME on handle sets value to min", function() {
expect( 2 );
2013-02-07 14:33:26 +00:00
element = $( "<div></div>" );
options = {
max: 5,
min: -5,
orientation: "horizontal",
step: 1
};
2013-02-07 14:33:26 +00:00
element.slider( options );
2013-02-07 14:33:26 +00:00
element.slider( "value", 0 );
2013-02-07 14:33:26 +00:00
handle().simulate( "keydown", { keyCode: $.ui.keyCode.HOME } );
equal(element.slider( "value" ), options.min );
2013-02-07 14:33:26 +00:00
element.slider( "destroy" );
2013-02-07 14:33:26 +00:00
element = $( "<div></div>" );
options = {
max: 5,
min: -5,
orientation: "vertical",
step: 1
};
2013-02-07 14:33:26 +00:00
element.slider( options );
2013-02-07 14:33:26 +00:00
element.slider( "value", 0 );
2013-02-07 14:33:26 +00:00
handle().simulate( "keydown", { keyCode: $.ui.keyCode.HOME } );
equal(element.slider( "value" ), options.min) ;
2013-02-07 14:33:26 +00:00
element.slider( "destroy" );
});
2013-02-07 14:33:26 +00:00
test( "keydown END on handle sets value to max", function() {
expect( 2 );
2013-02-07 14:33:26 +00:00
element = $( "<div></div>" );
options = {
max: 5,
min: -5,
orientation: "horizontal",
step: 1
};
2013-02-07 14:33:26 +00:00
element.slider( options );
2013-02-07 14:33:26 +00:00
element.slider( "value", 0 );
2013-02-07 14:33:26 +00:00
handle().simulate( "keydown", { keyCode: $.ui.keyCode.END } );
equal(element.slider( "value" ), options.max) ;
2013-02-07 14:33:26 +00:00
element.slider( "destroy" );
2013-02-07 14:33:26 +00:00
element = $( "<div></div>" );
options = {
max: 5,
min: -5,
orientation: "vertical",
step: 1
};
2013-02-07 14:33:26 +00:00
element.slider( options );
2013-02-07 14:33:26 +00:00
element.slider( "value", 0 );
2013-02-07 14:33:26 +00:00
handle().simulate( "keydown", { keyCode: $.ui.keyCode.END } );
equal(element.slider( "value" ), options.max );
2013-02-07 14:33:26 +00:00
element.slider( "destroy" );
});
2013-02-07 14:33:26 +00:00
test( "keydown PAGE_UP on handle increases value by 1/5 range, not greater than max", function() {
expect( 4 );
2013-02-07 14:33:26 +00:00
$.each( [ "horizontal", "vertical" ], function( i, orientation ) {
element = $( "<div></div>" );
options = {
max: 100,
min: 0,
orientation: orientation,
step: 1
};
2013-02-07 14:33:26 +00:00
element.slider( options );
2013-02-07 14:33:26 +00:00
element.slider( "value", 70);
2013-02-07 14:33:26 +00:00
handle().simulate( "keydown", { keyCode: $.ui.keyCode.PAGE_UP } );
equal(element.slider( "value" ), 90);
2013-02-07 14:33:26 +00:00
handle().simulate( "keydown", { keyCode: $.ui.keyCode.PAGE_UP } );
equal(element.slider( "value" ), 100);
2013-02-07 14:33:26 +00:00
element.slider( "destroy" );
});
});
2013-02-07 14:33:26 +00:00
test( "keydown PAGE_DOWN on handle decreases value by 1/5 range, not less than min", function() {
expect( 4 );
2013-02-07 14:33:26 +00:00
$.each( [ "horizontal", "vertical" ], function( i, orientation ) {
element = $( "<div></div>" );
options = {
max: 100,
min: 0,
orientation: orientation,
step: 1
};
2013-02-07 14:33:26 +00:00
element.slider( options );
2013-02-07 14:33:26 +00:00
element.slider( "value", 30);
2013-02-07 14:33:26 +00:00
handle().simulate( "keydown", { keyCode: $.ui.keyCode.PAGE_DOWN } );
equal(element.slider( "value" ), 10);
2013-02-07 14:33:26 +00:00
handle().simulate( "keydown", { keyCode: $.ui.keyCode.PAGE_DOWN } );
equal(element.slider( "value" ), 0 );
2013-02-07 14:33:26 +00:00
element.slider( "destroy" );
});
});
2013-02-07 14:33:26 +00:00
test( "keydown UP on handle increases value by step, not greater than max", function() {
expect( 4 );
2013-02-07 14:33:26 +00:00
element = $( "<div></div>" );
options = {
max: 5,
min: -5,
orientation: "horizontal",
step: 1
};
2013-02-07 14:33:26 +00:00
element.slider(options);
2013-02-07 14:33:26 +00:00
element.slider( "value", options.max - options.step );
2013-02-07 14:33:26 +00:00
handle().simulate( "keydown", { keyCode: $.ui.keyCode.UP } );
equal(element.slider( "value" ), options.max );
2013-02-07 14:33:26 +00:00
handle().simulate( "keydown", { keyCode: $.ui.keyCode.UP } );
equal(element.slider( "value" ), options.max );
2013-02-07 14:33:26 +00:00
element.slider( "destroy" );
2013-02-07 14:33:26 +00:00
element = $( "<div></div>" );
options = {
max: 5,
min: -5,
orientation: "vertical",
step: 1
};
2013-02-07 14:33:26 +00:00
element.slider( options );
2013-02-07 14:33:26 +00:00
element.slider( "value", options.max - options.step );
2013-02-07 14:33:26 +00:00
handle().simulate( "keydown", { keyCode: $.ui.keyCode.UP } );
equal(element.slider( "value" ), options.max );
2013-02-07 14:33:26 +00:00
handle().simulate( "keydown", { keyCode: $.ui.keyCode.UP } );
equal(element.slider( "value" ), options.max );
2013-02-07 14:33:26 +00:00
element.slider( "destroy" );
});
2013-02-07 14:33:26 +00:00
test( "keydown RIGHT on handle increases value by step, not greater than max", function() {
expect( 4 );
2013-02-07 14:33:26 +00:00
element = $( "<div></div>" );
options = {
max: 5,
min: -5,
orientation: "horizontal",
step: 1
};
2013-02-07 14:33:26 +00:00
element.slider(options);
2013-02-07 14:33:26 +00:00
element.slider( "value", options.max - options.step );
2013-02-07 14:33:26 +00:00
handle().simulate( "keydown", { keyCode: $.ui.keyCode.RIGHT } );
equal(element.slider( "value" ), options.max);
2013-02-07 14:33:26 +00:00
handle().simulate( "keydown", { keyCode: $.ui.keyCode.RIGHT } );
equal(element.slider( "value" ), options.max );
2013-02-07 14:33:26 +00:00
element.slider( "destroy" );
2013-02-07 14:33:26 +00:00
element = $( "<div></div>" );
options = {
max: 5,
min: -5,
orientation: "vertical",
step: 1
};
2013-02-07 14:33:26 +00:00
element.slider( options );
2013-02-07 14:33:26 +00:00
element.slider( "value", options.max - options.step );
2013-02-07 14:33:26 +00:00
handle().simulate( "keydown", { keyCode: $.ui.keyCode.RIGHT } );
equal(element.slider( "value" ), options.max );
2013-02-07 14:33:26 +00:00
handle().simulate( "keydown", { keyCode: $.ui.keyCode.RIGHT } );
equal(element.slider( "value" ), options.max );
2013-02-07 14:33:26 +00:00
element.slider( "destroy" );
});
2013-02-07 14:33:26 +00:00
test( "keydown DOWN on handle decreases value by step, not less than min", function() {
expect( 4 );
2013-02-07 14:33:26 +00:00
element = $( "<div></div>" );
options = {
max: 5,
min: -5,
orientation: "horizontal",
step: 1
};
2013-02-07 14:33:26 +00:00
element.slider( options );
2013-02-07 14:33:26 +00:00
element.slider( "value", options.min + options.step );
2013-02-07 14:33:26 +00:00
handle().simulate( "keydown", { keyCode: $.ui.keyCode.DOWN } );
equal(element.slider( "value" ), options.min);
2013-02-07 14:33:26 +00:00
handle().simulate( "keydown", { keyCode: $.ui.keyCode.DOWN } );
equal(element.slider( "value" ), options.min );
2013-02-07 14:33:26 +00:00
element.slider( "destroy" );
2013-02-07 14:33:26 +00:00
element = $( "<div></div>" );
options = {
max: 5,
min: -5,
orientation: "vertical",
step: 1
};
2013-02-07 14:33:26 +00:00
element.slider( options );
2013-02-07 14:33:26 +00:00
element.slider( "value", options.min + options.step );
2013-02-07 14:33:26 +00:00
handle().simulate( "keydown", { keyCode: $.ui.keyCode.DOWN } );
equal(element.slider( "value" ), options.min);
2013-02-07 14:33:26 +00:00
handle().simulate( "keydown", { keyCode: $.ui.keyCode.DOWN } );
equal(element.slider( "value" ), options.min );
2013-02-07 14:33:26 +00:00
element.slider( "destroy" );
});
2013-02-07 14:33:26 +00:00
test( "keydown LEFT on handle decreases value by step, not less than min", function() {
expect( 4 );
2013-02-07 14:33:26 +00:00
element = $( "<div></div>" );
options = {
max: 5,
min: -5,
orientation: "horizontal",
step: 1
};
2013-02-07 14:33:26 +00:00
element.slider(options);
2013-02-07 14:33:26 +00:00
element.slider( "value", options.min + options.step );
2013-02-07 14:33:26 +00:00
handle().simulate( "keydown", { keyCode: $.ui.keyCode.LEFT } );
equal(element.slider( "value" ), options.min );
2013-02-07 14:33:26 +00:00
handle().simulate( "keydown", { keyCode: $.ui.keyCode.LEFT } );
equal(element.slider( "value" ), options.min );
2013-02-07 14:33:26 +00:00
element.slider( "destroy" );
2013-02-07 14:33:26 +00:00
element = $( "<div></div>" );
options = {
max: 5,
min: -5,
orientation: "vertical",
step: 1
};
2013-02-07 14:33:26 +00:00
element.slider( options );
2013-02-07 14:33:26 +00:00
element.slider( "value", options.min + options.step );
2013-02-07 14:33:26 +00:00
handle().simulate( "keydown", { keyCode: $.ui.keyCode.LEFT } );
equal(element.slider( "value" ), options.min );
2013-02-07 14:33:26 +00:00
handle().simulate( "keydown", { keyCode: $.ui.keyCode.LEFT } );
equal(element.slider( "value" ), options.min );
2013-02-07 14:33:26 +00:00
element.slider( "destroy" );
});
2013-02-07 14:33:26 +00:00
})( jQuery );