2016-06-23 12:47:54 -04:00
|
|
|
/**
|
|
|
|
* @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
|
|
|
|
*/
|
|
|
|
|
2016-09-27 20:12:25 -04:00
|
|
|
import {AnimationMetadata, animate, sequence, style, transition, trigger} from '@angular/core';
|
|
|
|
import {beforeEach, describe, expect, inject, it} from '@angular/core/testing/testing_internal';
|
2016-09-23 16:37:04 -04:00
|
|
|
import {AnimationCompiler, AnimationEntryCompileResult} from '../../src/animation/animation_compiler';
|
|
|
|
import {AnimationParser} from '../../src/animation/animation_parser';
|
2016-07-11 13:56:47 -04:00
|
|
|
import {CompileAnimationEntryMetadata, CompileDirectiveMetadata, CompileTemplateMetadata, CompileTypeMetadata} from '../../src/compile_metadata';
|
2016-05-25 15:46:22 -04:00
|
|
|
import {CompileMetadataResolver} from '../../src/metadata_resolver';
|
|
|
|
|
|
|
|
export function main() {
|
|
|
|
describe('RuntimeAnimationCompiler', () => {
|
2016-10-07 20:36:08 -04:00
|
|
|
var resolver: CompileMetadataResolver;
|
2016-06-08 19:38:52 -04:00
|
|
|
beforeEach(
|
|
|
|
inject([CompileMetadataResolver], (res: CompileMetadataResolver) => { resolver = res; }));
|
2016-05-25 15:46:22 -04:00
|
|
|
|
2016-09-23 16:37:04 -04:00
|
|
|
const parser = new AnimationParser();
|
|
|
|
const compiler = new AnimationCompiler();
|
2016-05-25 15:46:22 -04:00
|
|
|
|
2016-08-22 20:18:25 -04:00
|
|
|
var compileAnimations =
|
2016-09-23 16:37:04 -04:00
|
|
|
(component: CompileDirectiveMetadata): AnimationEntryCompileResult[] => {
|
|
|
|
const parsedAnimations = parser.parseComponent(component);
|
|
|
|
return compiler.compile(component.type.name, parsedAnimations);
|
2016-08-22 20:18:25 -04:00
|
|
|
};
|
2016-05-25 15:46:22 -04:00
|
|
|
|
2016-07-11 13:56:47 -04:00
|
|
|
var compileTriggers = (input: any[]) => {
|
|
|
|
var entries: CompileAnimationEntryMetadata[] = input.map(entry => {
|
|
|
|
var animationTriggerData = trigger(entry[0], entry[1]);
|
|
|
|
return resolver.getAnimationEntryMetadata(animationTriggerData);
|
|
|
|
});
|
2016-05-25 15:46:22 -04:00
|
|
|
|
|
|
|
var component = CompileDirectiveMetadata.create({
|
2016-07-11 13:56:47 -04:00
|
|
|
type: new CompileTypeMetadata({name: 'myCmp'}),
|
|
|
|
template: new CompileTemplateMetadata({animations: entries})
|
2016-05-25 15:46:22 -04:00
|
|
|
});
|
|
|
|
|
|
|
|
return compileAnimations(component);
|
|
|
|
};
|
|
|
|
|
2016-07-11 13:56:47 -04:00
|
|
|
var compileSequence = (seq: AnimationMetadata) => {
|
|
|
|
return compileTriggers([['myAnimation', [transition('state1 => state2', seq)]]]);
|
|
|
|
};
|
|
|
|
|
2016-05-25 15:46:22 -04:00
|
|
|
it('should throw an exception containing all the inner animation parser errors', () => {
|
|
|
|
var animation = sequence([
|
2016-06-08 19:38:52 -04:00
|
|
|
style({'color': 'red'}), animate(1000, style({'font-size': '100px'})),
|
|
|
|
style({'color': 'blue'}), animate(1000, style(':missing_state')), style({'color': 'gold'}),
|
|
|
|
animate(1000, style('broken_state'))
|
2016-05-25 15:46:22 -04:00
|
|
|
]);
|
|
|
|
|
|
|
|
var capturedErrorMessage: string;
|
|
|
|
try {
|
2016-07-11 13:56:47 -04:00
|
|
|
compileSequence(animation);
|
2016-05-25 15:46:22 -04:00
|
|
|
} catch (e) {
|
|
|
|
capturedErrorMessage = e.message;
|
|
|
|
}
|
|
|
|
|
|
|
|
expect(capturedErrorMessage)
|
2016-06-22 17:53:02 -04:00
|
|
|
.toMatch(/Unable to apply styles due to missing a state: "missing_state"/g);
|
2016-05-25 15:46:22 -04:00
|
|
|
|
|
|
|
expect(capturedErrorMessage)
|
2016-06-22 17:53:02 -04:00
|
|
|
.toMatch(/Animation states via styles must be prefixed with a ":"/);
|
2016-05-25 15:46:22 -04:00
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|