From 1d23ef3be36be7e51a4a921fae30418a6aeb07e9 Mon Sep 17 00:00:00 2001 From: Chris Chua Date: Sun, 19 Apr 2015 16:01:46 -0700 Subject: [PATCH 1/2] fix(tooltip): template type should respect popup class - Test each option for each tooltip type - Tooltip popup now uses tooltip-classes directive --- src/tooltip/test/tooltip2.spec.js | 64 ++++++++++++++++++++--------- src/tooltip/tooltip.js | 2 +- template/tooltip/tooltip-popup.html | 5 ++- 3 files changed, 49 insertions(+), 22 deletions(-) diff --git a/src/tooltip/test/tooltip2.spec.js b/src/tooltip/test/tooltip2.spec.js index 98f2a93808..a7ed5005f9 100644 --- a/src/tooltip/test/tooltip2.spec.js +++ b/src/tooltip/test/tooltip2.spec.js @@ -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_; @@ -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('Trigger here'); - fragment.find('span').trigger( 'mouseenter' ); + beforeEach(inject(function ($sce, $templateCache) { + $rootScope.tooltipText = 'tooltip text'; + $rootScope.tooltipSafeHtml = $sce.trustAsHtml('tooltip text'); + $templateCache.put('tooltipTextUrl', [200, 'tooltip text', {}]); + })); - 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('Trigger here'); + 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('Trigger here'); + 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('Trigger here'); - 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(); }); }); diff --git a/src/tooltip/tooltip.js b/src/tooltip/tooltip.js index 3f0522a8bd..9c6db85413 100644 --- a/src/tooltip/tooltip.js +++ b/src/tooltip/tooltip.js @@ -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' }; diff --git a/template/tooltip/tooltip-popup.html b/template/tooltip/tooltip-popup.html index 9b62afe1bb..f43b9adad3 100644 --- a/template/tooltip/tooltip-popup.html +++ b/template/tooltip/tooltip-popup.html @@ -1,4 +1,7 @@ -
+
From 5f76fa09aceac5fb4bcf437ffc8fe8117c4dc294 Mon Sep 17 00:00:00 2001 From: Chris Chua Date: Sun, 19 Apr 2015 16:14:14 -0700 Subject: [PATCH 2/2] feat(popover): respect popover-class option Make this consistent with tooltips. --- src/popover/popover.js | 4 +- src/popover/test/popover-template.spec.js | 49 +++++++++++++++++++++++ src/popover/test/popover.spec.js | 48 ++++++++++++++++++++++ 3 files changed, 99 insertions(+), 2 deletions(-) diff --git a/src/popover/popover.js b/src/popover/popover.js index 4252be877e..dadf2dabc9 100644 --- a/src/popover/popover.js +++ b/src/popover/popover.js @@ -9,7 +9,7 @@ angular.module( 'ui.bootstrap.popover', [ 'ui.bootstrap.tooltip' ] ) return { restrict: 'EA', replace: true, - scope: { title: '@', contentExp: '&', placement: '@', animation: '&', isOpen: '&', + scope: { title: '@', contentExp: '&', placement: '@', popupClass: '@', animation: '&', isOpen: '&', originScope: '&' }, templateUrl: 'template/popover/popover-template.html' }; @@ -25,7 +25,7 @@ angular.module( 'ui.bootstrap.popover', [ 'ui.bootstrap.tooltip' ] ) return { restrict: 'EA', replace: true, - scope: { title: '@', content: '@', placement: '@', animation: '&', isOpen: '&' }, + scope: { title: '@', content: '@', placement: '@', popupClass: '@', animation: '&', isOpen: '&' }, templateUrl: 'template/popover/popover.html' }; }) diff --git a/src/popover/test/popover-template.spec.js b/src/popover/test/popover-template.spec.js index 1e74d31d5d..333156dba1 100644 --- a/src/popover/test/popover-template.spec.js +++ b/src/popover/test/popover-template.spec.js @@ -76,5 +76,54 @@ describe('popover template', function() { expect( elmBody.children().length ).toBe( 1 ); })); + describe('supports options', function () { + + describe('placement', function () { + + it('can specify an alternative, valid placement', inject(function ($compile) { + elmBody = angular.element( + '
Trigger
' + ); + $compile(elmBody)(scope); + scope.$digest(); + elm = elmBody.find('span'); + elmScope = elm.scope(); + tooltipScope = elmScope.$$childTail; + + elm.trigger( 'click' ); + expect( tooltipScope.isOpen ).toBe( true ); + + expect( elmBody.children().length ).toBe( 2 ); + var ttipElement = elmBody.find('div.popover'); + expect(ttipElement).toHaveClass('left'); + })); + + }); + + describe('class', function () { + + it('can specify a custom class', inject(function ($compile) { + elmBody = angular.element( + '
Trigger
' + ); + $compile(elmBody)(scope); + scope.$digest(); + elm = elmBody.find('span'); + elmScope = elm.scope(); + tooltipScope = elmScope.$$childTail; + + elm.trigger( 'click' ); + expect( tooltipScope.isOpen ).toBe( true ); + + expect( elmBody.children().length ).toBe( 2 ); + var ttipElement = elmBody.find('div.popover'); + expect(ttipElement).toHaveClass('custom'); + })); + + }); + + }); + + }); diff --git a/src/popover/test/popover.spec.js b/src/popover/test/popover.spec.js index d888d470dd..bc7f59167e 100644 --- a/src/popover/test/popover.spec.js +++ b/src/popover/test/popover.spec.js @@ -92,6 +92,54 @@ describe('popover', function() { expect(elmBody.children().eq(1)).not.toHaveClass('fade'); })); + describe('supports options', function () { + + describe('placement', function () { + + it('can specify an alternative, valid placement', inject(function ($compile) { + elmBody = angular.element( + '
Trigger here
' + ); + $compile(elmBody)(scope); + scope.$digest(); + elm = elmBody.find('span'); + elmScope = elm.scope(); + tooltipScope = elmScope.$$childTail; + + elm.trigger( 'click' ); + expect( tooltipScope.isOpen ).toBe( true ); + + expect( elmBody.children().length ).toBe( 2 ); + var ttipElement = elmBody.find('div.popover'); + expect(ttipElement).toHaveClass('left'); + })); + + }); + + describe('class', function () { + + it('can specify a custom class', inject(function ($compile) { + elmBody = angular.element( + '
Trigger here
' + ); + $compile(elmBody)(scope); + scope.$digest(); + elm = elmBody.find('span'); + elmScope = elm.scope(); + tooltipScope = elmScope.$$childTail; + + elm.trigger( 'click' ); + expect( tooltipScope.isOpen ).toBe( true ); + + expect( elmBody.children().length ).toBe( 2 ); + var ttipElement = elmBody.find('div.popover'); + expect(ttipElement).toHaveClass('custom'); + })); + + }); + + }); + });