fix(ngAnimate): fire callbacks in the correct order for certain skipped animations

This commit is contained in:
Martin Staffa
2016-03-14 18:49:41 +01:00
parent 97d2a08c5a
commit 23550b5e27
2 changed files with 71 additions and 5 deletions
+5 -5
View File
@@ -497,6 +497,11 @@ var $$AnimateQueueProvider = ['$animateProvider', function($animateProvider) {
markElementAnimationState(element, RUNNING_STATE);
var realRunner = $$animation(element, event, animationDetails.options);
// this will update the runner's flow-control events based on
// the `realRunner` object.
runner.setHost(realRunner);
notifyProgress(runner, event, 'start', {});
realRunner.done(function(status) {
close(!status);
var animationDetails = activeAnimationsLookup.get(node);
@@ -505,11 +510,6 @@ var $$AnimateQueueProvider = ['$animateProvider', function($animateProvider) {
}
notifyProgress(runner, event, 'close', {});
});
// this will update the runner's flow-control events based on
// the `realRunner` object.
runner.setHost(realRunner);
notifyProgress(runner, event, 'start', {});
});
return runner;
+66
View File
@@ -2137,5 +2137,71 @@ describe("animations", function() {
});
});
describe('when animations are skipped', function() {
var overriddenAnimationRunner;
var capturedAnimation;
var capturedAnimationHistory;
var defaultFakeAnimationRunner;
var parent;
var parent2;
beforeEach(module(function($provide) {
overriddenAnimationRunner = null;
capturedAnimation = null;
capturedAnimationHistory = [];
$provide.value('$$animation', function() {
capturedAnimationHistory.push(capturedAnimation = arguments);
return overriddenAnimationRunner || defaultFakeAnimationRunner;
});
return function($rootElement, $q, $animate, $$AnimateRunner, $document) {
defaultFakeAnimationRunner = new $$AnimateRunner();
$animate.enabled(true);
element = jqLite('<div class="element">element</div>');
parent = jqLite('<div class="parent1">parent</div>');
parent2 = jqLite('<div class="parent2">parent</div>');
$rootElement.append(parent);
$rootElement.append(parent2);
jqLite($document[0].body).append($rootElement);
};
}));
it('should trigger all callbacks if a follow-up structural animation takes over a running animation',
inject(function($animate, $rootScope) {
parent.append(element);
var moveSpy = jasmine.createSpy();
var leaveSpy = jasmine.createSpy();
$animate.on('move', parent2, moveSpy);
$animate.on('leave', parent2, leaveSpy);
$animate.move(element, parent2);
$rootScope.$digest();
$animate.flush();
expect(moveSpy.callCount).toBe(1);
expect(moveSpy.calls[0].args[1]).toBe('start');
$animate.leave(element);
$rootScope.$digest();
$animate.flush();
expect(moveSpy.callCount).toBe(2);
expect(moveSpy.calls[1].args[1]).toBe('close');
expect(leaveSpy.callCount).toBe(2);
expect(leaveSpy.calls[0].args[1]).toBe('start');
expect(leaveSpy.calls[1].args[1]).toBe('close');
}));
});
});
});