2 * mobile checkboxradio unit tests
5 module( 'jquery.mobile.forms.checkboxradio.js' );
7 test( "widget can be disabled and enabled", function(){
8 var input = $( "#checkbox-1" ),
9 button = input.parent().find( ".ui-btn" );
11 input.checkboxradio( "disable" );
12 input.checkboxradio( "enable" );
13 ok( !input.attr( "disabled" ), "start input as enabled" );
14 ok( !input.parent().hasClass( "ui-disabled" ), "no disabled styles" );
15 ok( !input.attr( "checked" ), "not checked before click" );
16 button.trigger( "click" );
17 ok( input.attr( "checked" ), "checked after click" );
18 ok( button.hasClass( "ui-checkbox-on" ), "active styles after click" );
19 button.trigger( "click" );
21 input.checkboxradio( "disable" );
22 ok( input.attr( "disabled" ), "input disabled" );
23 ok( input.parent().hasClass( "ui-disabled" ), "disabled styles" );
24 ok( !input.attr( "checked" ), "not checked before click" );
25 button.trigger( "click" );
26 ok( !input.attr( "checked" ), "not checked after click" );
27 ok( !button.hasClass( "ui-checkbox-on" ), "no active styles after click" );
30 test( "clicking a checkbox within a controlgroup does not affect checkboxes with the same name in the same controlgroup", function(){
31 var input1 = $("#checkbox-31");
32 var button1 = input1.parent().find(".ui-btn");
33 var input2 = $("#checkbox-32");
34 var button2 = input2.parent().find(".ui-btn");
36 ok(!input1.attr("checked"), "input1 not checked before click");
37 ok(!input2.attr("checked"), "input2 not checked before click");
39 button1.trigger("click");
40 ok(input1.attr("checked"), "input1 checked after click on input1");
41 ok(!input2.attr("checked"), "input2 not checked after click on input1");
43 button2.trigger("click");
44 ok(input1.attr("checked"), "input1 not changed after click on input2");
45 ok(input2.attr("checked"), "input2 checked after click on input2");
48 asyncTest( "change events fired on checkbox for both check and uncheck", function(){
49 var $checkbox = $( "#checkbox-2" ),
50 $checkboxLabel = $checkbox.parent().find( ".ui-btn" );
52 $checkbox.unbind( "change" );
56 $checkbox.one('change', function(){
57 ok( true, "change fired on click to check the box" );
60 $checkboxLabel.trigger( "click" );
62 //test above will be triggered twice, and the start here once
63 $checkbox.one('change', function(){
67 $checkboxLabel.trigger( "click" );
70 asyncTest( "radio button labels should update the active button class to last clicked and clear checked", function(){
71 var $radioBtns = $( '#radio-active-btn-test input' ),
72 singleActiveAndChecked = function(){
73 same( $( "#radio-active-btn-test .ui-radio-on" ).length, 1, "there should be only one active button" );
74 same( $( "#radio-active-btn-test :checked" ).length, 1, "there should be only one checked" );
77 $.testHelper.sequence([
79 $radioBtns.last().siblings( 'label' ).click();
83 ok( $radioBtns.last().prop( 'checked' ) );
84 ok( $radioBtns.last().siblings( 'label' ).hasClass( 'ui-radio-on' ),
85 "last input label is an active button" );
87 ok( !$radioBtns.first().prop( 'checked' ) );
88 ok( !$radioBtns.first().siblings( 'label' ).hasClass( 'ui-radio-on' ),
89 "first input label is not active" );
91 singleActiveAndChecked();
93 $radioBtns.first().siblings( 'label' ).click();
97 ok( $radioBtns.first().prop( 'checked' ));
98 ok( $radioBtns.first().siblings( 'label' ).hasClass( 'ui-radio-on' ),
99 "first input label is an active button" );
101 ok( !$radioBtns.last().prop( 'checked' ));
102 ok( !$radioBtns.last().siblings( 'label' ).hasClass( 'ui-radio-on' ),
103 "last input label is not active" );
105 singleActiveAndChecked();
113 test( "checkboxradio controls will create when inside a container that receives a 'create' event", function(){
114 ok( !$("#enhancetest").appendTo(".ui-page-active").find(".ui-checkbox").length, "did not have enhancements applied" );
115 ok( $("#enhancetest").trigger("create").find(".ui-checkbox").length, "enhancements applied" );
118 $.mobile.page.prototype.options.keepNative = "input.should-be-native";
120 // not testing the positive case here since's it's obviously tested elsewhere
121 test( "checkboxradio elements in the keepNative set shouldn't be enhanced", function() {
122 ok( !$("input.should-be-native").parent().is("div.ui-checkbox") );
125 asyncTest( "clicking the label triggers a click on the element", function() {
130 $( "#checkbox-click-triggered" ).one('click', function() {
134 $.testHelper.sequence([
136 $( "[for='checkbox-click-triggered']" ).click();
140 ok(clicked, "click was fired on input");