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

Commit

Permalink
fix(tooltip): template type should respect popup class
Browse files Browse the repository at this point in the history
- Test each option for each tooltip type
- Tooltip popup now uses tooltip-classes directive

Closes #3569
  • Loading branch information
chrisirhc authored and rvanbaalen committed Apr 30, 2015
1 parent 34044a7 commit 6af627a
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 22 deletions.
64 changes: 44 additions & 20 deletions src/tooltip/test/tooltip2.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ describe('tooltip directive', function () {

beforeEach(module('ui.bootstrap.tooltip'));
beforeEach(module('template/tooltip/tooltip-popup.html'));
beforeEach(module('template/tooltip/tooltip-template-popup.html'));
beforeEach(module('template/tooltip/tooltip-html-popup.html'));
beforeEach(module('template/tooltip/tooltip-html-unsafe-popup.html'));
beforeEach(inject(function (_$rootScope_, _$compile_, _$document_, _$timeout_) {
$rootScope = _$rootScope_;
$compile = _$compile_;
Expand Down Expand Up @@ -95,34 +98,55 @@ describe('tooltip directive', function () {

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

describe('placement', function () {
var tooltipTypes = {
'tooltip': 'tooltip="tooltip text"',
'tooltip-html': 'tooltip-html="tooltipSafeHtml"',
'tooltip-html-unsafe': 'tooltip-html-unsafe="tooltip text"',
'tooltip-template': 'tooltip-template="\'tooltipTextUrl\'"'
};

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' );
beforeEach(inject(function ($sce, $templateCache) {
$rootScope.tooltipText = 'tooltip text';
$rootScope.tooltipSafeHtml = $sce.trustAsHtml('tooltip text');
$templateCache.put('tooltipTextUrl', [200, '<span>tooltip text</span>', {}]);
}));

var ttipElement = fragment.find('div.tooltip');
expect(fragment).toHaveOpenTooltips();
expect(ttipElement).toHaveClass('left');
angular.forEach(tooltipTypes, function (html, key) {

closeTooltip(fragment.find('span'));
expect(fragment).not.toHaveOpenTooltips();
});
describe(key, function () {

});
describe('placement', function () {

it('can specify an alternative, valid placement', function () {
var fragment = compileTooltip('<span ' + html + ' 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();
});

});

describe('class', function () {

it('can specify a custom class', function () {
var fragment = compileTooltip('<span ' + html + ' tooltip-class="custom">Trigger here</span>');
fragment.find('span').trigger( 'mouseenter' );

describe('class', function () {
var ttipElement = fragment.find('div.tooltip');
expect(fragment).toHaveOpenTooltips();
expect(ttipElement).toHaveClass('custom');

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

var ttipElement = fragment.find('div.tooltip');
expect(fragment).toHaveOpenTooltips();
expect(ttipElement).toHaveClass('custom');
});

closeTooltip(fragment.find('span'));
expect(fragment).not.toHaveOpenTooltips();
});

});
Expand Down
2 changes: 1 addition & 1 deletion src/tooltip/tooltip.js
Original file line number Diff line number Diff line change
Expand Up @@ -478,7 +478,7 @@ function ($animate , $sce , $compile , $templateRequest) {
return {
restrict: 'EA',
replace: true,
scope: { title: '@', contentExp: '&', placement: '@', animation: '&', isOpen: '&',
scope: { contentExp: '&', placement: '@', popupClass: '@', animation: '&', isOpen: '&',
originScope: '&' },
templateUrl: 'template/tooltip/tooltip-template-popup.html'
};
Expand Down
5 changes: 4 additions & 1 deletion template/tooltip/tooltip-popup.html
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
<div class="tooltip {{placement}} {{popupClass}}" ng-class="{ in: isOpen(), fade: animation() }">
<div class="tooltip"
tooltip-animation-class="fade"
tooltip-classes
ng-class="{ in: isOpen() }">
<div class="tooltip-arrow"></div>
<div class="tooltip-inner" ng-bind="content"></div>
</div>

0 comments on commit 6af627a

Please sign in to comment.