jquery-ui/tests/unit/selectmenu/options.js

129 lines
3.6 KiB
JavaScript
Raw Normal View History

define( [
"jquery",
"ui/widgets/selectmenu"
], function( $ ) {
module( "selectmenu: options" );
test( "appendTo: null", function() {
expect( 1 );
2014-04-22 22:24:04 +00:00
var element = $( "#speed" ).selectmenu();
2014-04-22 22:24:04 +00:00
equal( element.selectmenu( "menuWidget" ).parent().parent()[ 0 ], document.body,
"defaults to body" );
2015-08-24 12:50:24 +00:00
} );
test( "appendTo: explicit", function() {
expect( 6 );
2014-04-22 22:24:04 +00:00
var detached = $( "<div>" ),
element = $( "#speed" );
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
} );
2014-04-22 22:24:04 +00:00
equal( element.selectmenu( "menuWidget" ).parent().parent()[ 0 ],
$( "#selectmenu-wrap1" )[ 0 ], "first found element" );
2013-04-29 18:34:16 +00:00
equal( $( "#selectmenu-wrap2 .ui-selectmenu" ).length, 0, "only appends to one element" );
element.selectmenu( "destroy" );
2013-04-29 18:34:16 +00:00
element.selectmenu().selectmenu( "option", "appendTo", "#selectmenu-wrap1" );
2014-04-22 22:24:04 +00:00
equal( element.selectmenu( "menuWidget" ).parent().parent()[ 0 ],
$( "#selectmenu-wrap1" )[ 0 ], "modified after init" );
element.selectmenu( "destroy" );
2015-08-24 12:50:24 +00:00
element.selectmenu( {
appendTo: detached
2015-08-24 12:50:24 +00:00
} );
2014-04-22 22:24:04 +00:00
equal( element.selectmenu( "menuWidget" ).parent().parent()[ 0 ], detached[ 0 ],
"detached jQuery object" );
element.selectmenu( "destroy" );
2012-05-16 18:43:42 +00:00
2015-08-24 12:50:24 +00:00
element.selectmenu( {
appendTo: detached[ 0 ]
2015-08-24 12:50:24 +00:00
} );
2014-04-22 22:24:04 +00:00
equal( element.selectmenu( "menuWidget" ).parent().parent()[ 0 ], detached[ 0 ],
"detached DOM element" );
element.selectmenu( "destroy" );
2012-05-16 18:43:42 +00:00
element.selectmenu().selectmenu( "option", "appendTo", detached );
2014-04-22 22:24:04 +00:00
equal( element.selectmenu( "menuWidget" ).parent().parent()[ 0 ], detached[ 0 ],
"detached DOM element via option()" );
element.selectmenu( "destroy" );
2015-08-24 12:50:24 +00:00
} );
test( "appendTo: ui-front", function() {
expect( 2 );
2014-04-22 22:24:04 +00:00
var element = $( "#speed" );
$( "#selectmenu-wrap2" ).addClass( "ui-front" );
element.selectmenu();
equal( element.selectmenu( "menuWidget" ).parent().parent()[ 0 ],
$( "#selectmenu-wrap2" )[ 0 ], "null, inside .ui-front" );
element.selectmenu( "destroy" );
2015-08-24 12:50:24 +00:00
element.selectmenu( {
appendTo: $()
2015-08-24 12:50:24 +00:00
} );
equal( element.selectmenu( "menuWidget" ).parent().parent()[ 0 ],
$( "#selectmenu-wrap2" )[ 0 ], "empty jQuery object, inside .ui-front" );
2015-08-24 12:50:24 +00:00
} );
test( "CSS styles", function( assert ) {
expect( 5 );
var element = $( "#speed" ).selectmenu(),
button = element.selectmenu( "widget" ),
menu = element.selectmenu( "menuWidget" );
element.selectmenu( "open" );
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
} );
test( "width", function() {
expect( 6 );
2014-07-29 19:18:46 +00:00
var button,
2014-04-22 22:24:04 +00:00
element = $( "#speed" );
element.selectmenu();
button = element.selectmenu( "widget" );
equal( button[ 0 ].style.width, "", "no inline style" );
element.selectmenu( "option", "width", null );
equal( button.outerWidth(), element.outerWidth(), "button width auto" );
element.outerWidth( 100 );
element.selectmenu( "refresh" );
equal( button.outerWidth(), 100, "button width set by CSS" );
2014-04-22 22:24:04 +00:00
element
.width( "" )
.selectmenu( "option", "width", 100 )
.selectmenu( "refresh" );
equal( button.outerWidth(), 100, "button width set by JS option" );
2014-04-22 22:24:04 +00:00
element
.append( $( "<option>", { text: "Option with a little longer text" } ) )
.selectmenu( "option", "width", null )
2014-04-22 22:24:04 +00:00
.selectmenu( "refresh" );
equal( button.outerWidth(), element.outerWidth(), "button width with long option" );
element.parent().outerWidth( 300 );
element
.selectmenu( "destroy" )
.css( "width", "100%" )
2015-08-24 12:50:24 +00:00
.selectmenu( { width: null } );
button = element.selectmenu( "widget" );
equal( button.outerWidth(), 300, "button width fills container" );
2015-08-24 12:50:24 +00:00
} );
} );