From 1cbd73d2271839732f08c6d75d865e7c76167e44 Mon Sep 17 00:00:00 2001 From: Anthony Cleaver Date: Mon, 20 Jun 2016 08:33:37 +0100 Subject: [PATCH] feat(modal): append using $animate - Use $animate.enter to append transcluded content Closes #6023 Closes #6029 --- src/modal/modal.js | 6 ++-- src/modal/test/modal.spec.js | 56 ++++++++++++++++++++++++++++++++++++ 2 files changed, 59 insertions(+), 3 deletions(-) diff --git a/src/modal/modal.js b/src/modal/modal.js index d797febac6..f5729d59b3 100644 --- a/src/modal/modal.js +++ b/src/modal/modal.js @@ -230,16 +230,16 @@ angular.module('ui.bootstrap.modal', ['ui.bootstrap.stackedMap', 'ui.bootstrap.p }; }) - .directive('uibModalTransclude', function() { + .directive('uibModalTransclude', ['$animate', function($animate) { return { link: function(scope, element, attrs, controller, transclude) { transclude(scope.$parent, function(clone) { element.empty(); - element.append(clone); + $animate.enter(clone, element); }); } }; - }) + }]) .factory('$uibModalStack', ['$animate', '$animateCss', '$document', '$compile', '$rootScope', '$q', '$$multiMap', '$$stackedMap', '$uibPosition', diff --git a/src/modal/test/modal.spec.js b/src/modal/test/modal.spec.js index 2bd0486666..4253b487ae 100644 --- a/src/modal/test/modal.spec.js +++ b/src/modal/test/modal.spec.js @@ -46,6 +46,62 @@ describe('$uibResolve', function() { }); }); +describe('uibModalTransclude', function() { + var uibModalTranscludeDDO, + $animate; + + beforeEach(module('ui.bootstrap.modal')); + beforeEach(module(function($provide) { + $animate = jasmine.createSpyObj('$animate', ['enter']); + $provide.value('$animate', $animate); + })); + + beforeEach(inject(function(uibModalTranscludeDirective) { + uibModalTranscludeDDO = uibModalTranscludeDirective[0]; + })); + + describe('when initialised', function() { + var scope, + element, + transcludeSpy, + transcludeFn; + + beforeEach(function() { + scope = { + $parent: 'parentScope' + }; + + element = jasmine.createSpyObj('containerElement', ['empty']); + transcludeSpy = jasmine.createSpy('transcludeSpy').and.callFake(function(scope, fn) { + transcludeFn = fn; + }); + + uibModalTranscludeDDO.link(scope, element, {}, {}, transcludeSpy); + }); + + it('should call the transclusion function', function() { + expect(transcludeSpy).toHaveBeenCalledWith(scope.$parent, jasmine.any(Function)); + }); + + describe('transclusion callback', function() { + var transcludedContent; + + beforeEach(function() { + transcludedContent = 'my transcluded content'; + transcludeFn(transcludedContent); + }); + + it('should empty the element', function() { + expect(element.empty).toHaveBeenCalledWith(); + }); + + it('should append the transcluded content', function() { + expect($animate.enter).toHaveBeenCalledWith(transcludedContent, element); + }); + }); + }); +}); + describe('$uibModal', function() { var $animate, $controllerProvider, $rootScope, $document, $compile, $templateCache, $timeout, $q; var $uibModal, $uibModalStack, $uibModalProvider;