2015-04-06 18:44:05 +00:00
|
|
|
define( [
|
2016-04-06 13:18:13 +00:00
|
|
|
"qunit",
|
2015-04-06 18:44:05 +00:00
|
|
|
"jquery",
|
2020-05-16 07:16:24 +00:00
|
|
|
"lib/helper",
|
2015-07-15 02:08:11 +00:00
|
|
|
"ui/widgets/slider"
|
2020-05-16 07:16:24 +00:00
|
|
|
], function( QUnit, $, helper ) {
|
2021-06-06 22:58:12 +00:00
|
|
|
"use strict";
|
2009-02-02 05:58:49 +00:00
|
|
|
|
2020-05-16 07:16:24 +00:00
|
|
|
QUnit.module( "slider: methods", { afterEach: helper.moduleAfterEach } );
|
2009-02-02 05:58:49 +00:00
|
|
|
|
2016-04-06 13:18:13 +00:00
|
|
|
QUnit.test( "init", function( assert ) {
|
|
|
|
assert.expect( 5 );
|
2009-02-02 07:13:25 +00:00
|
|
|
|
2013-02-07 14:33:26 +00:00
|
|
|
$( "<div></div>" ).appendTo( "body" ).slider().remove();
|
2016-04-06 13:18:13 +00:00
|
|
|
assert.ok( true, ".slider() called on element" );
|
2009-02-02 07:13:25 +00:00
|
|
|
|
2013-02-07 14:33:26 +00:00
|
|
|
$( [] ).slider().remove();
|
2016-04-06 13:18:13 +00:00
|
|
|
assert.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();
|
2016-04-06 13:18:13 +00:00
|
|
|
assert.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();
|
2016-04-06 13:18:13 +00:00
|
|
|
assert.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();
|
2016-04-06 13:18:13 +00:00
|
|
|
assert.ok( true, "arbitrary option setter after init" );
|
2015-08-24 12:58:09 +00:00
|
|
|
} );
|
2009-02-02 05:58:49 +00:00
|
|
|
|
2016-04-06 13:18:13 +00:00
|
|
|
QUnit.test( "destroy", function( assert ) {
|
|
|
|
assert.expect( 1 );
|
2015-04-06 18:44:05 +00:00
|
|
|
assert.domEqual( "#slider1", function() {
|
2012-07-17 19:04:16 +00:00
|
|
|
$( "#slider1" ).slider().slider( "destroy" );
|
2015-08-24 12:58:09 +00:00
|
|
|
} );
|
|
|
|
} );
|
2009-02-02 05:58:49 +00:00
|
|
|
|
2016-04-06 13:18:13 +00:00
|
|
|
QUnit.test( "enable", function( assert ) {
|
|
|
|
assert.expect( 3 );
|
2013-02-07 14:33:26 +00:00
|
|
|
var element,
|
|
|
|
expected = $( "<div></div>" ).slider(),
|
|
|
|
actual = expected.slider( "enable" );
|
2016-04-06 13:18:13 +00:00
|
|
|
assert.equal( actual, expected, "enable is chainable" );
|
2009-09-19 15:19:42 +00:00
|
|
|
|
2015-08-24 12:58:09 +00:00
|
|
|
element = $( "<div></div>" ).slider( { disabled: true } );
|
2015-01-30 15:55:53 +00:00
|
|
|
assert.hasClasses( element, "ui-state-disabled ui-slider-disabled" );
|
2013-02-07 14:33:26 +00:00
|
|
|
element.slider( "enable" );
|
2015-01-30 15:55:53 +00:00
|
|
|
assert.lacksClasses( element, "ui-state-disabled ui-slider-disabled" );
|
2015-08-24 12:58:09 +00:00
|
|
|
} );
|
2009-02-02 05:58:49 +00:00
|
|
|
|
2016-04-06 13:18:13 +00:00
|
|
|
QUnit.test( "disable", function( assert ) {
|
|
|
|
assert.expect( 4 );
|
2013-02-07 14:33:26 +00:00
|
|
|
var element,
|
|
|
|
expected = $( "<div></div>" ).slider(),
|
|
|
|
actual = expected.slider( "disable" );
|
2016-04-06 13:18:13 +00:00
|
|
|
assert.equal( actual, expected, "disable is chainable" );
|
2009-09-19 15:19:42 +00:00
|
|
|
|
2015-08-24 12:58:09 +00:00
|
|
|
element = $( "<div></div>" ).slider( { disabled: false } );
|
2015-01-30 15:55:53 +00:00
|
|
|
assert.lacksClasses( element, "ui-state-disabled ui-slider-disabled" );
|
2013-02-07 14:33:26 +00:00
|
|
|
element.slider( "disable" );
|
2015-01-30 15:55:53 +00:00
|
|
|
assert.hasClasses( element, "ui-state-disabled ui-slider-disabled" );
|
2016-04-06 13:18:13 +00:00
|
|
|
assert.ok( !element.attr( "aria-disabled" ), "slider does not have aria-disabled attr after disable method call" );
|
2015-08-24 12:58:09 +00:00
|
|
|
} );
|
2009-02-02 05:58:49 +00:00
|
|
|
|
2016-04-06 13:18:13 +00:00
|
|
|
QUnit.test( "value", function( assert ) {
|
|
|
|
assert.expect( 19 );
|
2015-08-24 12:58:09 +00:00
|
|
|
$( [ false, "min", "max" ] ).each( function() {
|
|
|
|
var element = $( "<div></div>" ).slider( {
|
2009-09-19 15:34:20 +00:00
|
|
|
range: this,
|
|
|
|
value: 5
|
2015-08-24 12:58:09 +00:00
|
|
|
} );
|
2016-04-06 13:18:13 +00:00
|
|
|
assert.equal( element.slider( "value" ), 5, "range: " + this + " slider method get" );
|
|
|
|
assert.equal( element.slider( "value", 10 ), element, "value method is chainable" );
|
|
|
|
assert.equal( element.slider( "value" ), 10, "range: " + this + " slider method set" );
|
2013-02-07 14:33:26 +00:00
|
|
|
element.remove();
|
2015-08-24 12:58:09 +00:00
|
|
|
} );
|
|
|
|
var element = $( "<div></div>" ).slider( {
|
2009-09-19 15:34:20 +00:00
|
|
|
min: -1, value: 0, max: 1
|
2015-08-24 12:58:09 +00:00
|
|
|
} );
|
|
|
|
|
2016-04-06 13:18:13 +00:00
|
|
|
// Min with value option vs value method
|
2013-02-07 14:33:26 +00:00
|
|
|
element.slider( "option", "value", -2 );
|
2016-04-06 13:18:13 +00:00
|
|
|
assert.equal( element.slider( "option", "value" ), -2, "value option does not respect min" );
|
|
|
|
assert.equal( element.slider( "value" ), -1, "value method get respects min" );
|
|
|
|
assert.equal( element.slider( "value", -2 ), element, "value method is chainable" );
|
|
|
|
assert.equal( element.slider( "option", "value" ), -1, "value method set respects min" );
|
2015-08-24 12:58:09 +00:00
|
|
|
|
2016-04-06 13:18:13 +00:00
|
|
|
// Max with value option vs value method
|
2015-08-24 12:58:09 +00:00
|
|
|
element.slider( "option", "value", 2 );
|
2016-04-06 13:18:13 +00:00
|
|
|
assert.equal( element.slider( "option", "value" ), 2, "value option does not respect max" );
|
|
|
|
assert.equal( element.slider( "value" ), 1, "value method get respects max" );
|
|
|
|
assert.equal( element.slider( "value", 2 ), element, "value method is chainable" );
|
|
|
|
assert.equal( element.slider( "option", "value" ), 1, "value method set respects max" );
|
2015-03-04 12:23:17 +00:00
|
|
|
|
2015-08-21 04:05:36 +00:00
|
|
|
// Set max value with step 0.01
|
2015-03-04 12:23:17 +00:00
|
|
|
element.slider( "option", {
|
|
|
|
min: 2,
|
|
|
|
value: 2,
|
|
|
|
max: 2.4,
|
|
|
|
step: 0.01
|
2015-08-24 12:58:09 +00:00
|
|
|
} );
|
2015-03-04 12:23:17 +00:00
|
|
|
element.slider( "option", "value", 2.4 );
|
2016-04-06 13:18:13 +00:00
|
|
|
assert.equal( element.slider( "value" ), 2.4, "value is set to max with 0.01 step" );
|
2015-03-12 07:26:24 +00:00
|
|
|
|
2015-08-24 12:58:09 +00:00
|
|
|
element = $( "<div></div>" ).slider( {
|
2015-03-12 07:26:24 +00:00
|
|
|
value: 100,
|
|
|
|
min: 10,
|
|
|
|
max: 500,
|
|
|
|
step: 50
|
2015-08-24 12:58:09 +00:00
|
|
|
} );
|
2015-03-12 07:26:24 +00:00
|
|
|
|
|
|
|
element.slider( "option", "value", 510 );
|
2016-04-06 13:18:13 +00:00
|
|
|
assert.equal( element.slider( "value" ), 460, "value is restricted to maximum valid step" );
|
2015-08-24 12:58:09 +00:00
|
|
|
} );
|
2009-02-02 07:13:25 +00:00
|
|
|
|
2016-04-06 13:18:13 +00:00
|
|
|
QUnit.test( "values, single step", function( assert ) {
|
|
|
|
assert.expect( 8 );
|
2015-07-06 11:18:57 +00:00
|
|
|
|
|
|
|
var element = $( "<div></div>" ).slider( {
|
|
|
|
range: false,
|
|
|
|
min: 10,
|
|
|
|
max: 100,
|
|
|
|
step: 1,
|
|
|
|
values: [ 20 ]
|
|
|
|
} );
|
|
|
|
|
2016-04-06 13:18:13 +00:00
|
|
|
assert.deepEqual( element.slider( "values" ), [ 20 ], "range: false, values - get value for handle" );
|
|
|
|
assert.equal( element.slider( "values", 0 ), 20, "values (index) - get value of handle" );
|
2015-07-06 11:18:57 +00:00
|
|
|
|
|
|
|
element.slider( "values", 0, 5 );
|
2016-04-06 13:18:13 +00:00
|
|
|
assert.equal( element.slider( "values", 0 ), 10, "values (index) - restrict against min" );
|
2015-07-06 11:18:57 +00:00
|
|
|
|
|
|
|
element.slider( "values", 0, 110 );
|
2016-04-06 13:18:13 +00:00
|
|
|
assert.equal( element.slider( "values", 0 ), 100, "values (index) - restrict against max" );
|
2015-07-06 11:18:57 +00:00
|
|
|
|
|
|
|
element.slider( "option", "range", true );
|
|
|
|
element.slider( "values", [ 20, 90 ] );
|
|
|
|
|
2016-04-06 13:18:13 +00:00
|
|
|
assert.deepEqual( element.slider( "values" ), [ 20, 90 ], "range: true, values - get value for all handles" );
|
|
|
|
assert.equal( element.slider( "values", 0 ), 20, "values (index) - 1st handle" );
|
|
|
|
assert.equal( element.slider( "values", 1 ), 90, "values (index) - 2nd handle" );
|
2015-07-06 11:18:57 +00:00
|
|
|
|
|
|
|
element.slider( "values", [ 5, 110 ] );
|
2016-04-06 13:18:13 +00:00
|
|
|
assert.deepEqual( element.slider( "values" ), [ 10, 100 ], "values - restricted against min and max" );
|
2015-07-06 11:18:57 +00:00
|
|
|
element.slider( "destroy" );
|
|
|
|
} );
|
|
|
|
|
2016-04-06 13:18:13 +00:00
|
|
|
QUnit.test( "values, multi step", function( assert ) {
|
|
|
|
assert.expect( 2 );
|
2015-07-06 11:18:57 +00:00
|
|
|
|
|
|
|
var element = $( "<div></div>" ).slider( {
|
|
|
|
range: false,
|
|
|
|
min: 9,
|
|
|
|
max: 20,
|
|
|
|
step: 3,
|
|
|
|
values: [ 9, 12 ]
|
|
|
|
} );
|
2016-04-06 13:18:13 +00:00
|
|
|
assert.deepEqual( element.slider( "values" ), [ 9, 12 ], "values - evenly divisible by step" );
|
2015-07-06 11:18:57 +00:00
|
|
|
|
|
|
|
element.slider( "values", [ 10, 20 ] );
|
2016-04-06 13:18:13 +00:00
|
|
|
assert.deepEqual( element.slider( "values" ), [ 9, 18 ], "values - not evenly divisible by step" );
|
2015-07-06 11:18:57 +00:00
|
|
|
|
|
|
|
element.slider( "destroy" );
|
|
|
|
} );
|
2009-02-02 07:13:25 +00:00
|
|
|
|
2015-04-06 18:44:05 +00:00
|
|
|
} );
|