corrade-http-templates – Blame information for rev 57
?pathlinks?
Rev | Author | Line No. | Line |
---|---|---|---|
57 | office | 1 | define( [ |
2 | "qunit", |
||
3 | "jquery", |
||
4 | "ui/widgets/checkboxradio" |
||
5 | ], function( QUnit, $ ) { |
||
6 | |||
7 | QUnit.module( "Checkboxradio: core" ); |
||
8 | |||
9 | QUnit.test( "Checkbox - Initial class structure", function( assert ) { |
||
10 | assert.expect( 2 ); |
||
11 | var input = $( "#check" ), |
||
12 | label = $( "label[for=check]" ); |
||
13 | |||
14 | input.checkboxradio(); |
||
15 | assert.hasClasses( input, "ui-helper-hidden-accessible ui-checkboxradio" ); |
||
16 | assert.hasClasses( label, "ui-button ui-widget ui-checkboxradio-label ui-corner-all" ); |
||
17 | } ); |
||
18 | |||
19 | QUnit.test( "Radios - Initial class structure", function( assert ) { |
||
20 | assert.expect( 6 ); |
||
21 | var inputs = $( "#radio0 input" ), |
||
22 | labels = $( "#radio0 label" ); |
||
23 | |||
24 | inputs.checkboxradio(); |
||
25 | inputs.each( function() { |
||
26 | assert.hasClasses( this, "ui-helper-hidden-accessible" ); |
||
27 | } ); |
||
28 | labels.each( function() { |
||
29 | assert.hasClasses( this, "ui-button" ); |
||
30 | } ); |
||
31 | } ); |
||
32 | |||
33 | QUnit.test( "Ensure checked after single click on checkbox label button", function( assert ) { |
||
34 | var ready = assert.async(); |
||
35 | assert.expect( 2 ); |
||
36 | |||
37 | $( "#check2" ).checkboxradio().change( function() { |
||
38 | var label = $( this ).checkboxradio( "widget" ); |
||
39 | assert.ok( this.checked, "checked ok" ); |
||
40 | |||
41 | assert.hasClasses( label, "ui-state-active" ); |
||
42 | } ); |
||
43 | |||
44 | // Support: Opera |
||
45 | // Opera doesn't trigger a change event when this is done synchronously. |
||
46 | // This seems to be a side effect of another test, but until that can be |
||
47 | // tracked down, this delay will have to do. |
||
48 | setTimeout( function() { |
||
49 | $( "#check2" ).checkboxradio( "widget" ).simulate( "click" ); |
||
50 | ready(); |
||
51 | } ); |
||
52 | } ); |
||
53 | |||
54 | QUnit.test( "Handle form association via form attribute", function( assert ) { |
||
55 | assert.expect( 4 ); |
||
56 | |||
57 | var radio1 = $( "#crazy-form-1" ).checkboxradio(); |
||
58 | var radio1Label = radio1.checkboxradio( "widget" ); |
||
59 | var radio2 = $( "#crazy-form-2" ).checkboxradio(); |
||
60 | var radio2Label = radio2.checkboxradio( "widget" ); |
||
61 | |||
62 | radio2.change( function() { |
||
63 | assert.ok( this.checked, "#2 checked" ); |
||
64 | assert.ok( !radio1[ 0 ].checked, "#1 not checked" ); |
||
65 | |||
66 | assert.hasClasses( radio2Label, "ui-state-active" ); |
||
67 | assert.lacksClasses( radio1Label, "ui-state-active" ); |
||
68 | } ); |
||
69 | |||
70 | radio2Label.simulate( "click" ); |
||
71 | } ); |
||
72 | |||
73 | QUnit.test( "Checkbox creation requires a label, and finds it in all cases", function( assert ) { |
||
74 | assert.expect( 7 ); |
||
75 | var groups = [ |
||
76 | "<span><label for='t7092a'></label><input type='checkbox' id='t7092a'></span>", |
||
77 | "<span><input type='checkbox' id='t7092b'><label for='t7092b'></label></span>", |
||
78 | "<span><span><input type='checkbox' id='t7092c'></span><label for='t7092c'></label></span>", |
||
79 | "<span><input type='checkbox' id='t7092d'></span><span><label for='t7092d'></label></span>", |
||
80 | "<span><input type='checkbox' id='t7092e'><span><label for='t7092e'></label></span></span>", |
||
81 | "<span><label><input type='checkbox' id='t7092f'></label></span>", |
||
82 | "<span><input type='checkbox' id='check:7534'><label for='check:7534'>Label</label></span>" |
||
83 | ]; |
||
84 | |||
85 | $.each( groups, function( index, markup ) { |
||
86 | var group = $( markup ); |
||
87 | |||
88 | group.find( "input[type=checkbox]" ).checkboxradio(); |
||
89 | assert.hasClasses( group.find( "label" ), "ui-button" ); |
||
90 | } ); |
||
91 | } ); |
||
92 | |||
93 | QUnit.test( "Calling checkboxradio on an unsupported element throws an error", function( assert ) { |
||
94 | assert.expect( 2 ); |
||
95 | |||
96 | var errorMessage = |
||
97 | "Can't create checkboxradio on element.nodeName=div and element.type=undefined"; |
||
98 | var error = new Error( errorMessage ); |
||
99 | assert.raises( |
||
100 | function() { |
||
101 | $( "<div>" ).checkboxradio(); |
||
102 | }, |
||
103 | |||
104 | // Support: jQuery 1.7.0 only |
||
105 | $.fn.jquery === "1.7" ? errorMessage : error, |
||
106 | "Proper error thrown" |
||
107 | ); |
||
108 | |||
109 | errorMessage = "Can't create checkboxradio on element.nodeName=input and element.type=button"; |
||
110 | error = new Error( errorMessage ); |
||
111 | assert.raises( |
||
112 | function() { |
||
113 | $( "<input type='button'>" ).checkboxradio(); |
||
114 | }, |
||
115 | |||
116 | // Support: jQuery 1.7.0 only |
||
117 | $.fn.jquery === "1.7" ? errorMessage : error, |
||
118 | "Proper error thrown" |
||
119 | ); |
||
120 | } ); |
||
121 | |||
122 | QUnit.test( "Calling checkboxradio on an input with no label throws an error", function( assert ) { |
||
123 | assert.expect( 1 ); |
||
124 | |||
125 | var errorMessage = "No label found for checkboxradio widget"; |
||
126 | var error = new Error( errorMessage ); |
||
127 | assert.raises( |
||
128 | function() { |
||
129 | $( "<input type='checkbox'>" ).checkboxradio(); |
||
130 | }, |
||
131 | |||
132 | // Support: jQuery 1.7.0 only |
||
133 | $.fn.jquery === "1.7" ? errorMessage : error, |
||
134 | "Proper error thrown" |
||
135 | ); |
||
136 | } ); |
||
137 | |||
138 | } ); |