Skip to content
This repository was archived by the owner on Sep 5, 2024. It is now read-only.

Commit 1eb1037

Browse files
topherfangioThomasBurleson
authored andcommitted
fix(input): Add missing Polyfill for ng1.3 and fix tests.
Angular 1.3 apparently did not include the `AnimateRunner.all()` method. Grab it from latest 1.5.8 code and add to our 1.3 polyfills. Additional, our $animateCss polyfill for 1.3 modifies the `to` and `from` options that are passed in and sets them to `null`. This was causing the tests to fail. Fix by keeping a cloned reference for test purposes. Closes #9169
1 parent 446b9ff commit 1eb1037

File tree

2 files changed

+37
-18
lines changed

2 files changed

+37
-18
lines changed

src/components/input/input-animations.spec.js

Lines changed: 21 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
describe('md-input-container animations', function() {
22
var $rootScope, $compile, $animate, $animateCss,
33
el, pageScope, invalidAnimation, messagesAnimation, messageAnimation,
4-
cssTransitionsDisabled = false;
4+
cssTransitionsDisabled = false, lastAnimateCall;
55

66
// Load our modules
77
beforeEach(module('ngAnimate', 'ngMessages', 'material.components.input'));
@@ -44,7 +44,7 @@ describe('md-input-container animations', function() {
4444

4545
expectError(getError(), 'pattern');
4646
expect(container).not.toHaveClass('md-input-invalid');
47-
expect(lastAnimateCall()).toEqual({element: getError(), options: {}});
47+
expect(lastAnimateCall).toEqual({element: getError(), options: {}});
4848

4949
/*
5050
* 2. Blur the input, which adds the md-input-invalid class
@@ -58,9 +58,9 @@ describe('md-input-container animations', function() {
5858

5959
expectError(getError(), 'pattern');
6060
expect(container).toHaveClass('md-input-invalid');
61-
expect(lastAnimateCall().element).toEqual(getError());
62-
expect(lastAnimateCall().options.event).toEqual('enter');
63-
expect(lastAnimateCall().options.to).toEqual({"opacity": 1, "margin-top": "0"});
61+
expect(lastAnimateCall.element).toEqual(getError());
62+
expect(lastAnimateCall.options.event).toEqual('enter');
63+
expect(lastAnimateCall.options.to).toEqual({"opacity": 1, "margin-top": "0"});
6464

6565
/*
6666
* 3. Clear the field
@@ -74,9 +74,9 @@ describe('md-input-container animations', function() {
7474
messageAnimation.leave(patternError).start().done(angular.noop);
7575
$animate.flush();
7676

77-
expect(lastAnimateCall().element).toEqual(patternError);
78-
expect(lastAnimateCall().options.event).toEqual('leave');
79-
expect(parseInt(lastAnimateCall().options.to["margin-top"])).toBeLessThan(0);
77+
expect(lastAnimateCall.element).toEqual(patternError);
78+
expect(lastAnimateCall.options.event).toEqual('leave');
79+
expect(parseInt(lastAnimateCall.options.to["margin-top"])).toBeLessThan(0);
8080

8181
setFoo('');
8282
expectError(getError(), 'required');
@@ -85,9 +85,9 @@ describe('md-input-container animations', function() {
8585
$animate.flush();
8686

8787
expect(container).toHaveClass('md-input-invalid');
88-
expect(lastAnimateCall().element).toEqual(getError());
89-
expect(lastAnimateCall().options.event).toEqual('enter');
90-
expect(lastAnimateCall().options.to).toEqual({"opacity": 1, "margin-top": "0"});
88+
expect(lastAnimateCall.element).toEqual(getError());
89+
expect(lastAnimateCall.options.event).toEqual('enter');
90+
expect(lastAnimateCall.options.to).toEqual({"opacity": 1, "margin-top": "0"});
9191
});
9292

9393
/*
@@ -103,13 +103,6 @@ describe('md-input-container animations', function() {
103103
return el;
104104
}
105105

106-
function lastAnimateCall() {
107-
return {
108-
element: $animateCss.calls.mostRecent().args[0],
109-
options: $animateCss.calls.mostRecent().args[1]
110-
}
111-
}
112-
113106
function setFoo(value) {
114107
pageScope.foo = value;
115108
pageScope.$digest();
@@ -132,6 +125,16 @@ describe('md-input-container animations', function() {
132125
module(function($provide) {
133126
$provide.decorator('$animateCss', function($delegate) {
134127
return jasmine.createSpy('$animateCss').and.callFake(function(element, options) {
128+
129+
// Store the last call to $animateCss
130+
//
131+
// NOTE: We handle this manually because the actual code modifies the options
132+
// and can make the tests fail if it executes before the expect() fires
133+
lastAnimateCall = {
134+
element: element,
135+
options: angular.copy(options)
136+
};
137+
135138
// Make sure any transitions happen immediately; NOTE: this is REQUIRED for the above
136139
// tests to pass without using window.setTimeout to wait for the animations
137140
if (cssTransitionsDisabled) {

src/core/util/animation/animateCss.js

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,22 @@ if (angular.version.minor >= 4) {
132132
}
133133
};
134134

135+
// Polyfill AnimateRunner.all which is used by input animations
136+
AnimateRunner.all = function(runners, callback) {
137+
var count = 0;
138+
var status = true;
139+
forEach(runners, function(runner) {
140+
runner.done(onProgress);
141+
});
142+
143+
function onProgress(response) {
144+
status = status && response;
145+
if (++count === runners.length) {
146+
callback(status);
147+
}
148+
}
149+
};
150+
135151
return AnimateRunner;
136152
}];
137153

0 commit comments

Comments
 (0)