271dbf91dbc17439a9a125d5a2d07d29cd0b93bf
[platform/framework/web/web-ui-fw.git] / libs / js / jquery-mobile-1.0.1pre / 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 native select defaults the text", function() {
50                 var select = $( "#native-refresh" ),
51       button = select.siblings( '.ui-btn-inner' ),
52       text = "foo";
53
54     same(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(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 })(jQuery);