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: options" ); |
||
8 | |||
9 | function assertDisabled( checkbox, assert ) { |
||
10 | assert.hasClasses( checkbox.checkboxradio( "widget" ), "ui-state-disabled", |
||
11 | "label gets ui-state-disabled" ); |
||
12 | assert.strictEqual( checkbox.is( ":disabled" ), true, "checkbox is disabled" ); |
||
13 | } |
||
14 | |||
15 | function assertEnabled( checkbox, assert ) { |
||
16 | assert.lacksClasses( checkbox.checkboxradio( "widget" ), "ui-state-disabled", |
||
17 | "label has ui-state-disabled removed when disabled set to false" ); |
||
18 | assert.strictEqual( checkbox.is( ":disabled" ), false, |
||
19 | "checkbox has disabled prop removed when disabled set to false" ); |
||
20 | } |
||
21 | |||
22 | QUnit.test( "disabled", function( assert ) { |
||
23 | assert.expect( 6 ); |
||
24 | |||
25 | var checkbox = $( "#checkbox-option-disabled" ); |
||
26 | checkbox.checkboxradio( { |
||
27 | disabled: true |
||
28 | } ); |
||
29 | |||
30 | assertDisabled( checkbox, assert ); |
||
31 | |||
32 | checkbox.checkboxradio( "option", "disabled", false ); |
||
33 | assertEnabled( checkbox, assert ); |
||
34 | |||
35 | checkbox.checkboxradio( "option", "disabled", true ); |
||
36 | assertDisabled( checkbox, assert ); |
||
37 | } ); |
||
38 | |||
39 | QUnit.test( "disabled - prop true on init", function( assert ) { |
||
40 | assert.expect( 2 ); |
||
41 | var checkbox = $( "#checkbox-option-disabled" ); |
||
42 | |||
43 | checkbox.prop( "disabled", true ); |
||
44 | checkbox.checkboxradio(); |
||
45 | |||
46 | assertDisabled( checkbox, assert ); |
||
47 | } ); |
||
48 | |||
49 | QUnit.test( "disabled - explicit null value, checks the DOM", function( assert ) { |
||
50 | assert.expect( 2 ); |
||
51 | var checkbox = $( "#checkbox-option-disabled" ); |
||
52 | |||
53 | checkbox.prop( "disabled", true ); |
||
54 | checkbox.checkboxradio( { |
||
55 | disabled: null |
||
56 | } ); |
||
57 | assertDisabled( checkbox, assert ); |
||
58 | } ); |
||
59 | |||
60 | function assertNoIcon( assert, checkbox ) { |
||
61 | assert.strictEqual( checkbox.checkboxradio( "widget" ).find( "span.ui-icon" ).length, 0, |
||
62 | "Label does not contain an icon" ); |
||
63 | } |
||
64 | |||
65 | function assertIcon( checkbox, icon, assert ) { |
||
66 | var iconElement = checkbox.checkboxradio( "widget" ).find( ".ui-icon" ); |
||
67 | |||
68 | icon = icon || "blank"; |
||
69 | assert.strictEqual( iconElement.length, 1, |
||
70 | "Label contains icon" ); |
||
71 | assert.hasClasses( iconElement, "ui-checkboxradio-icon ui-corner-all ui-icon " + |
||
72 | "ui-icon-background ui-icon-" + icon, |
||
73 | "Icon has proper classes" ); |
||
74 | if ( icon === "blank" ) { |
||
75 | assert.lacksClasses( iconElement, "ui-icon-check ui-state-checked" ); |
||
76 | } |
||
77 | } |
||
78 | |||
79 | QUnit.test( "icon - false on init", function( assert ) { |
||
80 | var checkbox = $( "#checkbox-option-icon" ); |
||
81 | |||
82 | assert.expect( 1 ); |
||
83 | |||
84 | checkbox.checkboxradio( { icon: false } ); |
||
85 | assertNoIcon( assert, checkbox ); |
||
86 | } ); |
||
87 | |||
88 | QUnit.test( "icon - default unchecked", function( assert ) { |
||
89 | var checkbox = $( "#checkbox-option-icon" ); |
||
90 | |||
91 | assert.expect( 3 ); |
||
92 | |||
93 | checkbox.checkboxradio(); |
||
94 | assertIcon( checkbox, false, assert ); |
||
95 | } ); |
||
96 | |||
97 | QUnit.test( "icon - default checked", function( assert ) { |
||
98 | var checkbox = $( "#checkbox-option-icon" ).attr( "checked", true ); |
||
99 | |||
100 | assert.expect( 2 ); |
||
101 | |||
102 | checkbox.checkboxradio(); |
||
103 | assertIcon( checkbox, "check ui-state-checked", assert ); |
||
104 | } ); |
||
105 | |||
106 | QUnit.test( "icon", function( assert ) { |
||
107 | var checkbox = $( "#checkbox-option-icon" ); |
||
108 | |||
109 | assert.expect( 9 ); |
||
110 | |||
111 | checkbox.prop( "checked", true ); |
||
112 | |||
113 | checkbox.checkboxradio(); |
||
114 | assertIcon( checkbox, "check ui-state-checked", assert ); |
||
115 | |||
116 | checkbox.checkboxradio( "option", "icon", false ); |
||
117 | assertNoIcon( assert, checkbox ); |
||
118 | |||
119 | checkbox.checkboxradio( "option", "icon", true ); |
||
120 | assertIcon( checkbox, "check ui-state-checked", assert ); |
||
121 | |||
122 | checkbox.checkboxradio( "option", "icon", false ); |
||
123 | assertNoIcon( assert, checkbox ); |
||
124 | |||
125 | checkbox.checkboxradio( "option", "icon", true ); |
||
126 | checkbox.prop( "checked", false ).checkboxradio( "refresh" ); |
||
127 | assertIcon( checkbox, false, assert ); |
||
128 | } ); |
||
129 | |||
130 | QUnit.test( "label - default", function( assert ) { |
||
131 | var checkbox = $( "#checkbox-option-label" ), |
||
132 | widget; |
||
133 | |||
134 | assert.expect( 2 ); |
||
135 | |||
136 | checkbox.checkboxradio(); |
||
137 | widget = checkbox.checkboxradio( "widget" ); |
||
138 | assert.strictEqual( checkbox.checkboxradio( "option", "label" ), |
||
139 | "checkbox label", "When no value passed on create text from dom is used for option" ); |
||
140 | assert.strictEqual( $.trim( widget.text() ), |
||
141 | "checkbox label", "When no value passed on create text from dom is used in dom" ); |
||
142 | } ); |
||
143 | |||
144 | QUnit.test( "label - explicit value", function( assert ) { |
||
145 | assert.expect( 5 ); |
||
146 | var checkbox = $( "#checkbox-option-label" ).checkboxradio( { |
||
147 | label: "foo" |
||
148 | } ), |
||
149 | widget = checkbox.checkboxradio( "widget" ), |
||
150 | icon = widget.find( ".ui-icon" ), |
||
151 | iconSpace = widget.find( ".ui-checkboxradio-icon-space" ); |
||
152 | |||
153 | assert.strictEqual( checkbox.checkboxradio( "option", "label" ), |
||
154 | "foo", "When value is passed on create value is used for option" ); |
||
155 | assert.strictEqual( $.trim( widget.text() ), |
||
156 | "foo", "When value is passed on create value is used in dom" ); |
||
157 | assert.strictEqual( icon.length, 1, |
||
158 | "Icon is preserved when label is set on init when wrapped in label" ); |
||
159 | assert.strictEqual( iconSpace.length, 1, |
||
160 | "Icon space is preserved when label is set on init when wrapped in label" ); |
||
161 | assert.strictEqual( $( "#checkbox-option-label" ).length, 1, |
||
162 | "Element is preserved when label is set on init when wrapped in label" ); |
||
163 | } ); |
||
164 | |||
165 | QUnit.test( "label - explicit null value", function( assert ) { |
||
166 | var checkbox = $( "#checkbox-option-label" ), |
||
167 | widget; |
||
168 | |||
169 | assert.expect( 2 ); |
||
170 | |||
171 | // The default null is a special value which means to check the DOM. |
||
172 | // We need to make sure that the option never return null. |
||
173 | // It should always be true or false after initialization. |
||
174 | checkbox.checkboxradio( { |
||
175 | label: null |
||
176 | } ); |
||
177 | widget = checkbox.checkboxradio( "widget" ); |
||
178 | assert.strictEqual( checkbox.checkboxradio( "option", "label" ), |
||
179 | "checkbox label", "When null is passed on create text from dom is used for option" ); |
||
180 | assert.strictEqual( $.trim( widget.text() ), |
||
181 | "checkbox label", "When null is passed on create text from dom is used in dom" ); |
||
182 | |||
183 | } ); |
||
184 | |||
185 | QUnit.test( "label", function( assert ) { |
||
186 | assert.expect( 4 ); |
||
187 | |||
188 | var checkbox = $( "#checkbox-option-label" ), |
||
189 | widget; |
||
190 | |||
191 | checkbox.checkboxradio(); |
||
192 | widget = checkbox.checkboxradio( "widget" ); |
||
193 | checkbox.checkboxradio( "option", "label", "bar" ); |
||
194 | assert.strictEqual( checkbox.checkboxradio( "option", "label" ), |
||
195 | "bar", "When value is passed value is used for option" ); |
||
196 | assert.strictEqual( $.trim( widget.text() ), |
||
197 | "bar", "When value is passed value is used in dom" ); |
||
198 | |||
199 | checkbox.checkboxradio( "option", "label", null ); |
||
200 | assert.strictEqual( checkbox.checkboxradio( "option", "label" ), |
||
201 | "bar", "When null is passed text from dom is used for option" ); |
||
202 | assert.strictEqual( $.trim( widget.text() ), |
||
203 | "bar", "When null is passed text from dom is used in dom" ); |
||
204 | } ); |
||
205 | |||
206 | } ); |