corrade-http-templates – Blame information for rev 57
?pathlinks?
Rev | Author | Line No. | Line |
---|---|---|---|
57 | office | 1 | define( [ |
2 | "qunit", |
||
3 | "jquery", |
||
4 | "ui/data", |
||
5 | "ui/escape-selector", |
||
6 | "ui/focusable", |
||
7 | "ui/tabbable" |
||
8 | ], function( QUnit, $ ) { |
||
9 | |||
10 | QUnit.module( "core - selectors" ); |
||
11 | |||
12 | QUnit.assert.isFocusable = function( selector, msg ) { |
||
13 | this.push( $( selector ).is( ":focusable" ), null, null, |
||
14 | msg + " - selector " + selector + " is focusable" ); |
||
15 | }; |
||
16 | |||
17 | QUnit.assert.isNotFocusable = function( selector, msg ) { |
||
18 | this.push( $( selector ).length && !$( selector ).is( ":focusable" ), null, null, |
||
19 | msg + " - selector " + selector + " is not focusable" ); |
||
20 | }; |
||
21 | |||
22 | QUnit.assert.isTabbable = function( selector, msg ) { |
||
23 | this.push( $( selector ).is( ":tabbable" ), null, null, |
||
24 | msg + " - selector " + selector + " is tabbable" ); |
||
25 | }; |
||
26 | |||
27 | QUnit.assert.isNotTabbable = function( selector, msg ) { |
||
28 | this.push( $( selector ).length && !$( selector ).is( ":tabbable" ), null, null, |
||
29 | msg + " - selector " + selector + " is not tabbable" ); |
||
30 | }; |
||
31 | |||
32 | QUnit.test( "data", function( assert ) { |
||
33 | assert.expect( 15 ); |
||
34 | |||
35 | var element; |
||
36 | |||
37 | function shouldHaveData( msg ) { |
||
38 | assert.ok( element.is( ":data(test)" ), msg ); |
||
39 | } |
||
40 | |||
41 | function shouldNotHaveData( msg ) { |
||
42 | assert.ok( !element.is( ":data(test)" ), msg ); |
||
43 | } |
||
44 | |||
45 | element = $( "<div>" ); |
||
46 | shouldNotHaveData( "data never set" ); |
||
47 | |||
48 | element = $( "<div>" ).data( "test", null ); |
||
49 | shouldNotHaveData( "data is null" ); |
||
50 | |||
51 | element = $( "<div>" ).data( "test", true ); |
||
52 | shouldHaveData( "data set to true" ); |
||
53 | |||
54 | element = $( "<div>" ).data( "test", false ); |
||
55 | shouldNotHaveData( "data set to false" ); |
||
56 | |||
57 | element = $( "<div>" ).data( "test", 0 ); |
||
58 | shouldNotHaveData( "data set to 0" ); |
||
59 | |||
60 | element = $( "<div>" ).data( "test", 1 ); |
||
61 | shouldHaveData( "data set to 1" ); |
||
62 | |||
63 | element = $( "<div>" ).data( "test", "" ); |
||
64 | shouldNotHaveData( "data set to empty string" ); |
||
65 | |||
66 | element = $( "<div>" ).data( "test", "foo" ); |
||
67 | shouldHaveData( "data set to string" ); |
||
68 | |||
69 | element = $( "<div>" ).data( "test", [] ); |
||
70 | shouldHaveData( "data set to empty array" ); |
||
71 | |||
72 | element = $( "<div>" ).data( "test", [ 1 ] ); |
||
73 | shouldHaveData( "data set to array" ); |
||
74 | |||
75 | element = $( "<div>" ).data( "test", {} ); |
||
76 | shouldHaveData( "data set to empty object" ); |
||
77 | |||
78 | element = $( "<div>" ).data( "test", { foo: "bar" } ); |
||
79 | shouldHaveData( "data set to object" ); |
||
80 | |||
81 | element = $( "<div>" ).data( "test", new Date() ); |
||
82 | shouldHaveData( "data set to date" ); |
||
83 | |||
84 | element = $( "<div>" ).data( "test", /test/ ); |
||
85 | shouldHaveData( "data set to regexp" ); |
||
86 | |||
87 | element = $( "<div>" ).data( "test", function() {} ); |
||
88 | shouldHaveData( "data set to function" ); |
||
89 | } ); |
||
90 | |||
91 | QUnit.test( "focusable - visible, enabled elements", function( assert ) { |
||
92 | assert.expect( 22 ); |
||
93 | |||
94 | assert.isNotFocusable( "#formNoTabindex", "form" ); |
||
95 | assert.isFocusable( "#formTabindex", "form with tabindex" ); |
||
96 | assert.isFocusable( "#enabledFieldset input", "input in enabled fieldset" ); |
||
97 | assert.isNotFocusable( "#disabledFieldset input", "input in disabled fieldset" ); |
||
98 | assert.isFocusable( "#visibleAncestor-inputTypeNone", "input, no type" ); |
||
99 | assert.isFocusable( "#visibleAncestor-inputTypeText", "input, type text" ); |
||
100 | assert.isFocusable( "#visibleAncestor-inputTypeCheckbox", "input, type checkbox" ); |
||
101 | assert.isFocusable( "#visibleAncestor-inputTypeRadio", "input, type radio" ); |
||
102 | assert.isFocusable( "#visibleAncestor-inputTypeButton", "input, type button" ); |
||
103 | assert.isNotFocusable( "#visibleAncestor-inputTypeHidden", "input, type hidden" ); |
||
104 | assert.isFocusable( "#visibleAncestor-button", "button" ); |
||
105 | assert.isFocusable( "#visibleAncestor-select", "select" ); |
||
106 | assert.isFocusable( "#visibleAncestor-textarea", "textarea" ); |
||
107 | assert.isFocusable( "#visibleAncestor-object", "object" ); |
||
108 | assert.isFocusable( "#visibleAncestor-anchorWithHref", "anchor with href" ); |
||
109 | assert.isNotFocusable( "#visibleAncestor-anchorWithoutHref", "anchor without href" ); |
||
110 | assert.isNotFocusable( "#visibleAncestor-span", "span" ); |
||
111 | assert.isNotFocusable( "#visibleAncestor-div", "div" ); |
||
112 | assert.isFocusable( "#visibleAncestor-spanWithTabindex", "span with tabindex" ); |
||
113 | assert.isFocusable( "#visibleAncestor-divWithNegativeTabindex", "div with tabindex" ); |
||
114 | assert.isFocusable( "#nestedVisibilityInheritWithVisibleAncestor", |
||
115 | "span, visibility: inherit inside visibility: visible parent" ); |
||
116 | assert.isFocusable( "#nestedVisibilityInheritWithVisibleAncestor-input", |
||
117 | "input, visibility: inherit inside visibility: visible parent" ); |
||
118 | } ); |
||
119 | |||
120 | QUnit.test( "focusable - disabled elements", function( assert ) { |
||
121 | assert.expect( 9 ); |
||
122 | |||
123 | assert.isNotFocusable( "#disabledElement-inputTypeNone", "input, no type" ); |
||
124 | assert.isNotFocusable( "#disabledElement-inputTypeText", "input, type text" ); |
||
125 | assert.isNotFocusable( "#disabledElement-inputTypeCheckbox", "input, type checkbox" ); |
||
126 | assert.isNotFocusable( "#disabledElement-inputTypeRadio", "input, type radio" ); |
||
127 | assert.isNotFocusable( "#disabledElement-inputTypeButton", "input, type button" ); |
||
128 | assert.isNotFocusable( "#disabledElement-inputTypeHidden", "input, type hidden" ); |
||
129 | assert.isNotFocusable( "#disabledElement-button", "button" ); |
||
130 | assert.isNotFocusable( "#disabledElement-select", "select" ); |
||
131 | assert.isNotFocusable( "#disabledElement-textarea", "textarea" ); |
||
132 | } ); |
||
133 | |||
134 | QUnit.test( "focusable - hidden styles", function( assert ) { |
||
135 | assert.expect( 12 ); |
||
136 | |||
137 | assert.isNotFocusable( "#displayNoneAncestor-input", "input, display: none parent" ); |
||
138 | assert.isNotFocusable( "#displayNoneAncestor-span", "span with tabindex, display: none parent" ); |
||
139 | |||
140 | assert.isNotFocusable( "#visibilityHiddenAncestor-input", "input, visibility: hidden parent" ); |
||
141 | assert.isNotFocusable( "#visibilityHiddenAncestor-span", "span with tabindex, visibility: hidden parent" ); |
||
142 | |||
143 | assert.isFocusable( "#nestedVisibilityOverrideAncestor-input", "input, visibility: visible parent but visibility: hidden grandparent" ); |
||
144 | assert.isFocusable( "#nestedVisibilityOverrideAncestor-span", "span with tabindex, visibility: visible parent but visibility: hidden grandparent " ); |
||
145 | |||
146 | assert.isNotFocusable( "#nestedVisibilityInheritWithHiddenAncestor", "span, visibility: inherit inside visibility: hidden parent" ); |
||
147 | assert.isNotFocusable( "#nestedVisibilityInheritWithHiddenAncestor-input", "input, visibility: inherit inside visibility: hidden parent" ); |
||
148 | |||
149 | assert.isNotFocusable( "#displayNone-input", "input, display: none" ); |
||
150 | assert.isNotFocusable( "#visibilityHidden-input", "input, visibility: hidden" ); |
||
151 | |||
152 | assert.isNotFocusable( "#displayNone-span", "span with tabindex, display: none" ); |
||
153 | assert.isNotFocusable( "#visibilityHidden-span", "span with tabindex, visibility: hidden" ); |
||
154 | } ); |
||
155 | |||
156 | QUnit.test( "focusable - natively focusable with various tabindex", function( assert ) { |
||
157 | assert.expect( 4 ); |
||
158 | |||
159 | assert.isFocusable( "#inputTabindex0", "input, tabindex 0" ); |
||
160 | assert.isFocusable( "#inputTabindex10", "input, tabindex 10" ); |
||
161 | assert.isFocusable( "#inputTabindex-1", "input, tabindex -1" ); |
||
162 | assert.isFocusable( "#inputTabindex-50", "input, tabindex -50" ); |
||
163 | } ); |
||
164 | |||
165 | QUnit.test( "focusable - not natively focusable with various tabindex", function( assert ) { |
||
166 | assert.expect( 4 ); |
||
167 | |||
168 | assert.isFocusable( "#spanTabindex0", "span, tabindex 0" ); |
||
169 | assert.isFocusable( "#spanTabindex10", "span, tabindex 10" ); |
||
170 | assert.isFocusable( "#spanTabindex-1", "span, tabindex -1" ); |
||
171 | assert.isFocusable( "#spanTabindex-50", "span, tabindex -50" ); |
||
172 | } ); |
||
173 | |||
174 | QUnit.test( "focusable - area elements", function( assert ) { |
||
175 | assert.expect( 3 ); |
||
176 | |||
177 | assert.isFocusable( "#areaCoordsHref", "coords and href" ); |
||
178 | assert.isFocusable( "#areaNoCoordsHref", "href but no coords" ); |
||
179 | assert.isNotFocusable( "#areaNoImg", "not associated with an image" ); |
||
180 | } ); |
||
181 | |||
182 | QUnit.test( "focusable - dimensionless parent with overflow", function( assert ) { |
||
183 | assert.expect( 1 ); |
||
184 | |||
185 | assert.isFocusable( "#dimensionlessParent", "input" ); |
||
186 | } ); |
||
187 | |||
188 | QUnit.test( "tabbable - visible, enabled elements", function( assert ) { |
||
189 | assert.expect( 20 ); |
||
190 | |||
191 | assert.isNotTabbable( "#formNoTabindex", "form" ); |
||
192 | assert.isTabbable( "#formTabindex", "form with tabindex" ); |
||
193 | assert.isTabbable( "#enabledFieldset input", "input in enabled fieldset" ); |
||
194 | assert.isNotTabbable( "#disabledFieldset input", "input in disabled fieldset" ); |
||
195 | assert.isTabbable( "#visibleAncestor-inputTypeNone", "input, no type" ); |
||
196 | assert.isTabbable( "#visibleAncestor-inputTypeText", "input, type text" ); |
||
197 | assert.isTabbable( "#visibleAncestor-inputTypeCheckbox", "input, type checkbox" ); |
||
198 | assert.isTabbable( "#visibleAncestor-inputTypeRadio", "input, type radio" ); |
||
199 | assert.isTabbable( "#visibleAncestor-inputTypeButton", "input, type button" ); |
||
200 | assert.isNotTabbable( "#visibleAncestor-inputTypeHidden", "input, type hidden" ); |
||
201 | assert.isTabbable( "#visibleAncestor-button", "button" ); |
||
202 | assert.isTabbable( "#visibleAncestor-select", "select" ); |
||
203 | assert.isTabbable( "#visibleAncestor-textarea", "textarea" ); |
||
204 | assert.isTabbable( "#visibleAncestor-object", "object" ); |
||
205 | assert.isTabbable( "#visibleAncestor-anchorWithHref", "anchor with href" ); |
||
206 | assert.isNotTabbable( "#visibleAncestor-anchorWithoutHref", "anchor without href" ); |
||
207 | assert.isNotTabbable( "#visibleAncestor-span", "span" ); |
||
208 | assert.isNotTabbable( "#visibleAncestor-div", "div" ); |
||
209 | assert.isTabbable( "#visibleAncestor-spanWithTabindex", "span with tabindex" ); |
||
210 | assert.isNotTabbable( "#visibleAncestor-divWithNegativeTabindex", "div with tabindex" ); |
||
211 | } ); |
||
212 | |||
213 | QUnit.test( "tabbable - disabled elements", function( assert ) { |
||
214 | assert.expect( 9 ); |
||
215 | |||
216 | assert.isNotTabbable( "#disabledElement-inputTypeNone", "input, no type" ); |
||
217 | assert.isNotTabbable( "#disabledElement-inputTypeText", "input, type text" ); |
||
218 | assert.isNotTabbable( "#disabledElement-inputTypeCheckbox", "input, type checkbox" ); |
||
219 | assert.isNotTabbable( "#disabledElement-inputTypeRadio", "input, type radio" ); |
||
220 | assert.isNotTabbable( "#disabledElement-inputTypeButton", "input, type button" ); |
||
221 | assert.isNotTabbable( "#disabledElement-inputTypeHidden", "input, type hidden" ); |
||
222 | assert.isNotTabbable( "#disabledElement-button", "button" ); |
||
223 | assert.isNotTabbable( "#disabledElement-select", "select" ); |
||
224 | assert.isNotTabbable( "#disabledElement-textarea", "textarea" ); |
||
225 | } ); |
||
226 | |||
227 | QUnit.test( "tabbable - hidden styles", function( assert ) { |
||
228 | assert.expect( 10 ); |
||
229 | |||
230 | assert.isNotTabbable( "#displayNoneAncestor-input", "input, display: none parent" ); |
||
231 | assert.isNotTabbable( "#displayNoneAncestor-span", "span with tabindex, display: none parent" ); |
||
232 | |||
233 | assert.isNotTabbable( "#visibilityHiddenAncestor-input", "input, visibility: hidden parent" ); |
||
234 | assert.isNotTabbable( "#visibilityHiddenAncestor-span", "span with tabindex, visibility: hidden parent" ); |
||
235 | |||
236 | assert.isTabbable( "#nestedVisibilityOverrideAncestor-input", "input, visibility: visible parent but visibility: hidden grandparent" ); |
||
237 | assert.isTabbable( "#nestedVisibilityOverrideAncestor-span", "span with tabindex, visibility: visible parent but visibility: hidden grandparent " ); |
||
238 | |||
239 | assert.isNotTabbable( "#displayNone-input", "input, display: none" ); |
||
240 | assert.isNotTabbable( "#visibilityHidden-input", "input, visibility: hidden" ); |
||
241 | |||
242 | assert.isNotTabbable( "#displayNone-span", "span with tabindex, display: none" ); |
||
243 | assert.isNotTabbable( "#visibilityHidden-span", "span with tabindex, visibility: hidden" ); |
||
244 | } ); |
||
245 | |||
246 | QUnit.test( "tabbable - natively tabbable with various tabindex", function( assert ) { |
||
247 | assert.expect( 4 ); |
||
248 | |||
249 | assert.isTabbable( "#inputTabindex0", "input, tabindex 0" ); |
||
250 | assert.isTabbable( "#inputTabindex10", "input, tabindex 10" ); |
||
251 | assert.isNotTabbable( "#inputTabindex-1", "input, tabindex -1" ); |
||
252 | assert.isNotTabbable( "#inputTabindex-50", "input, tabindex -50" ); |
||
253 | } ); |
||
254 | |||
255 | QUnit.test( "tabbable - not natively tabbable with various tabindex", function( assert ) { |
||
256 | assert.expect( 4 ); |
||
257 | |||
258 | assert.isTabbable( "#spanTabindex0", "span, tabindex 0" ); |
||
259 | assert.isTabbable( "#spanTabindex10", "span, tabindex 10" ); |
||
260 | assert.isNotTabbable( "#spanTabindex-1", "span, tabindex -1" ); |
||
261 | assert.isNotTabbable( "#spanTabindex-50", "span, tabindex -50" ); |
||
262 | } ); |
||
263 | |||
264 | QUnit.test( "tabbable - area elements", function( assert ) { |
||
265 | assert.expect( 3 ); |
||
266 | |||
267 | assert.isTabbable( "#areaCoordsHref", "coords and href" ); |
||
268 | assert.isTabbable( "#areaNoCoordsHref", "href but no coords" ); |
||
269 | assert.isNotTabbable( "#areaNoImg", "not associated with an image" ); |
||
270 | } ); |
||
271 | |||
272 | QUnit.test( "tabbable - dimensionless parent with overflow", function( assert ) { |
||
273 | assert.expect( 1 ); |
||
274 | |||
275 | assert.isTabbable( "#dimensionlessParent", "input" ); |
||
276 | } ); |
||
277 | |||
278 | QUnit.test( "escapeSelector", function( assert ) { |
||
279 | assert.expect( 1 ); |
||
280 | |||
281 | assert.equal( $( "#" + $.ui.escapeSelector( "weird-['x']-id" ) ).length, 1, |
||
282 | "properly escapes selectors to use as an id" ); |
||
283 | } ); |
||
284 | |||
285 | } ); |