|
| 1 | +/* |
| 2 | + * checkboxradio_core.js |
| 3 | + */ |
| 4 | + |
| 5 | + |
| 6 | +(function($) { |
| 7 | + |
| 8 | +module("Checkboxradio: core"); |
| 9 | +test("Checkbox", function() { |
| 10 | + expect( 4 ); |
| 11 | + var input = $("#check"), |
| 12 | + label = $("label[for=check]"); |
| 13 | + ok( input.is( ":visible" ) ); |
| 14 | + ok( !label.hasClass(".ui-button)") ); |
| 15 | + input.checkboxradio(); |
| 16 | + strictEqual( input.attr( "class" ), "ui-helper-hidden-accessible ui-checkboxradio" ); |
| 17 | + strictEqual( label.attr( "class" ), "ui-button ui-widget ui-corner-all ui-checkbox-label" ); |
| 18 | +}); |
| 19 | + |
| 20 | +test("Radios", function() { |
| 21 | + expect( 4 ); |
| 22 | + var inputs = $("#radio0 input"), |
| 23 | + labels = $("#radio0 label"); |
| 24 | + ok( inputs.is(":visible") ); |
| 25 | + ok( labels.is(":not(.ui-button)") ); |
| 26 | + inputs.checkboxradio(); |
| 27 | + ok( inputs.is(".ui-helper-hidden-accessible") ); |
| 28 | + ok( labels.is(".ui-button") ); |
| 29 | +}); |
| 30 | + |
| 31 | +function assert(noForm, form1, form2) { |
| 32 | + ok( $("#radio0 .ui-button" + noForm).is(".ui-state-active") ); |
| 33 | + ok( $("#radio1 .ui-button" + form1).is(".ui-state-active") ); |
| 34 | + ok( $("#radio2 .ui-button" + form2).is(".ui-state-active") ); |
| 35 | +} |
| 36 | + |
| 37 | +test("radio groups", function() { |
| 38 | + expect( 12 ); |
| 39 | + $("input[type=radio]").checkboxradio(); |
| 40 | + assert(":eq(0)", ":eq(1)", ":eq(2)"); |
| 41 | + |
| 42 | + // click outside of forms |
| 43 | + $("#radio0 .ui-button:eq(1)").simulate("click"); |
| 44 | + assert(":eq(1)", ":eq(1)", ":eq(2)"); |
| 45 | + |
| 46 | + // click in first form |
| 47 | + $("#radio1 .ui-button:eq(0)").simulate("click"); |
| 48 | + assert(":eq(1)", ":eq(0)", ":eq(2)"); |
| 49 | + |
| 50 | + // click in second form |
| 51 | + $("#radio2 .ui-button:eq(0)").simulate("click"); |
| 52 | + assert(":eq(1)", ":eq(0)", ":eq(0)"); |
| 53 | +}); |
| 54 | + |
| 55 | +asyncTest( "Checkbox/Radiobutton do not Show Focused State when using Keyboard Navigation", function() { |
| 56 | + expect( 2 ); |
| 57 | + var check = $( "#check" ).checkboxradio(), |
| 58 | + label = $( "label[for='check']" ); |
| 59 | + ok( !label.is( ".ui-state-focus" ) ); |
| 60 | + check.focus(); |
| 61 | + setTimeout(function() { |
| 62 | + ok( label.is( ".ui-state-focus" ) ); |
| 63 | + start(); |
| 64 | + }); |
| 65 | +}); |
| 66 | + |
| 67 | +// TODO: simulated click events don't behave like real click events in IE |
| 68 | +// remove this when simulate properly simulates this |
| 69 | +// see http://yuilibrary.com/projects/yui2/ticket/2528826 fore more info |
| 70 | +if ( !$.ui.ie || ( document.documentMode && document.documentMode > 8 ) ) { |
| 71 | + asyncTest( "Ensure checked after single click on checkbox label button", function() { |
| 72 | + expect( 2 ); |
| 73 | + |
| 74 | + $( "#check2" ).checkboxradio().change( function() { |
| 75 | + var label = $( this ).checkboxradio( "widget" ); |
| 76 | + ok( this.checked, "checked ok" ); |
| 77 | + |
| 78 | + // The following test is commented out for now because with new markup we are trying to avoid aria |
| 79 | + //ok( lbl.attr("aria-pressed") === "true", "aria ok" ); |
| 80 | + ok( label.hasClass( "ui-state-active" ), "ui-state-active ok" ); |
| 81 | + }); |
| 82 | + |
| 83 | + // Support: Opera |
| 84 | + // Opera doesn't trigger a change event when this is done synchronously. |
| 85 | + // This seems to be a side effect of another test, but until that can be |
| 86 | + // tracked down, this delay will have to do. |
| 87 | + setTimeout(function() { |
| 88 | + $( "#check2" ).checkboxradio( "widget" ).simulate( "click" ); |
| 89 | + start(); |
| 90 | + }, 1 ); |
| 91 | + }); |
| 92 | +} |
| 93 | +test( "Checkbox creation that requires a matching label does not find label in all cases", function() { |
| 94 | + expect( 5 ); |
| 95 | + var group = $( "<span><label for='t7092a'></label><input type='checkbox' id='t7092a'></span>" ); |
| 96 | + group.find( "input[type=checkbox]" ).checkboxradio(); |
| 97 | + ok( group.find( "label" ).is( ".ui-button" ) ); |
| 98 | + |
| 99 | + group = $( "<input type='checkbox' id='t7092b'><label for='t7092b'></label>" ); |
| 100 | + group.filter( "input[type=checkbox]" ).checkboxradio(); |
| 101 | + ok( group.filter( "label" ).is( ".ui-button" ) ); |
| 102 | + |
| 103 | + group = $( "<span><input type='checkbox' id='t7092c'></span><label for='t7092c'></label>" ); |
| 104 | + group.find( "input[type=checkbox]" ).checkboxradio(); |
| 105 | + ok( group.filter( "label" ).is( ".ui-button" ) ); |
| 106 | + |
| 107 | + group = $( "<span><input type='checkbox' id='t7092d'></span><span><label for='t7092d'></label></span>" ); |
| 108 | + group.find( "input[type=checkbox]" ).checkboxradio(); |
| 109 | + ok( group.find( "label" ).is( ".ui-button" ) ); |
| 110 | + |
| 111 | + group = $( "<input type='checkbox' id='t7092e'><span><label for='t7092e'></label></span>" ); |
| 112 | + group.filter( "input[type=checkbox]" ).checkboxradio(); |
| 113 | + ok( group.find( "label" ).is( ".ui-button" ) ); |
| 114 | +}); |
| 115 | + |
| 116 | +asyncTest( "Resetting a button's form should refresh the visual state of the button widget to match.", function() { |
| 117 | + expect( 2 ); |
| 118 | + var form = $( "<form>" + |
| 119 | + "<label for='c1'></label><input id='c1' type='checkbox' checked>" + |
| 120 | + "</form>" ), |
| 121 | + checkbox = form.find( "input[type=checkbox]" ).checkboxradio(); |
| 122 | + |
| 123 | + checkbox.prop( "checked", false ).checkboxradio( "refresh" ); |
| 124 | + ok( !checkbox.checkboxradio( "widget" ).hasClass( "ui-state-active" ) ); |
| 125 | + |
| 126 | + form.get( 0 ).reset(); |
| 127 | + |
| 128 | + setTimeout(function() { |
| 129 | + ok( checkbox.checkboxradio( "widget" ).hasClass( "ui-state-active" )); |
| 130 | + start(); |
| 131 | + }, 1 ); |
| 132 | +}); |
| 133 | +test( "Checkbox label selector works for ids with \":\"", function() { |
| 134 | + expect( 1 ); |
| 135 | + var group = $( "<span><input type='checkbox' id='check:7534'><label for='check:7534'>Label</label></span>" ); |
| 136 | + group.find( "input" ).checkboxradio(); |
| 137 | + ok( group.find( "label" ).is( ".ui-button" ), "Found an id with a :" ); |
| 138 | +}); |
| 139 | + |
| 140 | +})(jQuery); |
0 commit comments