diff --git a/modules/angular2/test/transform/template_compiler/all_tests.dart b/modules/angular2/test/transform/template_compiler/all_tests.dart index 09c146cd25..c6166f501c 100644 --- a/modules/angular2/test/transform/template_compiler/all_tests.dart +++ b/modules/angular2/test/transform/template_compiler/all_tests.dart @@ -1,7 +1,9 @@ library angular2.test.transform.template_compiler.all_tests; +import 'dart:async'; import 'package:barback/barback.dart'; import 'package:angular2/src/dom/html_adapter.dart'; +import 'package:angular2/src/render/api.dart'; import 'package:angular2/src/transform/common/asset_reader.dart'; import 'package:angular2/src/transform/common/parser.dart'; import 'package:angular2/src/transform/template_compiler/directive_metadata_reader.dart'; @@ -52,44 +54,49 @@ void allTests() { }); describe('DirectiveMetadataReader', () { - it('should parse simple expressions in inline templates', () async { - var inputPath = - 'template_compiler/inline_expression_files/hello.ng_deps.dart'; + Future readSingleMetadata(inputPath) async { var ngDeps = await parser.parse(new AssetId('a', inputPath)); - var metadata = readDirectiveMetadata(ngDeps.registeredTypes.first); - expect(metadata.length).toEqual(2); - expect(metadata[0].selector).toEqual('hello-app'); + expect(metadata.length).toEqual(1); + return metadata.first; + } + + it('should parse selectors', () async { + var metadata = await readSingleMetadata( + 'template_compiler/directive_metadata_files/selector.ng_deps.dart'); + expect(metadata.selector).toEqual('hello-app'); }); - it('should parse simple methods in inline templates', () async { - var inputPath = - 'template_compiler/inline_method_files/hello.ng_deps.dart'; - var ngDeps = await parser.parse(new AssetId('a', inputPath)); + it('should parse compile children values', () async { + var metadata = await readSingleMetadata('template_compiler/' + 'directive_metadata_files/compile_children.ng_deps.dart'); + expect(metadata.compileChildren).toBeTrue(); - var metadata = readDirectiveMetadata(ngDeps.registeredTypes.first); - expect(metadata.length).toEqual(2); - expect(metadata[0].selector).toEqual('hello-app'); + metadata = await readSingleMetadata( + 'template_compiler/directive_metadata_files/selector.ng_deps.dart'); + expect(metadata.compileChildren).toBeFalse(); }); - it('should parse simple expressions in linked templates.', () async { - var inputPath = - 'template_compiler/url_expression_files/hello.ng_deps.dart'; - var ngDeps = await parser.parse(new AssetId('a', inputPath)); - - var metadata = readDirectiveMetadata(ngDeps.registeredTypes.first); - expect(metadata.length).toEqual(2); - expect(metadata[0].selector).toEqual('hello-app'); + it('should parse properties.', () async { + var metadata = await readSingleMetadata('template_compiler/' + 'directive_metadata_files/properties.ng_deps.dart'); + expect(metadata.properties).toBeNotNull(); + expect(metadata.properties.length).toBe(2); + expect(metadata.properties).toContain('key1'); + expect(metadata.properties['key1']).toEqual('val1'); + expect(metadata.properties).toContain('key2'); + expect(metadata.properties['key2']).toEqual('val2'); }); - it('should parse simple methods in linked templates.', () async { - var inputPath = - 'template_compiler/url_method_files/hello.ng_deps.dart'; - var ngDeps = await parser.parse(new AssetId('a', inputPath)); - - var metadata = readDirectiveMetadata(ngDeps.registeredTypes.first); - expect(metadata.length).toEqual(2); - expect(metadata[0].selector).toEqual('hello-app'); + it('should parse host listeners.', () async { + var metadata = await readSingleMetadata('template_compiler/' + 'directive_metadata_files/host_listeners.ng_deps.dart'); + expect(metadata.hostListeners).toBeNotNull(); + expect(metadata.hostListeners.length).toBe(2); + expect(metadata.hostListeners).toContain('change'); + expect(metadata.hostListeners['change']).toEqual('onChange(\$event)'); + expect(metadata.hostListeners).toContain('keyDown'); + expect(metadata.hostListeners['keyDown']).toEqual('onKeyDown(\$event)'); }); }); } diff --git a/modules/angular2/test/transform/template_compiler/directive_metadata_files/compile_children.ng_deps.dart b/modules/angular2/test/transform/template_compiler/directive_metadata_files/compile_children.ng_deps.dart new file mode 100644 index 0000000000..2b4aa2b8da --- /dev/null +++ b/modules/angular2/test/transform/template_compiler/directive_metadata_files/compile_children.ng_deps.dart @@ -0,0 +1,17 @@ +library examples.hello_world.index_common_dart.ng_deps.dart; + +import 'hello.dart'; +import 'package:angular2/angular2.dart' + show bootstrap, Component, Decorator, View, NgElement; + +bool _visited = false; +void initReflector(reflector) { + if (_visited) return; + _visited = true; + reflector + ..registerType(HelloCmp, { + 'factory': () => new HelloCmp(), + 'parameters': const [const []], + 'annotations': const [const Decorator(compileChildren: true)] + }); +} diff --git a/modules/angular2/test/transform/template_compiler/directive_metadata_files/host_listeners.ng_deps.dart b/modules/angular2/test/transform/template_compiler/directive_metadata_files/host_listeners.ng_deps.dart new file mode 100644 index 0000000000..fb24890d87 --- /dev/null +++ b/modules/angular2/test/transform/template_compiler/directive_metadata_files/host_listeners.ng_deps.dart @@ -0,0 +1,23 @@ +library examples.hello_world.index_common_dart.ng_deps.dart; + +import 'hello.dart'; +import 'package:angular2/angular2.dart' + show bootstrap, Component, Decorator, View, NgElement; + +bool _visited = false; +void initReflector(reflector) { + if (_visited) return; + _visited = true; + reflector + ..registerType(HelloCmp, { + 'factory': () => new HelloCmp(), + 'parameters': const [const []], + 'annotations': const [ + const Component( + hostListeners: const { + 'change': 'onChange(\$event)', + 'keyDown': 'onKeyDown(\$event)' + }) + ] + }); +} diff --git a/modules/angular2/test/transform/template_compiler/directive_metadata_files/properties.ng_deps.dart b/modules/angular2/test/transform/template_compiler/directive_metadata_files/properties.ng_deps.dart new file mode 100644 index 0000000000..59f15ecca6 --- /dev/null +++ b/modules/angular2/test/transform/template_compiler/directive_metadata_files/properties.ng_deps.dart @@ -0,0 +1,19 @@ +library examples.hello_world.index_common_dart.ng_deps.dart; + +import 'hello.dart'; +import 'package:angular2/angular2.dart' + show bootstrap, Component, Decorator, View, NgElement; + +bool _visited = false; +void initReflector(reflector) { + if (_visited) return; + _visited = true; + reflector + ..registerType(HelloCmp, { + 'factory': () => new HelloCmp(), + 'parameters': const [const []], + 'annotations': const [ + const Component(properties: const {'key1': 'val1', 'key2': 'val2'}) + ] + }); +} diff --git a/modules/angular2/test/transform/template_compiler/directive_metadata_files/selector.ng_deps.dart b/modules/angular2/test/transform/template_compiler/directive_metadata_files/selector.ng_deps.dart new file mode 100644 index 0000000000..9c54bcf40f --- /dev/null +++ b/modules/angular2/test/transform/template_compiler/directive_metadata_files/selector.ng_deps.dart @@ -0,0 +1,17 @@ +library examples.hello_world.index_common_dart.ng_deps.dart; + +import 'hello.dart'; +import 'package:angular2/angular2.dart' + show bootstrap, Component, Decorator, View, NgElement; + +bool _visited = false; +void initReflector(reflector) { + if (_visited) return; + _visited = true; + reflector + ..registerType(HelloCmp, { + 'factory': () => new HelloCmp(), + 'parameters': const [const []], + 'annotations': const [const Component(selector: 'hello-app')] + }); +}