2 * mobile select unit tests
6 module("jquery.mobile.forms.select native");
8 test( "native menu selections alter the button text", function(){
9 var select = $( "#native-select-choice-few" ), setAndCheck;
11 setAndCheck = function(key){
14 select.val( key ).selectmenu( 'refresh' );
15 text = select.find( "option[value='" + key + "']" ).text();
16 same( select.parent().find(".ui-btn-text").text(), text );
19 setAndCheck( 'rush' );
20 setAndCheck( 'standard' );
23 asyncTest( "selecting a value removes the related buttons down state", function(){
24 var select = $( "#native-select-choice-few" );
26 $.testHelper.sequence([
28 // click the native menu parent button
29 select.parent().trigger( 'vmousedown' );
33 ok( select.parent().hasClass("ui-btn-down-c"), "button down class added" );
37 // trigger a change on the select
38 select.trigger( "change" );
42 ok( !select.parent().hasClass("ui-btn-down-c"), "button down class removed" );
48 // issue https://github.com/jquery/jquery-mobile/issues/2410
49 test( "adding options and refreshing a custom select defaults the text", function() {
50 var select = $( "#custom-refresh" ),
51 button = select.siblings( "a" ).find( ".ui-btn-inner" ),
54 same($.trim(button.text()), "default");
55 select.find( "option" ).remove(); //remove the loading message
56 select.append('<option value="1">' + text + '</option>');
57 select.selectmenu( 'refresh' );
58 same($.trim(button.text()), text);
62 test( "native selects should provide open and close as a no-op", function() {
63 // exception will prevent test success if undef
64 $( "#native-refresh" ).selectmenu( 'open' );
65 $( "#native-refresh" ).selectmenu( 'close' );
69 asyncTest( "The preventFocusZoom option is working as expected", function() {
71 var zoomoptiondefault = $.mobile.selectmenu.prototype.options.preventFocusZoom;
72 $.mobile.selectmenu.prototype.options.preventFocusZoom = true;
75 .one("vmousedown.test", function(){
76 ok( $.mobile.zoom.enabled === false, "zoom is disabled on vmousedown" );
78 .one("mouseup.test", function(){
79 ok( $.mobile.zoom.enabled === true, "zoom is enabled on mouseup" );
80 $.mobile.selectmenu.prototype.options.preventFocusZoom = zoomoptiondefault;
81 $(document).unbind(".test");
82 $( "#select-choice-native" ).selectmenu( "option", "preventFocusZoom", zoomoptiondefault )
86 $( "#select-choice-native" )
87 .selectmenu( "option", "preventFocusZoom", true )
89 .trigger( "vmousedown" )
90 .trigger( "mouseup" );
97 asyncTest( "The preventFocusZoom option does not manipulate zoom when it is false", function() {
99 var zoomstate = $.mobile.zoom.enabled,
100 zoomoptiondefault = $.mobile.selectmenu.prototype.options.preventFocusZoom;
104 .one("vmousedown.test", function(){
105 ok( $.mobile.zoom.enabled === zoomstate, "zoom is unaffected on vmousedown" );
107 .one("mouseup.test", function(){
108 ok( $.mobile.zoom.enabled === zoomstate, "zoom is unaffected on mouseup" );
109 $(document).unbind(".test");
110 $( "#select-choice-native" ).selectmenu( "option", "preventFocusZoom", zoomoptiondefault );
115 $( "#select-choice-native" )
116 .selectmenu( "option", "preventFocusZoom", false )
118 .trigger( "vmousedown" )
119 .trigger( "mouseup" );