2013-02-07 14:33:26 +00:00
|
|
|
(function( $ ) {
|
2009-02-02 05:58:49 +00:00
|
|
|
|
2013-02-07 14:33:26 +00:00
|
|
|
module( "slider: methods" );
|
2009-02-02 05:58:49 +00:00
|
|
|
|
2013-02-07 14:33:26 +00:00
|
|
|
test( "init", function() {
|
2010-08-27 18:48:17 +00:00
|
|
|
expect(5);
|
2009-02-02 07:13:25 +00:00
|
|
|
|
2013-02-07 14:33:26 +00:00
|
|
|
$( "<div></div>" ).appendTo( "body" ).slider().remove();
|
|
|
|
ok( true, ".slider() called on element" );
|
2009-02-02 07:13:25 +00:00
|
|
|
|
2013-02-07 14:33:26 +00:00
|
|
|
$( [] ).slider().remove();
|
|
|
|
ok( true, ".slider() called on empty collection" );
|
2009-02-02 07:13:25 +00:00
|
|
|
|
2013-02-07 14:33:26 +00:00
|
|
|
$( "<div></div>" ).slider().remove();
|
|
|
|
ok( true, ".slider() called on disconnected DOMElement" );
|
2009-02-02 07:13:25 +00:00
|
|
|
|
2013-02-07 14:33:26 +00:00
|
|
|
var element = $( "<div></div>" ).slider();
|
|
|
|
element.slider( "option", "foo" );
|
|
|
|
element.remove();
|
|
|
|
ok( true, "arbitrary option getter after init" );
|
2009-02-02 07:13:25 +00:00
|
|
|
|
2013-02-07 14:33:26 +00:00
|
|
|
$( "<div></div>" ).slider().slider( "option", "foo", "bar" ).remove();
|
|
|
|
ok( true, "arbitrary option setter after init" );
|
2009-02-02 05:58:49 +00:00
|
|
|
});
|
|
|
|
|
2013-02-07 14:33:26 +00:00
|
|
|
test( "destroy", function() {
|
2012-07-17 19:04:16 +00:00
|
|
|
expect( 1 );
|
|
|
|
domEqual( "#slider1", function() {
|
|
|
|
$( "#slider1" ).slider().slider( "destroy" );
|
|
|
|
});
|
2009-02-02 05:58:49 +00:00
|
|
|
});
|
|
|
|
|
2013-02-07 14:33:26 +00:00
|
|
|
test( "enable", function() {
|
2012-07-17 19:04:16 +00:00
|
|
|
expect( 5 );
|
2013-02-07 14:33:26 +00:00
|
|
|
var element,
|
|
|
|
expected = $( "<div></div>" ).slider(),
|
|
|
|
actual = expected.slider( "enable" );
|
|
|
|
equal(actual, expected, "enable is chainable" );
|
2009-09-19 15:19:42 +00:00
|
|
|
|
2013-02-07 14:33:26 +00:00
|
|
|
element = $( "<div></div>" ).slider({ disabled: true });
|
|
|
|
ok( element.hasClass( "ui-state-disabled" ), "slider has ui-state-disabled class before enable method call" );
|
|
|
|
ok( element.hasClass( "ui-slider-disabled" ), "slider has ui-slider-disabled class before enable method call" );
|
|
|
|
element.slider( "enable" );
|
|
|
|
ok( !element.hasClass( "ui-state-disabled" ), "slider does not have ui-state-disabled class after enable method call" );
|
|
|
|
ok( !element.hasClass( "ui-slider-disabled" ), "slider does not have ui-slider-disabled class after enable method call" );
|
2009-02-02 05:58:49 +00:00
|
|
|
});
|
|
|
|
|
2013-02-07 14:33:26 +00:00
|
|
|
test( "disable", function() {
|
2013-03-14 23:08:21 +00:00
|
|
|
expect( 6 );
|
2013-02-07 14:33:26 +00:00
|
|
|
var element,
|
|
|
|
expected = $( "<div></div>" ).slider(),
|
|
|
|
actual = expected.slider( "disable" );
|
|
|
|
equal(actual, expected, "disable is chainable" );
|
2009-09-19 15:19:42 +00:00
|
|
|
|
2013-02-07 14:33:26 +00:00
|
|
|
element = $( "<div></div>" ).slider({ disabled: false });
|
|
|
|
ok( !element.hasClass( "ui-state-disabled" ), "slider does not have ui-state-disabled class before disabled method call" );
|
|
|
|
ok( !element.hasClass( "ui-slider-disabled" ), "slider does not have ui-slider-disabled class before disable method call" );
|
|
|
|
element.slider( "disable" );
|
|
|
|
ok( element.hasClass( "ui-state-disabled" ), "slider has ui-state-disabled class after disable method call" );
|
|
|
|
ok( element.hasClass( "ui-slider-disabled" ), "slider has ui-slider-disabled class after disable method call" );
|
2013-03-14 23:08:21 +00:00
|
|
|
ok( !element.attr( "aria-disabled" ), "slider does not have aria-disabled attr after disable method call" );
|
2009-02-02 05:58:49 +00:00
|
|
|
});
|
|
|
|
|
2013-02-07 14:33:26 +00:00
|
|
|
test( "value", function() {
|
2015-03-04 12:23:17 +00:00
|
|
|
expect( 18 );
|
2013-02-07 14:33:26 +00:00
|
|
|
$( [ false, "min", "max" ] ).each(function() {
|
|
|
|
var element = $( "<div></div>" ).slider({
|
2009-09-19 15:34:20 +00:00
|
|
|
range: this,
|
|
|
|
value: 5
|
|
|
|
});
|
2013-02-07 14:33:26 +00:00
|
|
|
equal( element.slider( "value" ), 5, "range: " + this + " slider method get" );
|
|
|
|
equal( element.slider( "value", 10), element, "value method is chainable" );
|
|
|
|
equal( element.slider( "value" ), 10, "range: " + this + " slider method set" );
|
|
|
|
element.remove();
|
2009-09-19 15:34:20 +00:00
|
|
|
});
|
2013-02-07 14:33:26 +00:00
|
|
|
var element = $( "<div></div>" ).slider({
|
2009-09-19 15:34:20 +00:00
|
|
|
min: -1, value: 0, max: 1
|
|
|
|
});
|
|
|
|
// min with value option vs value method
|
2013-02-07 14:33:26 +00:00
|
|
|
element.slider( "option", "value", -2 );
|
|
|
|
equal( element.slider( "option", "value" ), -2, "value option does not respect min" );
|
|
|
|
equal( element.slider( "value" ), -1, "value method get respects min" );
|
|
|
|
equal( element.slider( "value", -2 ), element, "value method is chainable" );
|
|
|
|
equal( element.slider( "option", "value" ), -1, "value method set respects min" );
|
2009-09-19 15:34:20 +00:00
|
|
|
// max with value option vs value method
|
2013-02-07 14:33:26 +00:00
|
|
|
element.slider( "option", "value", 2);
|
|
|
|
equal( element.slider( "option", "value" ), 2, "value option does not respect max" );
|
|
|
|
equal( element.slider( "value" ), 1, "value method get respects max" );
|
|
|
|
equal( element.slider( "value", 2 ), element, "value method is chainable" );
|
|
|
|
equal( element.slider( "option", "value" ), 1, "value method set respects max" );
|
2015-03-04 12:23:17 +00:00
|
|
|
|
|
|
|
// set max value with step 0.01
|
|
|
|
element.slider( "option", {
|
|
|
|
min: 2,
|
|
|
|
value: 2,
|
|
|
|
max: 2.4,
|
|
|
|
step: 0.01
|
|
|
|
});
|
|
|
|
element.slider( "option", "value", 2.4 );
|
|
|
|
equal( element.slider( "value" ), 2.4, "value is set to max with 0.01 step" );
|
2009-02-02 07:13:25 +00:00
|
|
|
});
|
|
|
|
|
2013-02-07 14:33:26 +00:00
|
|
|
//test( "values", function() {
|
|
|
|
// ok(false, "missing test - untested code is broken code." );
|
2011-07-28 12:29:29 +00:00
|
|
|
//});
|
2009-02-02 07:13:25 +00:00
|
|
|
|
2013-02-07 14:33:26 +00:00
|
|
|
})( jQuery );
|