Tokentextarea: Fix issues
[platform/framework/web/web-ui-fw.git] / libs / js / jquery-mobile-1.1.0 / tests / unit / select / select_native.js
1 /*
2  * mobile select unit tests
3  */
4
5 (function($){
6         module("jquery.mobile.forms.select native");
7
8         test( "native menu selections alter the button text", function(){
9                 var select = $( "#native-select-choice-few" ), setAndCheck;
10
11                 setAndCheck = function(key){
12                         var text;
13
14                         select.val( key ).selectmenu( 'refresh' );
15                         text = select.find( "option[value='" + key + "']" ).text();
16                         same( select.parent().find(".ui-btn-text").text(), text );
17                 };
18
19                 setAndCheck( 'rush' );
20                 setAndCheck( 'standard' );
21         });
22
23         asyncTest( "selecting a value removes the related buttons down state", function(){
24                 var select = $( "#native-select-choice-few" );
25
26                 $.testHelper.sequence([
27                         function() {
28                                 // click the native menu parent button
29                                 select.parent().trigger( 'vmousedown' );
30                         },
31
32                         function() {
33                                 ok( select.parent().hasClass("ui-btn-down-c"), "button down class added" );
34                         },
35
36                         function() {
37                                 // trigger a change on the select
38                                 select.trigger( "change" );
39                         },
40
41                         function() {
42                                 ok( !select.parent().hasClass("ui-btn-down-c"), "button down class removed" );
43                                 start();
44                         }
45                 ], 300);
46         });
47
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" ),
52                         text = "foo";
53
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);
59         });
60
61         // issue 2424
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' );
66                 ok( true );
67         });
68
69         asyncTest( "The preventFocusZoom option is working as expected", function() {
70
71                 var zoomoptiondefault = $.mobile.selectmenu.prototype.options.preventFocusZoom;
72                 $.mobile.selectmenu.prototype.options.preventFocusZoom = true;
73
74                 $(document)
75                         .one("vmousedown.test", function(){
76                                 ok( $.mobile.zoom.enabled === false, "zoom is disabled on vmousedown" );
77                         })
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 )
83                                 start();
84                 });
85
86                 $( "#select-choice-native" )
87                         .selectmenu( "option", "preventFocusZoom", true )
88                         .parent()
89                         .trigger( "vmousedown" )
90                         .trigger( "mouseup" );
91
92
93
94
95         });
96
97         asyncTest( "The preventFocusZoom option does not manipulate zoom when it is false", function() {
98
99                 var zoomstate = $.mobile.zoom.enabled,
100                         zoomoptiondefault = $.mobile.selectmenu.prototype.options.preventFocusZoom;
101
102
103                 $(document)
104                         .one("vmousedown.test", function(){
105                                 ok( $.mobile.zoom.enabled === zoomstate, "zoom is unaffected on vmousedown" );
106                         })
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 );
111                                 start();
112
113                 });
114
115                 $( "#select-choice-native" )
116                         .selectmenu( "option", "preventFocusZoom", false )
117                         .parent()
118                         .trigger( "vmousedown" )
119                         .trigger( "mouseup" );
120
121         });
122 })(jQuery);