Tizen 2.1 base
[platform/framework/web/web-ui-fw.git] / libs / js / jquery-mobile-1.0.1pre / tests / unit / controlgroup / controlgroup_core.js
1 /*
2  * mobile checkboxradio unit tests
3  */
4 (function($){
5         module( 'vertical controlgroup, no refresh' , {
6                 setup: function() {
7                         this.vcontrolgroup = $( "#vertical-controlgroup" );
8                 }
9         });
10
11         test( "vertical controlgroup classes", function() {
12                 var buttons = this.vcontrolgroup.find( ".ui-btn" ),
13                         middlebuttons = buttons.filter(function(index) { return index > 0 && index < (length-1)}),
14                         length = buttons.length;
15
16                 ok( !buttons.hasClass( "ui-btn-corner-all" ), "no button should have class 'ui-btn-corner-all'");
17                 ok( buttons.first().hasClass( "ui-corner-top" ), "first button should have class 'ui-corner-top'" );
18                 ok( !middlebuttons.hasClass( "ui-corner-top" ), "middle buttons should not have class 'ui-corner-top'" );
19                 ok( !middlebuttons.hasClass( "ui-corner-bottom" ), "middle buttons should not have class 'ui-corner-bottom'" );
20                 ok( buttons.last().hasClass( "ui-corner-bottom"), "last button should have class 'ui-corner-bottom'" );
21         });
22
23         module( 'vertical controlgroup, refresh', {
24                 setup: function() {
25                         this.vcontrolgroup = $( "#vertical-controlgroup" );
26                         this.vcontrolgroup.find( ".ui-btn" ).show();
27                         this.vcontrolgroup.controlgroup();
28                 }
29         });
30
31         test( "vertical controlgroup after first button was hidden", function() {
32                 //https://github.com/jquery/jquery-mobile/issues/1929
33
34                 //We hide the first button and refresh
35                 this.vcontrolgroup.find( ".ui-btn" ).first().hide();
36                 this.vcontrolgroup.controlgroup();
37
38                 var buttons = this.vcontrolgroup.find( ".ui-btn" ).filter( ":visible" ),
39                         middlebuttons = buttons.filter(function(index) { return index > 0 && index < (length-1)}),
40                         length = buttons.length;
41
42                 ok( buttons.first().hasClass( "ui-corner-top" ), "first visible button should have class 'ui-corner-top'" );
43                 ok( !middlebuttons.hasClass( "ui-corner-top" ), "middle buttons should not have class 'ui-corner-top'" );
44                 ok( !middlebuttons.hasClass( "ui-corner-bottom" ), "middle buttons should not have class 'ui-corner-bottom'" );
45                 ok( buttons.last().hasClass( "ui-corner-bottom"), "last visible button should have class 'ui-corner-bottom'" );
46         });
47
48         test( "vertical controlgroup after last button was hidden", function() {
49                 //https://github.com/jquery/jquery-mobile/issues/1929
50
51                 //We hide the last button and refresh
52                 this.vcontrolgroup.find( ".ui-btn" ).last().hide();
53                 this.vcontrolgroup.controlgroup();
54
55                 var buttons = this.vcontrolgroup.find( ".ui-btn" ).filter( ":visible" ),
56                         middlebuttons = buttons.filter(function(index) { return index > 0 && index < (length-1)}),
57                         length = buttons.length;
58
59                 ok( buttons.first().hasClass( "ui-corner-top" ), "first visible button should have class 'ui-corner-top'" );
60                 ok( !middlebuttons.hasClass( "ui-corner-top" ), "middle buttons should not have class 'ui-corner-top'" );
61                 ok( !middlebuttons.hasClass( "ui-corner-bottom" ), "middle buttons should not have class 'ui-corner-bottom'" );
62                 ok( buttons.last().hasClass( "ui-corner-bottom"), "last visible button should have class 'ui-corner-bottom'" );
63         });
64
65         module( 'horizontal controlgroup, no refresh', {
66                 setup: function() {
67                         this.hcontrolgroup = $( "#horizontal-controlgroup" );
68                 }
69         });
70
71         test( "horizontal controlgroup classes", function() {
72                 var buttons = this.hcontrolgroup.find( ".ui-btn" ),
73                         middlebuttons = buttons.filter(function(index) { return index > 0 && index < (length-1)}),
74                         length = buttons.length;
75
76                 ok( !buttons.hasClass( "ui-btn-corner-all" ), "no button should have class 'ui-btn-corner-all'");
77                 ok( buttons.first().hasClass( "ui-corner-left" ), "first button should have class 'ui-corner-left'" );
78                 ok( !middlebuttons.hasClass( "ui-corner-left" ), "middle buttons should not have class 'ui-corner-left'" );
79                 ok( !middlebuttons.hasClass( "ui-corner-right" ), "middle buttons should not have class 'ui-corner-right'" );
80                 ok( buttons.last().hasClass( "ui-corner-right"), "last button should have class 'ui-corner-right'" );
81         });
82
83         module( 'horizontal controlgroup, refresh', {
84                 setup: function() {
85                         this.hcontrolgroup = $( "#horizontal-controlgroup" );
86                         this.hcontrolgroup.find( ".ui-btn" ).show();
87                         this.hcontrolgroup.controlgroup();
88                 }
89         });
90
91         test( "horizontal controlgroup after first button was hidden", function() {
92                 //We hide the first button and refresh
93                 this.hcontrolgroup.find( ".ui-btn" ).first().hide();
94                 this.hcontrolgroup.controlgroup();
95
96                 var buttons = this.hcontrolgroup.find( ".ui-btn" ).filter( ":visible" ),
97                         middlebuttons = buttons.filter(function(index) { return index > 0 && index < (length-1)}),
98                         length = buttons.length;
99
100                 ok( buttons.first().hasClass( "ui-corner-left" ), "first visible button should have class 'ui-corner-left'" );
101                 ok( !middlebuttons.hasClass( "ui-corner-left" ), "middle buttons should not have class 'ui-corner-left'" );
102                 ok( !middlebuttons.hasClass( "ui-corner-right" ), "middle buttons should not have class 'ui-corner-right'" );
103                 ok( buttons.last().hasClass( "ui-corner-right"), "last visible button should have class 'ui-corner-right'" );
104         });
105
106         test( "horizontal controlgroup after last button was hidden", function() {
107                 //We hide the last button and refresh
108                 this.hcontrolgroup.find( ".ui-btn" ).last().hide();
109                 this.hcontrolgroup.controlgroup();
110
111                 var buttons = this.hcontrolgroup.find( ".ui-btn" ).filter( ":visible" ),
112                         middlebuttons = buttons.filter(function(index) { return index > 0 && index < (length-1)}),
113                         length = buttons.length;
114
115                 ok( buttons.first().hasClass( "ui-corner-left" ), "first visible button should have class 'ui-corner-left'" );
116                 ok( !middlebuttons.hasClass( "ui-corner-left" ), "middle buttons should not have class 'ui-corner-left'" );
117                 ok( !middlebuttons.hasClass( "ui-corner-right" ), "middle buttons should not have class 'ui-corner-right'" );
118                 ok( buttons.last().hasClass( "ui-corner-right"), "last visible button should have class 'ui-corner-right'" );
119         });
120
121
122         test( "controlgroups will create when inside a container that receives a 'create' event", function(){
123                 ok( !$("#enhancetest").appendTo(".ui-page-active").find(".ui-controlgroup").length, "did not have enhancements applied" );
124                 ok( $("#enhancetest").trigger("create").find(".ui-controlgroup").length, "enhancements applied" );
125         });
126
127
128
129 })(jQuery);