2015-04-13 19:54:09 -04:00
|
|
|
library angular2.test.transform.template_compiler.all_tests;
|
2015-03-13 16:55:49 -04:00
|
|
|
|
2015-04-13 14:04:28 -04:00
|
|
|
import 'dart:async';
|
2015-03-13 16:55:49 -04:00
|
|
|
import 'package:barback/barback.dart';
|
2015-03-25 18:54:12 -04:00
|
|
|
import 'package:angular2/src/dom/html_adapter.dart';
|
2015-04-13 14:04:28 -04:00
|
|
|
import 'package:angular2/src/render/api.dart';
|
2015-03-13 16:55:49 -04:00
|
|
|
import 'package:angular2/src/transform/common/asset_reader.dart';
|
2015-04-16 11:54:44 -04:00
|
|
|
import 'package:angular2/src/transform/common/logging.dart';
|
2015-04-10 19:58:52 -04:00
|
|
|
import 'package:angular2/src/transform/common/parser.dart';
|
|
|
|
import 'package:angular2/src/transform/template_compiler/directive_metadata_reader.dart';
|
2015-03-13 16:55:49 -04:00
|
|
|
import 'package:angular2/src/transform/template_compiler/generator.dart';
|
|
|
|
import 'package:dart_style/dart_style.dart';
|
2015-03-20 18:25:29 -04:00
|
|
|
import 'package:guinness/guinness.dart';
|
2015-03-13 16:55:49 -04:00
|
|
|
|
|
|
|
import '../common/read_file.dart';
|
|
|
|
|
|
|
|
var formatter = new DartFormatter();
|
|
|
|
|
|
|
|
void allTests() {
|
|
|
|
Html5LibDomAdapter.makeCurrent();
|
|
|
|
AssetReader reader = new TestAssetReader();
|
2015-04-10 19:58:52 -04:00
|
|
|
var parser = new Parser(reader);
|
2015-03-13 16:55:49 -04:00
|
|
|
|
2015-04-16 11:54:44 -04:00
|
|
|
beforeEach(() => setLogger(new PrintLogger()));
|
|
|
|
|
2015-03-20 18:25:29 -04:00
|
|
|
it('should parse simple expressions in inline templates.', () async {
|
2015-03-13 16:55:49 -04:00
|
|
|
var inputPath =
|
|
|
|
'template_compiler/inline_expression_files/hello.ng_deps.dart';
|
|
|
|
var expected = readFile(
|
|
|
|
'template_compiler/inline_expression_files/expected/hello.ng_deps.dart');
|
|
|
|
var output = await processTemplates(reader, new AssetId('a', inputPath));
|
2015-03-19 12:16:21 -04:00
|
|
|
_formatThenExpectEquals(output, expected);
|
2015-03-13 16:55:49 -04:00
|
|
|
});
|
|
|
|
|
2015-03-20 18:25:29 -04:00
|
|
|
it('should parse simple methods in inline templates.', () async {
|
2015-03-13 16:55:49 -04:00
|
|
|
var inputPath = 'template_compiler/inline_method_files/hello.ng_deps.dart';
|
|
|
|
var expected = readFile(
|
|
|
|
'template_compiler/inline_method_files/expected/hello.ng_deps.dart');
|
|
|
|
var output = await processTemplates(reader, new AssetId('a', inputPath));
|
2015-03-19 12:16:21 -04:00
|
|
|
_formatThenExpectEquals(output, expected);
|
2015-03-13 16:55:49 -04:00
|
|
|
});
|
2015-03-19 12:16:21 -04:00
|
|
|
|
|
|
|
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);
|
|
|
|
});
|
2015-04-10 19:58:52 -04:00
|
|
|
|
|
|
|
describe('DirectiveMetadataReader', () {
|
2015-04-16 11:54:44 -04:00
|
|
|
Future<DirectiveMetadata> readMetadata(inputPath) async {
|
2015-04-10 19:58:52 -04:00
|
|
|
var ngDeps = await parser.parse(new AssetId('a', inputPath));
|
2015-04-16 11:54:44 -04:00
|
|
|
return readDirectiveMetadata(ngDeps.registeredTypes.first);
|
2015-04-13 14:04:28 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
it('should parse selectors', () async {
|
2015-04-16 11:54:44 -04:00
|
|
|
var metadata = await readMetadata(
|
2015-04-13 14:04:28 -04:00
|
|
|
'template_compiler/directive_metadata_files/selector.ng_deps.dart');
|
|
|
|
expect(metadata.selector).toEqual('hello-app');
|
2015-04-10 19:58:52 -04:00
|
|
|
});
|
|
|
|
|
2015-04-13 14:04:28 -04:00
|
|
|
it('should parse compile children values', () async {
|
2015-04-16 11:54:44 -04:00
|
|
|
var metadata = await readMetadata('template_compiler/'
|
2015-04-13 14:04:28 -04:00
|
|
|
'directive_metadata_files/compile_children.ng_deps.dart');
|
|
|
|
expect(metadata.compileChildren).toBeTrue();
|
2015-04-10 19:58:52 -04:00
|
|
|
|
2015-04-16 11:54:44 -04:00
|
|
|
metadata = await readMetadata(
|
2015-04-13 14:04:28 -04:00
|
|
|
'template_compiler/directive_metadata_files/selector.ng_deps.dart');
|
|
|
|
expect(metadata.compileChildren).toBeFalse();
|
2015-04-10 19:58:52 -04:00
|
|
|
});
|
|
|
|
|
2015-04-13 14:04:28 -04:00
|
|
|
it('should parse properties.', () async {
|
2015-04-16 11:54:44 -04:00
|
|
|
var metadata = await readMetadata('template_compiler/'
|
2015-04-13 14:04:28 -04:00
|
|
|
'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');
|
2015-04-10 19:58:52 -04:00
|
|
|
});
|
|
|
|
|
2015-04-13 14:04:28 -04:00
|
|
|
it('should parse host listeners.', () async {
|
2015-04-16 11:54:44 -04:00
|
|
|
var metadata = await readMetadata('template_compiler/'
|
2015-04-13 14:04:28 -04:00
|
|
|
'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)');
|
2015-04-10 19:58:52 -04:00
|
|
|
});
|
2015-04-16 11:54:44 -04:00
|
|
|
|
|
|
|
it('should fail when a class is annotated with multiple Directives.',
|
|
|
|
() async {
|
|
|
|
var ngDeps = await parser.parse(new AssetId('a', 'template_compiler/'
|
|
|
|
'directive_metadata_files/too_many_directives.ng_deps.dart'));
|
|
|
|
expect(() => readDirectiveMetadata(ngDeps.registeredTypes.first))
|
|
|
|
.toThrowWith(anInstanceOf: PrintLoggerError);
|
|
|
|
});
|
2015-04-10 19:58:52 -04:00
|
|
|
});
|
2015-03-19 12:16:21 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
void _formatThenExpectEquals(String actual, String expected) {
|
|
|
|
expect(formatter.format(actual)).toEqual(formatter.format(expected));
|
2015-03-13 16:55:49 -04:00
|
|
|
}
|