Skip to content

Commit ed5975d

Browse files
author
Tim Blasi
committed
test(dart/transform): Add unit tests for url-linked templates
Test expression and method generation from url-linked templates.
1 parent 1a788e6 commit ed5975d

File tree

7 files changed

+111
-6
lines changed

7 files changed

+111
-6
lines changed

modules/angular2/test/transform/template_compiler/all_tests.dart

Lines changed: 25 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,37 +3,56 @@ library angular2.test.transform.directive_processor.all_tests;
33
import 'package:barback/barback.dart';
44
import 'package:angular2/src/dom/html_adapter.dart';
55
import 'package:angular2/src/transform/common/asset_reader.dart';
6+
import 'package:angular2/src/transform/common/logging.dart';
67
import 'package:angular2/src/transform/common/formatter.dart';
78
import 'package:angular2/src/transform/template_compiler/generator.dart';
89
import 'package:dart_style/dart_style.dart';
910
import 'package:guinness/guinness.dart';
1011

12+
import '../common/logger.dart';
1113
import '../common/read_file.dart';
1214

1315
var formatter = new DartFormatter();
1416

1517
void allTests() {
1618
Html5LibDomAdapter.makeCurrent();
1719
AssetReader reader = new TestAssetReader();
20+
setLogger(new NullLogger());
1821

1922
it('should parse simple expressions in inline templates.', () async {
2023
var inputPath =
2124
'template_compiler/inline_expression_files/hello.ng_deps.dart';
2225
var expected = readFile(
2326
'template_compiler/inline_expression_files/expected/hello.ng_deps.dart');
2427
var output = await processTemplates(reader, new AssetId('a', inputPath));
25-
output = formatter.format(output);
26-
expected = formatter.format(expected);
27-
expect(output).toEqual(expected);
28+
_formatThenExpectEquals(output, expected);
2829
});
2930

3031
it('should parse simple methods in inline templates.', () async {
3132
var inputPath = 'template_compiler/inline_method_files/hello.ng_deps.dart';
3233
var expected = readFile(
3334
'template_compiler/inline_method_files/expected/hello.ng_deps.dart');
3435
var output = await processTemplates(reader, new AssetId('a', inputPath));
35-
output = formatter.format(output);
36-
expected = formatter.format(expected);
37-
expect(output).toEqual(expected);
36+
_formatThenExpectEquals(output, expected);
3837
});
38+
39+
it('should parse simple expressions in linked templates.', () async {
40+
var inputPath = 'template_compiler/url_expression_files/hello.ng_deps.dart';
41+
var expected = readFile(
42+
'template_compiler/url_expression_files/expected/hello.ng_deps.dart');
43+
var output = await processTemplates(reader, new AssetId('a', inputPath));
44+
_formatThenExpectEquals(output, expected);
45+
});
46+
47+
it('should parse simple methods in linked templates.', () async {
48+
var inputPath = 'template_compiler/url_method_files/hello.ng_deps.dart';
49+
var expected = readFile(
50+
'template_compiler/url_method_files/expected/hello.ng_deps.dart');
51+
var output = await processTemplates(reader, new AssetId('a', inputPath));
52+
_formatThenExpectEquals(output, expected);
53+
});
54+
}
55+
56+
void _formatThenExpectEquals(String actual, String expected) {
57+
expect(formatter.format(actual)).toEqual(formatter.format(expected));
3958
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
library examples.src.hello_world.index_common_dart;
2+
3+
import 'hello.dart';
4+
import 'package:angular2/angular2.dart'
5+
show bootstrap, Component, Decorator, Template, NgElement;
6+
7+
bool _visited = false;
8+
void setupReflection(reflector) {
9+
if (_visited) return;
10+
_visited = true;
11+
reflector
12+
..registerType(HelloCmp, {
13+
'factory': () => new HelloCmp(),
14+
'parameters': const [const []],
15+
'annotations': const [
16+
const Component(selector: 'hello-app'),
17+
const Template(url: 'template.html')
18+
]
19+
})
20+
..registerGetters({'greeting': (o) => o.greeting})
21+
..registerSetters({'greeting': (o, v) => o.greeting = v});
22+
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
library examples.src.hello_world.index_common_dart;
2+
3+
import 'hello.dart';
4+
import 'package:angular2/angular2.dart'
5+
show bootstrap, Component, Decorator, Template, NgElement;
6+
7+
bool _visited = false;
8+
void setupReflection(reflector) {
9+
if (_visited) return;
10+
_visited = true;
11+
reflector
12+
..registerType(HelloCmp, {
13+
'factory': () => new HelloCmp(),
14+
'parameters': const [const []],
15+
'annotations': const [
16+
const Component(selector: 'hello-app'),
17+
const Template(url: 'template.html')
18+
]
19+
});
20+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{{greeting}}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
library examples.src.hello_world.index_common_dart;
2+
3+
import 'hello.dart';
4+
import 'package:angular2/angular2.dart'
5+
show bootstrap, Component, Decorator, Template, NgElement;
6+
7+
bool _visited = false;
8+
void setupReflection(reflector) {
9+
if (_visited) return;
10+
_visited = true;
11+
reflector
12+
..registerType(HelloCmp, {
13+
'factory': () => new HelloCmp(),
14+
'parameters': const [const []],
15+
'annotations': const [
16+
const Component(selector: 'hello-app'),
17+
const Template(url: 'template.html')
18+
]
19+
})
20+
..registerMethods(
21+
{'action': (o, List args) => Function.apply(o.action, args)});
22+
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
library examples.src.hello_world.index_common_dart;
2+
3+
import 'hello.dart';
4+
import 'package:angular2/angular2.dart'
5+
show bootstrap, Component, Decorator, Template, NgElement;
6+
7+
bool _visited = false;
8+
void setupReflection(reflector) {
9+
if (_visited) return;
10+
_visited = true;
11+
reflector
12+
..registerType(HelloCmp, {
13+
'factory': () => new HelloCmp(),
14+
'parameters': const [const []],
15+
'annotations': const [
16+
const Component(selector: 'hello-app'),
17+
const Template(url: 'template.html')
18+
]
19+
});
20+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
<button (click)="action()">go</button>

0 commit comments

Comments
 (0)