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";
|
2012-02-28 14:56:32 +00:00
|
|
|
|
2020-05-16 07:16:24 +00:00
|
|
|
QUnit.module( "slider: events", { afterEach: helper.moduleAfterEach } );
|
2009-02-02 05:58:49 +00:00
|
|
|
|
2010-03-17 15:31:17 +00:00
|
|
|
//Specs from http://wiki.jqueryui.com/Slider#specs
|
|
|
|
//"change callback: triggers when the slider has stopped moving and has a new
|
|
|
|
// value (even if same as previous value), via mouse(mouseup) or keyboard(keyup)
|
|
|
|
// or value method/option"
|
2016-04-06 13:18:13 +00:00
|
|
|
QUnit.test( "mouse based interaction", function( assert ) {
|
|
|
|
assert.expect( 4 );
|
2012-02-28 14:56:32 +00:00
|
|
|
|
2013-02-07 14:33:26 +00:00
|
|
|
var element = $( "#slider1" )
|
2015-08-24 12:58:09 +00:00
|
|
|
.slider( {
|
2012-10-23 14:36:42 +00:00
|
|
|
start: function( event ) {
|
2016-04-06 13:18:13 +00:00
|
|
|
assert.equal( event.originalEvent.type, "mousedown", "start triggered by mousedown" );
|
2010-03-27 00:44:14 +00:00
|
|
|
},
|
2015-08-24 12:58:09 +00:00
|
|
|
slide: function( event ) {
|
2016-04-06 13:18:13 +00:00
|
|
|
assert.equal( event.originalEvent.type, "mousemove", "slider triggered by mousemove" );
|
2010-03-27 00:44:14 +00:00
|
|
|
},
|
2012-10-23 14:36:42 +00:00
|
|
|
stop: function( event ) {
|
2016-04-06 13:18:13 +00:00
|
|
|
assert.equal( event.originalEvent.type, "mouseup", "stop triggered by mouseup" );
|
2010-03-27 00:44:14 +00:00
|
|
|
},
|
2012-10-23 14:36:42 +00:00
|
|
|
change: function( event ) {
|
2016-04-06 13:18:13 +00:00
|
|
|
assert.equal( event.originalEvent.type, "mouseup", "change triggered by mouseup" );
|
2010-03-17 15:31:17 +00:00
|
|
|
}
|
2015-08-24 12:58:09 +00:00
|
|
|
} );
|
2010-03-17 15:31:17 +00:00
|
|
|
|
2013-02-07 14:33:26 +00:00
|
|
|
element.find( ".ui-slider-handle" ).eq( 0 )
|
2010-03-17 15:31:17 +00:00
|
|
|
.simulate( "drag", { dx: 10, dy: 10 } );
|
|
|
|
|
2015-08-24 12:58:09 +00:00
|
|
|
} );
|
2016-04-06 13:18:13 +00:00
|
|
|
QUnit.test( "keyboard based interaction", function( assert ) {
|
|
|
|
assert.expect( 3 );
|
2012-02-28 14:56:32 +00:00
|
|
|
|
2010-03-17 15:31:17 +00:00
|
|
|
// Test keyup at end of handle slide (keyboard)
|
2013-02-07 14:33:26 +00:00
|
|
|
var element = $( "#slider1" )
|
2015-08-24 12:58:09 +00:00
|
|
|
.slider( {
|
2012-10-23 14:36:42 +00:00
|
|
|
start: function( event ) {
|
2016-04-06 13:18:13 +00:00
|
|
|
assert.equal( event.originalEvent.type, "keydown", "start triggered by keydown" );
|
2010-03-27 00:44:14 +00:00
|
|
|
},
|
2012-10-23 14:36:42 +00:00
|
|
|
slide: function() {
|
2016-04-06 13:18:13 +00:00
|
|
|
assert.ok( false, "Slider never triggered by keys" );
|
2010-03-27 00:44:14 +00:00
|
|
|
},
|
2012-10-23 14:36:42 +00:00
|
|
|
stop: function( event ) {
|
2016-04-06 13:18:13 +00:00
|
|
|
assert.equal( event.originalEvent.type, "keyup", "stop triggered by keyup" );
|
2010-03-27 00:44:14 +00:00
|
|
|
},
|
2012-10-23 14:36:42 +00:00
|
|
|
change: function( event ) {
|
2016-04-06 13:18:13 +00:00
|
|
|
assert.equal( event.originalEvent.type, "keyup", "change triggered by keyup" );
|
2010-03-17 15:31:17 +00:00
|
|
|
}
|
2015-08-24 12:58:09 +00:00
|
|
|
} );
|
2010-03-17 15:31:17 +00:00
|
|
|
|
2013-02-07 14:33:26 +00:00
|
|
|
element.find( ".ui-slider-handle" ).eq( 0 )
|
2010-03-17 15:31:17 +00:00
|
|
|
.simulate( "keydown", { keyCode: $.ui.keyCode.LEFT } )
|
|
|
|
.simulate( "keypress", { keyCode: $.ui.keyCode.LEFT } )
|
2010-03-17 17:39:29 +00:00
|
|
|
.simulate( "keyup", { keyCode: $.ui.keyCode.LEFT } );
|
2010-03-17 15:31:17 +00:00
|
|
|
|
2015-08-24 12:58:09 +00:00
|
|
|
} );
|
2016-04-06 13:18:13 +00:00
|
|
|
QUnit.test( "programmatic event triggers", function( assert ) {
|
|
|
|
assert.expect( 6 );
|
2012-02-28 14:56:32 +00:00
|
|
|
|
2010-03-17 15:31:17 +00:00
|
|
|
// Test value method
|
2013-02-07 14:33:26 +00:00
|
|
|
var element = $( "<div></div>" )
|
2015-08-24 12:58:09 +00:00
|
|
|
.slider( {
|
2012-10-23 14:36:42 +00:00
|
|
|
change: function() {
|
2016-04-06 13:18:13 +00:00
|
|
|
assert.ok( true, "change triggered by value method" );
|
2010-03-17 15:31:17 +00:00
|
|
|
}
|
2015-08-24 12:58:09 +00:00
|
|
|
} )
|
2010-03-17 15:31:17 +00:00
|
|
|
.slider( "value", 0 );
|
|
|
|
|
2010-03-17 15:58:22 +00:00
|
|
|
// Test values method
|
2013-02-07 14:33:26 +00:00
|
|
|
element = $( "<div></div>" )
|
2015-08-24 12:58:09 +00:00
|
|
|
.slider( {
|
2010-03-17 15:58:22 +00:00
|
|
|
values: [ 10, 20 ],
|
2012-10-23 14:36:42 +00:00
|
|
|
change: function() {
|
2016-04-06 13:18:13 +00:00
|
|
|
assert.ok( true, "change triggered by values method" );
|
2010-03-17 15:58:22 +00:00
|
|
|
}
|
2015-08-24 12:58:09 +00:00
|
|
|
} )
|
2013-02-07 14:33:26 +00:00
|
|
|
.slider( "values", [ 80, 90 ] );
|
2010-03-17 15:58:22 +00:00
|
|
|
|
2010-03-17 15:31:17 +00:00
|
|
|
// Test value option
|
2013-02-07 14:33:26 +00:00
|
|
|
element = $( "<div></div>" )
|
2015-08-24 12:58:09 +00:00
|
|
|
.slider( {
|
2012-10-23 14:36:42 +00:00
|
|
|
change: function() {
|
2016-04-06 13:18:13 +00:00
|
|
|
assert.ok( true, "change triggered by value option" );
|
2010-03-17 15:31:17 +00:00
|
|
|
}
|
2015-08-24 12:58:09 +00:00
|
|
|
} )
|
2010-03-17 15:31:17 +00:00
|
|
|
.slider( "option", "value", 0 );
|
|
|
|
|
2010-03-17 15:58:22 +00:00
|
|
|
// Test values option
|
2013-02-07 14:33:26 +00:00
|
|
|
element = $( "<div></div>" )
|
2015-08-24 12:58:09 +00:00
|
|
|
.slider( {
|
2010-03-17 15:58:22 +00:00
|
|
|
values: [ 10, 20 ],
|
2012-10-23 14:36:42 +00:00
|
|
|
change: function() {
|
2016-04-06 13:18:13 +00:00
|
|
|
assert.ok( true, "change triggered by values option" );
|
2010-03-17 15:58:22 +00:00
|
|
|
}
|
2015-08-24 12:58:09 +00:00
|
|
|
} )
|
2013-02-07 14:33:26 +00:00
|
|
|
.slider( "option", "values", [ 80, 90 ] );
|
2010-03-17 15:58:22 +00:00
|
|
|
|
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( "mouse based interaction part two: when handles overlap", function( assert ) {
|
|
|
|
assert.expect( 6 );
|
2012-11-14 01:05:59 +00:00
|
|
|
|
2013-02-07 14:33:26 +00:00
|
|
|
var element = $( "#slider1" )
|
2015-08-24 12:58:09 +00:00
|
|
|
.slider( {
|
2012-11-14 01:05:59 +00:00
|
|
|
values: [ 0, 0, 0 ],
|
|
|
|
start: function( event, ui ) {
|
2016-04-06 13:18:13 +00:00
|
|
|
assert.equal( handles.index( ui.handle ), 2, "rightmost handle activated when overlapping at minimum (#3736)" );
|
2012-11-14 01:05:59 +00:00
|
|
|
}
|
2015-08-24 12:58:09 +00:00
|
|
|
} ),
|
2013-02-07 14:33:26 +00:00
|
|
|
handles = element.find( ".ui-slider-handle" );
|
|
|
|
handles.eq( 0 ).simulate( "drag", { dx: 10 } );
|
|
|
|
element.slider( "destroy" );
|
2012-11-14 01:05:59 +00:00
|
|
|
|
2013-02-07 14:33:26 +00:00
|
|
|
element = $( "#slider1" )
|
2015-08-24 12:58:09 +00:00
|
|
|
.slider( {
|
2012-11-14 01:05:59 +00:00
|
|
|
values: [ 10, 10, 10 ],
|
|
|
|
max: 10,
|
|
|
|
start: function( event, ui ) {
|
2016-04-06 13:18:13 +00:00
|
|
|
assert.equal( handles.index( ui.handle ), 0, "leftmost handle activated when overlapping at maximum" );
|
2012-11-14 01:05:59 +00:00
|
|
|
}
|
2021-06-06 22:58:12 +00:00
|
|
|
} );
|
|
|
|
handles = element.find( ".ui-slider-handle" );
|
2013-02-07 14:33:26 +00:00
|
|
|
handles.eq( 0 ).simulate( "drag", { dx: -10 } );
|
|
|
|
element.slider( "destroy" );
|
2012-11-14 01:05:59 +00:00
|
|
|
|
2013-02-07 14:33:26 +00:00
|
|
|
element = $( "#slider1" )
|
2015-08-24 12:58:09 +00:00
|
|
|
.slider( {
|
2012-11-14 01:05:59 +00:00
|
|
|
values: [ 19, 20 ]
|
2021-06-06 22:58:12 +00:00
|
|
|
} );
|
|
|
|
handles = element.find( ".ui-slider-handle" );
|
2013-02-07 14:33:26 +00:00
|
|
|
handles.eq( 0 ).simulate( "drag", { dx: 10 } );
|
|
|
|
element.one( "slidestart", function( event, ui ) {
|
2016-04-06 13:18:13 +00:00
|
|
|
assert.equal( handles.index( ui.handle ), 0, "left handle activated if left was moved last" );
|
2015-08-24 12:58:09 +00:00
|
|
|
} );
|
2013-02-07 14:33:26 +00:00
|
|
|
handles.eq( 0 ).simulate( "drag", { dx: 10 } );
|
|
|
|
element.slider( "destroy" );
|
2012-11-14 01:05:59 +00:00
|
|
|
|
2013-02-07 14:33:26 +00:00
|
|
|
element = $( "#slider1" )
|
2015-08-24 12:58:09 +00:00
|
|
|
.slider( {
|
2012-11-14 01:05:59 +00:00
|
|
|
values: [ 19, 20 ]
|
2021-06-06 22:58:12 +00:00
|
|
|
} );
|
|
|
|
handles = element.find( ".ui-slider-handle" );
|
2013-02-07 14:33:26 +00:00
|
|
|
handles.eq( 1 ).simulate( "drag", { dx: -10 } );
|
|
|
|
element.one( "slidestart", function( event, ui ) {
|
2016-04-06 13:18:13 +00:00
|
|
|
assert.equal( handles.index( ui.handle ), 1, "right handle activated if right was moved last (#3467)" );
|
2015-08-24 12:58:09 +00:00
|
|
|
} );
|
2013-02-07 14:33:26 +00:00
|
|
|
handles.eq( 0 ).simulate( "drag", { dx: 10 } );
|
2012-11-14 01:05:59 +00:00
|
|
|
|
2015-03-16 09:10:23 +00:00
|
|
|
element = $( "#slider1" )
|
2015-08-24 12:58:09 +00:00
|
|
|
.slider( {
|
2015-03-16 09:10:23 +00:00
|
|
|
range: true,
|
|
|
|
min: 0,
|
|
|
|
max: 100,
|
|
|
|
values: [ 0, 50 ]
|
2021-06-06 22:58:12 +00:00
|
|
|
} );
|
|
|
|
handles = element.find( ".ui-slider-handle" );
|
2015-03-16 09:10:23 +00:00
|
|
|
|
|
|
|
element.slider( "option", { values: [ 100, 100 ] } );
|
|
|
|
handles.eq( 0 ).simulate( "drag", { dx: -10 } );
|
2016-04-06 13:18:13 +00:00
|
|
|
assert.equal( element.slider( "values" )[ 0 ], 99, "setting both values of range slider to the maximum doesn't lock slider" );
|
2015-03-16 09:10:23 +00:00
|
|
|
|
|
|
|
element.slider( "option", { values: [ 0, 0 ] } );
|
|
|
|
handles.eq( 1 ).simulate( "drag", { dx: 10 } );
|
2016-04-06 13:18:13 +00:00
|
|
|
assert.equal( element.slider( "values" )[ 1 ], 1, "setting both values of range slider to the minimum doesn't lock slider" );
|
2015-08-24 12:58:09 +00:00
|
|
|
} );
|
2012-11-14 01:05:59 +00:00
|
|
|
|
2016-04-06 13:18:13 +00:00
|
|
|
QUnit.test( "event data", function( assert ) {
|
|
|
|
assert.expect( 6 );
|
2015-03-12 08:30:06 +00:00
|
|
|
|
|
|
|
var slideHandleIndex = 3,
|
|
|
|
values = [ 8, 9, 7, 4 ],
|
|
|
|
newValues = [ 8, 9, 7, 5 ],
|
|
|
|
element = $( "#slider1" )
|
2015-08-24 12:58:09 +00:00
|
|
|
.slider( {
|
2015-03-12 08:30:06 +00:00
|
|
|
values: values,
|
|
|
|
start: function( event, ui ) {
|
2016-04-06 13:18:13 +00:00
|
|
|
assert.deepEqual( ui, expectedUiHash, "passing ui to start event" );
|
2015-03-12 08:30:06 +00:00
|
|
|
},
|
|
|
|
slide: function( event, ui ) {
|
2016-04-06 13:18:13 +00:00
|
|
|
assert.deepEqual( ui, expectedChangedUiHash, "passing ui to slide event" );
|
2015-03-12 08:30:06 +00:00
|
|
|
},
|
|
|
|
stop: function( event, ui ) {
|
2016-04-06 13:18:13 +00:00
|
|
|
assert.deepEqual( ui, expectedChangedUiHash, "passing ui to stop event" );
|
2015-03-12 08:30:06 +00:00
|
|
|
},
|
|
|
|
change: function( event, ui ) {
|
2016-04-06 13:18:13 +00:00
|
|
|
assert.deepEqual( ui, expectedChangedUiHash, "passing ui to change event" );
|
2015-03-12 08:30:06 +00:00
|
|
|
}
|
2015-08-24 12:58:09 +00:00
|
|
|
} ),
|
2015-03-12 08:30:06 +00:00
|
|
|
handles = element.find( ".ui-slider-handle" ),
|
|
|
|
expectedUiHash = {
|
|
|
|
handle: handles.eq( slideHandleIndex )[ 0 ],
|
|
|
|
handleIndex: slideHandleIndex,
|
|
|
|
values: values,
|
|
|
|
value: values[ slideHandleIndex ]
|
|
|
|
},
|
|
|
|
expectedChangedUiHash = $.extend( {}, expectedUiHash, {
|
|
|
|
values: newValues,
|
|
|
|
value: newValues[ slideHandleIndex ]
|
2015-08-24 12:58:09 +00:00
|
|
|
} );
|
2015-03-12 08:30:06 +00:00
|
|
|
|
|
|
|
handles.eq( slideHandleIndex ).simulate( "drag", { dx: 10 } );
|
2015-04-17 08:34:33 +00:00
|
|
|
|
|
|
|
element.slider( "destroy" );
|
2015-08-24 12:58:09 +00:00
|
|
|
element = $( "#slider1" ).slider( {
|
2015-04-17 08:34:33 +00:00
|
|
|
min: 0,
|
|
|
|
max: 100,
|
|
|
|
value: 1,
|
2015-08-24 12:58:09 +00:00
|
|
|
slide: function( event, ui ) {
|
2016-04-06 13:18:13 +00:00
|
|
|
assert.equal( ui.value, 0, "should pass 0 value if slider reaches it" );
|
2015-04-17 08:34:33 +00:00
|
|
|
}
|
2015-08-24 12:58:09 +00:00
|
|
|
} );
|
2015-04-17 08:34:33 +00:00
|
|
|
handles = element.find( ".ui-slider-handle" );
|
|
|
|
handles.eq( 0 ).simulate( "drag", { dx: -10 } );
|
|
|
|
|
|
|
|
element.slider( "destroy" );
|
2015-08-24 12:58:09 +00:00
|
|
|
element = $( "#slider1" ).slider( {
|
2015-04-17 08:34:33 +00:00
|
|
|
min: 0,
|
|
|
|
max: 100,
|
|
|
|
values: [ 1, 2 ],
|
2015-08-24 12:58:09 +00:00
|
|
|
slide: function( event, ui ) {
|
2016-04-06 13:18:13 +00:00
|
|
|
assert.equal( ui.value, 0, "should pass 0 value if one of handles reaches it" );
|
2015-04-17 08:34:33 +00:00
|
|
|
}
|
2015-08-24 12:58:09 +00:00
|
|
|
} );
|
2015-04-17 08:34:33 +00:00
|
|
|
handles = element.find( ".ui-slider-handle" );
|
|
|
|
handles.eq( 0 ).simulate( "drag", { dx: -10 } );
|
2015-08-24 12:58:09 +00:00
|
|
|
} );
|
2015-03-12 08:30:06 +00:00
|
|
|
|
2015-04-06 18:44:05 +00:00
|
|
|
} );
|