Skip to content
This repository was archived by the owner on May 29, 2019. It is now read-only.

Commit 6af627a

Browse files
chrisirhcrvanbaalen
authored and
rvanbaalen
committedApr 30, 2015
fix(tooltip): template type should respect popup class
- Test each option for each tooltip type - Tooltip popup now uses tooltip-classes directive Closes #3569
1 parent 34044a7 commit 6af627a

File tree

3 files changed

+49
-22
lines changed

3 files changed

+49
-22
lines changed
 

Diff for: ‎src/tooltip/test/tooltip2.spec.js

+44-20
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@ describe('tooltip directive', function () {
44

55
beforeEach(module('ui.bootstrap.tooltip'));
66
beforeEach(module('template/tooltip/tooltip-popup.html'));
7+
beforeEach(module('template/tooltip/tooltip-template-popup.html'));
8+
beforeEach(module('template/tooltip/tooltip-html-popup.html'));
9+
beforeEach(module('template/tooltip/tooltip-html-unsafe-popup.html'));
710
beforeEach(inject(function (_$rootScope_, _$compile_, _$document_, _$timeout_) {
811
$rootScope = _$rootScope_;
912
$compile = _$compile_;
@@ -95,34 +98,55 @@ describe('tooltip directive', function () {
9598

9699
describe('option by option', function () {
97100

98-
describe('placement', function () {
101+
var tooltipTypes = {
102+
'tooltip': 'tooltip="tooltip text"',
103+
'tooltip-html': 'tooltip-html="tooltipSafeHtml"',
104+
'tooltip-html-unsafe': 'tooltip-html-unsafe="tooltip text"',
105+
'tooltip-template': 'tooltip-template="\'tooltipTextUrl\'"'
106+
};
99107

100-
it('can specify an alternative, valid placement', function () {
101-
var fragment = compileTooltip('<span tooltip="tooltip text" tooltip-placement="left">Trigger here</span>');
102-
fragment.find('span').trigger( 'mouseenter' );
108+
beforeEach(inject(function ($sce, $templateCache) {
109+
$rootScope.tooltipText = 'tooltip text';
110+
$rootScope.tooltipSafeHtml = $sce.trustAsHtml('tooltip text');
111+
$templateCache.put('tooltipTextUrl', [200, '<span>tooltip text</span>', {}]);
112+
}));
103113

104-
var ttipElement = fragment.find('div.tooltip');
105-
expect(fragment).toHaveOpenTooltips();
106-
expect(ttipElement).toHaveClass('left');
114+
angular.forEach(tooltipTypes, function (html, key) {
107115

108-
closeTooltip(fragment.find('span'));
109-
expect(fragment).not.toHaveOpenTooltips();
110-
});
116+
describe(key, function () {
111117

112-
});
118+
describe('placement', function () {
119+
120+
it('can specify an alternative, valid placement', function () {
121+
var fragment = compileTooltip('<span ' + html + ' tooltip-placement="left">Trigger here</span>');
122+
fragment.find('span').trigger( 'mouseenter' );
123+
124+
var ttipElement = fragment.find('div.tooltip');
125+
expect(fragment).toHaveOpenTooltips();
126+
expect(ttipElement).toHaveClass('left');
127+
128+
closeTooltip(fragment.find('span'));
129+
expect(fragment).not.toHaveOpenTooltips();
130+
});
131+
132+
});
133+
134+
describe('class', function () {
135+
136+
it('can specify a custom class', function () {
137+
var fragment = compileTooltip('<span ' + html + ' tooltip-class="custom">Trigger here</span>');
138+
fragment.find('span').trigger( 'mouseenter' );
113139

114-
describe('class', function () {
140+
var ttipElement = fragment.find('div.tooltip');
141+
expect(fragment).toHaveOpenTooltips();
142+
expect(ttipElement).toHaveClass('custom');
115143

116-
it('can specify a custom class', function () {
117-
var fragment = compileTooltip('<span tooltip="tooltip text" tooltip-class="custom">Trigger here</span>');
118-
fragment.find('span').trigger( 'mouseenter' );
144+
closeTooltip(fragment.find('span'));
145+
expect(fragment).not.toHaveOpenTooltips();
146+
});
119147

120-
var ttipElement = fragment.find('div.tooltip');
121-
expect(fragment).toHaveOpenTooltips();
122-
expect(ttipElement).toHaveClass('custom');
148+
});
123149

124-
closeTooltip(fragment.find('span'));
125-
expect(fragment).not.toHaveOpenTooltips();
126150
});
127151

128152
});

Diff for: ‎src/tooltip/tooltip.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -478,7 +478,7 @@ function ($animate , $sce , $compile , $templateRequest) {
478478
return {
479479
restrict: 'EA',
480480
replace: true,
481-
scope: { title: '@', contentExp: '&', placement: '@', animation: '&', isOpen: '&',
481+
scope: { contentExp: '&', placement: '@', popupClass: '@', animation: '&', isOpen: '&',
482482
originScope: '&' },
483483
templateUrl: 'template/tooltip/tooltip-template-popup.html'
484484
};

Diff for: ‎template/tooltip/tooltip-popup.html

+4-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
1-
<div class="tooltip {{placement}} {{popupClass}}" ng-class="{ in: isOpen(), fade: animation() }">
1+
<div class="tooltip"
2+
tooltip-animation-class="fade"
3+
tooltip-classes
4+
ng-class="{ in: isOpen() }">
25
<div class="tooltip-arrow"></div>
36
<div class="tooltip-inner" ng-bind="content"></div>
47
</div>

0 commit comments

Comments
 (0)