Skip to content

Commit

Permalink
wip: making tests green
Browse files Browse the repository at this point in the history
  • Loading branch information
matsko committed Apr 26, 2016
1 parent 3bcd91f commit a46a711
Show file tree
Hide file tree
Showing 12 changed files with 85 additions and 88 deletions.
18 changes: 1 addition & 17 deletions modules/angular2/src/compiler/animation/animation_parser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ export function parseAnimationEvent(eventStr: string): ParsedEventResult {
var matches = RegExpWrapper.firstMatch(eventRegex, eventStr);
var key, from, to;
if (!isPresent(matches)) {
errors.push(new AnimationParseError(`the provided ${event} is not of a supported format`));
errors.push(new AnimationParseError(`the provided ${eventStr} is not of a supported format`));
key = 'default';
from = ANY_STATE;
to = EMPTY_STATE;
Expand All @@ -92,22 +92,6 @@ export function parseAnimationEvent(eventStr: string): ParsedEventResult {
return new ParsedEventResult(animationEvent, errors);
}

function _checkAndStripQuotes(value: string, errors: AnimationParseError[]): string {
var DQ = '"';
var SQ = "'";
var firstVal = value[0];
if (firstVal == DQ || firstVal == SQ) {
var lastVal = value[value.length - 1];
if (lastVal == firstVal) {
value = value.substring(1, value.length - 1);
} else {
errors.push(new AnimationParseError(`Unbalanced string value " ${value} " detected`));
value = value.substring(1);
}
}
return value;
}

function _squashSiblingStyles(entry: CompileAnimationMetadata | CompileAnimationMetadata[],
errors: AnimationParseError[]): CompileAnimationMetadata {
var squashedEntries = _squashSiblingStylesEntry(entry, errors);
Expand Down
4 changes: 1 addition & 3 deletions modules/angular2/src/compiler/animation_compiler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import {BaseException} from 'angular2/src/facade/exceptions';
import {Identifiers} from './identifiers';
import * as o from './output/output_ast';

import {AnimationMetadata} from 'angular2/src/core/metadata/animations';
import {ListWrapper, Map, StringMapWrapper} from 'angular2/src/facade/collection';

import {AnimationStateEvent} from 'angular2/src/core/animation/animation_state_event';
Expand Down Expand Up @@ -32,7 +31,6 @@ export class CompileAnimation {

export class AnimationCompiler {
compileComponent(component: CompileDirectiveMetadata): CompileAnimation[] {
var animationDetails = component.template.animations;
var compiledAnimations: CompileAnimation[] = [];
var index = 0;
component.template.animations.forEach(metadata => {
Expand All @@ -45,7 +43,7 @@ export class AnimationCompiler {
errors.forEach((error: AnimationParseError) => { errorMessage += "\n- " + error.msg; });
// todo (matsko): include the component name when throwing
throw new BaseException(
`Unable to parse the animation sequence for "${event}" due to the following errors: ` +
`Unable to parse the animation sequence for "${metadata.name}" due to the following errors: ` +
errorMessage);
}
var ast = animationResults.ast;
Expand Down
24 changes: 16 additions & 8 deletions modules/angular2/src/compiler/compile_metadata.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ export class CompileAnimationEntryMetadata {
return new CompileAnimationEntryMetadata(name, animation);
}

constructor(public name: string = null, public animation: CompileAnimationMetadata = []) {}
constructor(public name: string = null, public animation: CompileAnimationMetadata = null) {}

toJson(): {[key: string]: any} {
return {
Expand All @@ -78,7 +78,7 @@ export class CompileAnimationStyleMetadata extends CompileAnimationMetadata {
return new CompileAnimationStyleMetadata(styles);
}

constructor(public styles: {[key: string]: string | number} = {}) { super(); }
constructor(public styles: {[key: string]: string | number} = null) { super(); }

toJson(): {[key: string]: any} {
return {
Expand All @@ -96,7 +96,7 @@ export class CompileAnimationAnimateMetadata extends CompileAnimationMetadata {
return new CompileAnimationAnimateMetadata(styles, timings);
}

constructor(public styles: Array<{[key: string]: string | number}> = [], public timings: string|number = 0) { super(); }
constructor(public styles: Array<{[key: string]: string | number}> = null, public timings: string|number = 0) { super(); }

toJson(): {[key: string]: any} {
return {
Expand All @@ -110,7 +110,7 @@ export class CompileAnimationAnimateMetadata extends CompileAnimationMetadata {
}

export abstract class CompileAnimationWithStepsMetadata extends CompileAnimationMetadata {
constructor(public steps: CompileAnimationMetadata[] = []) { super(); }
constructor(public steps: CompileAnimationMetadata[] = null) { super(); }
}

export class CompileAnimationSequenceMetadata extends CompileAnimationWithStepsMetadata {
Expand All @@ -119,14 +119,18 @@ export class CompileAnimationSequenceMetadata extends CompileAnimationWithStepsM
return new CompileAnimationSequenceMetadata(steps);
}

constructor(steps: CompileAnimationMetadata[] = []) {
constructor(steps: CompileAnimationMetadata[] = null) {
super(steps);
}

toJson(): {[key: string]: any} {
var steps: any[] = null;
if (isPresent(this.steps)) {
steps = this.steps.map(step => _objToJson(step));
}
return {
'class': 'AnimationSequenceMetadata',
'value': this.steps.map(step => _objToJson(step))
'value': steps
};
}
}
Expand All @@ -137,14 +141,18 @@ export class CompileAnimationGroupMetadata extends CompileAnimationWithStepsMeta
return new CompileAnimationGroupMetadata(steps);
}

constructor(steps: CompileAnimationMetadata[] = []) {
constructor(steps: CompileAnimationMetadata[] = null) {
super(steps);
}

toJson(): {[key: string]: any} {
var steps: any[] = null;
if (isPresent(this.steps)) {
steps = this.steps.map(step => _objToJson(step));
}
return {
'class': 'AnimationGroupMetadata',
'value': this.steps.map(step => _objToJson(step))
'value': steps
};
}
}
Expand Down
27 changes: 17 additions & 10 deletions modules/angular2/src/compiler/view_compiler/property_binder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -141,24 +141,31 @@ function bindAndWriteToRenderer(boundProps: BoundElementPropertyAst[], context:
throw new BaseException(`Internal Error: couldn't find animations for ${boundProp.name}`);
}

var ANIMATION_FIRED_VAL = o.variable('animationFired');
var TRUE_VAL = o.literal(true);
var FALSE_VAL = o.literal(false);
updateStmts.push(ANIMATION_FIRED_VAL.set(FALSE_VAL).toDeclStmt());
var PLAYER_VAR = o.variable('player');
updateStmts.push(PLAYER_VAR.set(o.NULL_EXPR).toDeclStmt());
animations.forEach((animation: CompileAnimation) => {
updateStmts.push(
new o.IfStmt(
ANIMATION_FIRED_VAL.equals(FALSE_VAL)
PLAYER_VAR.equals(o.NULL_EXPR)
.and(_compareToAnimationStateExpr(fieldExpr, animation.event.fromState))
.and(_compareToAnimationStateExpr(currValExpr, animation.event.toState)), [
animation.animationFactory.callFn([
o.THIS_EXPR.prop('renderer'),
renderNode
]).callMethod('play', []).toStmt(),
ANIMATION_FIRED_VAL.set(TRUE_VAL).toStmt()
PLAYER_VAR.set(
animation.animationFactory.callFn([
o.THIS_EXPR.prop('renderer'),
renderNode
])
).toStmt()
])
);
});
updateStmts.push(new o.IfStmt(o.not(PLAYER_VAR.equals(o.NULL_EXPR)), [
PLAYER_VAR.callMethod('onDone', [
o.fn([], [
PLAYER_VAR.callMethod('destroy', []).toStmt()
])
]).toStmt(),
PLAYER_VAR.callMethod('play', []).toStmt()
]));
break;
}

Expand Down
5 changes: 3 additions & 2 deletions modules/angular2/src/core/metadata.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import 'package:angular2/src/core/change_detection/change_detection.dart';
import './metadata/di.dart';
import './metadata/directives.dart';
import './metadata/view.dart';
import './metadata/animations.dart' show AnimationEntryMetadata;

export './metadata/di.dart';
export './metadata/directives.dart';
Expand Down Expand Up @@ -80,7 +81,7 @@ class Component extends ComponentMetadata {
ViewEncapsulation encapsulation,
List<String> styles,
List<String> styleUrls,
List<dynamic> animations)
List<AnimationEntryMetadata> animations})
: super(
selector: selector,
inputs: inputs,
Expand Down Expand Up @@ -118,7 +119,7 @@ class View extends ViewMetadata {
ViewEncapsulation encapsulation,
List<String> styles,
List<String> styleUrls,
List<dynamic> animations)
List<AnimationEntryMetadata> animations})
: super(
templateUrl: templateUrl,
template: template,
Expand Down
16 changes: 5 additions & 11 deletions modules/angular2/src/core/metadata/animations.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import {isArray, isString, isStringMap} from 'angular2/src/facade/lang';
import {StringMapWrapper} from 'angular2/src/facade/collection';
import {BaseException} from 'angular2/src/facade/exceptions';
import {CONST} from 'angular2/src/facade/lang';

Expand All @@ -8,15 +7,7 @@ export abstract class AnimationMetadata {}

@CONST()
export class AnimationEntryMetadata extends AnimationMetadata {
public animation: AnimationMetadata;
constructor(public name: string, animation: AnimationMetadata|AnimationMetadata[]) {
super();
if (isArray(animation)) {
this.animation = new AnimationSequenceMetadata(<AnimationMetadata[]>animation);
} else {
this.animation = <AnimationMetadata>animation;
}
}
constructor(public name: string, public animation: AnimationMetadata) { super(); }
}

@CONST()
Expand Down Expand Up @@ -75,5 +66,8 @@ export function style(token: {[key: string]: string | number}): AnimationStyleMe
}

export function animation(name: string, animation: AnimationMetadata|AnimationMetadata[]): AnimationEntryMetadata {
return new AnimationEntryMetadata(name, animation);
var entry = isArray(animation)
? new AnimationSequenceMetadata(<AnimationMetadata[]>animation)
: <AnimationMetadata>animation;
return new AnimationEntryMetadata(name, entry);
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,13 @@ export class WebAnimationsDriver implements AnimationDriver {
easing: string): AnimationPlayer {

var formattedSteps = [];
if (!StringMapWrapper.isEmpty(startingStyles)) {
if (startingStyles.length > 0) {
let data = _populateStyles(startingStyles);
data['offset'] = 0;
formattedSteps.push(data);
}

keyframes.forEach((keyframe) => {
keyframes.forEach((keyframe: AnimationKeyframe) => {
let data = _populateStyles(keyframe.styles);
data['offset'] = keyframe.position / 100;
formattedSteps.push(data);
Expand All @@ -44,7 +44,7 @@ export class WebAnimationsDriver implements AnimationDriver {
}
}

function _populateStyles(styles) {
function _populateStyles(styles: AnimationStyles[]) {
var data = {};
styles.forEach((entry) => {
StringMapWrapper.forEach(entry.styles, (val, prop) => {
Expand Down
7 changes: 4 additions & 3 deletions modules/angular2/src/testing/test_component_builder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ import {DebugNode, DebugElement, getDebugNode} from 'angular2/src/core/debug/deb

import {tick} from './fake_async';

import {AnimationEntryMetadata} from 'angular2/animate';

/**
* Fixture for debugging and testing a component.
*/
Expand Down Expand Up @@ -99,7 +101,7 @@ export class TestComponentBuilder {
/** @internal */
_templateOverrides = new Map<Type, string>();
/** @internal */
_animationOverrides = new Map<Type, {[key: string]: any | any[]}>();
_animationOverrides = new Map<Type, AnimationEntryMetadata[]>();
/** @internal */
_viewBindingsOverrides = new Map<Type, any[]>();
/** @internal */
Expand Down Expand Up @@ -134,8 +136,7 @@ export class TestComponentBuilder {
return clone;
}

overrideAnimations(componentType: Type,
animations: {[key: string]: any | any[]}): TestComponentBuilder {
overrideAnimations(componentType: Type, animations: AnimationEntryMetadata[]): TestComponentBuilder {
var clone = this._clone();
clone._animationOverrides.set(componentType, animations);
return clone;
Expand Down
7 changes: 3 additions & 4 deletions modules/angular2/test/compiler/compile_metadata_spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,10 +69,10 @@ export function main() {
styles: ['someStyle'],
styleUrls: ['someStyleUrl'],
animations: [
new CompileAnimationEntryMetadata('animation', [
new CompileAnimationEntryMetadata('animation', new CompileAnimationSequenceMetadata([
new CompileAnimationStyleMetadata({ 'opacity': 0 }),
new CompileAnimationAnimateMetadata([{ 'opacity': 1 }], 1000)
])
]))
],
ngContentSelectors: ['*']
});
Expand Down Expand Up @@ -244,8 +244,7 @@ export function main() {
new CompileAnimationSequenceMetadata([
new CompileAnimationStyleMetadata({ "color": "red" }),
new CompileAnimationAnimateMetadata([{ "color": "blue" }], 1000),
])
);
]));
expect(CompileAnimationEntryMetadata.fromJson(full.toJson())).toEqual(full);
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -413,14 +413,14 @@ function declareTests() {
expect(enterCompleted).toEqual(true);
});
})));
*/

it('should destroy all animation players once the animation is complete',
inject([TestComponentBuilder, AnimationDriver, NgZone],
fakeAsync(
(tcb: TestComponentBuilder, driver: MockAnimationDriver, zone: MockNgZone) => {
tcb.overrideAnimations(DummyIfCmp,
{
"ngEnter": [
tcb.overrideAnimations(DummyIfCmp, [
animation("myAnimation(void => *)", [
style({'background': 'red', 'opacity': 0.5}),
animate({'background': 'black'}, 500),
group([
Expand All @@ -431,9 +431,8 @@ function declareTests() {
animate({'opacity': '1'}, 500),
animate({'background': 'white'}, 1000)
])
]
})
.createAsync(DummyIfCmp)
])
]).createAsync(DummyIfCmp)
.then((fixture) => {
tick();

Expand All @@ -444,7 +443,7 @@ function declareTests() {
flushMicrotasks();
zone.simulateMicrotaskEmpty();

expect(driver.log.length).toEqual(6);
expect(driver.log.length).toEqual(5);

driver.log.forEach(entry => entry['player'].finish());
driver.log.forEach(entry => {
Expand All @@ -454,8 +453,6 @@ function declareTests() {
});
});
})));
});
*/

it('should use first matched animation when multiple animations are registered',
inject(
Expand Down

0 comments on commit a46a711

Please sign in to comment.