2 * mobile checkboxradio unit tests
5 module( 'vertical controlgroup, no refresh' , {
7 this.vcontrolgroup = $( "#vertical-controlgroup" );
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;
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'" );
23 module( 'vertical controlgroup, refresh', {
25 this.vcontrolgroup = $( "#vertical-controlgroup" );
26 this.vcontrolgroup.find( ".ui-btn" ).show();
27 this.vcontrolgroup.controlgroup();
31 test( "vertical controlgroup after first button was hidden", function() {
32 //https://github.com/jquery/jquery-mobile/issues/1929
34 //We hide the first button and refresh
35 this.vcontrolgroup.find( ".ui-btn" ).first().hide();
36 this.vcontrolgroup.controlgroup();
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;
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'" );
48 test( "vertical controlgroup after last button was hidden", function() {
49 //https://github.com/jquery/jquery-mobile/issues/1929
51 //We hide the last button and refresh
52 this.vcontrolgroup.find( ".ui-btn" ).last().hide();
53 this.vcontrolgroup.controlgroup();
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;
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'" );
65 module( 'horizontal controlgroup, no refresh', {
67 this.hcontrolgroup = $( "#horizontal-controlgroup" );
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;
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'" );
83 module( 'horizontal controlgroup, refresh', {
85 this.hcontrolgroup = $( "#horizontal-controlgroup" );
86 this.hcontrolgroup.find( ".ui-btn" ).show();
87 this.hcontrolgroup.controlgroup();
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();
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;
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'" );
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();
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;
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'" );
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" );
127 test( "controlgroups in ignored containers aren't enhanced", function() {
128 var $unenhancedFieldSet = $( "#unenhanced-fieldset" ),
129 $enhancedFieldSet = $( "#enhanced-fieldset" );
131 $.mobile.ignoreContentEnabled = true;
133 // attempt to enhance the controlgroup
134 $unenhancedFieldSet.parent().trigger("create");
136 same( $unenhancedFieldSet.length, 1, "the fieldset test fixtures exist" );
137 ok( !$unenhancedFieldSet.is(".ui-controlgroup"), "there is no control group" );
139 // attempt to enhance the controlgroup
140 $enhancedFieldSet.parent().trigger("create");
142 same( $enhancedFieldSet.length, 1, "the fieldset test fixtures exist" );
143 ok( $enhancedFieldSet.is(".ui-controlgroup"), "there is a control group" );
145 $.mobile.ignoreContentEnabled = false;