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.
feat(tooltip): add tooltip-template directive
Fixes #220
- Loading branch information
Showing
5 changed files
with
104 additions
and
5 deletions.
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
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
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,65 @@ | ||
describe('tooltip template', function() { | ||
var elm, | ||
elmBody, | ||
scope, | ||
elmScope, | ||
tooltipScope; | ||
|
||
// load the popover code | ||
beforeEach(module('ui.bootstrap.tooltip')); | ||
|
||
// load the template | ||
beforeEach(module('template/tooltip/tooltip-template-popup.html')); | ||
|
||
beforeEach(inject(function ($templateCache) { | ||
$templateCache.put('myUrl', [200, '<span>{{ myTemplateText }}</span>', {}]); | ||
})); | ||
|
||
beforeEach(inject(function($rootScope, $compile) { | ||
elmBody = angular.element( | ||
'<div><span tooltip-template="{{ templateUrl }}">Selector Text</span></div>' | ||
); | ||
|
||
scope = $rootScope; | ||
$compile(elmBody)(scope); | ||
scope.templateUrl = 'myUrl'; | ||
|
||
scope.$digest(); | ||
elm = elmBody.find('span'); | ||
elmScope = elm.scope(); | ||
tooltipScope = elmScope.$$childTail; | ||
})); | ||
|
||
it('should open on mouseenter', inject(function() { | ||
elm.trigger( 'mouseenter' ); | ||
expect( tooltipScope.isOpen ).toBe( true ); | ||
|
||
expect( elmBody.children().length ).toBe( 2 ); | ||
})); | ||
|
||
it('should not open on mouseenter if templateUrl is empty', inject(function() { | ||
scope.templateUrl = null; | ||
scope.$digest(); | ||
|
||
elm.trigger( 'mouseenter' ); | ||
expect( tooltipScope.isOpen ).toBe( false ); | ||
|
||
expect( elmBody.children().length ).toBe( 1 ); | ||
})); | ||
|
||
it('should show updated text', inject(function() { | ||
scope.myTemplateText = 'some text'; | ||
scope.$digest(); | ||
|
||
elm.trigger( 'mouseenter' ); | ||
expect( tooltipScope.isOpen ).toBe( true ); | ||
|
||
expect( elmBody.children().eq(1).text().trim() ).toBe( 'some text' ); | ||
|
||
scope.myTemplateText = 'new text'; | ||
scope.$digest(); | ||
|
||
expect( elmBody.children().eq(1).text().trim() ).toBe( 'new text' ); | ||
})); | ||
}); | ||
|
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
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,6 @@ | ||
<div class="tooltip {{placement}}" ng-class="{ in: isOpen(), fade: animation() }"> | ||
<div class="tooltip-arrow"></div> | ||
<div class="tooltip-inner" | ||
tooltip-template-transclude="content" | ||
tooltip-template-transclude-scope="originScope()"></div> | ||
</div> |