test(dart/transform): Add unit tests for url-linked templates

Test expression and method generation from url-linked templates.
This commit is contained in:
Tim Blasi 2015-03-19 09:16:21 -07:00
parent 1a788e6b0d
commit ed5975d3e5
7 changed files with 111 additions and 6 deletions

View File

@ -3,11 +3,13 @@ library angular2.test.transform.directive_processor.all_tests;
import 'package:barback/barback.dart';
import 'package:angular2/src/dom/html_adapter.dart';
import 'package:angular2/src/transform/common/asset_reader.dart';
import 'package:angular2/src/transform/common/logging.dart';
import 'package:angular2/src/transform/common/formatter.dart';
import 'package:angular2/src/transform/template_compiler/generator.dart';
import 'package:dart_style/dart_style.dart';
import 'package:guinness/guinness.dart';
import '../common/logger.dart';
import '../common/read_file.dart';
var formatter = new DartFormatter();
@ -15,6 +17,7 @@ var formatter = new DartFormatter();
void allTests() {
Html5LibDomAdapter.makeCurrent();
AssetReader reader = new TestAssetReader();
setLogger(new NullLogger());
it('should parse simple expressions in inline templates.', () async {
var inputPath =
@ -22,9 +25,7 @@ void allTests() {
var expected = readFile(
'template_compiler/inline_expression_files/expected/hello.ng_deps.dart');
var output = await processTemplates(reader, new AssetId('a', inputPath));
output = formatter.format(output);
expected = formatter.format(expected);
expect(output).toEqual(expected);
_formatThenExpectEquals(output, expected);
});
it('should parse simple methods in inline templates.', () async {
@ -32,8 +33,26 @@ void allTests() {
var expected = readFile(
'template_compiler/inline_method_files/expected/hello.ng_deps.dart');
var output = await processTemplates(reader, new AssetId('a', inputPath));
output = formatter.format(output);
expected = formatter.format(expected);
expect(output).toEqual(expected);
_formatThenExpectEquals(output, expected);
});
it('should parse simple expressions in linked templates.', () async {
var inputPath = 'template_compiler/url_expression_files/hello.ng_deps.dart';
var expected = readFile(
'template_compiler/url_expression_files/expected/hello.ng_deps.dart');
var output = await processTemplates(reader, new AssetId('a', inputPath));
_formatThenExpectEquals(output, expected);
});
it('should parse simple methods in linked templates.', () async {
var inputPath = 'template_compiler/url_method_files/hello.ng_deps.dart';
var expected = readFile(
'template_compiler/url_method_files/expected/hello.ng_deps.dart');
var output = await processTemplates(reader, new AssetId('a', inputPath));
_formatThenExpectEquals(output, expected);
});
}
void _formatThenExpectEquals(String actual, String expected) {
expect(formatter.format(actual)).toEqual(formatter.format(expected));
}

View File

@ -0,0 +1,22 @@
library examples.src.hello_world.index_common_dart;
import 'hello.dart';
import 'package:angular2/angular2.dart'
show bootstrap, Component, Decorator, Template, NgElement;
bool _visited = false;
void setupReflection(reflector) {
if (_visited) return;
_visited = true;
reflector
..registerType(HelloCmp, {
'factory': () => new HelloCmp(),
'parameters': const [const []],
'annotations': const [
const Component(selector: 'hello-app'),
const Template(url: 'template.html')
]
})
..registerGetters({'greeting': (o) => o.greeting})
..registerSetters({'greeting': (o, v) => o.greeting = v});
}

View File

@ -0,0 +1,20 @@
library examples.src.hello_world.index_common_dart;
import 'hello.dart';
import 'package:angular2/angular2.dart'
show bootstrap, Component, Decorator, Template, NgElement;
bool _visited = false;
void setupReflection(reflector) {
if (_visited) return;
_visited = true;
reflector
..registerType(HelloCmp, {
'factory': () => new HelloCmp(),
'parameters': const [const []],
'annotations': const [
const Component(selector: 'hello-app'),
const Template(url: 'template.html')
]
});
}

View File

@ -0,0 +1,22 @@
library examples.src.hello_world.index_common_dart;
import 'hello.dart';
import 'package:angular2/angular2.dart'
show bootstrap, Component, Decorator, Template, NgElement;
bool _visited = false;
void setupReflection(reflector) {
if (_visited) return;
_visited = true;
reflector
..registerType(HelloCmp, {
'factory': () => new HelloCmp(),
'parameters': const [const []],
'annotations': const [
const Component(selector: 'hello-app'),
const Template(url: 'template.html')
]
})
..registerMethods(
{'action': (o, List args) => Function.apply(o.action, args)});
}

View File

@ -0,0 +1,20 @@
library examples.src.hello_world.index_common_dart;
import 'hello.dart';
import 'package:angular2/angular2.dart'
show bootstrap, Component, Decorator, Template, NgElement;
bool _visited = false;
void setupReflection(reflector) {
if (_visited) return;
_visited = true;
reflector
..registerType(HelloCmp, {
'factory': () => new HelloCmp(),
'parameters': const [const []],
'annotations': const [
const Component(selector: 'hello-app'),
const Template(url: 'template.html')
]
});
}

View File

@ -0,0 +1 @@
<button (click)="action()">go</button>