@@ -54,6 +54,7 @@ describe('tooltip', function() {
5454 elm = $compile ( angular . element (
5555 '<span tooltip="tooltip text" tooltip-placement="bottom">Selector Text</span>'
5656 ) ) ( scope ) ;
57+ scope . $apply ( ) ;
5758 elmScope = elm . scope ( ) ;
5859
5960 elm . trigger ( 'mouseenter' ) ;
@@ -161,6 +162,46 @@ describe('tooltip', function() {
161162
162163 } ) ;
163164
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+
164205} ) ;
165206
166207describe ( 'tooltipHtmlUnsafe' , function ( ) {
@@ -202,13 +243,13 @@ describe( 'tooltipHtmlUnsafe', function() {
202243} ) ;
203244
204245describe ( '$tooltipProvider' , function ( ) {
205-
206- describe ( 'popupDelay' , function ( ) {
207- var elm ,
246+ var elm ,
208247 elmBody ,
209- scope ,
210- elmScope ;
248+ scope ,
249+ elmScope ,
250+ body ;
211251
252+ describe ( 'popupDelay' , function ( ) {
212253 beforeEach ( module ( 'ui.bootstrap.tooltip' , function ( $tooltipProvider ) {
213254 $tooltipProvider . options ( { popupDelay : 1000 } ) ;
214255 } ) ) ;
@@ -241,12 +282,6 @@ describe( '$tooltipProvider', function() {
241282 } ) ;
242283
243284 describe ( 'appendToBody' , function ( ) {
244- var elm ,
245- elmBody ,
246- scope ,
247- elmScope ,
248- body ;
249-
250285 // load the tooltip code
251286 beforeEach ( module ( 'ui.bootstrap.tooltip' , function ( $tooltipProvider ) {
252287 $tooltipProvider . options ( { appendToBody : true } ) ;
@@ -275,5 +310,61 @@ describe( '$tooltipProvider', function() {
275310 expect ( $body . children ( ) . length ) . toEqual ( bodyLength + 1 ) ;
276311 } ) ) ;
277312 } ) ;
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+ } ) ;
278369} ) ;
279370
0 commit comments