Skip to content

Commit 1656cd2

Browse files
committed
Selectmenu Tests: add unit and visual tests for width option
1 parent 06bcd8e commit 1656cd2

File tree

2 files changed

+92
-1
lines changed

2 files changed

+92
-1
lines changed

tests/unit/selectmenu/selectmenu_options.js

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,4 +57,43 @@ test( "CSS styles", function () {
5757
ok( menu.hasClass( "ui-corner-bottom" ) && !menu.hasClass( "ui-corner-all" ), "menu styles dropdown" );
5858
});
5959

60+
61+
test( "Width", function () {
62+
expect( 8 );
63+
64+
var element = $( "#speed" ),
65+
button, menu;
66+
67+
element.selectmenu();
68+
button = element.selectmenu( "widget" );
69+
menu = element.selectmenu( "menuWidget" );
70+
71+
equal( button.outerWidth(), element.outerWidth(), "button width auto" );
72+
element.selectmenu( "open" );
73+
equal( menu.outerWidth(), element.outerWidth(), "menu width auto" );
74+
75+
element.outerWidth( 100 );
76+
element.selectmenu( "refresh" );
77+
78+
equal( button.outerWidth(), 100, "button width set by CSS" );
79+
element.selectmenu( "open" );
80+
equal( menu.outerWidth(), 100, "menu width set by CSS" );
81+
82+
element.width( "" );
83+
element.selectmenu( "option", "width", 100 );
84+
element.selectmenu( "refresh" );
85+
86+
equal( button.outerWidth(), 100, "button width set by JS option" );
87+
element.selectmenu( "open" );
88+
equal( menu.outerWidth(), 100, "menu width set by JS option" );
89+
90+
element.append( $( "<option>", { text: "Option with a little longer text" } ) );
91+
element.selectmenu( "option", "width", "" );
92+
element.selectmenu( "refresh" );
93+
94+
equal( button.outerWidth(), element.outerWidth(), "button width with long option" );
95+
element.selectmenu( "open" );
96+
ok( menu.outerWidth() >= element.outerWidth(), "menu width with long option" );
97+
});
98+
6099
})( jQuery );

tests/visual/selectmenu/selectmenu.html

Lines changed: 53 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,18 @@
107107
});
108108

109109
/* empty */
110-
$('.empty select').selectmenu();
110+
$(".empty select").selectmenu();
111+
112+
/* width */
113+
$("#width_auto1, #width_auto2").selectmenu();
114+
115+
$("#width_js1, #width_js2").selectmenu({
116+
width: 200
117+
});
118+
119+
var widthMenu = $("#width_menu").selectmenu();
120+
widthMenu.selectmenu("menuWidget").addClass("width-menu");
121+
111122
});
112123
</script>
113124
<style>
@@ -117,6 +128,9 @@
117128
select { width: 200px; }
118129

119130
.ui-selectmenu-button { display: block; margin-bottom: 1em;}
131+
132+
/* width */
133+
.width-menu { width: 196px; }
120134
</style>
121135
</head>
122136
<body>
@@ -237,6 +251,44 @@ <h2>Empty tests</h2>
237251
</optgroup>
238252
</select>
239253
</fieldset>
254+
255+
<h2>Width tests</h2>
256+
<fieldset>
257+
<label for="width_auto1">Width auto</label>
258+
<select name="width_auto1" id="width_auto1" style="width: auto;">
259+
<option>Width test 1</option>
260+
<option>Width test 2</option>
261+
<option>Width test 3</option>
262+
</select>
263+
264+
<label for="width_auto2">Width auto with long option</label>
265+
<select name="width_auto2" id="width_auto2" style="width: auto;">
266+
<option>Width test 1</option>
267+
<option>Width test 2</option>
268+
<option>Width test 3 Width test 3 Width test 3</option>
269+
</select>
270+
271+
<label for="width_js1">Width set by JS</label>
272+
<select name="width_js1" id="width_js1">
273+
<option>Width test 1</option>
274+
<option>Width test 2</option>
275+
<option>Width test 3</option>
276+
</select>
277+
278+
<label for="width_js2">Width set by JS with long option</label>
279+
<select name="width_js2" id="width_js2">
280+
<option>Width test 1</option>
281+
<option>Width test 2</option>
282+
<option>Width test 3 Width test 3 Width test 3</option>
283+
</select>
284+
285+
<label for="width_menu">Width set by JS with long option</label>
286+
<select name="width_menu" id="width_menu">
287+
<option>Width test 1</option>
288+
<option>Width test 2</option>
289+
<option>Width test 3 Width test 3 Width test 3</option>
290+
</select>
291+
</fieldset>
240292
</form>
241293

242294
<div style="position: absolute; top: 1em; right: 1em;">

0 commit comments

Comments
 (0)