corrade-http-templates – Blame information for rev 62
?pathlinks?
Rev | Author | Line No. | Line |
---|---|---|---|
62 | office | 1 | define( [ |
2 | "qunit", |
||
3 | "jquery", |
||
4 | "ui/widgets/tooltip" |
||
5 | ], function( QUnit, $ ) { |
||
6 | |||
7 | QUnit.module( "tooltip: core" ); |
||
8 | |||
9 | QUnit.test( "markup structure", function( assert ) { |
||
10 | assert.expect( 7 ); |
||
11 | var element = $( "#tooltipped1" ).tooltip(), |
||
12 | tooltip = $( ".ui-tooltip" ); |
||
13 | |||
14 | assert.equal( element.attr( "aria-describedby" ), undefined, "no aria-describedby on init" ); |
||
15 | assert.equal( tooltip.length, 0, "no tooltip on init" ); |
||
16 | |||
17 | element.tooltip( "open" ); |
||
18 | tooltip = $( "#" + element.data( "ui-tooltip-id" ) ); |
||
19 | assert.equal( tooltip.length, 1, "tooltip exists" ); |
||
20 | assert.equal( element.attr( "aria-describedby" ), tooltip.attr( "id" ), "aria-describedby" ); |
||
21 | assert.hasClasses( tooltip, "ui-tooltip ui-widget ui-widget-content ui-widget-shadow" ); |
||
22 | assert.equal( tooltip.length, 1, ".ui-tooltip exists" ); |
||
23 | assert.equal( tooltip.find( ".ui-tooltip-content" ).length, 1, |
||
24 | ".ui-tooltip-content exists" ); |
||
25 | } ); |
||
26 | |||
27 | QUnit.test( "accessibility", function( assert ) { |
||
28 | assert.expect( 15 ); |
||
29 | |||
30 | var tooltipId, tooltip, |
||
31 | element = $( "#multiple-describedby" ).tooltip(), |
||
32 | liveRegion = element.tooltip( "instance" ).liveRegion; |
||
33 | |||
34 | assert.equal( liveRegion.find( ">div" ).length, 0 ); |
||
35 | assert.equal( liveRegion.attr( "role" ), "log" ); |
||
36 | assert.equal( liveRegion.attr( "aria-live" ), "assertive" ); |
||
37 | assert.equal( liveRegion.attr( "aria-relevant" ), "additions" ); |
||
38 | element.tooltip( "open" ); |
||
39 | tooltipId = element.data( "ui-tooltip-id" ); |
||
40 | tooltip = $( "#" + tooltipId ); |
||
41 | assert.equal( tooltip.attr( "role" ), "tooltip", "role" ); |
||
42 | assert.equal( element.attr( "aria-describedby" ), "fixture-span " + tooltipId, |
||
43 | "multiple describedby when open" ); |
||
44 | |||
45 | assert.equal( element.attr( "title" ), null, "no title when open" ); |
||
46 | assert.equal( liveRegion.children().length, 1 ); |
||
47 | assert.equal( liveRegion.children().last().html(), "..." ); |
||
48 | element.tooltip( "close" ); |
||
49 | assert.equal( element.attr( "aria-describedby" ), "fixture-span", |
||
50 | "correct describedby when closed" ); |
||
51 | assert.equal( element.attr( "title" ), "...", "title restored when closed" ); |
||
52 | |||
53 | element.tooltip( "open" ); |
||
54 | assert.equal( liveRegion.children().length, 2, |
||
55 | "After the second tooltip show, there should be two children" ); |
||
56 | assert.equal( liveRegion.children().filter( ":visible" ).length, 1, |
||
57 | "Only one of the children should be visible" ); |
||
58 | assert.ok( liveRegion.children().last().is( ":visible" ), |
||
59 | "Only the last child should be visible" ); |
||
60 | element.tooltip( "close" ); |
||
61 | |||
62 | element.tooltip( "destroy" ); |
||
63 | assert.equal( liveRegion.parent().length, 0, |
||
64 | "Tooltip liveregion element should be removed" ); |
||
65 | } ); |
||
66 | |||
67 | QUnit.test( "delegated removal", function( assert ) { |
||
68 | assert.expect( 2 ); |
||
69 | |||
70 | var container = $( "#contains-tooltipped" ).tooltip(), |
||
71 | element = $( "#contained-tooltipped" ); |
||
72 | |||
73 | element.trigger( "mouseover" ); |
||
74 | assert.equal( $( ".ui-tooltip" ).length, 1 ); |
||
75 | |||
76 | container.empty(); |
||
77 | assert.equal( $( ".ui-tooltip" ).length, 0 ); |
||
78 | } ); |
||
79 | |||
80 | QUnit.test( "nested tooltips", function( assert ) { |
||
81 | assert.expect( 2 ); |
||
82 | |||
83 | var child = $( "#contained-tooltipped" ), |
||
84 | parent = $( "#contains-tooltipped" ).tooltip( { |
||
85 | show: null, |
||
86 | hide: null |
||
87 | } ); |
||
88 | |||
89 | parent.trigger( "mouseover" ); |
||
90 | assert.equal( $( ".ui-tooltip:visible" ).text(), "parent" ); |
||
91 | |||
92 | child.trigger( "mouseover" ); |
||
93 | assert.equal( $( ".ui-tooltip" ).text(), "child" ); |
||
94 | } ); |
||
95 | |||
96 | // #8742 |
||
97 | QUnit.test( "form containing an input with name title", function( assert ) { |
||
98 | assert.expect( 4 ); |
||
99 | |||
100 | var form = $( "#tooltip-form" ).tooltip( { |
||
101 | show: null, |
||
102 | hide: null |
||
103 | } ), |
||
104 | input = form.find( "[name=title]" ); |
||
105 | |||
106 | assert.equal( $( ".ui-tooltip" ).length, 0, "no tooltips on init" ); |
||
107 | |||
108 | input.trigger( "mouseover" ); |
||
109 | assert.equal( $( ".ui-tooltip" ).length, 1, "tooltip for input" ); |
||
110 | input.trigger( "mouseleave" ); |
||
111 | assert.equal( $( ".ui-tooltip" ).length, 0, "tooltip for input closed" ); |
||
112 | |||
113 | form.trigger( "mouseover" ); |
||
114 | assert.equal( $( ".ui-tooltip" ).length, 0, "no tooltip for form" ); |
||
115 | } ); |
||
116 | |||
117 | QUnit.test( "tooltip on .ui-state-disabled element", function( assert ) { |
||
118 | assert.expect( 2 ); |
||
119 | |||
120 | var container = $( "#contains-tooltipped" ).tooltip(), |
||
121 | element = $( "#contained-tooltipped" ).addClass( "ui-state-disabled" ); |
||
122 | |||
123 | element.trigger( "mouseover" ); |
||
124 | assert.equal( $( ".ui-tooltip" ).length, 1 ); |
||
125 | |||
126 | container.empty(); |
||
127 | assert.equal( $( ".ui-tooltip" ).length, 0 ); |
||
128 | } ); |
||
129 | |||
130 | // http://bugs.jqueryui.com/ticket/8740 |
||
131 | QUnit.test( "programmatic focus with async content", function( assert ) { |
||
132 | var ready = assert.async(); |
||
133 | assert.expect( 2 ); |
||
134 | var element = $( "#tooltipped1" ).tooltip( { |
||
135 | content: function( response ) { |
||
136 | setTimeout( function() { |
||
137 | response( "test" ); |
||
138 | } ); |
||
139 | } |
||
140 | } ); |
||
141 | |||
142 | element.on( "tooltipopen", function( event ) { |
||
143 | assert.deepEqual( event.originalEvent.type, "focusin" ); |
||
144 | |||
145 | element.on( "tooltipclose", function( event ) { |
||
146 | assert.deepEqual( event.originalEvent.type, "focusout" ); |
||
147 | ready(); |
||
148 | } ); |
||
149 | |||
150 | setTimeout( function() { |
||
151 | element.trigger( "blur" ); |
||
152 | } ); |
||
153 | } ); |
||
154 | |||
155 | element.trigger( "focus" ); |
||
156 | } ); |
||
157 | |||
158 | QUnit.test( "destroy during hide animation; only one close event", function( assert ) { |
||
159 | var ready = assert.async(); |
||
160 | assert.expect( 1 ); |
||
161 | |||
162 | var element = $( "#tooltipped1" ).tooltip( { |
||
163 | show: false, |
||
164 | hide: true |
||
165 | } ); |
||
166 | |||
167 | element.on( "tooltipclose", function() { |
||
168 | assert.ok( true, "tooltip closed" ); |
||
169 | } ); |
||
170 | |||
171 | element.tooltip( "open" ); |
||
172 | element.tooltip( "close" ); |
||
173 | setTimeout( function() { |
||
174 | element.tooltip( "destroy" ); |
||
175 | ready(); |
||
176 | } ); |
||
177 | } ); |
||
178 | |||
179 | // http://bugs.jqueryui.com/ticket/10602 |
||
180 | QUnit.test( "multiple active delegated tooltips", function( assert ) { |
||
181 | var ready = assert.async(); |
||
182 | assert.expect( 1 ); |
||
183 | |||
184 | var anchor = $( "#tooltipped1" ), |
||
185 | input = anchor.next(), |
||
186 | actions = []; |
||
187 | |||
188 | $( document ).tooltip( { |
||
189 | show: false, |
||
190 | hide: false, |
||
191 | open: function( event, ui ) { |
||
192 | actions.push( "open:" + ui.tooltip.text() ); |
||
193 | }, |
||
194 | close: function( event, ui ) { |
||
195 | actions.push( "close:" + ui.tooltip.text() ); |
||
196 | } |
||
197 | } ); |
||
198 | |||
199 | function step1() { |
||
200 | anchor.simulate( "mouseover" ); |
||
201 | setTimeout( step2 ); |
||
202 | } |
||
203 | |||
204 | function step2() { |
||
205 | input.simulate( "focus" ); |
||
206 | setTimeout( step3 ); |
||
207 | } |
||
208 | |||
209 | function step3() { |
||
210 | input.simulate( "blur" ); |
||
211 | setTimeout( step4 ); |
||
212 | } |
||
213 | |||
214 | function step4() { |
||
215 | anchor.simulate( "mouseout" ); |
||
216 | assert.deepEqual( actions, [ |
||
217 | "open:anchortitle", |
||
218 | "open:inputtitle", |
||
219 | "close:inputtitle", |
||
220 | "close:anchortitle" |
||
221 | ], "Both tooltips open and close" ); |
||
222 | ready(); |
||
223 | } |
||
224 | |||
225 | step1(); |
||
226 | } ); |
||
227 | |||
228 | // http://bugs.jqueryui.com/ticket/11272 |
||
229 | QUnit.test( "remove conflicting attributes from live region", function( assert ) { |
||
230 | assert.expect( 2 ); |
||
231 | |||
232 | var element = $( |
||
233 | "<div id='content'>" + |
||
234 | "<input type='radio' name='hobby' id='hobby1' checked='checked'>" + |
||
235 | "<label for='hobby1'>option 1</label>" + |
||
236 | "<input type='radio' name='hobby' id='hobby2'>" + |
||
237 | "<label for='hobby2'>option 2</label>" + |
||
238 | "</div>" ); |
||
239 | |||
240 | $( "#tooltipped1" ) |
||
241 | .tooltip( { |
||
242 | content: element, |
||
243 | open: function() { |
||
244 | assert.equal( $( ".ui-helper-hidden-accessible [name]" ).length, 0, |
||
245 | "no name attributes within live region" ); |
||
246 | assert.equal( $( ".ui-helper-hidden-accessible [id]" ).length, 0, |
||
247 | "no id attributes within live region" ); |
||
248 | } |
||
249 | } ) |
||
250 | .tooltip( "open" ); |
||
251 | } ); |
||
252 | |||
253 | } ); |