This repository has been archived by the owner on May 29, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 6.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(tooltip): hide tooltips when content becomes empty
Closes #875
- Loading branch information
1 parent
0149eff
commit cf5c27a
Showing
2 changed files
with
101 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
describe('tooltip directive', function () { | ||
|
||
var $rootScope, $compile, $document, $timeout; | ||
|
||
beforeEach(module('ui.bootstrap.tooltip')); | ||
beforeEach(module('template/tooltip/tooltip-popup.html')); | ||
beforeEach(inject(function (_$rootScope_, _$compile_, _$document_, _$timeout_) { | ||
$rootScope = _$rootScope_; | ||
$compile = _$compile_; | ||
$document = _$document_; | ||
$timeout = _$timeout_; | ||
})); | ||
|
||
beforeEach(function(){ | ||
this.addMatchers({ | ||
toHaveOpenTooltips: function(noOfOpened) { | ||
var ttipElements = this.actual.find('div.tooltip'); | ||
noOfOpened = noOfOpened || 1; | ||
|
||
this.message = function() { | ||
return "Expected '" + angular.mock.dump(ttipElements) + "' to have '" + ttipElements.length + "' opened tooltips."; | ||
}; | ||
|
||
return ttipElements.length === noOfOpened; | ||
} | ||
}); | ||
}); | ||
|
||
function compileTooltip(ttipMarkup) { | ||
var fragment = $compile('<div>'+ttipMarkup+'</div>')($rootScope); | ||
$rootScope.$digest(); | ||
return fragment; | ||
} | ||
|
||
function closeTooltip(hostEl, trigger, shouldNotFlush) { | ||
hostEl.trigger(trigger || 'mouseleave' ); | ||
if (!shouldNotFlush) { | ||
$timeout.flush(); | ||
} | ||
} | ||
|
||
describe('basic scenarios with default options', function () { | ||
|
||
it('shows default tooltip on mouse enter and closes on mouse leave', function () { | ||
var fragment = compileTooltip('<span tooltip="tooltip text">Trigger here</span>'); | ||
|
||
fragment.find('span').trigger( 'mouseenter' ); | ||
expect(fragment).toHaveOpenTooltips(); | ||
|
||
closeTooltip(fragment.find('span')); | ||
expect(fragment).not.toHaveOpenTooltips(); | ||
}); | ||
|
||
it('should not show a tooltip when its content is empty', function () { | ||
var fragment = compileTooltip('<span tooltip=""></span>'); | ||
fragment.find('span').trigger( 'mouseenter' ); | ||
expect(fragment).not.toHaveOpenTooltips(); | ||
}); | ||
|
||
it('should not show a tooltip when its content becomes empty', function () { | ||
|
||
$rootScope.content = 'some text'; | ||
var fragment = compileTooltip('<span tooltip="{{ content }}"></span>'); | ||
|
||
fragment.find('span').trigger( 'mouseenter' ); | ||
expect(fragment).toHaveOpenTooltips(); | ||
|
||
$rootScope.content = ''; | ||
$rootScope.$digest(); | ||
$timeout.flush(); | ||
expect(fragment).not.toHaveOpenTooltips(); | ||
}); | ||
}); | ||
|
||
describe('option by option', function () { | ||
|
||
describe('placement', function () { | ||
|
||
it('can specify an alternative, valid placement', function () { | ||
var fragment = compileTooltip('<span tooltip="tooltip text" tooltip-placement="left">Trigger here</span>'); | ||
fragment.find('span').trigger( 'mouseenter' ); | ||
|
||
var ttipElement = fragment.find('div.tooltip'); | ||
expect(fragment).toHaveOpenTooltips(); | ||
expect(ttipElement).toHaveClass('left'); | ||
|
||
closeTooltip(fragment.find('span')); | ||
expect(fragment).not.toHaveOpenTooltips(); | ||
}); | ||
|
||
}); | ||
|
||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters