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/tooltip" |
||
5 | ], function( QUnit, $ ) { |
||
6 | |||
7 | QUnit.module( "tooltip: options" ); |
||
8 | |||
9 | QUnit.test( "disabled: true", function( assert ) { |
||
10 | assert.expect( 1 ); |
||
11 | $( "#tooltipped1" ).tooltip( { |
||
12 | disabled: true |
||
13 | } ).tooltip( "open" ); |
||
14 | assert.equal( $( ".ui-tooltip" ).length, 0 ); |
||
15 | } ); |
||
16 | |||
17 | QUnit.test( "content: default", function( assert ) { |
||
18 | assert.expect( 1 ); |
||
19 | var element = $( "#tooltipped1" ).tooltip().tooltip( "open" ); |
||
20 | assert.deepEqual( $( "#" + element.data( "ui-tooltip-id" ) ).text(), "anchortitle" ); |
||
21 | } ); |
||
22 | |||
23 | QUnit.test( "content: default; HTML escaping", function( assert ) { |
||
24 | assert.expect( 2 ); |
||
25 | var scriptText = "<script>$.ui.tooltip.hacked = true;</script>", |
||
26 | element = $( "#tooltipped1" ); |
||
27 | |||
28 | $.ui.tooltip.hacked = false; |
||
29 | element.attr( "title", scriptText ) |
||
30 | .tooltip() |
||
31 | .tooltip( "open" ); |
||
32 | assert.equal( $.ui.tooltip.hacked, false, "script did not execute" ); |
||
33 | assert.deepEqual( $( "#" + element.data( "ui-tooltip-id" ) ).text(), scriptText, |
||
34 | "correct tooltip text" ); |
||
35 | } ); |
||
36 | |||
37 | QUnit.test( "content: return string", function( assert ) { |
||
38 | assert.expect( 1 ); |
||
39 | var element = $( "#tooltipped1" ).tooltip( { |
||
40 | content: function() { |
||
41 | return "customstring"; |
||
42 | } |
||
43 | } ).tooltip( "open" ); |
||
44 | assert.deepEqual( $( "#" + element.data( "ui-tooltip-id" ) ).text(), "customstring" ); |
||
45 | } ); |
||
46 | |||
47 | QUnit.test( "content: return jQuery", function( assert ) { |
||
48 | assert.expect( 2 ); |
||
49 | var element = $( "#tooltipped1" ).tooltip( { |
||
50 | content: function() { |
||
51 | return $( "<div id='unique'>" ).html( "cu<b id='bold'>s</b>tomstring" ); |
||
52 | } |
||
53 | } ).tooltip( "open" ), |
||
54 | liveRegion = element.tooltip( "instance" ).liveRegion; |
||
55 | assert.deepEqual( $( "#" + element.data( "ui-tooltip-id" ) ).text(), "customstring" ); |
||
56 | assert.equal( liveRegion.children().last().html().toLowerCase(), "<div>cu<b>s</b>tomstring</div>", |
||
57 | "The accessibility live region will strip the ids but keep the structure" ); |
||
58 | } ); |
||
59 | |||
60 | QUnit.test( "content: sync + async callback", function( assert ) { |
||
61 | var ready = assert.async(); |
||
62 | assert.expect( 2 ); |
||
63 | var element = $( "#tooltipped1" ).tooltip( { |
||
64 | content: function( response ) { |
||
65 | setTimeout( function() { |
||
66 | assert.deepEqual( $( "#" + element.data( "ui-tooltip-id" ) ).text(), "loading..." ); |
||
67 | |||
68 | response( "customstring2" ); |
||
69 | setTimeout( function() { |
||
70 | assert.deepEqual( $( "#" + element.data( "ui-tooltip-id" ) ).text(), "customstring2" ); |
||
71 | ready(); |
||
72 | }, 13 ); |
||
73 | }, 13 ); |
||
74 | return "loading..."; |
||
75 | } |
||
76 | } ).tooltip( "open" ); |
||
77 | } ); |
||
78 | |||
79 | // http://bugs.jqueryui.com/ticket/8740 |
||
80 | QUnit.test( "content: async callback loses focus before load", function( assert ) { |
||
81 | var ready = assert.async(); |
||
82 | assert.expect( 1 ); |
||
83 | |||
84 | var element = $( "#tooltipped1" ).tooltip( { |
||
85 | content: function( response ) { |
||
86 | setTimeout( function() { |
||
87 | element.trigger( "mouseleave" ); |
||
88 | setTimeout( function() { |
||
89 | response( "sometext" ); |
||
90 | setTimeout( function() { |
||
91 | assert.ok( !$( "#" + element.data( "ui-tooltip-id" ) ).is( ":visible" ), |
||
92 | "Tooltip should not display" ); |
||
93 | ready(); |
||
94 | } ); |
||
95 | } ); |
||
96 | } ); |
||
97 | } |
||
98 | } ); |
||
99 | element.trigger( "mouseover" ); |
||
100 | } ); |
||
101 | |||
102 | QUnit.test( "content: change while open", function( assert ) { |
||
103 | assert.expect( 2 ) ; |
||
104 | var element = $( "#tooltipped1" ).tooltip( { |
||
105 | content: function() { |
||
106 | return "old"; |
||
107 | } |
||
108 | } ); |
||
109 | |||
110 | element.one( "tooltipopen", function( event, ui ) { |
||
111 | assert.equal( ui.tooltip.text(), "old", "original content" ); |
||
112 | element.tooltip( "option", "content", function() { |
||
113 | return "new"; |
||
114 | } ); |
||
115 | assert.equal( ui.tooltip.text(), "new", "updated content" ); |
||
116 | } ); |
||
117 | |||
118 | element.tooltip( "open" ); |
||
119 | } ); |
||
120 | |||
121 | QUnit.test( "content: string", function( assert ) { |
||
122 | assert.expect( 1 ); |
||
123 | $( "#tooltipped1" ).tooltip( { |
||
124 | content: "just a string", |
||
125 | open: function( event, ui ) { |
||
126 | assert.equal( ui.tooltip.text(), "just a string" ); |
||
127 | } |
||
128 | } ).tooltip( "open" ); |
||
129 | } ); |
||
130 | |||
131 | QUnit.test( "content: element", function( assert ) { |
||
132 | assert.expect( 1 ); |
||
133 | var content = "<p>this is a <i>test</i> of the emergency broadcast system.</p>", |
||
134 | element = $( content )[ 0 ]; |
||
135 | $( "#tooltipped1" ).tooltip( { |
||
136 | content: element, |
||
137 | open: function( event, ui ) { |
||
138 | assert.equal( ui.tooltip.children().html().toLowerCase(), content ); |
||
139 | } |
||
140 | } ).tooltip( "open" ); |
||
141 | } ); |
||
142 | |||
143 | QUnit.test( "content: jQuery", function( assert ) { |
||
144 | assert.expect( 1 ); |
||
145 | var content = "<p>this is a <i>test</i> of the emergency broadcast system.</p>", |
||
146 | element = $( content ); |
||
147 | $( "#tooltipped1" ).tooltip( { |
||
148 | content: element, |
||
149 | open: function( event, ui ) { |
||
150 | assert.equal( ui.tooltip.children().html().toLowerCase(), content ); |
||
151 | } |
||
152 | } ).tooltip( "open" ); |
||
153 | } ); |
||
154 | |||
155 | QUnit.test( "items", function( assert ) { |
||
156 | assert.expect( 2 ); |
||
157 | var event, |
||
158 | element = $( "#qunit-fixture" ).tooltip( { |
||
159 | items: "#fixture-span" |
||
160 | } ); |
||
161 | |||
162 | event = $.Event( "mouseenter" ); |
||
163 | event.target = $( "#fixture-span" )[ 0 ]; |
||
164 | element.tooltip( "open", event ); |
||
165 | assert.deepEqual( $( "#" + $( "#fixture-span" ).data( "ui-tooltip-id" ) ).text(), "title-text" ); |
||
166 | |||
167 | // Make sure default [title] doesn't get used |
||
168 | event.target = $( "#tooltipped1" )[ 0 ]; |
||
169 | element.tooltip( "open", event ); |
||
170 | assert.deepEqual( $( "#tooltipped1" ).data( "ui-tooltip-id" ), undefined ); |
||
171 | |||
172 | element.tooltip( "destroy" ); |
||
173 | } ); |
||
174 | |||
175 | QUnit.test( "track + show delay", function( assert ) { |
||
176 | assert.expect( 2 ); |
||
177 | var event, |
||
178 | leftVal = 314, |
||
179 | topVal = 159, |
||
180 | offsetVal = 26, |
||
181 | element = $( "#tooltipped1" ).tooltip( { |
||
182 | track: true, |
||
183 | show: { |
||
184 | delay: 1 |
||
185 | }, |
||
186 | position: { |
||
187 | my: "left+" + offsetVal + " top+" + offsetVal, |
||
188 | at: "right bottom" |
||
189 | } |
||
190 | } ); |
||
191 | |||
192 | event = $.Event( "mouseover" ); |
||
193 | event.target = $( "#tooltipped1" )[ 0 ]; |
||
194 | event.originalEvent = { type: "mouseover" }; |
||
195 | event.pageX = leftVal; |
||
196 | event.pageY = topVal; |
||
197 | element.trigger( event ); |
||
198 | |||
199 | event = $.Event( "mousemove" ); |
||
200 | event.target = $( "#tooltipped1" )[ 0 ]; |
||
201 | event.originalEvent = { type: "mousemove" }; |
||
202 | event.pageX = leftVal; |
||
203 | event.pageY = topVal; |
||
204 | element.trigger( event ); |
||
205 | |||
206 | assert.close( |
||
207 | parseFloat( $( ".ui-tooltip" ).css( "left" ) ), |
||
208 | leftVal + offsetVal, 0.5, |
||
209 | "left position" |
||
210 | ); |
||
211 | assert.close( |
||
212 | parseFloat( $( ".ui-tooltip" ).css( "top" ) ), |
||
213 | topVal + offsetVal, 0.5, |
||
214 | "top position" |
||
215 | ); |
||
216 | } ); |
||
217 | |||
218 | QUnit.test( "track and programmatic focus", function( assert ) { |
||
219 | assert.expect( 1 ); |
||
220 | $( "#qunit-fixture div input" ).tooltip( { |
||
221 | track: true |
||
222 | } ).trigger( "focus" ); |
||
223 | assert.equal( "inputtitle", $( ".ui-tooltip" ).text() ); |
||
224 | } ); |
||
225 | |||
226 | } ); |