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-11-23 12:42:19 -05:00
|
|
|
import {CompileAnimationEntryMetadata, CompileDirectiveMetadata, CompileTemplateMetadata, CompileTypeMetadata, identifierName} from '../../src/compile_metadata';
|
2016-05-25 15:46:22 -04:00
|
|
|
import {CompileMetadataResolver} from '../../src/metadata_resolver';
|
2016-11-08 18:45:30 -05:00
|
|
|
import {ElementSchemaRegistry} from '../../src/schema/element_schema_registry';
|
2016-05-25 15:46:22 -04:00
|
|
|
|
|
|
|
export function main() {
|
|
|
|
describe('RuntimeAnimationCompiler', () => {
|
2016-11-12 08:08:58 -05:00
|
|
|
let resolver: CompileMetadataResolver;
|
|
|
|
let parser: AnimationParser;
|
2016-11-08 18:45:30 -05:00
|
|
|
beforeEach(inject(
|
|
|
|
[CompileMetadataResolver, ElementSchemaRegistry],
|
|
|
|
(res: CompileMetadataResolver, schema: ElementSchemaRegistry) => {
|
|
|
|
resolver = res;
|
|
|
|
parser = new AnimationParser(schema);
|
|
|
|
}));
|
2016-05-25 15:46:22 -04:00
|
|
|
|
2016-09-23 16:37:04 -04:00
|
|
|
const compiler = new AnimationCompiler();
|
2016-05-25 15:46:22 -04:00
|
|
|
|
2016-11-12 08:08:58 -05:00
|
|
|
const compileAnimations =
|
2016-09-23 16:37:04 -04:00
|
|
|
(component: CompileDirectiveMetadata): AnimationEntryCompileResult[] => {
|
|
|
|
const parsedAnimations = parser.parseComponent(component);
|
2016-11-23 12:42:19 -05:00
|
|
|
return compiler.compile(identifierName(component.type), parsedAnimations);
|
2016-08-22 20:18:25 -04:00
|
|
|
};
|
2016-05-25 15:46:22 -04:00
|
|
|
|
2016-11-12 08:08:58 -05:00
|
|
|
const compileTriggers = (input: any[]) => {
|
|
|
|
const entries: CompileAnimationEntryMetadata[] = input.map(entry => {
|
|
|
|
const animationTriggerData = trigger(entry[0], entry[1]);
|
2016-07-11 13:56:47 -04:00
|
|
|
return resolver.getAnimationEntryMetadata(animationTriggerData);
|
|
|
|
});
|
2016-05-25 15:46:22 -04:00
|
|
|
|
2016-11-12 08:08:58 -05:00
|
|
|
const component = CompileDirectiveMetadata.create({
|
2016-11-30 13:52:51 -05:00
|
|
|
type: {reference: {name: 'myCmp', filePath: ''}, diDeps: [], lifecycleHooks: []},
|
2016-07-11 13:56:47 -04:00
|
|
|
template: new CompileTemplateMetadata({animations: entries})
|
2016-05-25 15:46:22 -04:00
|
|
|
});
|
|
|
|
|
|
|
|
return compileAnimations(component);
|
|
|
|
};
|
|
|
|
|
2016-11-12 08:08:58 -05:00
|
|
|
const compileSequence = (seq: AnimationMetadata) => {
|
2016-07-11 13:56:47 -04:00
|
|
|
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', () => {
|
2016-11-12 08:08:58 -05:00
|
|
|
const 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
|
|
|
]);
|
|
|
|
|
2016-11-12 08:08:58 -05:00
|
|
|
let capturedErrorMessage: string;
|
2016-05-25 15:46:22 -04:00
|
|
|
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
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|