From 1dc8ba69203d9041a6e36050232178a09e7b7620 Mon Sep 17 00:00:00 2001
From: Tobias Bosch
Date: Tue, 26 May 2015 09:25:39 -0700
Subject: [PATCH] =?UTF-8?q?refactor(render):=20ts=E2=80=99ify=20tests?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
...owser_spec.js => compiler_browser_spec.ts} | 6 +-
.../dom/compiler/compiler_common_tests.js | 229 --------
.../dom/compiler/compiler_common_tests.ts | 221 ++++++++
...arser_spec.js => directive_parser_spec.ts} | 169 +++---
.../{pipeline_spec.js => pipeline_spec.ts} | 66 +--
...pec.js => property_binding_parser_spec.ts} | 54 +-
.../{selector_spec.js => selector_spec.ts} | 127 +++--
.../dom/compiler/template_loader_spec.js | 100 ----
.../dom/compiler/template_loader_spec.ts | 96 ++++
...c.js => text_interpolation_parser_spec.ts} | 15 +-
...splitter_spec.js => view_splitter_spec.ts} | 50 +-
.../dom/{convert_spec.js => convert_spec.ts} | 48 +-
.../dom/dom_renderer_integration_spec.js | 197 -------
.../dom/dom_renderer_integration_spec.ts | 194 +++++++
.../dom/{dom_testbed.js => dom_testbed.ts} | 82 +--
..._manager_spec.js => event_manager_spec.ts} | 54 +-
...{key_events_spec.js => key_events_spec.ts} | 72 ++-
...ontent_tag_spec.js => content_tag_spec.ts} | 21 +-
...ulated_scoped_shadow_dom_strategy_spec.ts} | 33 +-
...ated_unscoped_shadow_dom_strategy_spec.ts} | 8 +-
.../{light_dom_spec.js => light_dom_spec.ts} | 118 ++--
....js => native_shadow_dom_strategy_spec.ts} | 7 +-
...{shadow_css_spec.js => shadow_css_spec.ts} | 12 +-
.../dom/shadow_dom/style_inliner_spec.js | 234 --------
.../dom/shadow_dom/style_inliner_spec.ts | 203 +++++++
...ver_spec.js => style_url_resolver_spec.ts} | 4 +-
.../shadow_dom_emulation_integration_spec.js | 507 ------------------
.../shadow_dom_emulation_integration_spec.ts | 495 +++++++++++++++++
...pec.js => property_setter_factory_spec.ts} | 21 +-
.../dom/view/{view_spec.js => view_spec.ts} | 48 +-
30 files changed, 1690 insertions(+), 1801 deletions(-)
rename modules/angular2/test/render/dom/compiler/{compiler_browser_spec.js => compiler_browser_spec.ts} (66%)
delete mode 100644 modules/angular2/test/render/dom/compiler/compiler_common_tests.js
create mode 100644 modules/angular2/test/render/dom/compiler/compiler_common_tests.ts
rename modules/angular2/test/render/dom/compiler/{directive_parser_spec.js => directive_parser_spec.ts} (68%)
rename modules/angular2/test/render/dom/compiler/{pipeline_spec.js => pipeline_spec.ts} (83%)
rename modules/angular2/test/render/dom/compiler/{property_binding_parser_spec.js => property_binding_parser_spec.ts} (82%)
rename modules/angular2/test/render/dom/compiler/{selector_spec.js => selector_spec.ts} (75%)
delete mode 100644 modules/angular2/test/render/dom/compiler/template_loader_spec.js
create mode 100644 modules/angular2/test/render/dom/compiler/template_loader_spec.ts
rename modules/angular2/test/render/dom/compiler/{text_interpolation_parser_spec.js => text_interpolation_parser_spec.ts} (84%)
rename modules/angular2/test/render/dom/compiler/{view_splitter_spec.js => view_splitter_spec.ts} (84%)
rename modules/angular2/test/render/dom/{convert_spec.js => convert_spec.ts} (54%)
delete mode 100644 modules/angular2/test/render/dom/dom_renderer_integration_spec.js
create mode 100644 modules/angular2/test/render/dom/dom_renderer_integration_spec.ts
rename modules/angular2/test/render/dom/{dom_testbed.js => dom_testbed.ts} (56%)
rename modules/angular2/test/render/dom/events/{event_manager_spec.js => event_manager_spec.ts} (83%)
rename modules/angular2/test/render/dom/events/{key_events_spec.js => key_events_spec.ts} (57%)
rename modules/angular2/test/render/dom/shadow_dom/{content_tag_spec.js => content_tag_spec.ts} (72%)
rename modules/angular2/test/render/dom/shadow_dom/{emulated_scoped_shadow_dom_strategy_spec.js => emulated_scoped_shadow_dom_strategy_spec.ts} (84%)
rename modules/angular2/test/render/dom/shadow_dom/{emulated_unscoped_shadow_dom_strategy_spec.js => emulated_unscoped_shadow_dom_strategy_spec.ts} (95%)
rename modules/angular2/test/render/dom/shadow_dom/{light_dom_spec.js => light_dom_spec.ts} (72%)
rename modules/angular2/test/render/dom/shadow_dom/{native_shadow_dom_strategy_spec.js => native_shadow_dom_strategy_spec.ts} (92%)
rename modules/angular2/test/render/dom/shadow_dom/{shadow_css_spec.js => shadow_css_spec.ts} (92%)
delete mode 100644 modules/angular2/test/render/dom/shadow_dom/style_inliner_spec.js
create mode 100644 modules/angular2/test/render/dom/shadow_dom/style_inliner_spec.ts
rename modules/angular2/test/render/dom/shadow_dom/{style_url_resolver_spec.js => style_url_resolver_spec.ts} (96%)
delete mode 100644 modules/angular2/test/render/dom/shadow_dom_emulation_integration_spec.js
create mode 100644 modules/angular2/test/render/dom/shadow_dom_emulation_integration_spec.ts
rename modules/angular2/test/render/dom/view/{property_setter_factory_spec.js => property_setter_factory_spec.ts} (88%)
rename modules/angular2/test/render/dom/view/{view_spec.js => view_spec.ts} (62%)
diff --git a/modules/angular2/test/render/dom/compiler/compiler_browser_spec.js b/modules/angular2/test/render/dom/compiler/compiler_browser_spec.ts
similarity index 66%
rename from modules/angular2/test/render/dom/compiler/compiler_browser_spec.js
rename to modules/angular2/test/render/dom/compiler/compiler_browser_spec.ts
index aedb546227..b8c35ff7dc 100644
--- a/modules/angular2/test/render/dom/compiler/compiler_browser_spec.js
+++ b/modules/angular2/test/render/dom/compiler/compiler_browser_spec.ts
@@ -1,6 +1,6 @@
- /*
- * Runs compiler tests using in-browser DOM adapter.
- */
+/*
+* Runs compiler tests using in-browser DOM adapter.
+*/
import {runCompilerCommonTests} from './compiler_common_tests';
diff --git a/modules/angular2/test/render/dom/compiler/compiler_common_tests.js b/modules/angular2/test/render/dom/compiler/compiler_common_tests.js
deleted file mode 100644
index d71a8d3d1d..0000000000
--- a/modules/angular2/test/render/dom/compiler/compiler_common_tests.js
+++ /dev/null
@@ -1,229 +0,0 @@
-import {
- AsyncTestCompleter,
- beforeEach,
- ddescribe,
- describe,
- el,
- expect,
- iit,
- inject,
- IS_DARTIUM,
- it,
-} from 'angular2/test_lib';
-
-import {DOM} from 'angular2/src/dom/dom_adapter';
-import {List, ListWrapper, Map, MapWrapper, StringMapWrapper} from 'angular2/src/facade/collection';
-import {Type, isBlank, stringify, isPresent} from 'angular2/src/facade/lang';
-import {PromiseWrapper, Promise} from 'angular2/src/facade/async';
-
-import {DomCompiler} from 'angular2/src/render/dom/compiler/compiler';
-import {ProtoViewDto, ViewDefinition, DirectiveMetadata} from 'angular2/src/render/api';
-import {CompileElement} from 'angular2/src/render/dom/compiler/compile_element';
-import {CompileStep} from 'angular2/src/render/dom/compiler/compile_step'
-import {CompileStepFactory} from 'angular2/src/render/dom/compiler/compile_step_factory';
-import {CompileControl} from 'angular2/src/render/dom/compiler/compile_control';
-import {TemplateLoader} from 'angular2/src/render/dom/compiler/template_loader';
-
-import {UrlResolver} from 'angular2/src/services/url_resolver';
-
-import {resolveInternalDomProtoView} from 'angular2/src/render/dom/view/proto_view';
-
-export function runCompilerCommonTests() {
- describe('DomCompiler', function() {
- var mockStepFactory;
-
- function createCompiler(processClosure, urlData = null) {
- if (isBlank(urlData)) {
- urlData = MapWrapper.create();
- }
- var tplLoader = new FakeTemplateLoader(urlData);
- mockStepFactory = new MockStepFactory([new MockStep(processClosure)]);
- return new DomCompiler(mockStepFactory, tplLoader);
- }
-
- describe('compile', () => {
-
- it('should run the steps and build the AppProtoView of the root element', inject([AsyncTestCompleter], (async) => {
- var compiler = createCompiler((parent, current, control) => {
- current.inheritedProtoView.bindVariable('b', 'a');
- });
- compiler.compile(new ViewDefinition({
- componentId: 'someComponent',
- template: ''
- })).then( (protoView) => {
- expect(protoView.variableBindings).toEqual(MapWrapper.createFromStringMap({
- 'a': 'b'
- }));
- async.done();
- });
- }));
-
- it('should run the steps and build the proto view', inject([AsyncTestCompleter], (async) => {
- var compiler = createCompiler((parent, current, control) => {
- current.inheritedProtoView.bindVariable('b', 'a');
- });
-
- var dirMetadata = new DirectiveMetadata({id: 'id', selector: 'CUSTOM', type: DirectiveMetadata.COMPONENT_TYPE});
- compiler.compileHost(dirMetadata).then( (protoView) => {
- expect(DOM.tagName(resolveInternalDomProtoView(protoView.render).element)).toEqual('CUSTOM')
- expect(mockStepFactory.viewDef.directives).toEqual([dirMetadata]);
- expect(protoView.variableBindings).toEqual(MapWrapper.createFromStringMap({
- 'a': 'b'
- }));
- async.done();
- });
- }));
-
- it('should use the inline template and compile in sync', inject([AsyncTestCompleter], (async) => {
- var compiler = createCompiler(EMPTY_STEP);
- compiler.compile(new ViewDefinition({
- componentId: 'someId',
- template: 'inline component'
- })).then( (protoView) => {
- expect(DOM.getInnerHTML(resolveInternalDomProtoView(protoView.render).element)).toEqual('inline component');
- async.done();
- });
- }));
-
- it('should load url templates', inject([AsyncTestCompleter], (async) => {
- var urlData = MapWrapper.createFromStringMap({
- 'someUrl': 'url component'
- });
- var compiler = createCompiler(EMPTY_STEP, urlData);
- compiler.compile(new ViewDefinition({
- componentId: 'someId',
- absUrl: 'someUrl'
- })).then( (protoView) => {
- expect(DOM.getInnerHTML(resolveInternalDomProtoView(protoView.render).element)).toEqual('url component');
- async.done();
- });
- }));
-
- it('should report loading errors', inject([AsyncTestCompleter], (async) => {
- var compiler = createCompiler(EMPTY_STEP, MapWrapper.create());
- PromiseWrapper.catchError(compiler.compile(new ViewDefinition({
- componentId: 'someId',
- absUrl: 'someUrl'
- })), (e) => {
- expect(e.message).toContain(`Failed to load the template "someId"`);
- async.done();
- });
- }));
-
- it('should wait for async subtasks to be resolved', inject([AsyncTestCompleter], (async) => {
- var subTasksCompleted = false;
-
- var completer = PromiseWrapper.completer();
-
- var compiler = createCompiler( (parent, current, control) => {
- ListWrapper.push(mockStepFactory.subTaskPromises, completer.promise.then((_) => {
- subTasksCompleted = true;
- }));
- });
-
- // It should always return a Promise because the subtask is async
- var pvPromise = compiler.compile(new ViewDefinition({
- componentId: 'someId',
- template: 'some component'
- }));
- expect(pvPromise).toBePromise();
- expect(subTasksCompleted).toEqual(false);
-
- // The Promise should resolve after the subtask is ready
- completer.resolve(null);
- pvPromise.then((protoView) => {
- expect(subTasksCompleted).toEqual(true);
- async.done();
- });
- }));
-
- it('should return ProtoViews of type COMPONENT_VIEW_TYPE', inject([AsyncTestCompleter], (async) => {
- var compiler = createCompiler(EMPTY_STEP);
- compiler.compile(new ViewDefinition({
- componentId: 'someId',
- template: 'inline component'
- })).then( (protoView) => {
- expect(protoView.type).toEqual(ProtoViewDto.COMPONENT_VIEW_TYPE);
- async.done();
- });
- }));
-
- });
-
- describe('compileHost', () => {
-
- it('should return ProtoViews of type HOST_VIEW_TYPE', inject([AsyncTestCompleter], (async) => {
- var compiler = createCompiler(EMPTY_STEP);
- compiler.compileHost(someComponent).then( (protoView) => {
- expect(protoView.type).toEqual(ProtoViewDto.HOST_VIEW_TYPE);
- async.done();
- });
- }));
-
- });
-
- });
-
-}
-
-class MockStepFactory extends CompileStepFactory {
- steps:List;
- subTaskPromises:List;
- viewDef:ViewDefinition;
-
- constructor(steps) {
- super();
- this.steps = steps;
- }
- createSteps(viewDef, subTaskPromises) {
- this.viewDef = viewDef;
- this.subTaskPromises = subTaskPromises;
- ListWrapper.forEach(this.subTaskPromises, (p) => ListWrapper.push(subTaskPromises, p) );
- return this.steps;
- }
-}
-
-class MockStep /*implements CompileStep*/ {
- processClosure:Function;
- constructor(process) {
- this.processClosure = process;
- }
- process(parent:CompileElement, current:CompileElement, control:CompileControl) {
- this.processClosure(parent, current, control);
- }
-}
-
-var EMPTY_STEP = (parent, current, control) => {
- if (isPresent(parent)) {
- current.inheritedProtoView = parent.inheritedProtoView;
- }
-};
-
-class FakeTemplateLoader extends TemplateLoader {
- _urlData: Map;
- constructor(urlData) {
- super(null, new UrlResolver());
- this._urlData = urlData;
- }
-
- load(template: ViewDefinition) {
- if (isPresent(template.template)) {
- return PromiseWrapper.resolve(DOM.createTemplate(template.template));
- }
-
- if (isPresent(template.absUrl)) {
- var content = MapWrapper.get(this._urlData, template.absUrl);
- if (isPresent(content)) {
- return PromiseWrapper.resolve(DOM.createTemplate(content));
- }
- }
-
- return PromiseWrapper.reject('Load failed', null);
- }
-}
-
-var someComponent = new DirectiveMetadata({
- selector: 'some-comp',
- id: 'someComponent',
- type: DirectiveMetadata.COMPONENT_TYPE
-});
diff --git a/modules/angular2/test/render/dom/compiler/compiler_common_tests.ts b/modules/angular2/test/render/dom/compiler/compiler_common_tests.ts
new file mode 100644
index 0000000000..eeca0a8966
--- /dev/null
+++ b/modules/angular2/test/render/dom/compiler/compiler_common_tests.ts
@@ -0,0 +1,221 @@
+import {
+ AsyncTestCompleter,
+ beforeEach,
+ ddescribe,
+ describe,
+ el,
+ expect,
+ iit,
+ inject,
+ IS_DARTIUM,
+ it,
+} from 'angular2/test_lib';
+
+import {DOM} from 'angular2/src/dom/dom_adapter';
+import {List, ListWrapper, Map, MapWrapper, StringMapWrapper} from 'angular2/src/facade/collection';
+import {Type, isBlank, stringify, isPresent} from 'angular2/src/facade/lang';
+import {PromiseWrapper, Promise} from 'angular2/src/facade/async';
+
+import {DomCompiler} from 'angular2/src/render/dom/compiler/compiler';
+import {ProtoViewDto, ViewDefinition, DirectiveMetadata} from 'angular2/src/render/api';
+import {CompileElement} from 'angular2/src/render/dom/compiler/compile_element';
+import {CompileStep} from 'angular2/src/render/dom/compiler/compile_step';
+import {CompileStepFactory} from 'angular2/src/render/dom/compiler/compile_step_factory';
+import {CompileControl} from 'angular2/src/render/dom/compiler/compile_control';
+import {TemplateLoader} from 'angular2/src/render/dom/compiler/template_loader';
+
+import {UrlResolver} from 'angular2/src/services/url_resolver';
+
+import {resolveInternalDomProtoView} from 'angular2/src/render/dom/view/proto_view';
+
+export function runCompilerCommonTests() {
+ describe('DomCompiler', function() {
+ var mockStepFactory;
+
+ function createCompiler(processClosure, urlData = null) {
+ if (isBlank(urlData)) {
+ urlData = MapWrapper.create();
+ }
+ var tplLoader = new FakeTemplateLoader(urlData);
+ mockStepFactory = new MockStepFactory([new MockStep(processClosure)]);
+ return new DomCompiler(mockStepFactory, tplLoader);
+ }
+
+ describe('compile', () => {
+
+ it('should run the steps and build the AppProtoView of the root element',
+ inject([AsyncTestCompleter], (async) => {
+ var compiler = createCompiler((parent, current, control) => {
+ current.inheritedProtoView.bindVariable('b', 'a');
+ });
+ compiler.compile(
+ new ViewDefinition({componentId: 'someComponent', template: ''}))
+ .then((protoView) => {
+ expect(protoView.variableBindings)
+ .toEqual(MapWrapper.createFromStringMap({'a': 'b'}));
+ async.done();
+ });
+ }));
+
+ it('should run the steps and build the proto view', inject([AsyncTestCompleter], (async) => {
+ var compiler = createCompiler((parent, current, control) => {
+ current.inheritedProtoView.bindVariable('b', 'a');
+ });
+
+ var dirMetadata = new DirectiveMetadata(
+ {id: 'id', selector: 'CUSTOM', type: DirectiveMetadata.COMPONENT_TYPE});
+ compiler.compileHost(dirMetadata)
+ .then((protoView) => {
+ expect(DOM.tagName(resolveInternalDomProtoView(protoView.render).element))
+ .toEqual('CUSTOM');
+ expect(mockStepFactory.viewDef.directives).toEqual([dirMetadata]);
+ expect(protoView.variableBindings)
+ .toEqual(MapWrapper.createFromStringMap({'a': 'b'}));
+ async.done();
+ });
+ }));
+
+ it('should use the inline template and compile in sync',
+ inject([AsyncTestCompleter], (async) => {
+ var compiler = createCompiler(EMPTY_STEP);
+ compiler.compile(
+ new ViewDefinition({componentId: 'someId', template: 'inline component'}))
+ .then((protoView) => {
+ expect(DOM.getInnerHTML(resolveInternalDomProtoView(protoView.render).element))
+ .toEqual('inline component');
+ async.done();
+ });
+ }));
+
+ it('should load url templates', inject([AsyncTestCompleter], (async) => {
+ var urlData = MapWrapper.createFromStringMap({'someUrl': 'url component'});
+ var compiler = createCompiler(EMPTY_STEP, urlData);
+ compiler.compile(new ViewDefinition({componentId: 'someId', absUrl: 'someUrl'}))
+ .then((protoView) => {
+ expect(DOM.getInnerHTML(resolveInternalDomProtoView(protoView.render).element))
+ .toEqual('url component');
+ async.done();
+ });
+ }));
+
+ it('should report loading errors', inject([AsyncTestCompleter], (async) => {
+ var compiler = createCompiler(EMPTY_STEP, MapWrapper.create());
+ PromiseWrapper.catchError(
+ compiler.compile(new ViewDefinition({componentId: 'someId', absUrl: 'someUrl'})),
+ (e) => {
+ expect(e.message).toContain(`Failed to load the template "someId"`);
+ async.done();
+ return null;
+ });
+ }));
+
+ it('should wait for async subtasks to be resolved', inject([AsyncTestCompleter], (async) => {
+ var subTasksCompleted = false;
+
+ var completer = PromiseWrapper.completer();
+
+ var compiler = createCompiler((parent, current, control) => {
+ ListWrapper.push(mockStepFactory.subTaskPromises,
+ completer.promise.then((_) => { subTasksCompleted = true; }));
+ });
+
+ // It should always return a Promise because the subtask is async
+ var pvPromise = compiler.compile(
+ new ViewDefinition({componentId: 'someId', template: 'some component'}));
+ expect(pvPromise).toBePromise();
+ expect(subTasksCompleted).toEqual(false);
+
+ // The Promise should resolve after the subtask is ready
+ completer.resolve(null);
+ pvPromise.then((protoView) => {
+ expect(subTasksCompleted).toEqual(true);
+ async.done();
+ });
+ }));
+
+ it('should return ProtoViews of type COMPONENT_VIEW_TYPE',
+ inject([AsyncTestCompleter], (async) => {
+ var compiler = createCompiler(EMPTY_STEP);
+ compiler.compile(
+ new ViewDefinition({componentId: 'someId', template: 'inline component'}))
+ .then((protoView) => {
+ expect(protoView.type).toEqual(ProtoViewDto.COMPONENT_VIEW_TYPE);
+ async.done();
+ });
+ }));
+
+ });
+
+ describe('compileHost', () => {
+
+ it('should return ProtoViews of type HOST_VIEW_TYPE',
+ inject([AsyncTestCompleter], (async) => {
+ var compiler = createCompiler(EMPTY_STEP);
+ compiler.compileHost(someComponent)
+ .then((protoView) => {
+ expect(protoView.type).toEqual(ProtoViewDto.HOST_VIEW_TYPE);
+ async.done();
+ });
+ }));
+
+ });
+
+ });
+}
+
+class MockStepFactory extends CompileStepFactory {
+ steps: List;
+ subTaskPromises: List>;
+ viewDef: ViewDefinition;
+
+ constructor(steps) {
+ super();
+ this.steps = steps;
+ }
+ createSteps(viewDef, subTaskPromises) {
+ this.viewDef = viewDef;
+ this.subTaskPromises = subTaskPromises;
+ ListWrapper.forEach(this.subTaskPromises, (p) => ListWrapper.push(subTaskPromises, p));
+ return this.steps;
+ }
+}
+
+class MockStep implements CompileStep {
+ processClosure: Function;
+ constructor(process) { this.processClosure = process; }
+ process(parent: CompileElement, current: CompileElement, control: CompileControl) {
+ this.processClosure(parent, current, control);
+ }
+}
+
+var EMPTY_STEP = (parent, current, control) => {
+ if (isPresent(parent)) {
+ current.inheritedProtoView = parent.inheritedProtoView;
+ }
+};
+
+class FakeTemplateLoader extends TemplateLoader {
+ _urlData: Map;
+ constructor(urlData) {
+ super(null, new UrlResolver());
+ this._urlData = urlData;
+ }
+
+ load(template: ViewDefinition) {
+ if (isPresent(template.template)) {
+ return PromiseWrapper.resolve(DOM.createTemplate(template.template));
+ }
+
+ if (isPresent(template.absUrl)) {
+ var content = MapWrapper.get(this._urlData, template.absUrl);
+ if (isPresent(content)) {
+ return PromiseWrapper.resolve(DOM.createTemplate(content));
+ }
+ }
+
+ return PromiseWrapper.reject('Load failed', null);
+ }
+}
+
+var someComponent = new DirectiveMetadata(
+ {selector: 'some-comp', id: 'someComponent', type: DirectiveMetadata.COMPONENT_TYPE});
diff --git a/modules/angular2/test/render/dom/compiler/directive_parser_spec.js b/modules/angular2/test/render/dom/compiler/directive_parser_spec.ts
similarity index 68%
rename from modules/angular2/test/render/dom/compiler/directive_parser_spec.js
rename to modules/angular2/test/render/dom/compiler/directive_parser_spec.ts
index 0cd68caf27..f1ea8096e6 100644
--- a/modules/angular2/test/render/dom/compiler/directive_parser_spec.js
+++ b/modules/angular2/test/render/dom/compiler/directive_parser_spec.ts
@@ -9,12 +9,13 @@ import {CompileElement} from 'angular2/src/render/dom/compiler/compile_element';
import {CompileControl} from 'angular2/src/render/dom/compiler/compile_control';
import {ViewDefinition, DirectiveMetadata} from 'angular2/src/render/api';
import {Lexer, Parser} from 'angular2/change_detection';
+import {ElementBinderBuilder} from 'angular2/src/render/dom/view/proto_view_builder';
export function main() {
describe('DirectiveParser', () => {
var parser, annotatedDirectives;
- beforeEach( () => {
+ beforeEach(() => {
annotatedDirectives = [
someComponent,
someComponent2,
@@ -35,20 +36,21 @@ export function main() {
if (isBlank(directives)) directives = annotatedDirectives;
return new CompilePipeline([
- new MockStep( (parent, current, control) => {
- if (isPresent(propertyBindings)) {
- StringMapWrapper.forEach(propertyBindings, (ast, name) => {
- current.bindElement().bindProperty(name, ast);
- });
- }
- }),
+ new MockStep((parent, current, control) =>
+ {
+ if (isPresent(propertyBindings)) {
+ StringMapWrapper.forEach(propertyBindings, (ast, name) => {
+ current.bindElement().bindProperty(name, ast);
+ });
+ }
+ }),
new DirectiveParser(parser, directives)
]);
}
- function process(el, propertyBindings = null, directives = null) {
+ function process(el, propertyBindings = null, directives = null): List {
var pipeline = createPipeline(propertyBindings, directives);
- return ListWrapper.map(pipeline.process(el), (ce) => ce.inheritedElementBinder );
+ return ListWrapper.map(pipeline.process(el), (ce) => ce.inheritedElementBinder);
}
it('should not add directives if they are not used', () => {
@@ -58,16 +60,14 @@ export function main() {
it('should detect directives in attributes', () => {
var results = process(el(''));
- expect(results[0].directives[0].directiveIndex).toBe(
- annotatedDirectives.indexOf(someDirective)
- );
+ expect(results[0].directives[0].directiveIndex)
+ .toBe(annotatedDirectives.indexOf(someDirective));
});
it('should detect directives with multiple attributes', () => {
var results = process(el(''));
- expect(results[0].directives[0].directiveIndex).toBe(
- annotatedDirectives.indexOf(decoratorWithMultipleAttrs)
- );
+ expect(results[0].directives[0].directiveIndex)
+ .toBe(annotatedDirectives.indexOf(decoratorWithMultipleAttrs));
});
it('should compile children by default', () => {
@@ -81,36 +81,26 @@ export function main() {
});
it('should bind directive properties from bound properties', () => {
- var results = process(
- el(''),
- {
- 'elProp': parser.parseBinding('someExpr', '')
- }
- );
+ var results = process(el(''),
+ {'elProp': parser.parseBinding('someExpr', '')});
var directiveBinding = results[0].directives[0];
expect(MapWrapper.get(directiveBinding.propertyBindings, 'dirProp').source)
- .toEqual('someExpr');
+ .toEqual('someExpr');
});
it('should bind directive properties with pipes', () => {
- var results = process(
- el(''),
- {
- 'elProp': parser.parseBinding('someExpr', '')
- }
- );
+ var results = process(el(''),
+ {'elProp': parser.parseBinding('someExpr', '')});
var directiveBinding = results[0].directives[0];
- var pipedProp = MapWrapper.get(directiveBinding.propertyBindings, 'doubleProp');
- var simpleProp = MapWrapper.get(directiveBinding.propertyBindings, 'dirProp');
+ var pipedProp = MapWrapper.get(directiveBinding.propertyBindings, 'doubleProp');
+ var simpleProp = MapWrapper.get(directiveBinding.propertyBindings, 'dirProp');
expect(pipedProp.ast.name).toEqual('double');
expect(pipedProp.ast.exp).toEqual(simpleProp.ast);
expect(simpleProp.source).toEqual('someExpr');
});
it('should bind directive properties from attribute values', () => {
- var results = process(
- el('')
- );
+ var results = process(el(''));
var directiveBinding = results[0].directives[0];
var simpleProp = MapWrapper.get(directiveBinding.propertyBindings, 'dirProp');
expect(simpleProp.source).toEqual('someValue');
@@ -160,9 +150,7 @@ export function main() {
});
it('should bind directive events', () => {
- var results = process(
- el('')
- );
+ var results = process(el(''));
var directiveBinding = results[0].directives[0];
expect(directiveBinding.eventBindings.length).toEqual(1);
var eventBinding = directiveBinding.eventBindings[0];
@@ -171,9 +159,7 @@ export function main() {
});
it('should bind directive global events', () => {
- var results = process(
- el('')
- );
+ var results = process(el(''));
var directiveBinding = results[0].directives[0];
expect(directiveBinding.eventBindings.length).toEqual(1);
var eventBinding = directiveBinding.eventBindings[0];
@@ -182,83 +168,61 @@ export function main() {
});
it('should bind directive host actions', () => {
- var results = process(
- el('')
- );
+ var results = process(el(''));
var directiveBinding = results[0].directives[0];
expect(directiveBinding.hostActions[0].actionName).toEqual('focus');
});
- //TODO: assertions should be enabled when running tests: https://github.com/angular/angular/issues/1340
+ // TODO: assertions should be enabled when running tests:
+ // https://github.com/angular/angular/issues/1340
describe('component directives', () => {
it('should save the component id', () => {
- var results = process(
- el('')
- );
+ var results = process(el(''));
expect(results[0].componentId).toEqual('someComponent');
});
it('should throw when the provided selector is not an element selector', () => {
- expect( () => {
- createPipeline(null, [componentWithNonElementSelector]);
- }).toThrowError(`Component 'componentWithNonElementSelector' can only have an element selector, but had '[attr]'`);
+ expect(() => { createPipeline(null, [componentWithNonElementSelector]); })
+ .toThrowError(
+ `Component 'componentWithNonElementSelector' can only have an element selector, but had '[attr]'`);
});
it('should not allow multiple component directives on the same element', () => {
- expect( () => {
- process(
- el(''),
- null,
- [someComponent, someComponentDup]
- );
- }).toThrowError(new RegExp('Only one component directive is allowed per element' ));
+ expect(() => {
+ process(el(''), null, [someComponent, someComponentDup]);
+ }).toThrowError(new RegExp('Only one component directive is allowed per element'));
});
it('should sort the directives and store the component as the first directive', () => {
- var results = process(
- el('')
- );
- expect(annotatedDirectives[results[0].directives[0].directiveIndex].id).toEqual('someComponent');
- expect(annotatedDirectives[results[0].directives[1].directiveIndex].id).toEqual('someDirective');
+ var results = process(el(''));
+ expect(annotatedDirectives[results[0].directives[0].directiveIndex].id)
+ .toEqual('someComponent');
+ expect(annotatedDirectives[results[0].directives[1].directiveIndex].id)
+ .toEqual('someDirective');
});
});
});
}
-@IMPLEMENTS(CompileStep)
-class MockStep {
- processClosure:Function;
- constructor(process) {
- this.processClosure = process;
- }
- process(parent:CompileElement, current:CompileElement, control:CompileControl) {
+class MockStep implements CompileStep {
+ processClosure: Function;
+ constructor(process) { this.processClosure = process; }
+ process(parent: CompileElement, current: CompileElement, control: CompileControl) {
this.processClosure(parent, current, control);
}
}
-var someComponent = new DirectiveMetadata({
- selector: 'some-comp',
- id: 'someComponent',
- type: DirectiveMetadata.COMPONENT_TYPE
-});
+var someComponent = new DirectiveMetadata(
+ {selector: 'some-comp', id: 'someComponent', type: DirectiveMetadata.COMPONENT_TYPE});
-var someComponentDup = new DirectiveMetadata({
- selector: 'some-comp',
- id: 'someComponentDup',
- type: DirectiveMetadata.COMPONENT_TYPE
-});
+var someComponentDup = new DirectiveMetadata(
+ {selector: 'some-comp', id: 'someComponentDup', type: DirectiveMetadata.COMPONENT_TYPE});
-var someComponent2 = new DirectiveMetadata({
- selector: 'some-comp2',
- id: 'someComponent2',
- type: DirectiveMetadata.COMPONENT_TYPE
-});
+var someComponent2 = new DirectiveMetadata(
+ {selector: 'some-comp2', id: 'someComponent2', type: DirectiveMetadata.COMPONENT_TYPE});
-var someDirective = new DirectiveMetadata({
- selector: '[some-decor]',
- id: 'someDirective',
- type: DirectiveMetadata.DIRECTIVE_TYPE
-});
+var someDirective = new DirectiveMetadata(
+ {selector: '[some-decor]', id: 'someDirective', type: DirectiveMetadata.DIRECTIVE_TYPE});
var someDirectiveIgnoringChildren = new DirectiveMetadata({
selector: '[some-decor-ignoring-children]',
@@ -275,47 +239,34 @@ var decoratorWithMultipleAttrs = new DirectiveMetadata({
var someDirectiveWithProps = new DirectiveMetadata({
selector: '[some-decor-props]',
- properties: MapWrapper.createFromStringMap({
- 'dirProp': 'elProp',
- 'doubleProp': 'elProp | double'
- }),
+ properties:
+ MapWrapper.createFromStringMap({'dirProp': 'elProp', 'doubleProp': 'elProp | double'}),
readAttributes: ['some-attr']
});
var someDirectiveWithHostProperties = new DirectiveMetadata({
selector: '[some-decor-with-host-props]',
- hostProperties: MapWrapper.createFromStringMap({
- 'dirProp': 'hostProperty'
- })
+ hostProperties: MapWrapper.createFromStringMap({'dirProp': 'hostProperty'})
});
var someDirectiveWithHostAttributes = new DirectiveMetadata({
selector: '[some-decor-with-host-attrs]',
- hostAttributes: MapWrapper.createFromStringMap({
- 'attr_name': 'attr_val',
- 'class': 'foo bar'
- })
+ hostAttributes: MapWrapper.createFromStringMap({'attr_name': 'attr_val', 'class': 'foo bar'})
});
var someDirectiveWithEvents = new DirectiveMetadata({
selector: '[some-decor-events]',
- hostListeners: MapWrapper.createFromStringMap({
- 'click': 'doIt()'
- })
+ hostListeners: MapWrapper.createFromStringMap({'click': 'doIt()'})
});
var someDirectiveWithHostActions = new DirectiveMetadata({
selector: '[some-decor-host-actions]',
- hostActions: MapWrapper.createFromStringMap({
- 'focus': 'focus()'
- })
+ hostActions: MapWrapper.createFromStringMap({'focus': 'focus()'})
});
var someDirectiveWithGlobalEvents = new DirectiveMetadata({
selector: '[some-decor-globalevents]',
- hostListeners: MapWrapper.createFromStringMap({
- 'window:resize': 'doItGlobal()'
- })
+ hostListeners: MapWrapper.createFromStringMap({'window:resize': 'doItGlobal()'})
});
var componentWithNonElementSelector = new DirectiveMetadata({
diff --git a/modules/angular2/test/render/dom/compiler/pipeline_spec.js b/modules/angular2/test/render/dom/compiler/pipeline_spec.ts
similarity index 83%
rename from modules/angular2/test/render/dom/compiler/pipeline_spec.js
rename to modules/angular2/test/render/dom/compiler/pipeline_spec.ts
index 4577407123..839ba75881 100644
--- a/modules/angular2/test/render/dom/compiler/pipeline_spec.js
+++ b/modules/angular2/test/render/dom/compiler/pipeline_spec.ts
@@ -5,7 +5,7 @@ import {isPresent, NumberWrapper, StringWrapper, IMPLEMENTS} from 'angular2/src/
import {CompilePipeline} from 'angular2/src/render/dom/compiler/compile_pipeline';
import {CompileElement} from 'angular2/src/render/dom/compiler/compile_element';
-import {CompileStep} from 'angular2/src/render/dom/compiler/compile_step'
+import {CompileStep} from 'angular2/src/render/dom/compiler/compile_step';
import {CompileControl} from 'angular2/src/render/dom/compiler/compile_control';
import {ProtoViewBuilder} from 'angular2/src/render/dom/view/proto_view_builder';
@@ -25,7 +25,8 @@ export function main() {
});
it('should stop walking the tree when compileChildren is false', () => {
- var element = el('
');
+ var element = el(
+ '
');
var step0Log = [];
var pipeline = new CompilePipeline([new IgnoreChildrenStep(), createLoggerStep(step0Log)]);
@@ -40,7 +41,8 @@ export function main() {
var element = el('
');
var pipeline = new CompilePipeline([new MockStep((parent, current, control) => {
if (isPresent(DOM.getAttribute(current.element, 'viewroot'))) {
- current.inheritedProtoView = new ProtoViewBuilder(current.element, ProtoViewDto.EMBEDDED_VIEW_TYPE);
+ current.inheritedProtoView =
+ new ProtoViewBuilder(current.element, ProtoViewDto.EMBEDDED_VIEW_TYPE);
}
})]);
var results = pipeline.process(element);
@@ -99,10 +101,8 @@ export function main() {
var element = el('
');
var step0Log = [];
var step1Log = [];
- var pipeline = new CompilePipeline([
- createWrapperStep('wrap0', step0Log),
- createLoggerStep(step1Log)
- ]);
+ var pipeline = new CompilePipeline(
+ [createWrapperStep('wrap0', step0Log), createLoggerStep(step1Log)]);
var result = pipeline.process(element);
expect(step0Log).toEqual(['1', '1<2', '2<3']);
expect(step1Log).toEqual(['1', '1 {
- var element = el('
');
+ var element =
+ el('
');
var step0Log = [];
var step1Log = [];
var step2Log = [];
@@ -127,7 +128,8 @@ export function main() {
});
it('should allow to add a parent by multiple processors to different elements', () => {
- var element = el('
');
+ var element =
+ el('
');
var step0Log = [];
var step1Log = [];
var step2Log = [];
@@ -147,10 +149,8 @@ export function main() {
var element = el('
');
var step0Log = [];
var step1Log = [];
- var pipeline = new CompilePipeline([
- createWrapperStep('wrap0', step0Log),
- createLoggerStep(step1Log)
- ]);
+ var pipeline = new CompilePipeline(
+ [createWrapperStep('wrap0', step0Log), createLoggerStep(step1Log)]);
var result = pipeline.process(element);
expect(step0Log).toEqual(['1', '1<2', '2<3']);
expect(step1Log).toEqual(['1', '1'));
var pipeline = new CompilePipeline([
- new MockStep((parent, current, control) => {
- if (StringWrapper.equals(DOM.getAttribute(current.element, 'id'), '1')) {
- control.addChild(newChild);
- }
- }),
+ new MockStep((parent, current, control) =>
+ {
+ if (StringWrapper.equals(DOM.getAttribute(current.element, 'id'), '1')) {
+ control.addChild(newChild);
+ }
+ }),
createLoggerStep(resultLog)
]);
var result = pipeline.process(element);
@@ -182,20 +183,16 @@ export function main() {
});
}
-@IMPLEMENTS(CompileStep)
-class MockStep {
- processClosure:Function;
- constructor(process) {
- this.processClosure = process;
- }
- process(parent:CompileElement, current:CompileElement, control:CompileControl) {
+class MockStep implements CompileStep {
+ processClosure: Function;
+ constructor(process) { this.processClosure = process; }
+ process(parent: CompileElement, current: CompileElement, control: CompileControl) {
this.processClosure(parent, current, control);
}
}
-@IMPLEMENTS(CompileStep)
-export class IgnoreChildrenStep {
- process(parent:CompileElement, current:CompileElement, control:CompileControl) {
+export class IgnoreChildrenStep implements CompileStep {
+ process(parent: CompileElement, current: CompileElement, control: CompileControl) {
var attributeMap = DOM.attributeMap(current.element);
if (MapWrapper.contains(attributeMap, 'ignore-children')) {
current.compileChildren = false;
@@ -203,9 +200,8 @@ export class IgnoreChildrenStep {
}
}
-@IMPLEMENTS(CompileStep)
-class IgnoreCurrentElementStep {
- process(parent:CompileElement, current:CompileElement, control:CompileControl) {
+class IgnoreCurrentElementStep implements CompileStep {
+ process(parent: CompileElement, current: CompileElement, control: CompileControl) {
var attributeMap = DOM.attributeMap(current.element);
if (MapWrapper.contains(attributeMap, 'ignore-current')) {
control.ignoreCurrentElement();
@@ -222,9 +218,7 @@ function logEntry(log, parent, current) {
}
function createLoggerStep(log) {
- return new MockStep((parent, current, control) => {
- logEntry(log, parent, current);
- });
+ return new MockStep((parent, current, control) => { logEntry(log, parent, current); });
}
function createWrapperStep(wrapperId, log) {
@@ -244,8 +238,6 @@ function createWrapperStep(wrapperId, log) {
function resultIdLog(result) {
var idLog = [];
- ListWrapper.forEach(result, (current) => {
- logEntry(idLog, null, current);
- });
+ ListWrapper.forEach(result, (current) => { logEntry(idLog, null, current); });
return idLog;
}
diff --git a/modules/angular2/test/render/dom/compiler/property_binding_parser_spec.js b/modules/angular2/test/render/dom/compiler/property_binding_parser_spec.ts
similarity index 82%
rename from modules/angular2/test/render/dom/compiler/property_binding_parser_spec.js
rename to modules/angular2/test/render/dom/compiler/property_binding_parser_spec.ts
index 54762c0791..4d882e8e17 100644
--- a/modules/angular2/test/render/dom/compiler/property_binding_parser_spec.js
+++ b/modules/angular2/test/render/dom/compiler/property_binding_parser_spec.ts
@@ -7,6 +7,7 @@ import {CompileElement} from 'angular2/src/render/dom/compiler/compile_element';
import {CompileStep} from 'angular2/src/render/dom/compiler/compile_step';
import {CompileControl} from 'angular2/src/render/dom/compiler/compile_control';
import {Lexer, Parser} from 'angular2/change_detection';
+import {ElementBinderBuilder} from 'angular2/src/render/dom/view/proto_view_builder';
var EMPTY_MAP = MapWrapper.create();
@@ -14,19 +15,19 @@ export function main() {
describe('PropertyBindingParser', () => {
function createPipeline(hasNestedProtoView = false) {
return new CompilePipeline([
- new MockStep((parent, current, control) => {
- if (hasNestedProtoView) {
- current.bindElement().bindNestedProtoView(el(''));
- }
- }),
- new PropertyBindingParser(new Parser(new Lexer()))]);
+ new MockStep((parent, current, control) =>
+ {
+ if (hasNestedProtoView) {
+ current.bindElement().bindNestedProtoView(el(''));
+ }
+ }),
+ new PropertyBindingParser(new Parser(new Lexer()))
+ ]);
}
- function process(element, hasNestedProtoView = false) {
- return ListWrapper.map(
- createPipeline(hasNestedProtoView).process(element),
- (compileElement) => compileElement.inheritedElementBinder
- );
+ function process(element, hasNestedProtoView = false): List {
+ return ListWrapper.map(createPipeline(hasNestedProtoView).process(element),
+ (compileElement) => compileElement.inheritedElementBinder);
}
it('should detect [] syntax', () => {
@@ -44,9 +45,8 @@ export function main() {
expect(MapWrapper.get(results[0].propertyBindings, 'a').source).toEqual('b');
});
- it('should detect bind- syntax only if an attribute name starts with bind', () => {
- expect(process(el(''))[0]).toEqual(null);
- });
+ it('should detect bind- syntax only if an attribute name starts with bind',
+ () => { expect(process(el(''))[0]).toEqual(null); });
it('should detect interpolation syntax', () => {
var results = process(el(''));
@@ -67,14 +67,17 @@ export function main() {
it('should store variable binding for a template element on the nestedProtoView', () => {
var results = process(el('
'), true);
expect(results[0].variableBindings).toEqual(EMPTY_MAP);
- expect(MapWrapper.get(results[0].nestedProtoView.variableBindings, 'washington')).toEqual('george');
+ expect(MapWrapper.get(results[0].nestedProtoView.variableBindings, 'washington'))
+ .toEqual('george');
});
- it('should store variable binding for a non-template element using shorthand syntax on the nestedProtoView', () => {
- var results = process(el(''), true);
- expect(results[0].variableBindings).toEqual(EMPTY_MAP);
- expect(MapWrapper.get(results[0].nestedProtoView.variableBindings, 'washington')).toEqual('george');
- });
+ it('should store variable binding for a non-template element using shorthand syntax on the nestedProtoView',
+ () => {
+ var results = process(el(''), true);
+ expect(results[0].variableBindings).toEqual(EMPTY_MAP);
+ expect(MapWrapper.get(results[0].nestedProtoView.variableBindings, 'washington'))
+ .toEqual('george');
+ });
it('should store variable binding for a non-template element', () => {
var results = process(el(''));
@@ -165,13 +168,10 @@ export function main() {
});
}
-@IMPLEMENTS(CompileStep)
-class MockStep {
- processClosure:Function;
- constructor(process) {
- this.processClosure = process;
- }
- process(parent:CompileElement, current:CompileElement, control:CompileControl) {
+class MockStep implements CompileStep {
+ processClosure: Function;
+ constructor(process) { this.processClosure = process; }
+ process(parent: CompileElement, current: CompileElement, control: CompileControl) {
this.processClosure(parent, current, control);
}
}
diff --git a/modules/angular2/test/render/dom/compiler/selector_spec.js b/modules/angular2/test/render/dom/compiler/selector_spec.ts
similarity index 75%
rename from modules/angular2/test/render/dom/compiler/selector_spec.js
rename to modules/angular2/test/render/dom/compiler/selector_spec.ts
index b0a0555cf4..58e415c4ac 100644
--- a/modules/angular2/test/render/dom/compiler/selector_spec.js
+++ b/modules/angular2/test/render/dom/compiler/selector_spec.ts
@@ -8,9 +8,7 @@ export function main() {
describe('SelectorMatcher', () => {
var matcher, matched, selectableCollector, s1, s2, s3, s4;
- function reset() {
- matched = ListWrapper.create();
- }
+ function reset() { matched = ListWrapper.create(); }
beforeEach(() => {
reset();
@@ -18,52 +16,58 @@ export function main() {
selectableCollector = (selector, context) => {
ListWrapper.push(matched, selector);
ListWrapper.push(matched, context);
- }
+ };
matcher = new SelectorMatcher();
});
it('should select by element name case insensitive', () => {
matcher.addSelectables(s1 = CssSelector.parse('someTag'), 1);
- expect(matcher.match(CssSelector.parse('SOMEOTHERTAG')[0], selectableCollector)).toEqual(false);
+ expect(matcher.match(CssSelector.parse('SOMEOTHERTAG')[0], selectableCollector))
+ .toEqual(false);
expect(matched).toEqual([]);
expect(matcher.match(CssSelector.parse('SOMETAG')[0], selectableCollector)).toEqual(true);
- expect(matched).toEqual([s1[0],1]);
+ expect(matched).toEqual([s1[0], 1]);
});
it('should select by class name case insensitive', () => {
matcher.addSelectables(s1 = CssSelector.parse('.someClass'), 1);
matcher.addSelectables(s2 = CssSelector.parse('.someClass.class2'), 2);
- expect(matcher.match(CssSelector.parse('.SOMEOTHERCLASS')[0], selectableCollector)).toEqual(false);
+ expect(matcher.match(CssSelector.parse('.SOMEOTHERCLASS')[0], selectableCollector))
+ .toEqual(false);
expect(matched).toEqual([]);
expect(matcher.match(CssSelector.parse('.SOMECLASS')[0], selectableCollector)).toEqual(true);
- expect(matched).toEqual([s1[0],1]);
+ expect(matched).toEqual([s1[0], 1]);
reset();
- expect(matcher.match(CssSelector.parse('.someClass.class2')[0], selectableCollector)).toEqual(true);
- expect(matched).toEqual([s1[0],1,s2[0],2]);
+ expect(matcher.match(CssSelector.parse('.someClass.class2')[0], selectableCollector))
+ .toEqual(true);
+ expect(matched).toEqual([s1[0], 1, s2[0], 2]);
});
it('should select by attr name case insensitive independent of the value', () => {
matcher.addSelectables(s1 = CssSelector.parse('[someAttr]'), 1);
matcher.addSelectables(s2 = CssSelector.parse('[someAttr][someAttr2]'), 2);
- expect(matcher.match(CssSelector.parse('[SOMEOTHERATTR]')[0], selectableCollector)).toEqual(false);
+ expect(matcher.match(CssSelector.parse('[SOMEOTHERATTR]')[0], selectableCollector))
+ .toEqual(false);
expect(matched).toEqual([]);
expect(matcher.match(CssSelector.parse('[SOMEATTR]')[0], selectableCollector)).toEqual(true);
- expect(matched).toEqual([s1[0],1]);
+ expect(matched).toEqual([s1[0], 1]);
reset();
- expect(matcher.match(CssSelector.parse('[SOMEATTR=someValue]')[0], selectableCollector)).toEqual(true);
- expect(matched).toEqual([s1[0],1]);
+ expect(matcher.match(CssSelector.parse('[SOMEATTR=someValue]')[0], selectableCollector))
+ .toEqual(true);
+ expect(matched).toEqual([s1[0], 1]);
reset();
- expect(matcher.match(CssSelector.parse('[someAttr][someAttr2]')[0], selectableCollector)).toEqual(true);
- expect(matched).toEqual([s1[0],1,s2[0],2]);
+ expect(matcher.match(CssSelector.parse('[someAttr][someAttr2]')[0], selectableCollector))
+ .toEqual(true);
+ expect(matched).toEqual([s1[0], 1, s2[0], 2]);
});
it('should select by attr name only once if the value is from the DOM', () => {
@@ -74,36 +78,48 @@ export function main() {
var empty = DOM.getAttribute(element, 'attr');
elementSelector.addAttribute('some-decor', empty);
matcher.match(elementSelector, selectableCollector);
- expect(matched).toEqual([s1[0],1]);
+ expect(matched).toEqual([s1[0], 1]);
});
it('should select by attr name and value case insensitive', () => {
matcher.addSelectables(s1 = CssSelector.parse('[someAttr=someValue]'), 1);
- expect(matcher.match(CssSelector.parse('[SOMEATTR=SOMEOTHERATTR]')[0], selectableCollector)).toEqual(false);
+ expect(matcher.match(CssSelector.parse('[SOMEATTR=SOMEOTHERATTR]')[0], selectableCollector))
+ .toEqual(false);
expect(matched).toEqual([]);
- expect(matcher.match(CssSelector.parse('[SOMEATTR=SOMEVALUE]')[0], selectableCollector)).toEqual(true);
- expect(matched).toEqual([s1[0],1]);
+ expect(matcher.match(CssSelector.parse('[SOMEATTR=SOMEVALUE]')[0], selectableCollector))
+ .toEqual(true);
+ expect(matched).toEqual([s1[0], 1]);
});
it('should select by element name, class name and attribute name with value', () => {
matcher.addSelectables(s1 = CssSelector.parse('someTag.someClass[someAttr=someValue]'), 1);
- expect(matcher.match(CssSelector.parse('someOtherTag.someOtherClass[someOtherAttr]')[0], selectableCollector)).toEqual(false);
+ expect(matcher.match(CssSelector.parse('someOtherTag.someOtherClass[someOtherAttr]')[0],
+ selectableCollector))
+ .toEqual(false);
expect(matched).toEqual([]);
- expect(matcher.match(CssSelector.parse('someTag.someOtherClass[someOtherAttr]')[0], selectableCollector)).toEqual(false);
+ expect(matcher.match(CssSelector.parse('someTag.someOtherClass[someOtherAttr]')[0],
+ selectableCollector))
+ .toEqual(false);
expect(matched).toEqual([]);
- expect(matcher.match(CssSelector.parse('someTag.someClass[someOtherAttr]')[0], selectableCollector)).toEqual(false);
+ expect(matcher.match(CssSelector.parse('someTag.someClass[someOtherAttr]')[0],
+ selectableCollector))
+ .toEqual(false);
expect(matched).toEqual([]);
- expect(matcher.match(CssSelector.parse('someTag.someClass[someAttr]')[0], selectableCollector)).toEqual(false);
+ expect(
+ matcher.match(CssSelector.parse('someTag.someClass[someAttr]')[0], selectableCollector))
+ .toEqual(false);
expect(matched).toEqual([]);
- expect(matcher.match(CssSelector.parse('someTag.someClass[someAttr=someValue]')[0], selectableCollector)).toEqual(true);
- expect(matched).toEqual([s1[0],1]);
+ expect(matcher.match(CssSelector.parse('someTag.someClass[someAttr=someValue]')[0],
+ selectableCollector))
+ .toEqual(true);
+ expect(matched).toEqual([s1[0], 1]);
});
it('should select by many attributes and independent of the value', () => {
@@ -124,20 +140,24 @@ export function main() {
matcher.addSelectables(s3 = CssSelector.parse('.class1.class2'), 3);
matcher.addSelectables(s4 = CssSelector.parse('.class2.class1'), 4);
- expect(matcher.match(CssSelector.parse('[someAttr].someClass')[0], selectableCollector)).toEqual(true);
- expect(matched).toEqual([s1[0],1,s2[0],2]);
+ expect(matcher.match(CssSelector.parse('[someAttr].someClass')[0], selectableCollector))
+ .toEqual(true);
+ expect(matched).toEqual([s1[0], 1, s2[0], 2]);
reset();
- expect(matcher.match(CssSelector.parse('.someClass[someAttr]')[0], selectableCollector)).toEqual(true);
- expect(matched).toEqual([s1[0],1,s2[0],2]);
+ expect(matcher.match(CssSelector.parse('.someClass[someAttr]')[0], selectableCollector))
+ .toEqual(true);
+ expect(matched).toEqual([s1[0], 1, s2[0], 2]);
reset();
- expect(matcher.match(CssSelector.parse('.class1.class2')[0], selectableCollector)).toEqual(true);
- expect(matched).toEqual([s3[0],3,s4[0],4]);
+ expect(matcher.match(CssSelector.parse('.class1.class2')[0], selectableCollector))
+ .toEqual(true);
+ expect(matched).toEqual([s3[0], 3, s4[0], 4]);
reset();
- expect(matcher.match(CssSelector.parse('.class2.class1')[0], selectableCollector)).toEqual(true);
- expect(matched).toEqual([s4[0],4,s3[0],3]);
+ expect(matcher.match(CssSelector.parse('.class2.class1')[0], selectableCollector))
+ .toEqual(true);
+ expect(matched).toEqual([s4[0], 4, s3[0], 3]);
});
it('should not select with a matching :not selector', () => {
@@ -147,7 +167,8 @@ export function main() {
matcher.addSelectables(CssSelector.parse(':not(p)'), 4);
matcher.addSelectables(CssSelector.parse(':not(p[someAttr])'), 5);
- expect(matcher.match(CssSelector.parse('p.someClass[someAttr]')[0], selectableCollector)).toEqual(false);
+ expect(matcher.match(CssSelector.parse('p.someClass[someAttr]')[0], selectableCollector))
+ .toEqual(false);
expect(matched).toEqual([]);
});
@@ -157,27 +178,31 @@ export function main() {
matcher.addSelectables(s3 = CssSelector.parse(':not(.someClass)'), 3);
matcher.addSelectables(s4 = CssSelector.parse(':not(.someOtherClass[someAttr])'), 4);
- expect(matcher.match(CssSelector.parse('p[someOtherAttr].someOtherClass')[0], selectableCollector)).toEqual(true);
- expect(matched).toEqual([s1[0],1,s2[0],2,s3[0],3,s4[0],4]);
+ expect(matcher.match(CssSelector.parse('p[someOtherAttr].someOtherClass')[0],
+ selectableCollector))
+ .toEqual(true);
+ expect(matched).toEqual([s1[0], 1, s2[0], 2, s3[0], 3, s4[0], 4]);
});
it('should select with one match in a list', () => {
- matcher.addSelectables(s1 = CssSelector.parse('input[type=text], textbox'), 1);
+ matcher.addSelectables(s1 = CssSelector.parse('input[type=text], textbox'), 1);
- expect(matcher.match(CssSelector.parse('textbox')[0], selectableCollector)).toEqual(true);
- expect(matched).toEqual([s1[1],1]);
+ expect(matcher.match(CssSelector.parse('textbox')[0], selectableCollector)).toEqual(true);
+ expect(matched).toEqual([s1[1], 1]);
- reset();
- expect(matcher.match(CssSelector.parse('input[type=text]')[0], selectableCollector)).toEqual(true);
- expect(matched).toEqual([s1[0],1]);
+ reset();
+ expect(matcher.match(CssSelector.parse('input[type=text]')[0], selectableCollector))
+ .toEqual(true);
+ expect(matched).toEqual([s1[0], 1]);
});
it('should not select twice with two matches in a list', () => {
- matcher.addSelectables(s1 = CssSelector.parse('input, .someClass'), 1);
+ matcher.addSelectables(s1 = CssSelector.parse('input, .someClass'), 1);
- expect(matcher.match(CssSelector.parse('input.someclass')[0], selectableCollector)).toEqual(true);
- expect(matched.length).toEqual(2);
- expect(matched).toEqual([s1[0],1]);
+ expect(matcher.match(CssSelector.parse('input.someclass')[0], selectableCollector))
+ .toEqual(true);
+ expect(matched.length).toEqual(2);
+ expect(matched).toEqual([s1[0], 1]);
});
});
@@ -251,9 +276,8 @@ export function main() {
});
it('should throw when nested :not', () => {
- expect(() => {
- CssSelector.parse('sometag:not(:not([attrname=attrvalue].someclass))')[0];
- }).toThrowError('Nesting :not is not allowed in a selector');
+ expect(() => { CssSelector.parse('sometag:not(:not([attrname=attrvalue].someclass))')[0]; })
+ .toThrowError('Nesting :not is not allowed in a selector');
});
it('should detect lists of selectors', () => {
@@ -266,7 +290,8 @@ export function main() {
});
it('should detect lists of selectors with :not', () => {
- var cssSelectors = CssSelector.parse('input[type=text], :not(textarea), textbox:not(.special)');
+ var cssSelectors =
+ CssSelector.parse('input[type=text], :not(textarea), textbox:not(.special)');
expect(cssSelectors.length).toEqual(3);
expect(cssSelectors[0].element).toEqual('input');
diff --git a/modules/angular2/test/render/dom/compiler/template_loader_spec.js b/modules/angular2/test/render/dom/compiler/template_loader_spec.js
deleted file mode 100644
index ba290d187f..0000000000
--- a/modules/angular2/test/render/dom/compiler/template_loader_spec.js
+++ /dev/null
@@ -1,100 +0,0 @@
-import {
- AsyncTestCompleter,
- beforeEach,
- ddescribe,
- describe,
- el,
- expect,
- iit,
- inject,
- it,
- xit,
-} from 'angular2/test_lib';
-import {DOM} from 'angular2/src/dom/dom_adapter';
-import {TemplateLoader} from 'angular2/src/render/dom/compiler/template_loader';
-import {UrlResolver} from 'angular2/src/services/url_resolver';
-
-import {ViewDefinition} from 'angular2/src/render/api';
-import {PromiseWrapper} from 'angular2/src/facade/async';
-import {MockXHR} from 'angular2/src/mock/xhr_mock';
-
-export function main() {
- describe('TemplateLoader', () => {
- var loader, xhr;
-
- beforeEach(() => {
- xhr = new MockXHR();
- loader = new TemplateLoader(xhr, new FakeUrlResolver());
- });
-
- it('should load inline templates', inject([AsyncTestCompleter], (async) => {
- var template = new ViewDefinition({template: 'template template'});
- loader.load(template).then( (el) => {
- expect(DOM.content(el)).toHaveText('template template');
- async.done();
- });
- }));
-
- it('should load templates through XHR', inject([AsyncTestCompleter], (async) => {
- xhr.expect('base/foo', 'xhr template');
- var template = new ViewDefinition({absUrl: 'base/foo'});
- loader.load(template).then((el) => {
- expect(DOM.content(el)).toHaveText('xhr template');
- async.done();
- });
- xhr.flush();
- }));
-
- it('should cache template loaded through XHR but clone it as the compiler might change it', inject([AsyncTestCompleter], (async) => {
- var firstEl;
- // we have only one xhr.expect, so there can only be one xhr call!
- xhr.expect('base/foo', 'xhr template');
- var template = new ViewDefinition({absUrl: 'base/foo'});
- loader.load(template)
- .then((el) => {
- expect(DOM.content(el)).toHaveText('xhr template');
- firstEl = el;
- return loader.load(template);
- })
- .then((el) =>{
- expect(el).not.toBe(firstEl);
- expect(DOM.content(el)).toHaveText('xhr template');
- async.done();
- });
- xhr.flush();
- }));
-
- it('should throw when no template is defined', () => {
- var template = new ViewDefinition({template: null, absUrl: null});
- expect(() => loader.load(template))
- .toThrowError('View should have either the url or template property set');
- });
-
- it('should return a rejected Promise when xhr loading fails', inject([AsyncTestCompleter], (async) => {
- xhr.expect('base/foo', null);
- var template = new ViewDefinition({absUrl: 'base/foo'});
- PromiseWrapper.then(loader.load(template),
- function(_) { throw 'Unexpected response'; },
- function(error) {
- expect(error).toEqual('Failed to load base/foo');
- async.done();
- }
- )
- xhr.flush();
- }));
-
- });
-}
-
-class SomeComponent {
-}
-
-class FakeUrlResolver extends UrlResolver {
- constructor() {
- super();
- }
-
- resolve(baseUrl: string, url: string): string {
- return baseUrl + url;
- }
-}
diff --git a/modules/angular2/test/render/dom/compiler/template_loader_spec.ts b/modules/angular2/test/render/dom/compiler/template_loader_spec.ts
new file mode 100644
index 0000000000..343570f0a4
--- /dev/null
+++ b/modules/angular2/test/render/dom/compiler/template_loader_spec.ts
@@ -0,0 +1,96 @@
+import {
+ AsyncTestCompleter,
+ beforeEach,
+ ddescribe,
+ describe,
+ el,
+ expect,
+ iit,
+ inject,
+ it,
+ xit,
+} from 'angular2/test_lib';
+import {DOM} from 'angular2/src/dom/dom_adapter';
+import {TemplateLoader} from 'angular2/src/render/dom/compiler/template_loader';
+import {UrlResolver} from 'angular2/src/services/url_resolver';
+
+import {ViewDefinition} from 'angular2/src/render/api';
+import {PromiseWrapper} from 'angular2/src/facade/async';
+import {MockXHR} from 'angular2/src/mock/xhr_mock';
+
+export function main() {
+ describe('TemplateLoader', () => {
+ var loader, xhr;
+
+ beforeEach(() => {
+ xhr = new MockXHR();
+ loader = new TemplateLoader(xhr, new FakeUrlResolver());
+ });
+
+ it('should load inline templates', inject([AsyncTestCompleter], (async) => {
+ var template = new ViewDefinition({template: 'template template'});
+ loader.load(template).then((el) => {
+ expect(DOM.content(el)).toHaveText('template template');
+ async.done();
+ });
+ }));
+
+ it('should load templates through XHR', inject([AsyncTestCompleter], (async) => {
+ xhr.expect('base/foo', 'xhr template');
+ var template = new ViewDefinition({absUrl: 'base/foo'});
+ loader.load(template).then((el) => {
+ expect(DOM.content(el)).toHaveText('xhr template');
+ async.done();
+ });
+ xhr.flush();
+ }));
+
+ it('should cache template loaded through XHR but clone it as the compiler might change it',
+ inject([AsyncTestCompleter], (async) => {
+ var firstEl;
+ // we have only one xhr.expect, so there can only be one xhr call!
+ xhr.expect('base/foo', 'xhr template');
+ var template = new ViewDefinition({absUrl: 'base/foo'});
+ loader.load(template)
+ .then((el) =>
+ {
+ expect(DOM.content(el)).toHaveText('xhr template');
+ firstEl = el;
+ return loader.load(template);
+ })
+ .then((el) => {
+ expect(el).not.toBe(firstEl);
+ expect(DOM.content(el)).toHaveText('xhr template');
+ async.done();
+ });
+ xhr.flush();
+ }));
+
+ it('should throw when no template is defined', () => {
+ var template = new ViewDefinition({template: null, absUrl: null});
+ expect(() => loader.load(template))
+ .toThrowError('View should have either the url or template property set');
+ });
+
+ it('should return a rejected Promise when xhr loading fails',
+ inject([AsyncTestCompleter], (async) => {
+ xhr.expect('base/foo', null);
+ var template = new ViewDefinition({absUrl: 'base/foo'});
+ PromiseWrapper.then(loader.load(template), function(_) { throw 'Unexpected response'; },
+ function(error) {
+ expect(error).toEqual('Failed to load base/foo');
+ async.done();
+ });
+ xhr.flush();
+ }));
+
+ });
+}
+
+class SomeComponent {}
+
+class FakeUrlResolver extends UrlResolver {
+ constructor() { super(); }
+
+ resolve(baseUrl: string, url: string): string { return baseUrl + url; }
+}
diff --git a/modules/angular2/test/render/dom/compiler/text_interpolation_parser_spec.js b/modules/angular2/test/render/dom/compiler/text_interpolation_parser_spec.ts
similarity index 84%
rename from modules/angular2/test/render/dom/compiler/text_interpolation_parser_spec.js
rename to modules/angular2/test/render/dom/compiler/text_interpolation_parser_spec.ts
index 0e3ff7722d..ba9f9e1f48 100644
--- a/modules/angular2/test/render/dom/compiler/text_interpolation_parser_spec.js
+++ b/modules/angular2/test/render/dom/compiler/text_interpolation_parser_spec.ts
@@ -4,21 +4,18 @@ import {CompilePipeline} from 'angular2/src/render/dom/compiler/compile_pipeline
import {MapWrapper, ListWrapper} from 'angular2/src/facade/collection';
import {Lexer, Parser} from 'angular2/change_detection';
import {IgnoreChildrenStep} from './pipeline_spec';
+import {ElementBinderBuilder} from 'angular2/src/render/dom/view/proto_view_builder';
export function main() {
describe('TextInterpolationParser', () => {
function createPipeline() {
- return new CompilePipeline([
- new IgnoreChildrenStep(),
- new TextInterpolationParser(new Parser(new Lexer()))
- ]);
+ return new CompilePipeline(
+ [new IgnoreChildrenStep(), new TextInterpolationParser(new Parser(new Lexer()))]);
}
- function process(element) {
- return ListWrapper.map(
- createPipeline().process(element),
- (compileElement) => compileElement.inheritedElementBinder
- );
+ function process(element): List {
+ return ListWrapper.map(createPipeline().process(element),
+ (compileElement) => compileElement.inheritedElementBinder);
}
function assertTextBinding(elementBinder, bindingIndex, nodeIndex, expression) {
diff --git a/modules/angular2/test/render/dom/compiler/view_splitter_spec.js b/modules/angular2/test/render/dom/compiler/view_splitter_spec.ts
similarity index 84%
rename from modules/angular2/test/render/dom/compiler/view_splitter_spec.js
rename to modules/angular2/test/render/dom/compiler/view_splitter_spec.ts
index 9c65840ab4..ba398ae39b 100644
--- a/modules/angular2/test/render/dom/compiler/view_splitter_spec.js
+++ b/modules/angular2/test/render/dom/compiler/view_splitter_spec.ts
@@ -21,7 +21,8 @@ export function main() {
var rootElement = el('
a
');
var results = createPipeline().process(rootElement);
- expect(DOM.getOuterHTML(results[1].element)).toEqual('');
+ expect(DOM.getOuterHTML(results[1].element))
+ .toEqual('');
expect(results[1].isViewRoot).toBe(false);
expect(DOM.getOuterHTML(results[2].element)).toEqual('a');
expect(results[2].isViewRoot).toBe(true);
@@ -56,9 +57,11 @@ export function main() {
var rootElement = el('
');
var results = createPipeline().process(rootElement);
- expect(MapWrapper.get(results[1].inheritedElementBinder.propertyBindings, 'someProp').source).toEqual('expr');
+ expect(
+ MapWrapper.get(results[1].inheritedElementBinder.propertyBindings, 'someProp').source)
+ .toEqual('expr');
expect(MapWrapper.get(results[1].attrs(), 'some-prop')).toEqual('expr');
});
it('should add variable mappings from the template attribute to the nestedProtoView', () => {
var rootElement = el('
');
var results = createPipeline().process(rootElement);
- expect(results[2].inheritedProtoView.variableBindings).toEqual(MapWrapper.createFromStringMap({'mapName': 'varName'}));
+ expect(results[2].inheritedProtoView.variableBindings)
+ .toEqual(MapWrapper.createFromStringMap({'mapName': 'varName'}));
});
it('should add entries without value as attributes to the element', () => {
@@ -137,8 +145,10 @@ export function main() {
var rootElement = el('
');
var results = createPipeline().process(rootElement);
- expect(MapWrapper.get(results[1].inheritedElementBinder.propertyBindings, 'prop').source).toEqual('expr');
+ expect(MapWrapper.get(results[1].inheritedElementBinder.propertyBindings, 'prop').source)
+ .toEqual('expr');
expect(MapWrapper.get(results[1].attrs(), 'prop')).toEqual('expr');
});
it('should add variable mappings from the template attribute to the nestedProtoView', () => {
var rootElement = el('
');
var results = createPipeline().process(rootElement);
- expect(results[2].inheritedProtoView.variableBindings).toEqual(MapWrapper.createFromStringMap({'mapName': 'varName'}));
+ expect(results[2].inheritedProtoView.variableBindings)
+ .toEqual(MapWrapper.createFromStringMap({'mapName': 'varName'}));
});
it('should add entries without value as attribute to the element', () => {
@@ -217,8 +231,10 @@ export function main() {
var rootElement = el('
");
var lightDom = createLightDom(lightDomView, new FakeView(), lightDomEl);
expect(toHtml(lightDom.expandedDomNodes())).toEqual([""]);
});
@@ -144,14 +137,11 @@ export function main() {
it("should include view container nodes", () => {
var lightDomEl = el("");
var lightDom = createLightDom(
- new FakeView([
- new FakeViewContainer(
- DOM.firstChild(lightDomEl), // template element
- [el('')] // light DOM nodes of view container
- )
- ]),
- null,
- lightDomEl);
+ new FakeView(
+ [new FakeViewContainer(DOM.firstChild(lightDomEl), // template element
+ [el('')] // light DOM nodes of view container
+ )]),
+ null, lightDomEl);
expect(toHtml(lightDom.expandedDomNodes())).toEqual([""]);
});
@@ -159,15 +149,11 @@ export function main() {
it("should include content nodes", () => {
var lightDomEl = el("
");
var lightDom = createLightDom(
- new FakeView([
- new FakeContentTag(
- DOM.firstChild(lightDomEl), // content element
- '', // selector
- [el('')] // light DOM nodes of content tag
- )
- ]),
- null,
- lightDomEl);
+ new FakeView([new FakeContentTag(DOM.firstChild(lightDomEl), // content element
+ '', // selector
+ [el('')] // light DOM nodes of content tag
+ )]),
+ null, lightDomEl);
expect(toHtml(lightDom.expandedDomNodes())).toEqual([""]);
});
@@ -175,12 +161,9 @@ export function main() {
it("should work when the element injector array contains nulls", () => {
var lightDomEl = el("
")
- var lightDomView = new FakeView();
+ var lightDomView = new FakeView();
- var lightDom = createLightDom(
- lightDomView,
- new FakeView(),
- lightDomEl);
+ var lightDom = createLightDom(lightDomView, new FakeView(), lightDomEl);
expect(toHtml(lightDom.expandedDomNodes())).toEqual([""]);
});
@@ -193,10 +176,8 @@ export function main() {
var lightDomEl = el("
")
- var lightDom = createLightDom(lightDomView, new FakeView([
- wildcard,
- contentB
- ]), lightDomEl);
+ var lightDom =
+ createLightDom(lightDomView, new FakeView([wildcard, contentB]), lightDomEl);
lightDom.redistribute();
@@ -224,7 +203,7 @@ export function main() {
it("should remove all nodes if there are no content tags", () => {
var lightDomEl = el("
")
- var lightDom = createLightDom(lightDomView, new FakeView([]), lightDomEl);
+ var lightDom = createLightDom(lightDomView, new FakeView([]), lightDomEl);
lightDom.redistribute();
@@ -235,9 +214,8 @@ export function main() {
var lightDomEl = el("