2015-04-06 18:40:47 +00:00
|
|
|
define( [
|
2016-04-06 13:16:23 +00:00
|
|
|
"qunit",
|
2015-04-06 18:40:47 +00:00
|
|
|
"jquery",
|
2020-05-16 07:16:24 +00:00
|
|
|
"lib/helper",
|
2015-07-15 02:06:31 +00:00
|
|
|
"ui/widgets/selectmenu"
|
2020-05-16 07:16:24 +00:00
|
|
|
], function( QUnit, $, helper ) {
|
2021-06-06 22:58:12 +00:00
|
|
|
"use strict";
|
2011-10-19 17:47:02 +00:00
|
|
|
|
2020-05-16 07:16:24 +00:00
|
|
|
QUnit.module( "selectmenu: options", { afterEach: helper.moduleAfterEach } );
|
2012-01-13 18:49:42 +00:00
|
|
|
|
2016-04-06 13:16:23 +00:00
|
|
|
QUnit.test( "appendTo: null", function( assert ) {
|
|
|
|
assert.expect( 1 );
|
2014-04-22 22:24:04 +00:00
|
|
|
|
2014-02-21 12:40:32 +00:00
|
|
|
var element = $( "#speed" ).selectmenu();
|
2016-04-06 13:16:23 +00:00
|
|
|
assert.equal( element.selectmenu( "menuWidget" ).parent().parent()[ 0 ], document.body,
|
2014-02-21 12:40:32 +00:00
|
|
|
"defaults to body" );
|
2015-08-24 12:50:24 +00:00
|
|
|
} );
|
2013-02-13 22:58:14 +00:00
|
|
|
|
2016-04-06 13:16:23 +00:00
|
|
|
QUnit.test( "appendTo: explicit", function( assert ) {
|
|
|
|
assert.expect( 6 );
|
2014-04-22 22:24:04 +00:00
|
|
|
|
2012-12-15 01:24:10 +00:00
|
|
|
var detached = $( "<div>" ),
|
2014-02-21 12:40:32 +00:00
|
|
|
element = $( "#speed" );
|
2012-12-15 01:24:10 +00:00
|
|
|
|
2015-08-24 12:50:24 +00:00
|
|
|
element.selectmenu( {
|
2013-04-29 18:34:16 +00:00
|
|
|
appendTo: ".selectmenu-wrap"
|
2015-08-24 12:50:24 +00:00
|
|
|
} );
|
2016-04-06 13:16:23 +00:00
|
|
|
assert.equal( element.selectmenu( "menuWidget" ).parent().parent()[ 0 ],
|
2014-04-22 22:24:04 +00:00
|
|
|
$( "#selectmenu-wrap1" )[ 0 ], "first found element" );
|
2016-04-06 13:16:23 +00:00
|
|
|
assert.equal( $( "#selectmenu-wrap2 .ui-selectmenu" ).length, 0, "only appends to one element" );
|
2012-12-15 01:24:10 +00:00
|
|
|
element.selectmenu( "destroy" );
|
|
|
|
|
2013-04-29 18:34:16 +00:00
|
|
|
element.selectmenu().selectmenu( "option", "appendTo", "#selectmenu-wrap1" );
|
2016-04-06 13:16:23 +00:00
|
|
|
assert.equal( element.selectmenu( "menuWidget" ).parent().parent()[ 0 ],
|
2014-04-22 22:24:04 +00:00
|
|
|
$( "#selectmenu-wrap1" )[ 0 ], "modified after init" );
|
2012-12-15 01:24:10 +00:00
|
|
|
element.selectmenu( "destroy" );
|
|
|
|
|
2015-08-24 12:50:24 +00:00
|
|
|
element.selectmenu( {
|
2012-12-15 01:24:10 +00:00
|
|
|
appendTo: detached
|
2015-08-24 12:50:24 +00:00
|
|
|
} );
|
2016-04-06 13:16:23 +00:00
|
|
|
assert.equal( element.selectmenu( "menuWidget" ).parent().parent()[ 0 ], detached[ 0 ],
|
2014-04-22 22:24:04 +00:00
|
|
|
"detached jQuery object" );
|
2012-12-15 01:24:10 +00:00
|
|
|
element.selectmenu( "destroy" );
|
2012-05-16 18:43:42 +00:00
|
|
|
|
2015-08-24 12:50:24 +00:00
|
|
|
element.selectmenu( {
|
2013-04-29 19:03:12 +00:00
|
|
|
appendTo: detached[ 0 ]
|
2015-08-24 12:50:24 +00:00
|
|
|
} );
|
2016-04-06 13:16:23 +00:00
|
|
|
assert.equal( element.selectmenu( "menuWidget" ).parent().parent()[ 0 ], detached[ 0 ],
|
2014-04-22 22:24:04 +00:00
|
|
|
"detached DOM element" );
|
2012-12-15 01:24:10 +00:00
|
|
|
element.selectmenu( "destroy" );
|
2012-05-16 18:43:42 +00:00
|
|
|
|
2012-12-15 01:24:10 +00:00
|
|
|
element.selectmenu().selectmenu( "option", "appendTo", detached );
|
2016-04-06 13:16:23 +00:00
|
|
|
assert.equal( element.selectmenu( "menuWidget" ).parent().parent()[ 0 ], detached[ 0 ],
|
2014-04-22 22:24:04 +00:00
|
|
|
"detached DOM element via option()" );
|
2012-12-15 01:24:10 +00:00
|
|
|
element.selectmenu( "destroy" );
|
2015-08-24 12:50:24 +00:00
|
|
|
} );
|
2012-01-13 18:49:42 +00:00
|
|
|
|
2016-04-06 13:16:23 +00:00
|
|
|
QUnit.test( "appendTo: ui-front", function( assert ) {
|
|
|
|
assert.expect( 2 );
|
2014-04-22 22:24:04 +00:00
|
|
|
|
2014-02-21 12:40:32 +00:00
|
|
|
var element = $( "#speed" );
|
|
|
|
|
|
|
|
$( "#selectmenu-wrap2" ).addClass( "ui-front" );
|
|
|
|
element.selectmenu();
|
2016-04-06 13:16:23 +00:00
|
|
|
assert.equal( element.selectmenu( "menuWidget" ).parent().parent()[ 0 ],
|
2014-02-21 12:40:32 +00:00
|
|
|
$( "#selectmenu-wrap2" )[ 0 ], "null, inside .ui-front" );
|
|
|
|
element.selectmenu( "destroy" );
|
|
|
|
|
2015-08-24 12:50:24 +00:00
|
|
|
element.selectmenu( {
|
2014-02-21 12:40:32 +00:00
|
|
|
appendTo: $()
|
2015-08-24 12:50:24 +00:00
|
|
|
} );
|
2016-04-06 13:16:23 +00:00
|
|
|
assert.equal( element.selectmenu( "menuWidget" ).parent().parent()[ 0 ],
|
2014-02-21 12:40:32 +00:00
|
|
|
$( "#selectmenu-wrap2" )[ 0 ], "empty jQuery object, inside .ui-front" );
|
2015-08-24 12:50:24 +00:00
|
|
|
} );
|
2014-02-21 12:40:32 +00:00
|
|
|
|
2016-04-06 13:16:23 +00:00
|
|
|
QUnit.test( "CSS styles", function( assert ) {
|
|
|
|
assert.expect( 5 );
|
2012-02-26 00:24:52 +00:00
|
|
|
|
2013-04-29 19:03:12 +00:00
|
|
|
var element = $( "#speed" ).selectmenu(),
|
|
|
|
button = element.selectmenu( "widget" ),
|
|
|
|
menu = element.selectmenu( "menuWidget" );
|
2012-02-21 17:08:14 +00:00
|
|
|
|
2013-02-13 22:58:14 +00:00
|
|
|
element.selectmenu( "open" );
|
2015-01-30 15:00:56 +00:00
|
|
|
|
|
|
|
assert.hasClasses( button, "ui-corner-top" );
|
|
|
|
assert.lacksClasses( button, "ui-corner-all" );
|
|
|
|
assert.hasClasses( button.find( "span.ui-icon" ), "ui-icon-triangle-1-s" );
|
|
|
|
assert.hasClasses( menu, "ui-corner-bottom" );
|
|
|
|
assert.lacksClasses( button, "ui-corner-all" );
|
2015-08-24 12:50:24 +00:00
|
|
|
} );
|
2012-02-26 00:24:52 +00:00
|
|
|
|
2016-04-06 13:16:23 +00:00
|
|
|
QUnit.test( "width", function( assert ) {
|
|
|
|
assert.expect( 6 );
|
2013-12-05 21:12:05 +00:00
|
|
|
|
2014-07-29 19:18:46 +00:00
|
|
|
var button,
|
2014-04-22 22:24:04 +00:00
|
|
|
element = $( "#speed" );
|
2013-12-05 21:12:05 +00:00
|
|
|
|
|
|
|
element.selectmenu();
|
|
|
|
button = element.selectmenu( "widget" );
|
|
|
|
|
2016-04-06 13:16:23 +00:00
|
|
|
assert.equal( button[ 0 ].style.width, "", "no inline style" );
|
2015-03-04 19:27:10 +00:00
|
|
|
|
|
|
|
element.selectmenu( "option", "width", null );
|
2023-05-10 08:56:02 +00:00
|
|
|
assert.close( button.outerWidth(), element.outerWidth(), 0.01, "button width auto" );
|
2013-12-05 21:12:05 +00:00
|
|
|
|
|
|
|
element.outerWidth( 100 );
|
|
|
|
element.selectmenu( "refresh" );
|
2016-04-06 13:16:23 +00:00
|
|
|
assert.equal( button.outerWidth(), 100, "button width set by CSS" );
|
2013-12-05 21:12:05 +00:00
|
|
|
|
2014-04-22 22:24:04 +00:00
|
|
|
element
|
|
|
|
.width( "" )
|
|
|
|
.selectmenu( "option", "width", 100 )
|
|
|
|
.selectmenu( "refresh" );
|
2016-04-06 13:16:23 +00:00
|
|
|
assert.equal( button.outerWidth(), 100, "button width set by JS option" );
|
2013-12-05 21:12:05 +00:00
|
|
|
|
2014-04-22 22:24:04 +00:00
|
|
|
element
|
|
|
|
.append( $( "<option>", { text: "Option with a little longer text" } ) )
|
2015-03-04 19:27:10 +00:00
|
|
|
.selectmenu( "option", "width", null )
|
2014-04-22 22:24:04 +00:00
|
|
|
.selectmenu( "refresh" );
|
2023-05-10 08:56:02 +00:00
|
|
|
assert.close( button.outerWidth(), element.outerWidth(), 0.01,
|
|
|
|
"button width with long option" );
|
2014-07-29 14:40:02 +00:00
|
|
|
|
|
|
|
element.parent().outerWidth( 300 );
|
|
|
|
element
|
|
|
|
.selectmenu( "destroy" )
|
|
|
|
.css( "width", "100%" )
|
2015-08-24 12:50:24 +00:00
|
|
|
.selectmenu( { width: null } );
|
2014-07-29 14:40:02 +00:00
|
|
|
button = element.selectmenu( "widget" );
|
2016-04-06 13:16:23 +00:00
|
|
|
assert.equal( button.outerWidth(), 300, "button width fills container" );
|
2015-08-24 12:50:24 +00:00
|
|
|
} );
|
2013-12-05 21:12:05 +00:00
|
|
|
|
2015-04-06 18:40:47 +00:00
|
|
|
} );
|