@@ -54,6 +54,7 @@ describe('tooltip', function() {
54
54
elm = $compile ( angular . element (
55
55
'<span tooltip="tooltip text" tooltip-placement="bottom">Selector Text</span>'
56
56
) ) ( scope ) ;
57
+ scope . $apply ( ) ;
57
58
elmScope = elm . scope ( ) ;
58
59
59
60
elm . trigger ( 'mouseenter' ) ;
@@ -161,6 +162,46 @@ describe('tooltip', function() {
161
162
162
163
} ) ;
163
164
165
+ describe ( 'with a trigger attribute' , function ( ) {
166
+ var scope , elmBody , elm , elmScope ;
167
+
168
+ beforeEach ( inject ( function ( $rootScope ) {
169
+ scope = $rootScope ;
170
+ } ) ) ;
171
+
172
+ it ( 'should use it to show but set the hide trigger based on the map for mapped triggers' , inject ( function ( $compile ) {
173
+ elmBody = angular . element (
174
+ '<div><input tooltip="Hello!" tooltip-trigger="focus" /></div>'
175
+ ) ;
176
+ $compile ( elmBody ) ( scope ) ;
177
+ scope . $apply ( ) ;
178
+ elm = elmBody . find ( 'input' ) ;
179
+ elmScope = elm . scope ( ) ;
180
+
181
+ expect ( elmScope . tt_isOpen ) . toBeFalsy ( ) ;
182
+ elm . trigger ( 'focus' ) ;
183
+ expect ( elmScope . tt_isOpen ) . toBeTruthy ( ) ;
184
+ elm . trigger ( 'blur' ) ;
185
+ expect ( elmScope . tt_isOpen ) . toBeFalsy ( ) ;
186
+ } ) ) ;
187
+
188
+ it ( 'should use it as both the show and hide triggers for unmapped triggers' , inject ( function ( $compile ) {
189
+ elmBody = angular . element (
190
+ '<div><input tooltip="Hello!" tooltip-trigger="fakeTriggerAttr" /></div>'
191
+ ) ;
192
+ $compile ( elmBody ) ( scope ) ;
193
+ scope . $apply ( ) ;
194
+ elm = elmBody . find ( 'input' ) ;
195
+ elmScope = elm . scope ( ) ;
196
+
197
+ expect ( elmScope . tt_isOpen ) . toBeFalsy ( ) ;
198
+ elm . trigger ( 'fakeTriggerAttr' ) ;
199
+ expect ( elmScope . tt_isOpen ) . toBeTruthy ( ) ;
200
+ elm . trigger ( 'fakeTriggerAttr' ) ;
201
+ expect ( elmScope . tt_isOpen ) . toBeFalsy ( ) ;
202
+ } ) ) ;
203
+ } ) ;
204
+
164
205
} ) ;
165
206
166
207
describe ( 'tooltipHtmlUnsafe' , function ( ) {
@@ -202,13 +243,13 @@ describe( 'tooltipHtmlUnsafe', function() {
202
243
} ) ;
203
244
204
245
describe ( '$tooltipProvider' , function ( ) {
205
-
206
- describe ( 'popupDelay' , function ( ) {
207
- var elm ,
246
+ var elm ,
208
247
elmBody ,
209
- scope ,
210
- elmScope ;
248
+ scope ,
249
+ elmScope ,
250
+ body ;
211
251
252
+ describe ( 'popupDelay' , function ( ) {
212
253
beforeEach ( module ( 'ui.bootstrap.tooltip' , function ( $tooltipProvider ) {
213
254
$tooltipProvider . options ( { popupDelay : 1000 } ) ;
214
255
} ) ) ;
@@ -241,12 +282,6 @@ describe( '$tooltipProvider', function() {
241
282
} ) ;
242
283
243
284
describe ( 'appendToBody' , function ( ) {
244
- var elm ,
245
- elmBody ,
246
- scope ,
247
- elmScope ,
248
- body ;
249
-
250
285
// load the tooltip code
251
286
beforeEach ( module ( 'ui.bootstrap.tooltip' , function ( $tooltipProvider ) {
252
287
$tooltipProvider . options ( { appendToBody : true } ) ;
@@ -275,5 +310,61 @@ describe( '$tooltipProvider', function() {
275
310
expect ( $body . children ( ) . length ) . toEqual ( bodyLength + 1 ) ;
276
311
} ) ) ;
277
312
} ) ;
313
+
314
+ describe ( 'triggers' , function ( ) {
315
+ describe ( 'triggers with a mapped value' , function ( ) {
316
+ beforeEach ( module ( 'ui.bootstrap.tooltip' , function ( $tooltipProvider ) {
317
+ $tooltipProvider . options ( { trigger : 'focus' } ) ;
318
+ } ) ) ;
319
+
320
+ // load the template
321
+ beforeEach ( module ( 'template/tooltip/tooltip-popup.html' ) ) ;
322
+
323
+ it ( 'should use the show trigger and the mapped value for the hide trigger' , inject ( function ( $rootScope , $compile ) {
324
+ elmBody = angular . element (
325
+ '<div><input tooltip="tooltip text" /></div>'
326
+ ) ;
327
+
328
+ scope = $rootScope ;
329
+ $compile ( elmBody ) ( scope ) ;
330
+ scope . $digest ( ) ;
331
+ elm = elmBody . find ( 'input' ) ;
332
+ elmScope = elm . scope ( ) ;
333
+
334
+ expect ( elmScope . tt_isOpen ) . toBeFalsy ( ) ;
335
+ elm . trigger ( 'focus' ) ;
336
+ expect ( elmScope . tt_isOpen ) . toBeTruthy ( ) ;
337
+ elm . trigger ( 'blur' ) ;
338
+ expect ( elmScope . tt_isOpen ) . toBeFalsy ( ) ;
339
+ } ) ) ;
340
+ } ) ;
341
+
342
+ describe ( 'triggers without a mapped value' , function ( ) {
343
+ beforeEach ( module ( 'ui.bootstrap.tooltip' , function ( $tooltipProvider ) {
344
+ $tooltipProvider . options ( { trigger : 'fakeTrigger' } ) ;
345
+ } ) ) ;
346
+
347
+ // load the template
348
+ beforeEach ( module ( 'template/tooltip/tooltip-popup.html' ) ) ;
349
+
350
+ it ( 'should use the show trigger to hide' , inject ( function ( $rootScope , $compile ) {
351
+ elmBody = angular . element (
352
+ '<div><span tooltip="tooltip text">Selector Text</span></div>'
353
+ ) ;
354
+
355
+ scope = $rootScope ;
356
+ $compile ( elmBody ) ( scope ) ;
357
+ scope . $digest ( ) ;
358
+ elm = elmBody . find ( 'span' ) ;
359
+ elmScope = elm . scope ( ) ;
360
+
361
+ expect ( elmScope . tt_isOpen ) . toBeFalsy ( ) ;
362
+ elm . trigger ( 'fakeTrigger' ) ;
363
+ expect ( elmScope . tt_isOpen ) . toBeTruthy ( ) ;
364
+ elm . trigger ( 'fakeTrigger' ) ;
365
+ expect ( elmScope . tt_isOpen ) . toBeFalsy ( ) ;
366
+ } ) ) ;
367
+ } ) ;
368
+ } ) ;
278
369
} ) ;
279
370
0 commit comments