@ -0,0 +1,35 @@
|
||||
import {AnimationDriver} from '../../src/animation/animation_driver';
|
||||
import {AnimationKeyframe} from '../../src/animation/animation_keyframe';
|
||||
import {AnimationPlayer} from '../../src/animation/animation_player';
|
||||
import {StringMapWrapper} from '../../src/facade/collection';
|
||||
import {AnimationStyles} from '../../src/animation/animation_styles';
|
||||
import {MockAnimationPlayer} from '../../testing/animation/mock_animation_player';
|
||||
|
||||
export class MockAnimationDriver extends AnimationDriver {
|
||||
log = [];
|
||||
animate(element: any, startingStyles: AnimationStyles, keyframes: AnimationKeyframe[], duration: number, delay: number,
|
||||
easing: string): AnimationPlayer {
|
||||
var player = new MockAnimationPlayer();
|
||||
this.log.push({
|
||||
'element': element,
|
||||
'startingStyles': _serializeStyles(startingStyles),
|
||||
'keyframes': keyframes,
|
||||
'keyframeLookup': _serializeKeyframes(keyframes),
|
||||
'duration': duration,
|
||||
'delay': delay,
|
||||
'easing': easing,
|
||||
'player': player
|
||||
});
|
||||
return player;
|
||||
}
|
||||
}
|
||||
|
||||
function _serializeKeyframes(keyframes: AnimationKeyframe[]): any[] {
|
||||
return keyframes.map(keyframe => [keyframe.offset, _serializeStyles(keyframe.styles)]);
|
||||
}
|
||||
|
||||
function _serializeStyles(styles: AnimationStyles): {[key: string]: any} {
|
||||
var flatStyles = {};
|
||||
styles.styles.forEach(entry => StringMapWrapper.forEach(entry, (val, prop) => { flatStyles[prop] = val; }));
|
||||
return flatStyles;
|
||||
}
|
@ -0,0 +1,47 @@
|
||||
import {isPresent} from '../../src/facade/lang';
|
||||
import {AnimationPlayer} from '../../src/animation/animation_player';
|
||||
|
||||
export class MockAnimationPlayer implements AnimationPlayer {
|
||||
private _subscriptions = [];
|
||||
private _finished = false;
|
||||
private _destroyed = false;
|
||||
public parentPlayer: AnimationPlayer = null;
|
||||
|
||||
public log = [];
|
||||
|
||||
private _onfinish(): void {
|
||||
if (!this._finished) {
|
||||
this._finished = true;
|
||||
this.log.push('finish');
|
||||
|
||||
this._subscriptions.forEach((entry) => { entry(); });
|
||||
this._subscriptions = [];
|
||||
if (!isPresent(this.parentPlayer)) {
|
||||
this.destroy();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
onDone(fn: Function): void { this._subscriptions.push(fn); }
|
||||
|
||||
play(): void { this.log.push('play'); }
|
||||
|
||||
pause(): void { this.log.push('pause'); }
|
||||
|
||||
restart(): void { this.log.push('restart'); }
|
||||
|
||||
finish(): void { this._onfinish(); }
|
||||
|
||||
reset(): void { this.log.push('reset'); }
|
||||
|
||||
destroy(): void {
|
||||
if (!this._destroyed) {
|
||||
this._destroyed = true;
|
||||
this.finish();
|
||||
this.log.push('destroy');
|
||||
}
|
||||
}
|
||||
|
||||
setPosition(p): void {}
|
||||
getPosition(): number { return 0; }
|
||||
}
|
Reference in New Issue
Block a user