2008-06-09 05:59:18 +00:00
|
|
|
/*
|
|
|
|
* slider unit tests
|
|
|
|
*/
|
|
|
|
(function($) {
|
2008-11-12 02:52:31 +00:00
|
|
|
//
|
2008-12-23 10:38:12 +00:00
|
|
|
// Slider Test Helper Functions
|
2008-11-12 02:52:31 +00:00
|
|
|
//
|
|
|
|
|
2008-12-23 10:38:12 +00:00
|
|
|
var el, options;
|
2008-06-04 02:34:33 +00:00
|
|
|
|
2008-12-23 10:38:12 +00:00
|
|
|
function handle() {
|
|
|
|
return el.find(".ui-slider-handle");
|
2008-06-04 02:34:33 +00:00
|
|
|
}
|
|
|
|
|
2008-11-12 02:52:31 +00:00
|
|
|
// Slider Tests
|
2009-02-02 05:58:49 +00:00
|
|
|
module("slider: core");
|
2008-11-12 02:52:31 +00:00
|
|
|
|
2008-12-23 10:38:12 +00:00
|
|
|
test("keydown HOME on handle sets value to min", function() {
|
2012-07-17 19:04:16 +00:00
|
|
|
expect( 2 );
|
2008-12-23 10:38:12 +00:00
|
|
|
el = $('<div></div>');
|
|
|
|
options = {
|
|
|
|
max: 5,
|
|
|
|
min: -5,
|
|
|
|
orientation: 'horizontal',
|
|
|
|
step: 1
|
|
|
|
};
|
|
|
|
el.slider(options);
|
|
|
|
|
|
|
|
el.slider("value", 0);
|
|
|
|
|
|
|
|
handle().simulate("keydown", { keyCode: $.ui.keyCode.HOME });
|
2012-02-28 14:56:32 +00:00
|
|
|
equal(el.slider("value"), options.min);
|
2008-12-23 10:38:12 +00:00
|
|
|
|
2012-02-28 14:56:32 +00:00
|
|
|
el.slider('destroy');
|
2008-12-23 10:38:12 +00:00
|
|
|
|
|
|
|
el = $('<div></div>');
|
|
|
|
options = {
|
|
|
|
max: 5,
|
|
|
|
min: -5,
|
|
|
|
orientation: 'vertical',
|
|
|
|
step: 1
|
|
|
|
};
|
|
|
|
el.slider(options);
|
|
|
|
|
|
|
|
el.slider("value", 0);
|
|
|
|
|
|
|
|
handle().simulate("keydown", { keyCode: $.ui.keyCode.HOME });
|
2012-02-28 14:56:32 +00:00
|
|
|
equal(el.slider("value"), options.min);
|
2008-12-23 10:38:12 +00:00
|
|
|
|
|
|
|
el.slider('destroy');
|
|
|
|
});
|
|
|
|
|
|
|
|
test("keydown END on handle sets value to max", function() {
|
2012-07-17 19:04:16 +00:00
|
|
|
expect( 2 );
|
2008-12-23 10:38:12 +00:00
|
|
|
el = $('<div></div>');
|
|
|
|
options = {
|
|
|
|
max: 5,
|
|
|
|
min: -5,
|
|
|
|
orientation: 'horizontal',
|
|
|
|
step: 1
|
|
|
|
};
|
|
|
|
el.slider(options);
|
|
|
|
|
|
|
|
el.slider("value", 0);
|
|
|
|
|
|
|
|
handle().simulate("keydown", { keyCode: $.ui.keyCode.END });
|
2012-02-28 14:56:32 +00:00
|
|
|
equal(el.slider("value"), options.max);
|
2008-12-23 10:38:12 +00:00
|
|
|
|
2012-02-28 14:56:32 +00:00
|
|
|
el.slider('destroy');
|
2008-12-23 10:38:12 +00:00
|
|
|
|
|
|
|
el = $('<div></div>');
|
|
|
|
options = {
|
|
|
|
max: 5,
|
|
|
|
min: -5,
|
|
|
|
orientation: 'vertical',
|
|
|
|
step: 1
|
|
|
|
};
|
|
|
|
el.slider(options);
|
|
|
|
|
|
|
|
el.slider("value", 0);
|
|
|
|
|
|
|
|
handle().simulate("keydown", { keyCode: $.ui.keyCode.END });
|
2012-02-28 14:56:32 +00:00
|
|
|
equal(el.slider("value"), options.max);
|
2008-12-23 10:38:12 +00:00
|
|
|
|
|
|
|
el.slider('destroy');
|
|
|
|
});
|
|
|
|
|
2009-11-09 03:10:57 +00:00
|
|
|
test("keydown PAGE_UP on handle increases value by 1/5 range, not greater than max", function() {
|
2012-07-17 19:04:16 +00:00
|
|
|
expect( 4 );
|
2009-11-09 03:10:57 +00:00
|
|
|
$.each(['horizontal', 'vertical'], function(i, orientation) {
|
|
|
|
el = $('<div></div>');
|
|
|
|
options = {
|
|
|
|
max: 100,
|
|
|
|
min: 0,
|
|
|
|
orientation: orientation,
|
|
|
|
step: 1
|
|
|
|
};
|
|
|
|
el.slider(options);
|
|
|
|
|
|
|
|
el.slider("value", 70);
|
|
|
|
|
|
|
|
handle().simulate("keydown", { keyCode: $.ui.keyCode.PAGE_UP });
|
2012-02-28 14:56:32 +00:00
|
|
|
equal(el.slider("value"), 90);
|
2009-11-09 03:10:57 +00:00
|
|
|
|
|
|
|
handle().simulate("keydown", { keyCode: $.ui.keyCode.PAGE_UP });
|
2012-02-28 14:56:32 +00:00
|
|
|
equal(el.slider("value"), 100);
|
2009-11-09 03:10:57 +00:00
|
|
|
|
|
|
|
el.slider("destroy");
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
test("keydown PAGE_DOWN on handle decreases value by 1/5 range, not less than min", function() {
|
2012-07-17 19:04:16 +00:00
|
|
|
expect( 4 );
|
2009-11-09 03:10:57 +00:00
|
|
|
$.each(['horizontal', 'vertical'], function(i, orientation) {
|
|
|
|
el = $('<div></div>');
|
|
|
|
options = {
|
|
|
|
max: 100,
|
|
|
|
min: 0,
|
|
|
|
orientation: orientation,
|
|
|
|
step: 1
|
|
|
|
};
|
|
|
|
el.slider(options);
|
|
|
|
|
|
|
|
el.slider("value", 30);
|
|
|
|
|
|
|
|
handle().simulate("keydown", { keyCode: $.ui.keyCode.PAGE_DOWN });
|
2012-02-28 14:56:32 +00:00
|
|
|
equal(el.slider("value"), 10);
|
2009-11-09 03:10:57 +00:00
|
|
|
|
|
|
|
handle().simulate("keydown", { keyCode: $.ui.keyCode.PAGE_DOWN });
|
2012-02-28 14:56:32 +00:00
|
|
|
equal(el.slider("value"), 0);
|
2009-11-09 03:10:57 +00:00
|
|
|
|
|
|
|
el.slider("destroy");
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2008-12-23 10:38:12 +00:00
|
|
|
test("keydown UP on handle increases value by step, not greater than max", function() {
|
2012-07-17 19:04:16 +00:00
|
|
|
expect( 4 );
|
2008-12-23 10:38:12 +00:00
|
|
|
el = $('<div></div>');
|
|
|
|
options = {
|
|
|
|
max: 5,
|
|
|
|
min: -5,
|
|
|
|
orientation: 'horizontal',
|
|
|
|
step: 1
|
|
|
|
};
|
|
|
|
el.slider(options);
|
|
|
|
|
|
|
|
el.slider("value", options.max - options.step);
|
|
|
|
|
|
|
|
handle().simulate("keydown", { keyCode: $.ui.keyCode.UP });
|
2012-02-28 14:56:32 +00:00
|
|
|
equal(el.slider("value"), options.max);
|
2008-12-23 10:38:12 +00:00
|
|
|
|
|
|
|
handle().simulate("keydown", { keyCode: $.ui.keyCode.UP });
|
2012-02-28 14:56:32 +00:00
|
|
|
equal(el.slider("value"), options.max);
|
2008-12-23 10:38:12 +00:00
|
|
|
|
2012-02-28 14:56:32 +00:00
|
|
|
el.slider("destroy");
|
2008-12-23 10:38:12 +00:00
|
|
|
|
|
|
|
el = $('<div></div>');
|
|
|
|
options = {
|
|
|
|
max: 5,
|
|
|
|
min: -5,
|
|
|
|
orientation: 'vertical',
|
|
|
|
step: 1
|
|
|
|
};
|
|
|
|
el.slider(options);
|
|
|
|
|
|
|
|
el.slider("value", options.max - options.step);
|
|
|
|
|
|
|
|
handle().simulate("keydown", { keyCode: $.ui.keyCode.UP });
|
2012-02-28 14:56:32 +00:00
|
|
|
equal(el.slider("value"), options.max);
|
2008-12-23 10:38:12 +00:00
|
|
|
|
|
|
|
handle().simulate("keydown", { keyCode: $.ui.keyCode.UP });
|
2012-02-28 14:56:32 +00:00
|
|
|
equal(el.slider("value"), options.max);
|
2008-12-23 10:38:12 +00:00
|
|
|
|
2012-02-28 14:56:32 +00:00
|
|
|
el.slider("destroy");
|
2008-12-23 10:38:12 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
test("keydown RIGHT on handle increases value by step, not greater than max", function() {
|
2012-07-17 19:04:16 +00:00
|
|
|
expect( 4 );
|
2008-12-23 10:38:12 +00:00
|
|
|
el = $('<div></div>');
|
|
|
|
options = {
|
|
|
|
max: 5,
|
|
|
|
min: -5,
|
|
|
|
orientation: 'horizontal',
|
|
|
|
step: 1
|
|
|
|
};
|
|
|
|
el.slider(options);
|
|
|
|
|
|
|
|
el.slider("value", options.max - options.step);
|
|
|
|
|
|
|
|
handle().simulate("keydown", { keyCode: $.ui.keyCode.RIGHT });
|
2012-02-28 14:56:32 +00:00
|
|
|
equal(el.slider("value"), options.max);
|
2008-12-23 10:38:12 +00:00
|
|
|
|
|
|
|
handle().simulate("keydown", { keyCode: $.ui.keyCode.RIGHT });
|
2012-02-28 14:56:32 +00:00
|
|
|
equal(el.slider("value"), options.max);
|
2008-12-23 10:38:12 +00:00
|
|
|
|
2012-02-28 14:56:32 +00:00
|
|
|
el.slider("destroy");
|
2008-12-23 10:38:12 +00:00
|
|
|
|
|
|
|
el = $('<div></div>');
|
|
|
|
options = {
|
|
|
|
max: 5,
|
|
|
|
min: -5,
|
|
|
|
orientation: 'vertical',
|
|
|
|
step: 1
|
|
|
|
};
|
|
|
|
el.slider(options);
|
|
|
|
|
|
|
|
el.slider("value", options.max - options.step);
|
|
|
|
|
|
|
|
handle().simulate("keydown", { keyCode: $.ui.keyCode.RIGHT });
|
2012-02-28 14:56:32 +00:00
|
|
|
equal(el.slider("value"), options.max);
|
2008-12-23 10:38:12 +00:00
|
|
|
|
|
|
|
handle().simulate("keydown", { keyCode: $.ui.keyCode.RIGHT });
|
2012-02-28 14:56:32 +00:00
|
|
|
equal(el.slider("value"), options.max);
|
2008-12-23 10:38:12 +00:00
|
|
|
|
2012-02-28 14:56:32 +00:00
|
|
|
el.slider("destroy");
|
2008-12-23 10:38:12 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
test("keydown DOWN on handle decreases value by step, not less than min", function() {
|
2012-07-17 19:04:16 +00:00
|
|
|
expect( 4 );
|
2008-12-23 10:38:12 +00:00
|
|
|
el = $('<div></div>');
|
|
|
|
options = {
|
|
|
|
max: 5,
|
|
|
|
min: -5,
|
|
|
|
orientation: 'horizontal',
|
|
|
|
step: 1
|
|
|
|
};
|
|
|
|
el.slider(options);
|
|
|
|
|
|
|
|
el.slider("value", options.min + options.step);
|
|
|
|
|
|
|
|
handle().simulate("keydown", { keyCode: $.ui.keyCode.DOWN });
|
2012-02-28 14:56:32 +00:00
|
|
|
equal(el.slider("value"), options.min);
|
2008-12-23 10:38:12 +00:00
|
|
|
|
|
|
|
handle().simulate("keydown", { keyCode: $.ui.keyCode.DOWN });
|
2012-02-28 14:56:32 +00:00
|
|
|
equal(el.slider("value"), options.min);
|
2008-12-23 10:38:12 +00:00
|
|
|
|
2012-02-28 14:56:32 +00:00
|
|
|
el.slider("destroy");
|
2008-12-23 10:38:12 +00:00
|
|
|
|
|
|
|
el = $('<div></div>');
|
|
|
|
options = {
|
|
|
|
max: 5,
|
|
|
|
min: -5,
|
|
|
|
orientation: 'vertical',
|
|
|
|
step: 1
|
|
|
|
};
|
|
|
|
el.slider(options);
|
|
|
|
|
|
|
|
el.slider("value", options.min + options.step);
|
|
|
|
|
|
|
|
handle().simulate("keydown", { keyCode: $.ui.keyCode.DOWN });
|
2012-02-28 14:56:32 +00:00
|
|
|
equal(el.slider("value"), options.min);
|
2008-12-23 10:38:12 +00:00
|
|
|
|
|
|
|
handle().simulate("keydown", { keyCode: $.ui.keyCode.DOWN });
|
2012-02-28 14:56:32 +00:00
|
|
|
equal(el.slider("value"), options.min);
|
2008-12-23 10:38:12 +00:00
|
|
|
|
2012-02-28 14:56:32 +00:00
|
|
|
el.slider("destroy");
|
2008-12-23 10:38:12 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
test("keydown LEFT on handle decreases value by step, not less than min", function() {
|
2012-07-17 19:04:16 +00:00
|
|
|
expect( 4 );
|
2008-12-23 10:38:12 +00:00
|
|
|
el = $('<div></div>');
|
|
|
|
options = {
|
|
|
|
max: 5,
|
|
|
|
min: -5,
|
|
|
|
orientation: 'horizontal',
|
|
|
|
step: 1
|
|
|
|
};
|
|
|
|
el.slider(options);
|
|
|
|
|
|
|
|
el.slider("value", options.min + options.step);
|
|
|
|
|
|
|
|
handle().simulate("keydown", { keyCode: $.ui.keyCode.LEFT });
|
2012-02-28 14:56:32 +00:00
|
|
|
equal(el.slider("value"), options.min);
|
2008-12-23 10:38:12 +00:00
|
|
|
|
|
|
|
handle().simulate("keydown", { keyCode: $.ui.keyCode.LEFT });
|
2012-02-28 14:56:32 +00:00
|
|
|
equal(el.slider("value"), options.min);
|
2008-12-23 10:38:12 +00:00
|
|
|
|
2012-02-28 14:56:32 +00:00
|
|
|
el.slider("destroy");
|
2008-12-23 10:38:12 +00:00
|
|
|
|
|
|
|
el = $('<div></div>');
|
|
|
|
options = {
|
|
|
|
max: 5,
|
|
|
|
min: -5,
|
|
|
|
orientation: 'vertical',
|
|
|
|
step: 1
|
|
|
|
};
|
|
|
|
el.slider(options);
|
|
|
|
|
|
|
|
el.slider("value", options.min + options.step);
|
|
|
|
|
|
|
|
handle().simulate("keydown", { keyCode: $.ui.keyCode.LEFT });
|
2012-02-28 14:56:32 +00:00
|
|
|
equal(el.slider("value"), options.min);
|
2008-12-23 10:38:12 +00:00
|
|
|
|
|
|
|
handle().simulate("keydown", { keyCode: $.ui.keyCode.LEFT });
|
2012-02-28 14:56:32 +00:00
|
|
|
equal(el.slider("value"), options.min);
|
2008-12-23 10:38:12 +00:00
|
|
|
|
2012-02-28 14:56:32 +00:00
|
|
|
el.slider("destroy");
|
2008-12-23 10:38:12 +00:00
|
|
|
});
|
|
|
|
|
2008-06-09 05:59:18 +00:00
|
|
|
})(jQuery);
|