test(dart/transform): Add unit tests for DirectiveMetadataReader
This commit is contained in:
parent
cf7bef58b0
commit
0d0b3a35da
|
@ -1,7 +1,9 @@
|
||||||
library angular2.test.transform.template_compiler.all_tests;
|
library angular2.test.transform.template_compiler.all_tests;
|
||||||
|
|
||||||
|
import 'dart:async';
|
||||||
import 'package:barback/barback.dart';
|
import 'package:barback/barback.dart';
|
||||||
import 'package:angular2/src/dom/html_adapter.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/asset_reader.dart';
|
||||||
import 'package:angular2/src/transform/common/parser.dart';
|
import 'package:angular2/src/transform/common/parser.dart';
|
||||||
import 'package:angular2/src/transform/template_compiler/directive_metadata_reader.dart';
|
import 'package:angular2/src/transform/template_compiler/directive_metadata_reader.dart';
|
||||||
|
@ -52,44 +54,49 @@ void allTests() {
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('DirectiveMetadataReader', () {
|
describe('DirectiveMetadataReader', () {
|
||||||
it('should parse simple expressions in inline templates', () async {
|
Future<DirectiveMetadata> readSingleMetadata(inputPath) async {
|
||||||
var inputPath =
|
|
||||||
'template_compiler/inline_expression_files/hello.ng_deps.dart';
|
|
||||||
var ngDeps = await parser.parse(new AssetId('a', inputPath));
|
var ngDeps = await parser.parse(new AssetId('a', inputPath));
|
||||||
|
|
||||||
var metadata = readDirectiveMetadata(ngDeps.registeredTypes.first);
|
var metadata = readDirectiveMetadata(ngDeps.registeredTypes.first);
|
||||||
expect(metadata.length).toEqual(2);
|
expect(metadata.length).toEqual(1);
|
||||||
expect(metadata[0].selector).toEqual('hello-app');
|
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 {
|
it('should parse compile children values', () async {
|
||||||
var inputPath =
|
var metadata = await readSingleMetadata('template_compiler/'
|
||||||
'template_compiler/inline_method_files/hello.ng_deps.dart';
|
'directive_metadata_files/compile_children.ng_deps.dart');
|
||||||
var ngDeps = await parser.parse(new AssetId('a', inputPath));
|
expect(metadata.compileChildren).toBeTrue();
|
||||||
|
|
||||||
var metadata = readDirectiveMetadata(ngDeps.registeredTypes.first);
|
metadata = await readSingleMetadata(
|
||||||
expect(metadata.length).toEqual(2);
|
'template_compiler/directive_metadata_files/selector.ng_deps.dart');
|
||||||
expect(metadata[0].selector).toEqual('hello-app');
|
expect(metadata.compileChildren).toBeFalse();
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should parse simple expressions in linked templates.', () async {
|
it('should parse properties.', () async {
|
||||||
var inputPath =
|
var metadata = await readSingleMetadata('template_compiler/'
|
||||||
'template_compiler/url_expression_files/hello.ng_deps.dart';
|
'directive_metadata_files/properties.ng_deps.dart');
|
||||||
var ngDeps = await parser.parse(new AssetId('a', inputPath));
|
expect(metadata.properties).toBeNotNull();
|
||||||
|
expect(metadata.properties.length).toBe(2);
|
||||||
var metadata = readDirectiveMetadata(ngDeps.registeredTypes.first);
|
expect(metadata.properties).toContain('key1');
|
||||||
expect(metadata.length).toEqual(2);
|
expect(metadata.properties['key1']).toEqual('val1');
|
||||||
expect(metadata[0].selector).toEqual('hello-app');
|
expect(metadata.properties).toContain('key2');
|
||||||
|
expect(metadata.properties['key2']).toEqual('val2');
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should parse simple methods in linked templates.', () async {
|
it('should parse host listeners.', () async {
|
||||||
var inputPath =
|
var metadata = await readSingleMetadata('template_compiler/'
|
||||||
'template_compiler/url_method_files/hello.ng_deps.dart';
|
'directive_metadata_files/host_listeners.ng_deps.dart');
|
||||||
var ngDeps = await parser.parse(new AssetId('a', inputPath));
|
expect(metadata.hostListeners).toBeNotNull();
|
||||||
|
expect(metadata.hostListeners.length).toBe(2);
|
||||||
var metadata = readDirectiveMetadata(ngDeps.registeredTypes.first);
|
expect(metadata.hostListeners).toContain('change');
|
||||||
expect(metadata.length).toEqual(2);
|
expect(metadata.hostListeners['change']).toEqual('onChange(\$event)');
|
||||||
expect(metadata[0].selector).toEqual('hello-app');
|
expect(metadata.hostListeners).toContain('keyDown');
|
||||||
|
expect(metadata.hostListeners['keyDown']).toEqual('onKeyDown(\$event)');
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
|
@ -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)]
|
||||||
|
});
|
||||||
|
}
|
|
@ -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)'
|
||||||
|
})
|
||||||
|
]
|
||||||
|
});
|
||||||
|
}
|
|
@ -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'})
|
||||||
|
]
|
||||||
|
});
|
||||||
|
}
|
|
@ -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')]
|
||||||
|
});
|
||||||
|
}
|
Loading…
Reference in New Issue