perf: delete pre-view-engine core, compiler, platform-browser, etc code (#14788)
After the introduction of the view engine, we can drop a lot of code that is not used any more. This should reduce the size of the app bundles because a lot of this code was not being properly tree-shaken by today's tools even though it was dead code.
This commit is contained in:
@ -1,76 +0,0 @@
|
||||
/**
|
||||
* @license
|
||||
* Copyright Google Inc. All Rights Reserved.
|
||||
*
|
||||
* Use of this source code is governed by an MIT-style license that can be
|
||||
* found in the LICENSE file at https://angular.io/license
|
||||
*/
|
||||
|
||||
import {getDOM} from '@angular/platform-browser/src/dom/dom_adapter';
|
||||
import {el} from '@angular/platform-browser/testing/browser_util';
|
||||
|
||||
import {ViewAnimationMap} from '../../src/animation/view_animation_map';
|
||||
import {MockAnimationPlayer} from '../../testing/mock_animation_player';
|
||||
import {beforeEach, describe, expect, it} from '../../testing/testing_internal';
|
||||
|
||||
export function main() {
|
||||
describe('ActiveAnimationsPlayersMap', function() {
|
||||
let playersMap: any /** TODO #9100 */;
|
||||
let elementNode: any /** TODO #9100 */;
|
||||
const animationName = 'animationName';
|
||||
|
||||
beforeEach(() => {
|
||||
playersMap = new ViewAnimationMap();
|
||||
elementNode = el('<div></div>');
|
||||
});
|
||||
|
||||
afterEach(() => {
|
||||
getDOM().remove(elementNode);
|
||||
elementNode = null;
|
||||
});
|
||||
|
||||
it('should register a player an allow it to be accessed', () => {
|
||||
const player = new MockAnimationPlayer();
|
||||
playersMap.set(elementNode, animationName, player);
|
||||
|
||||
expect(playersMap.find(elementNode, animationName)).toBe(player);
|
||||
expect(playersMap.findAllPlayersByElement(elementNode)).toEqual([player]);
|
||||
expect(playersMap.getAllPlayers()).toEqual([player]);
|
||||
expect(countPlayers(playersMap)).toEqual(1);
|
||||
});
|
||||
|
||||
it('should remove a registered player when remove() is called', () => {
|
||||
const player = new MockAnimationPlayer();
|
||||
playersMap.set(elementNode, animationName, player);
|
||||
expect(playersMap.find(elementNode, animationName)).toBe(player);
|
||||
expect(countPlayers(playersMap)).toEqual(1);
|
||||
playersMap.remove(elementNode, animationName);
|
||||
expect(playersMap.find(elementNode, animationName)).not.toBe(player);
|
||||
expect(countPlayers(playersMap)).toEqual(0);
|
||||
});
|
||||
|
||||
it('should allow multiple players to be registered on the same element', () => {
|
||||
const player1 = new MockAnimationPlayer();
|
||||
const player2 = new MockAnimationPlayer();
|
||||
playersMap.set(elementNode, 'myAnimation1', player1);
|
||||
playersMap.set(elementNode, 'myAnimation2', player2);
|
||||
expect(countPlayers(playersMap)).toEqual(2);
|
||||
expect(playersMap.findAllPlayersByElement(elementNode)).toEqual([player1, player2]);
|
||||
});
|
||||
|
||||
it('should only allow one player to be set for a given element/animationName pair', () => {
|
||||
const player1 = new MockAnimationPlayer();
|
||||
const player2 = new MockAnimationPlayer();
|
||||
playersMap.set(elementNode, animationName, player1);
|
||||
expect(playersMap.find(elementNode, animationName)).toBe(player1);
|
||||
expect(countPlayers(playersMap)).toEqual(1);
|
||||
playersMap.set(elementNode, animationName, player2);
|
||||
expect(playersMap.find(elementNode, animationName)).toBe(player2);
|
||||
expect(countPlayers(playersMap)).toEqual(1);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
function countPlayers(map: ViewAnimationMap): number {
|
||||
return map.getAllPlayers().length;
|
||||
}
|
@ -1,204 +0,0 @@
|
||||
/**
|
||||
* @license
|
||||
* Copyright Google Inc. All Rights Reserved.
|
||||
*
|
||||
* Use of this source code is governed by an MIT-style license that can be
|
||||
* found in the LICENSE file at https://angular.io/license
|
||||
*/
|
||||
|
||||
import {AnimationGroupPlayer} from '../../src/animation/animation_group_player';
|
||||
import {fakeAsync, flushMicrotasks} from '../../testing';
|
||||
import {MockAnimationPlayer} from '../../testing/mock_animation_player';
|
||||
import {beforeEach, describe, expect, it} from '../../testing/testing_internal';
|
||||
|
||||
export function main() {
|
||||
describe('AnimationGroupPlayer', function() {
|
||||
let players: any /** TODO #9100 */;
|
||||
beforeEach(() => {
|
||||
players = [
|
||||
new MockAnimationPlayer(),
|
||||
new MockAnimationPlayer(),
|
||||
new MockAnimationPlayer(),
|
||||
];
|
||||
});
|
||||
|
||||
const assertLastStatus =
|
||||
(player: MockAnimationPlayer, status: string, match: boolean, iOffset: number = 0) => {
|
||||
const index = player.log.length - 1 + iOffset;
|
||||
const actual = player.log.length > 0 ? player.log[index] : null;
|
||||
if (match) {
|
||||
expect(actual).toEqual(status);
|
||||
} else {
|
||||
expect(actual).not.toEqual(status);
|
||||
}
|
||||
};
|
||||
|
||||
const assertPlaying = (player: MockAnimationPlayer, isPlaying: boolean) => {
|
||||
assertLastStatus(player, 'play', isPlaying);
|
||||
};
|
||||
|
||||
it('should play and pause all players in parallel', () => {
|
||||
const group = new AnimationGroupPlayer(players);
|
||||
|
||||
assertPlaying(players[0], false);
|
||||
assertPlaying(players[1], false);
|
||||
assertPlaying(players[2], false);
|
||||
|
||||
group.play();
|
||||
|
||||
assertPlaying(players[0], true);
|
||||
assertPlaying(players[1], true);
|
||||
assertPlaying(players[2], true);
|
||||
|
||||
group.pause();
|
||||
|
||||
assertPlaying(players[0], false);
|
||||
assertPlaying(players[1], false);
|
||||
assertPlaying(players[2], false);
|
||||
});
|
||||
|
||||
it('should finish when all players have finished', () => {
|
||||
const group = new AnimationGroupPlayer(players);
|
||||
let completed = false;
|
||||
group.onDone(() => completed = true);
|
||||
|
||||
group.play();
|
||||
|
||||
expect(completed).toBeFalsy();
|
||||
|
||||
players[0].finish();
|
||||
|
||||
expect(completed).toBeFalsy();
|
||||
|
||||
players[1].finish();
|
||||
|
||||
expect(completed).toBeFalsy();
|
||||
|
||||
players[2].finish();
|
||||
|
||||
expect(completed).toBeTruthy();
|
||||
});
|
||||
|
||||
it('should restart all the players', () => {
|
||||
const group = new AnimationGroupPlayer(players);
|
||||
|
||||
group.play();
|
||||
|
||||
assertLastStatus(players[0], 'restart', false);
|
||||
assertLastStatus(players[1], 'restart', false);
|
||||
assertLastStatus(players[2], 'restart', false);
|
||||
|
||||
group.restart();
|
||||
|
||||
assertLastStatus(players[0], 'restart', true);
|
||||
assertLastStatus(players[1], 'restart', true);
|
||||
assertLastStatus(players[2], 'restart', true);
|
||||
});
|
||||
|
||||
it('should not destroy the inner the players when finished', () => {
|
||||
const group = new AnimationGroupPlayer(players);
|
||||
|
||||
let completed = false;
|
||||
group.onDone(() => completed = true);
|
||||
|
||||
expect(completed).toBeFalsy();
|
||||
|
||||
group.play();
|
||||
|
||||
assertLastStatus(players[0], 'finish', false);
|
||||
assertLastStatus(players[1], 'finish', false);
|
||||
assertLastStatus(players[2], 'finish', false);
|
||||
|
||||
expect(completed).toBeFalsy();
|
||||
|
||||
group.finish();
|
||||
|
||||
assertLastStatus(players[0], 'finish', true);
|
||||
assertLastStatus(players[1], 'finish', true);
|
||||
assertLastStatus(players[2], 'finish', true);
|
||||
|
||||
expect(completed).toBeTruthy();
|
||||
});
|
||||
|
||||
it('should not call destroy automatically when finished even if a parent player finishes',
|
||||
() => {
|
||||
const group = new AnimationGroupPlayer(players);
|
||||
const parent = new AnimationGroupPlayer([group, new MockAnimationPlayer()]);
|
||||
|
||||
group.play();
|
||||
|
||||
assertLastStatus(players[0], 'destroy', false);
|
||||
assertLastStatus(players[1], 'destroy', false);
|
||||
assertLastStatus(players[2], 'destroy', false);
|
||||
|
||||
group.finish();
|
||||
|
||||
assertLastStatus(players[0], 'destroy', false);
|
||||
assertLastStatus(players[1], 'destroy', false);
|
||||
assertLastStatus(players[2], 'destroy', false);
|
||||
|
||||
parent.finish();
|
||||
|
||||
assertLastStatus(players[0], 'destroy', false);
|
||||
assertLastStatus(players[1], 'destroy', false);
|
||||
assertLastStatus(players[2], 'destroy', false);
|
||||
});
|
||||
|
||||
it('should function without any players', () => {
|
||||
const group = new AnimationGroupPlayer([]);
|
||||
group.onDone(() => {});
|
||||
group.pause();
|
||||
group.play();
|
||||
group.finish();
|
||||
group.restart();
|
||||
group.destroy();
|
||||
});
|
||||
|
||||
it('should run the onStart method when started but only once', () => {
|
||||
const player = new AnimationGroupPlayer([]);
|
||||
let calls = 0;
|
||||
player.onStart(() => calls++);
|
||||
expect(calls).toEqual(0);
|
||||
player.play();
|
||||
expect(calls).toEqual(1);
|
||||
player.pause();
|
||||
player.play();
|
||||
expect(calls).toEqual(1);
|
||||
});
|
||||
|
||||
it('should call onDone after the next microtask if no players are provided', fakeAsync(() => {
|
||||
const group = new AnimationGroupPlayer([]);
|
||||
let completed = false;
|
||||
group.onDone(() => completed = true);
|
||||
expect(completed).toEqual(false);
|
||||
flushMicrotasks();
|
||||
expect(completed).toEqual(true);
|
||||
}));
|
||||
|
||||
it('should not allow the player to be destroyed if it already has been destroyed unless reset',
|
||||
fakeAsync(() => {
|
||||
const p1 = new MockAnimationPlayer();
|
||||
const p2 = new MockAnimationPlayer();
|
||||
const innerPlayers = [p1, p2];
|
||||
|
||||
const groupPlayer = new AnimationGroupPlayer(innerPlayers);
|
||||
expect(p1.log[p1.log.length - 1]).not.toContain('destroy');
|
||||
expect(p2.log[p2.log.length - 1]).not.toContain('destroy');
|
||||
|
||||
groupPlayer.destroy();
|
||||
expect(p1.log[p1.log.length - 1]).toContain('destroy');
|
||||
expect(p2.log[p2.log.length - 1]).toContain('destroy');
|
||||
|
||||
p1.log = p2.log = [];
|
||||
|
||||
groupPlayer.destroy();
|
||||
expect(p1.log[p1.log.length - 1]).not.toContain('destroy');
|
||||
expect(p2.log[p2.log.length - 1]).not.toContain('destroy');
|
||||
|
||||
groupPlayer.reset();
|
||||
groupPlayer.destroy();
|
||||
expect(p1.log[p1.log.length - 1]).toContain('destroy');
|
||||
expect(p2.log[p2.log.length - 1]).toContain('destroy');
|
||||
}));
|
||||
});
|
||||
}
|
@ -6,7 +6,6 @@
|
||||
* found in the LICENSE file at https://angular.io/license
|
||||
*/
|
||||
import {AUTO_STYLE, AnimationEvent, animate, keyframes, state, style, transition, trigger} from '@angular/animations';
|
||||
import {USE_VIEW_ENGINE} from '@angular/compiler/src/config';
|
||||
import {Component, HostBinding, HostListener, ViewChild} from '@angular/core';
|
||||
import {AnimationDriver, BrowserAnimationsModule, ɵAnimationEngine} from '@angular/platform-browser/animations';
|
||||
import {MockAnimationDriver, MockAnimationPlayer} from '@angular/platform-browser/animations/testing';
|
||||
@ -14,22 +13,6 @@ import {getDOM} from '@angular/platform-browser/src/dom/dom_adapter';
|
||||
import {TestBed} from '../../testing';
|
||||
|
||||
export function main() {
|
||||
describe('view engine', () => {
|
||||
beforeEach(() => {
|
||||
TestBed.configureCompiler({
|
||||
useJit: true,
|
||||
providers: [{
|
||||
provide: USE_VIEW_ENGINE,
|
||||
useValue: true,
|
||||
}],
|
||||
});
|
||||
});
|
||||
|
||||
declareTests({useJit: true});
|
||||
});
|
||||
}
|
||||
|
||||
function declareTests({useJit}: {useJit: boolean}) {
|
||||
// these tests are only mean't to be run within the DOM (for now)
|
||||
if (typeof Element == 'undefined') return;
|
||||
|
@ -1,45 +0,0 @@
|
||||
/**
|
||||
* @license
|
||||
* Copyright Google Inc. All Rights Reserved.
|
||||
*
|
||||
* Use of this source code is governed by an MIT-style license that can be
|
||||
* found in the LICENSE file at https://angular.io/license
|
||||
*/
|
||||
|
||||
import {NoOpAnimationPlayer} from '../../src/animation/animation_player';
|
||||
import {fakeAsync, flushMicrotasks} from '../../testing';
|
||||
import {describe, expect, it} from '../../testing/testing_internal';
|
||||
|
||||
export function main() {
|
||||
describe('NoOpAnimationPlayer', function() {
|
||||
it('should call onDone after the next microtask when constructed', fakeAsync(() => {
|
||||
const player = new NoOpAnimationPlayer();
|
||||
let completed = false;
|
||||
player.onDone(() => completed = true);
|
||||
expect(completed).toEqual(false);
|
||||
flushMicrotasks();
|
||||
expect(completed).toEqual(true);
|
||||
}));
|
||||
|
||||
it('should be able to run each of the player methods', fakeAsync(() => {
|
||||
const player = new NoOpAnimationPlayer();
|
||||
player.pause();
|
||||
player.play();
|
||||
player.finish();
|
||||
player.restart();
|
||||
player.destroy();
|
||||
}));
|
||||
|
||||
it('should run the onStart method when started but only once', fakeAsync(() => {
|
||||
const player = new NoOpAnimationPlayer();
|
||||
let calls = 0;
|
||||
player.onStart(() => calls++);
|
||||
expect(calls).toEqual(0);
|
||||
player.play();
|
||||
expect(calls).toEqual(1);
|
||||
player.pause();
|
||||
player.play();
|
||||
expect(calls).toEqual(1);
|
||||
}));
|
||||
});
|
||||
}
|
@ -1,143 +0,0 @@
|
||||
/**
|
||||
* @license
|
||||
* Copyright Google Inc. All Rights Reserved.
|
||||
*
|
||||
* Use of this source code is governed by an MIT-style license that can be
|
||||
* found in the LICENSE file at https://angular.io/license
|
||||
*/
|
||||
import {AnimationQueue} from '@angular/core/src/animation/animation_queue';
|
||||
|
||||
import {NgZone} from '../../src/zone/ng_zone';
|
||||
import {TestBed, fakeAsync, flushMicrotasks} from '../../testing';
|
||||
import {MockAnimationPlayer} from '../../testing/mock_animation_player';
|
||||
import {beforeEach, describe, expect, it} from '../../testing/testing_internal';
|
||||
|
||||
export function main() {
|
||||
describe('AnimationQueue', function() {
|
||||
beforeEach(() => { TestBed.configureTestingModule({declarations: [], imports: []}); });
|
||||
|
||||
it('should queue animation players and run when flushed, but only as the next scheduled microtask',
|
||||
fakeAsync(() => {
|
||||
const zone = TestBed.get(NgZone);
|
||||
const queue = new AnimationQueue(zone);
|
||||
|
||||
const log: string[] = [];
|
||||
const p1 = new MockAnimationPlayer();
|
||||
const p2 = new MockAnimationPlayer();
|
||||
const p3 = new MockAnimationPlayer();
|
||||
|
||||
p1.onStart(() => log.push('1'));
|
||||
p2.onStart(() => log.push('2'));
|
||||
p3.onStart(() => log.push('3'));
|
||||
|
||||
queue.enqueue(p1);
|
||||
queue.enqueue(p2);
|
||||
queue.enqueue(p3);
|
||||
expect(log).toEqual([]);
|
||||
|
||||
queue.flush();
|
||||
expect(log).toEqual([]);
|
||||
|
||||
flushMicrotasks();
|
||||
expect(log).toEqual(['1', '2', '3']);
|
||||
}));
|
||||
|
||||
it('should always run each of the animation players outside of the angular zone on start',
|
||||
fakeAsync(() => {
|
||||
const zone = TestBed.get(NgZone);
|
||||
const queue = new AnimationQueue(zone);
|
||||
|
||||
const player = new MockAnimationPlayer();
|
||||
let eventHasRun = false;
|
||||
player.onStart(() => {
|
||||
NgZone.assertNotInAngularZone();
|
||||
eventHasRun = true;
|
||||
});
|
||||
|
||||
zone.run(() => {
|
||||
NgZone.assertInAngularZone();
|
||||
queue.enqueue(player);
|
||||
queue.flush();
|
||||
flushMicrotasks();
|
||||
});
|
||||
|
||||
expect(eventHasRun).toBe(true);
|
||||
}));
|
||||
|
||||
it('should always run each of the animation players outside of the angular zone on done',
|
||||
fakeAsync(() => {
|
||||
const zone = TestBed.get(NgZone);
|
||||
const queue = new AnimationQueue(zone);
|
||||
|
||||
const player = new MockAnimationPlayer();
|
||||
let eventHasRun = false;
|
||||
player.onDone(() => {
|
||||
NgZone.assertNotInAngularZone();
|
||||
eventHasRun = true;
|
||||
});
|
||||
|
||||
zone.run(() => {
|
||||
NgZone.assertInAngularZone();
|
||||
queue.enqueue(player);
|
||||
queue.flush();
|
||||
flushMicrotasks();
|
||||
});
|
||||
|
||||
expect(eventHasRun).toBe(false);
|
||||
player.finish();
|
||||
expect(eventHasRun).toBe(true);
|
||||
}));
|
||||
|
||||
it('should not run animations again incase an animation midway fails', fakeAsync(() => {
|
||||
const zone = TestBed.get(NgZone);
|
||||
const queue = new AnimationQueue(zone);
|
||||
|
||||
const log: string[] = [];
|
||||
const p1 = new PlayerThatFails(false);
|
||||
const p2 = new PlayerThatFails(true);
|
||||
const p3 = new PlayerThatFails(false);
|
||||
|
||||
p1.onStart(() => log.push('1'));
|
||||
p2.onStart(() => log.push('2'));
|
||||
p3.onStart(() => log.push('3'));
|
||||
|
||||
queue.enqueue(p1);
|
||||
queue.enqueue(p2);
|
||||
queue.enqueue(p3);
|
||||
|
||||
queue.flush();
|
||||
|
||||
expect(() => flushMicrotasks()).toThrowError();
|
||||
|
||||
expect(log).toEqual(['1', '2']);
|
||||
|
||||
// let's reset this so that it gets triggered again
|
||||
p2.reset();
|
||||
p2.onStart(() => log.push('2'));
|
||||
|
||||
queue.flush();
|
||||
|
||||
expect(() => flushMicrotasks()).not.toThrowError();
|
||||
|
||||
expect(log).toEqual(['1', '2', '3']);
|
||||
}));
|
||||
});
|
||||
}
|
||||
|
||||
class PlayerThatFails extends MockAnimationPlayer {
|
||||
private _animationStarted = false;
|
||||
|
||||
constructor(public doFail: boolean) { super(); }
|
||||
|
||||
play() {
|
||||
super.play();
|
||||
this._animationStarted = true;
|
||||
if (this.doFail) {
|
||||
throw new Error('Oh nooooo');
|
||||
}
|
||||
}
|
||||
|
||||
reset() { this._animationStarted = false; }
|
||||
|
||||
hasStarted() { return this._animationStarted; }
|
||||
}
|
@ -1,226 +0,0 @@
|
||||
/**
|
||||
* @license
|
||||
* Copyright Google Inc. All Rights Reserved.
|
||||
*
|
||||
* Use of this source code is governed by an MIT-style license that can be
|
||||
* found in the LICENSE file at https://angular.io/license
|
||||
*/
|
||||
|
||||
import {AnimationSequencePlayer} from '../../src/animation/animation_sequence_player';
|
||||
import {fakeAsync, flushMicrotasks} from '../../testing';
|
||||
import {MockAnimationPlayer} from '../../testing/mock_animation_player';
|
||||
import {beforeEach, describe, expect, it} from '../../testing/testing_internal';
|
||||
|
||||
export function main() {
|
||||
describe('AnimationSequencePlayer', function() {
|
||||
let players: any /** TODO #9100 */;
|
||||
beforeEach(() => {
|
||||
players = [
|
||||
new MockAnimationPlayer(),
|
||||
new MockAnimationPlayer(),
|
||||
new MockAnimationPlayer(),
|
||||
];
|
||||
});
|
||||
|
||||
const assertLastStatus =
|
||||
(player: MockAnimationPlayer, status: string, match: boolean, iOffset: number = 0) => {
|
||||
const index = player.log.length - 1 + iOffset;
|
||||
const actual = player.log.length > 0 ? player.log[index] : null;
|
||||
if (match) {
|
||||
expect(actual).toEqual(status);
|
||||
} else {
|
||||
expect(actual).not.toEqual(status);
|
||||
}
|
||||
};
|
||||
|
||||
const assertPlaying = (player: MockAnimationPlayer, isPlaying: boolean) => {
|
||||
assertLastStatus(player, 'play', isPlaying);
|
||||
};
|
||||
|
||||
it('should pause/play the active player', () => {
|
||||
const sequence = new AnimationSequencePlayer(players);
|
||||
|
||||
assertPlaying(players[0], false);
|
||||
assertPlaying(players[1], false);
|
||||
assertPlaying(players[2], false);
|
||||
|
||||
sequence.play();
|
||||
|
||||
assertPlaying(players[0], true);
|
||||
assertPlaying(players[1], false);
|
||||
assertPlaying(players[2], false);
|
||||
|
||||
sequence.pause();
|
||||
|
||||
assertPlaying(players[0], false);
|
||||
assertPlaying(players[1], false);
|
||||
assertPlaying(players[2], false);
|
||||
|
||||
sequence.play();
|
||||
players[0].finish();
|
||||
|
||||
assertPlaying(players[0], false);
|
||||
assertPlaying(players[1], true);
|
||||
assertPlaying(players[2], false);
|
||||
|
||||
players[1].finish();
|
||||
|
||||
assertPlaying(players[0], false);
|
||||
assertPlaying(players[1], false);
|
||||
assertPlaying(players[2], true);
|
||||
|
||||
players[2].finish();
|
||||
sequence.pause();
|
||||
|
||||
assertPlaying(players[0], false);
|
||||
assertPlaying(players[1], false);
|
||||
assertPlaying(players[2], false);
|
||||
});
|
||||
|
||||
it('should finish when all players have finished', () => {
|
||||
const sequence = new AnimationSequencePlayer(players);
|
||||
|
||||
let completed = false;
|
||||
sequence.onDone(() => completed = true);
|
||||
sequence.play();
|
||||
|
||||
expect(completed).toBeFalsy();
|
||||
|
||||
players[0].finish();
|
||||
|
||||
expect(completed).toBeFalsy();
|
||||
|
||||
players[1].finish();
|
||||
|
||||
expect(completed).toBeFalsy();
|
||||
|
||||
players[2].finish();
|
||||
|
||||
expect(completed).toBeTruthy();
|
||||
});
|
||||
|
||||
it('should restart all the players', () => {
|
||||
const sequence = new AnimationSequencePlayer(players);
|
||||
|
||||
sequence.play();
|
||||
|
||||
assertPlaying(players[0], true);
|
||||
assertPlaying(players[1], false);
|
||||
assertPlaying(players[2], false);
|
||||
|
||||
players[0].finish();
|
||||
|
||||
assertPlaying(players[0], false);
|
||||
assertPlaying(players[1], true);
|
||||
assertPlaying(players[2], false);
|
||||
|
||||
sequence.restart();
|
||||
|
||||
assertLastStatus(players[0], 'restart', true);
|
||||
assertLastStatus(players[1], 'reset', true);
|
||||
assertLastStatus(players[2], 'reset', true);
|
||||
});
|
||||
|
||||
it('should finish all the players', () => {
|
||||
const sequence = new AnimationSequencePlayer(players);
|
||||
|
||||
let completed = false;
|
||||
sequence.onDone(() => completed = true);
|
||||
|
||||
sequence.play();
|
||||
|
||||
assertLastStatus(players[0], 'finish', false);
|
||||
assertLastStatus(players[1], 'finish', false);
|
||||
assertLastStatus(players[2], 'finish', false);
|
||||
|
||||
sequence.finish();
|
||||
|
||||
assertLastStatus(players[0], 'finish', true);
|
||||
assertLastStatus(players[1], 'finish', true);
|
||||
assertLastStatus(players[2], 'finish', true);
|
||||
|
||||
expect(completed).toBeTruthy();
|
||||
});
|
||||
|
||||
it('should not call destroy automatically when finished even if a parent player is present',
|
||||
() => {
|
||||
const sequence = new AnimationSequencePlayer(players);
|
||||
const parent = new AnimationSequencePlayer([sequence, new MockAnimationPlayer()]);
|
||||
|
||||
sequence.play();
|
||||
|
||||
assertLastStatus(players[0], 'destroy', false);
|
||||
assertLastStatus(players[1], 'destroy', false);
|
||||
assertLastStatus(players[2], 'destroy', false);
|
||||
|
||||
sequence.finish();
|
||||
|
||||
assertLastStatus(players[0], 'destroy', false);
|
||||
assertLastStatus(players[1], 'destroy', false);
|
||||
assertLastStatus(players[2], 'destroy', false);
|
||||
|
||||
parent.finish();
|
||||
|
||||
assertLastStatus(players[0], 'destroy', false);
|
||||
assertLastStatus(players[1], 'destroy', false);
|
||||
assertLastStatus(players[2], 'destroy', false);
|
||||
});
|
||||
|
||||
it('should function without any players', () => {
|
||||
const sequence = new AnimationSequencePlayer([]);
|
||||
sequence.onDone(() => {});
|
||||
sequence.pause();
|
||||
sequence.play();
|
||||
sequence.finish();
|
||||
sequence.restart();
|
||||
sequence.destroy();
|
||||
});
|
||||
|
||||
it('should run the onStart method when started but only once', () => {
|
||||
const player = new AnimationSequencePlayer([]);
|
||||
let calls = 0;
|
||||
player.onStart(() => calls++);
|
||||
expect(calls).toEqual(0);
|
||||
player.play();
|
||||
expect(calls).toEqual(1);
|
||||
player.pause();
|
||||
player.play();
|
||||
expect(calls).toEqual(1);
|
||||
});
|
||||
|
||||
it('should call onDone after the next microtask if no players are provided', fakeAsync(() => {
|
||||
const sequence = new AnimationSequencePlayer([]);
|
||||
let completed = false;
|
||||
sequence.onDone(() => completed = true);
|
||||
expect(completed).toEqual(false);
|
||||
flushMicrotasks();
|
||||
expect(completed).toEqual(true);
|
||||
}));
|
||||
|
||||
it('should not allow the player to be destroyed if it already has been destroyed unless reset',
|
||||
fakeAsync(() => {
|
||||
const p1 = new MockAnimationPlayer();
|
||||
const p2 = new MockAnimationPlayer();
|
||||
const innerPlayers = [p1, p2];
|
||||
|
||||
const sequencePlayer = new AnimationSequencePlayer(innerPlayers);
|
||||
expect(p1.log[p1.log.length - 1]).not.toContain('destroy');
|
||||
expect(p2.log[p2.log.length - 1]).not.toContain('destroy');
|
||||
|
||||
sequencePlayer.destroy();
|
||||
expect(p1.log[p1.log.length - 1]).toContain('destroy');
|
||||
expect(p2.log[p2.log.length - 1]).toContain('destroy');
|
||||
|
||||
p1.log = p2.log = [];
|
||||
|
||||
sequencePlayer.destroy();
|
||||
expect(p1.log[p1.log.length - 1]).not.toContain('destroy');
|
||||
expect(p2.log[p2.log.length - 1]).not.toContain('destroy');
|
||||
|
||||
sequencePlayer.reset();
|
||||
sequencePlayer.destroy();
|
||||
expect(p1.log[p1.log.length - 1]).toContain('destroy');
|
||||
expect(p2.log[p2.log.length - 1]).toContain('destroy');
|
||||
}));
|
||||
});
|
||||
}
|
@ -1,148 +0,0 @@
|
||||
/**
|
||||
* @license
|
||||
* Copyright Google Inc. All Rights Reserved.
|
||||
*
|
||||
* Use of this source code is governed by an MIT-style license that can be
|
||||
* found in the LICENSE file at https://angular.io/license
|
||||
*/
|
||||
|
||||
import {FILL_STYLE_FLAG} from '../../src/animation/animation_constants';
|
||||
import {AnimationKeyframe} from '../../src/animation/animation_keyframe';
|
||||
import * as animationUtils from '../../src/animation/animation_style_util';
|
||||
import {AnimationStyles} from '../../src/animation/animation_styles';
|
||||
import {AUTO_STYLE} from '../../src/animation/metadata';
|
||||
import {describe, expect, it} from '../../testing/testing_internal';
|
||||
|
||||
export function main() {
|
||||
describe('Animation Style Utils', function() {
|
||||
|
||||
describe('prepareFinalAnimationStyles', () => {
|
||||
it('should set all non-shared styles to the provided null value between the two sets of styles',
|
||||
() => {
|
||||
const styles = {opacity: 0, color: 'red'};
|
||||
const newStyles = {background: 'red'};
|
||||
const flag = '*';
|
||||
const result = animationUtils.prepareFinalAnimationStyles(styles, newStyles, flag);
|
||||
expect(result).toEqual({opacity: flag, color: flag, background: 'red'});
|
||||
});
|
||||
|
||||
it('should handle an empty set of styles', () => {
|
||||
const value = '*';
|
||||
|
||||
expect(animationUtils.prepareFinalAnimationStyles({}, {opacity: '0'}, value)).toEqual({
|
||||
opacity: '0'
|
||||
});
|
||||
|
||||
expect(animationUtils.prepareFinalAnimationStyles({opacity: '0'}, {}, value)).toEqual({
|
||||
opacity: value
|
||||
});
|
||||
});
|
||||
|
||||
it('should set all AUTO styles to the null value', () => {
|
||||
const styles = {opacity: 0};
|
||||
const newStyles = {color: '*', border: '*'};
|
||||
const flag = '*';
|
||||
const result = animationUtils.prepareFinalAnimationStyles(styles, newStyles, null);
|
||||
expect(result).toEqual({opacity: null, color: null, border: null});
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('balanceAnimationKeyframes', () => {
|
||||
it('should balance both the starting and final keyframes with thep provided styles', () => {
|
||||
const collectedStyles = {width: 100, height: 200};
|
||||
|
||||
const finalStyles = {background: 'red', border: '1px solid black'};
|
||||
|
||||
const keyframes = [
|
||||
new AnimationKeyframe(0, new AnimationStyles([{height: 100, opacity: 1}])),
|
||||
new AnimationKeyframe(
|
||||
1, new AnimationStyles([{background: 'blue', left: '100px', top: '100px'}]))
|
||||
];
|
||||
|
||||
const result =
|
||||
animationUtils.balanceAnimationKeyframes(collectedStyles, finalStyles, keyframes);
|
||||
|
||||
expect(animationUtils.flattenStyles(result[0].styles.styles)).toEqual({
|
||||
'width': 100,
|
||||
'height': 100,
|
||||
'opacity': 1,
|
||||
'background': '*',
|
||||
'border': '*',
|
||||
'left': '*',
|
||||
'top': '*'
|
||||
});
|
||||
|
||||
expect(animationUtils.flattenStyles(result[1].styles.styles)).toEqual({
|
||||
'width': '*',
|
||||
'height': '*',
|
||||
'opacity': '*',
|
||||
'background': 'blue',
|
||||
'border': '1px solid black',
|
||||
'left': '100px',
|
||||
'top': '100px'
|
||||
});
|
||||
});
|
||||
|
||||
it('should perform balancing when no collected and final styles are provided', () => {
|
||||
const keyframes = [
|
||||
new AnimationKeyframe(0, new AnimationStyles([{height: 100, opacity: 1}])),
|
||||
new AnimationKeyframe(1, new AnimationStyles([{width: 100}]))
|
||||
];
|
||||
|
||||
const result = animationUtils.balanceAnimationKeyframes({}, {}, keyframes);
|
||||
|
||||
expect(animationUtils.flattenStyles(result[0].styles.styles))
|
||||
.toEqual({'height': 100, 'opacity': 1, 'width': '*'});
|
||||
|
||||
expect(animationUtils.flattenStyles(result[1].styles.styles))
|
||||
.toEqual({'width': 100, 'height': '*', 'opacity': '*'});
|
||||
});
|
||||
});
|
||||
|
||||
describe('clearStyles', () => {
|
||||
it('should set all the style values to "null"', () => {
|
||||
const styles: {[key: string]:
|
||||
string | number} = {'opacity': 0, 'width': 100, 'color': 'red'};
|
||||
const expectedResult: {[key: string]: string |
|
||||
number} = {'opacity': null, 'width': null, 'color': null};
|
||||
expect(animationUtils.clearStyles(styles)).toEqual(expectedResult);
|
||||
});
|
||||
|
||||
it('should handle an empty set of styles',
|
||||
() => { expect(animationUtils.clearStyles({})).toEqual({}); });
|
||||
});
|
||||
|
||||
describe('collectAndResolveStyles', () => {
|
||||
it('should keep a record of the styles as they are called', () => {
|
||||
const styles1 = [{'opacity': 0, 'width': 100}];
|
||||
|
||||
const styles2 = [{'height': 999, 'opacity': 1}];
|
||||
|
||||
const collection: {[key: string]: string | number} = {};
|
||||
|
||||
expect(animationUtils.collectAndResolveStyles(collection, styles1)).toEqual(styles1);
|
||||
expect(collection).toEqual({'opacity': 0, 'width': 100});
|
||||
|
||||
expect(animationUtils.collectAndResolveStyles(collection, styles2)).toEqual(styles2);
|
||||
expect(collection).toEqual({'opacity': 1, 'width': 100, 'height': 999});
|
||||
});
|
||||
|
||||
it('should resolve styles if they contain a FILL_STYLE_FLAG value', () => {
|
||||
const styles1 = [{'opacity': 0, 'width': FILL_STYLE_FLAG}];
|
||||
|
||||
const styles2 = [{'height': 999, 'opacity': FILL_STYLE_FLAG}];
|
||||
|
||||
const collection = {};
|
||||
|
||||
expect(animationUtils.collectAndResolveStyles(collection, styles1)).toEqual([
|
||||
{'opacity': 0, 'width': AUTO_STYLE}
|
||||
]);
|
||||
|
||||
expect(animationUtils.collectAndResolveStyles(collection, styles2)).toEqual([
|
||||
{'opacity': 0, 'height': 999}
|
||||
]);
|
||||
});
|
||||
});
|
||||
});
|
||||
}
|
Reference in New Issue
Block a user