|
2 | 2 | * mobile checkboxradio unit tests |
3 | 3 | */ |
4 | 4 | (function($){ |
5 | | - module('jquery.mobile.forms.checkboxradio.js'); |
| 5 | + module( 'jquery.mobile.forms.checkboxradio.js' ); |
6 | 6 |
|
7 | 7 | test( "widget can be disabled and enabled", function(){ |
8 | | - var input = $("#checkbox-1"); |
9 | | - var button = input.parent().find(".ui-btn"); |
10 | | - |
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"); |
20 | | - |
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"); |
| 8 | + var input = $( "#checkbox-1" ), |
| 9 | + button = input.parent().find( ".ui-btn" ); |
| 10 | + |
| 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" ); |
| 20 | + |
| 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" ); |
28 | 28 | }); |
29 | 29 |
|
30 | 30 | asyncTest( "change events fired on checkbox for both check and uncheck", function(){ |
31 | | - var $checkbox = $("#checkbox-2"), |
32 | | - $checkboxLabel = $checkbox.parent().find(".ui-btn"); |
| 31 | + var $checkbox = $( "#checkbox-2" ), |
| 32 | + $checkboxLabel = $checkbox.parent().find( ".ui-btn" ); |
33 | 33 |
|
34 | | - $checkbox.unbind("change"); |
| 34 | + $checkbox.unbind( "change" ); |
35 | 35 |
|
36 | 36 | expect( 2 ); |
37 | 37 |
|
38 | 38 | $checkbox.change(function(){ |
39 | | - ok(true, "change fired on click to check the box"); |
| 39 | + ok( true, "change fired on click to check the box" ); |
40 | 40 | }); |
41 | 41 |
|
42 | | - $checkboxLabel.trigger("click"); |
| 42 | + $checkboxLabel.trigger( "click" ); |
43 | 43 |
|
44 | 44 | //test above will be triggered twice, and the start here once |
45 | | - $checkbox.change(function(){ |
| 45 | + $checkbox.change( function(){ |
46 | 46 | start(); |
47 | 47 | }); |
48 | 48 |
|
49 | | - $checkboxLabel.trigger("click"); |
| 49 | + $checkboxLabel.trigger( "click" ); |
50 | 50 | }); |
51 | 51 |
|
52 | 52 | asyncTest( "radio button labels should update the active button class to last clicked and clear checked", function(){ |
53 | | - var $radioBtns = $('#radio-active-btn-test input'), |
54 | | - singleActiveAndChecked = function(){ |
55 | | - same($("#radio-active-btn-test .ui-radio-on").length, 1, "there should be only one active button"); |
56 | | - same($("#radio-active-btn-test :checked").length, 1, "there should be only one checked"); |
57 | | - }; |
| 53 | + var $radioBtns = $( '#radio-active-btn-test input' ), |
| 54 | + singleActiveAndChecked = function(){ |
| 55 | + same( $( "#radio-active-btn-test .ui-radio-on" ).length, 1, "there should be only one active button" ); |
| 56 | + same( $( "#radio-active-btn-test :checked" ).length, 1, "there should be only one checked" ); |
| 57 | + }; |
58 | 58 |
|
59 | 59 | $.testHelper.sequence([ |
60 | 60 | function(){ |
61 | | - $radioBtns.last().siblings('label').click(); |
| 61 | + $radioBtns.last().siblings( 'label' ).click(); |
62 | 62 | }, |
63 | 63 |
|
64 | 64 | function(){ |
65 | | - ok($radioBtns.last().attr('checked')); |
66 | | - ok($radioBtns.last().siblings('label').hasClass('ui-radio-on'), |
67 | | - "last input label is an active button"); |
| 65 | + ok( $radioBtns.last().attr( 'checked' ) ); |
| 66 | + ok( $radioBtns.last().siblings( 'label' ).hasClass( 'ui-radio-on' ), |
| 67 | + "last input label is an active button" ); |
68 | 68 |
|
69 | | - ok(!$radioBtns.first().attr('checked')); |
70 | | - ok(!$radioBtns.first().siblings('label').hasClass('ui-radio-on'), |
71 | | - "first input label is not active"); |
| 69 | + ok( !$radioBtns.first().attr( 'checked' ) ); |
| 70 | + ok( !$radioBtns.first().siblings( 'label' ).hasClass( 'ui-radio-on' ), |
| 71 | + "first input label is not active" ); |
72 | 72 |
|
73 | 73 | singleActiveAndChecked(); |
74 | 74 |
|
75 | | - $radioBtns.first().siblings('label').click(); |
| 75 | + $radioBtns.first().siblings( 'label' ).click(); |
76 | 76 | }, |
77 | 77 |
|
78 | 78 | function(){ |
79 | | - ok($radioBtns.first().attr('checked')); |
80 | | - ok($radioBtns.first().siblings('label').hasClass('ui-radio-on'), |
81 | | - "first input label is an active button"); |
| 79 | + ok( $radioBtns.first().attr( 'checked' )); |
| 80 | + ok( $radioBtns.first().siblings( 'label' ).hasClass( 'ui-radio-on' ), |
| 81 | + "first input label is an active button" ); |
82 | 82 |
|
83 | | - ok(!$radioBtns.last().attr('checked')); |
84 | | - ok(!$radioBtns.last().siblings('label').hasClass('ui-radio-on'), |
85 | | - "last input label is not active"); |
| 83 | + ok( !$radioBtns.last().attr( 'checked' )); |
| 84 | + ok( !$radioBtns.last().siblings( 'label' ).hasClass( 'ui-radio-on' ), |
| 85 | + "last input label is not active" ); |
86 | 86 |
|
87 | 87 | singleActiveAndChecked(); |
88 | 88 |
|
|
0 commit comments