Skip to content
This repository was archived by the owner on Dec 4, 2017. It is now read-only.

Commit bead362

Browse files
teropanaomiblack
authored andcommitted
docs(animate): add animations documentation
1 parent 82b4657 commit bead362

37 files changed

+1627
-0
lines changed
Lines changed: 285 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,285 @@
1+
/// <reference path='../_protractor/e2e.d.ts' />
2+
/**
3+
* The tests here basically just checking that the end styles
4+
* of each animation are in effect.
5+
*
6+
* Relies on the Angular 2 testability only becoming stable once
7+
* animation(s) have finished.
8+
*
9+
* Ideally we'd use https://developer.mozilla.org/en-US/docs/Web/API/Document/getAnimations
10+
* but they're not supported in Chrome at the moment. The upcoming nganimate polyfill
11+
* may also add some introspection support.
12+
*/
13+
describe('Animation Tests', () => {
14+
15+
const INACTIVE_COLOR = 'rgba(238, 238, 238, 1)';
16+
const ACTIVE_COLOR = 'rgba(207, 216, 220, 1)';
17+
const NO_TRANSFORM_MATRIX_REGEX = /matrix\(1,\s*0,\s*0,\s*1,\s*0,\s*0\)/;
18+
19+
beforeEach(() => {
20+
browser.get('');
21+
});
22+
23+
describe('basic states', () => {
24+
25+
let host: protractor.ElementFinder;
26+
27+
beforeEach(() => {
28+
host = element(by.css('hero-list-basic'));
29+
});
30+
31+
it('animates between active and inactive', () => {
32+
addHero();
33+
34+
let li = host.element(by.css('li'));
35+
36+
expect(getScaleX(li)).toBe(1.0);
37+
expect(li.getCssValue('backgroundColor')).toBe(INACTIVE_COLOR);
38+
39+
li.click();
40+
expect(getScaleX(li)).toBe(1.1);
41+
expect(li.getCssValue('backgroundColor')).toBe(ACTIVE_COLOR);
42+
43+
li.click();
44+
expect(getScaleX(li)).toBe(1.0);
45+
expect(li.getCssValue('backgroundColor')).toBe(INACTIVE_COLOR);
46+
});
47+
48+
});
49+
50+
describe('styles inline in transitions', () => {
51+
52+
var host: protractor.ElementFinder;
53+
54+
beforeEach(function() {
55+
host = element(by.css('hero-list-inline-styles'));
56+
});
57+
58+
it('are not kept after animation', () => {
59+
addHero();
60+
61+
var li = host.element(by.css('li'));
62+
63+
li.click();
64+
expect(getScaleX(li)).toBe(1.0);
65+
expect(li.getCssValue('backgroundColor')).toBe(INACTIVE_COLOR);
66+
});
67+
68+
});
69+
70+
describe('combined transition syntax', () => {
71+
72+
let host: protractor.ElementFinder;
73+
74+
beforeEach(() => {
75+
host = element(by.css('hero-list-combined-transitions'));
76+
});
77+
78+
it('animates between active and inactive', () => {
79+
addHero();
80+
81+
let li = host.element(by.css('li'));
82+
83+
expect(getScaleX(li)).toBe(1.0);
84+
expect(li.getCssValue('backgroundColor')).toBe(INACTIVE_COLOR);
85+
86+
li.click();
87+
expect(getScaleX(li)).toBe(1.1);
88+
expect(li.getCssValue('backgroundColor')).toBe(ACTIVE_COLOR);
89+
90+
li.click();
91+
expect(getScaleX(li)).toBe(1.0);
92+
expect(li.getCssValue('backgroundColor')).toBe(INACTIVE_COLOR);
93+
});
94+
95+
});
96+
97+
describe('two-way transition syntax', () => {
98+
99+
let host: protractor.ElementFinder;
100+
101+
beforeEach(() => {
102+
host = element(by.css('hero-list-twoway'));
103+
});
104+
105+
it('animates between active and inactive', () => {
106+
addHero();
107+
108+
let li = host.element(by.css('li'));
109+
110+
expect(getScaleX(li)).toBe(1.0);
111+
expect(li.getCssValue('backgroundColor')).toBe(INACTIVE_COLOR);
112+
113+
li.click();
114+
expect(getScaleX(li)).toBe(1.1);
115+
expect(li.getCssValue('backgroundColor')).toBe(ACTIVE_COLOR);
116+
117+
li.click();
118+
expect(getScaleX(li)).toBe(1.0);
119+
expect(li.getCssValue('backgroundColor')).toBe(INACTIVE_COLOR);
120+
});
121+
122+
});
123+
124+
describe('enter & leave', () => {
125+
126+
let host: protractor.ElementFinder;
127+
128+
beforeEach(() => {
129+
host = element(by.css('hero-list-enter-leave'));
130+
});
131+
132+
it('adds and removes element', () => {
133+
addHero();
134+
135+
let li = host.element(by.css('li'));
136+
expect(li.getCssValue('transform')).toMatch(NO_TRANSFORM_MATRIX_REGEX);
137+
138+
removeHero();
139+
expect(li.isPresent()).toBe(false);
140+
});
141+
142+
});
143+
144+
describe('enter & leave & states', () => {
145+
146+
let host: protractor.ElementFinder;
147+
148+
beforeEach(function() {
149+
host = element(by.css('hero-list-enter-leave-states'));
150+
});
151+
152+
it('adds and removes and animates between active and inactive', () => {
153+
addHero();
154+
155+
let li = host.element(by.css('li'));
156+
157+
expect(li.getCssValue('transform')).toMatch(NO_TRANSFORM_MATRIX_REGEX);
158+
159+
li.click();
160+
expect(getScaleX(li)).toBe(1.1);
161+
162+
li.click();
163+
expect(li.getCssValue('transform')).toMatch(NO_TRANSFORM_MATRIX_REGEX);
164+
165+
removeHero();
166+
expect(li.isPresent()).toBe(false);
167+
});
168+
169+
});
170+
171+
describe('auto style calc', () => {
172+
173+
let host: protractor.ElementFinder;
174+
175+
beforeEach(function() {
176+
host = element(by.css('hero-list-auto'));
177+
});
178+
179+
it('adds and removes element', () => {
180+
addHero();
181+
182+
let li = host.element(by.css('li'));
183+
expect(li.getCssValue('height')).toBe('50px');
184+
185+
removeHero();
186+
expect(li.isPresent()).toBe(false);
187+
});
188+
189+
});
190+
191+
describe('different timings', () => {
192+
193+
let host: protractor.ElementFinder;
194+
195+
beforeEach(() => {
196+
host = element(by.css('hero-list-timings'));
197+
});
198+
199+
it('adds and removes element', () => {
200+
addHero();
201+
202+
let li = host.element(by.css('li'));
203+
expect(li.getCssValue('transform')).toMatch(NO_TRANSFORM_MATRIX_REGEX);
204+
expect(li.getCssValue('opacity')).toMatch('1');
205+
206+
removeHero();
207+
expect(li.isPresent()).toBe(false);
208+
});
209+
210+
});
211+
212+
describe('multiple keyframes', () => {
213+
214+
let host: protractor.ElementFinder;
215+
216+
beforeEach(() => {
217+
host = element(by.css('hero-list-multistep'));
218+
});
219+
220+
it('adds and removes element', () => {
221+
addHero();
222+
223+
let li = host.element(by.css('li'));
224+
expect(li.getCssValue('transform')).toMatch(NO_TRANSFORM_MATRIX_REGEX);
225+
expect(li.getCssValue('opacity')).toMatch('1');
226+
227+
removeHero();
228+
expect(li.isPresent()).toBe(false);
229+
});
230+
231+
});
232+
233+
describe('parallel groups', () => {
234+
235+
var host: protractor.ElementFinder;
236+
237+
beforeEach(() => {
238+
host = element(by.css('hero-list-groups'));
239+
});
240+
241+
it('adds and removes element', () => {
242+
addHero();
243+
244+
let li = host.element(by.css('li'));
245+
expect(li.getCssValue('transform')).toMatch(NO_TRANSFORM_MATRIX_REGEX);
246+
expect(li.getCssValue('opacity')).toMatch('1');
247+
248+
removeHero();
249+
expect(li.isPresent()).toBe(false);
250+
});
251+
252+
});
253+
254+
function addHero() {
255+
element(by.buttonText('Add hero')).click();
256+
}
257+
258+
function removeHero() {
259+
element(by.buttonText('Remove hero')).click();
260+
}
261+
262+
function getScaleX(el: protractor.ElementFinder) {
263+
return protractor.promise.all([
264+
getBoundingClientWidth(el),
265+
getOffsetWidth(el)
266+
]).then(function([clientWidth, offsetWidth]) {
267+
return clientWidth / offsetWidth;
268+
});
269+
}
270+
271+
function getBoundingClientWidth(el: protractor.ElementFinder): protractor.promise.Promise<number> {
272+
return browser.executeScript(
273+
'return arguments[0].getBoundingClientRect().width',
274+
el.getWebElement()
275+
);
276+
}
277+
278+
function getOffsetWidth(el: protractor.ElementFinder): protractor.promise.Promise<number> {
279+
return browser.executeScript(
280+
'return arguments[0].offsetWidth',
281+
el.getWebElement()
282+
);
283+
}
284+
285+
});
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
**/*.js
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
This example folder is in a WIP state as Animations are not merged into Angular yet.
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
import {
2+
Component,
3+
Input,
4+
trigger,
5+
state,
6+
style,
7+
animate,
8+
transition,
9+
group
10+
} from '@angular/core';
11+
import { Hero, Heroes } from './hero.service';
12+
13+
@Component({
14+
moduleId: module.id,
15+
selector: 'hero-list-auto',
16+
// #docregion template
17+
template: `
18+
<ul>
19+
<li *ngFor="let hero of heroes"
20+
@shrinkOut="'in'">
21+
{{hero.name}}
22+
</li>
23+
</ul>
24+
`,
25+
// #enddocregion template
26+
styleUrls: ['hero-list.component.css'],
27+
28+
/* When the element leaves (transition "in => void" occurs),
29+
* get the element's current computed height and animate
30+
* it down to 0.
31+
*/
32+
// #docregion animationdef
33+
animations: [
34+
trigger('shrinkOut', [
35+
state('in', style({height: '*'})),
36+
transition('* => void', [
37+
style({height: '*'}),
38+
animate(250, style({height: 0}))
39+
])
40+
])
41+
]
42+
// #enddocregion animationdef
43+
})
44+
export class HeroListAutoComponent {
45+
@Input() heroes:Heroes;
46+
}

0 commit comments

Comments
 (0)