From 22c6c09dafaca6d9f2300d1807bba847994efe30 Mon Sep 17 00:00:00 2001 From: Marc Laval Date: Tue, 21 Apr 2015 19:30:55 +0200 Subject: [PATCH] chore(build): run event tests in Node Closes #1476 --- gulpfile.js | 1 - modules/angular2/src/dom/parse5_adapter.cjs | 47 +- .../src/forms/validator_directives.js | 3 +- .../test/core/compiler/integration_spec.js | 160 ++--- .../angular2/test/forms/integration_spec.js | 632 +++++++++--------- .../render/dom/events/event_manager_spec.js | 5 +- 6 files changed, 443 insertions(+), 405 deletions(-) diff --git a/gulpfile.js b/gulpfile.js index 5966f5c4fa..5ccd8e37b2 100644 --- a/gulpfile.js +++ b/gulpfile.js @@ -215,7 +215,6 @@ var CONFIG = { }; CONFIG.test.js.cjs = CONFIG.test.js.cjs.map(function(s) {return CONFIG.dest.js.cjs + s}); CONFIG.test.js.cjs.push('!**/core/zone/vm_turn_zone_spec.js'); //Disabled in nodejs because it relies on Zone.js -CONFIG.test.js.cjs.push('!**/render/dom/events/event_manager_spec.js'); //Disabled in nodejs because it relies on DOM events // ------------ // clean diff --git a/modules/angular2/src/dom/parse5_adapter.cjs b/modules/angular2/src/dom/parse5_adapter.cjs index 96c34394d4..df7e4b1ff1 100644 --- a/modules/angular2/src/dom/parse5_adapter.cjs +++ b/modules/angular2/src/dom/parse5_adapter.cjs @@ -84,19 +84,46 @@ export class Parse5DomAdapter extends DomAdapter { return result; } on(el, evt, listener) { - //Do nothing, in order to not break forms integration tests + var listenersMap = el._eventListenersMap; + if (isBlank(listenersMap)) { + var listenersMap = StringMapWrapper.create(); + el._eventListenersMap = listenersMap; + } + var listeners = StringMapWrapper.get(listenersMap, evt); + if (isBlank(listeners)) { + listeners = ListWrapper.create(); + } + ListWrapper.push(listeners, listener); + StringMapWrapper.set(listenersMap, evt, listeners); } onAndCancel(el, evt, listener): Function { - //Do nothing, in order to not break forms integration tests + this.on(el, evt, listener); + return () => {ListWrapper.remove(StringMapWrapper.get(el._eventListenersMap, evt), listener);}; } dispatchEvent(el, evt) { - throw _notImplemented('dispatchEvent'); + if (isBlank(evt.target)) { + evt.target = el; + } + if (isPresent(el._eventListenersMap)) { + var listeners = StringMapWrapper.get(el._eventListenersMap, evt.type); + if (isPresent(listeners)) { + for (var i = 0; i < listeners.length; i++) { + listeners[i](evt); + } + } + } + if (isPresent(el.parent)) { + this.dispatchEvent(el.parent, evt); + } + if (isPresent(el._window)) { + this.dispatchEvent(el._window, evt); + } } createMouseEvent(eventType) { - throw _notImplemented('createMouseEvent'); + return this.createEvent(eventType); } createEvent(eventType) { - throw _notImplemented('createEvent'); + return {type: eventType}; } getInnerHTML(el) { return serializer.serialize(this.templateAwareRoot(el)); @@ -378,6 +405,7 @@ export class Parse5DomAdapter extends DomAdapter { this.appendChild(newDoc, body); StringMapWrapper.set(newDoc, "head", head); StringMapWrapper.set(newDoc, "body", body); + StringMapWrapper.set(newDoc, "_window", StringMapWrapper.create()); return newDoc; } defaultDoc() { @@ -482,6 +510,15 @@ export class Parse5DomAdapter extends DomAdapter { supportsNativeShadowDOM(): boolean { return false; } + getGlobalEventTarget(target:string) { + if (target == "window") { + return this.defaultDoc()._window; + } else if (target == "document") { + return this.defaultDoc(); + } else if (target == "body") { + return this.defaultDoc().body; + } + } } //TODO: build a proper list, this one is all the keys of a HTMLInputElement diff --git a/modules/angular2/src/forms/validator_directives.js b/modules/angular2/src/forms/validator_directives.js index e592d65f8d..1d607e8b57 100644 --- a/modules/angular2/src/forms/validator_directives.js +++ b/modules/angular2/src/forms/validator_directives.js @@ -1,6 +1,7 @@ import {Decorator} from 'angular2/angular2'; -import {ControlDirective, Validators} from 'angular2/forms'; +import {Validators} from './validators'; +import {ControlDirective} from './directives'; @Decorator({ selector: '[required]' diff --git a/modules/angular2/test/core/compiler/integration_spec.js b/modules/angular2/test/core/compiler/integration_spec.js index f60da12e5a..3bac335f5b 100644 --- a/modules/angular2/test/core/compiler/integration_spec.js +++ b/modules/angular2/test/core/compiler/integration_spec.js @@ -545,53 +545,53 @@ export function main() { }); })); + it('should support render events', inject([TestBed, AsyncTestCompleter], (tb, async) => { + tb.overrideView(MyComp, new View({ + template: '
', + directives: [DecoratorListeningDomEvent] + })); + + tb.createView(MyComp, {context: ctx}).then((view) => { + + var injector = view.rawView.elementInjectors[0]; + + var listener = injector.get(DecoratorListeningDomEvent); + + dispatchEvent(view.rootNodes[0], 'domEvent'); + + expect(listener.eventType).toEqual('domEvent'); + + async.done(); + }); + })); + + it('should support render global events', inject([TestBed, AsyncTestCompleter], (tb, async) => { + tb.overrideView(MyComp, new View({ + template: '
', + directives: [DecoratorListeningDomEvent] + })); + + tb.createView(MyComp, {context: ctx}).then((view) => { + var injector = view.rawView.elementInjectors[0]; + + var listener = injector.get(DecoratorListeningDomEvent); + dispatchEvent(DOM.getGlobalEventTarget("window"), 'domEvent'); + expect(listener.eventType).toEqual('window_domEvent'); + + listener = injector.get(DecoratorListeningDomEvent); + dispatchEvent(DOM.getGlobalEventTarget("document"), 'domEvent'); + expect(listener.eventType).toEqual('document_domEvent'); + + view.destroy(); + listener = injector.get(DecoratorListeningDomEvent); + dispatchEvent(DOM.getGlobalEventTarget("body"), 'domEvent'); + expect(listener.eventType).toEqual(''); + + async.done(); + }); + })); + if (DOM.supportsDOMEvents()) { - it('should support render events', inject([TestBed, AsyncTestCompleter], (tb, async) => { - tb.overrideView(MyComp, new View({ - template: '
', - directives: [DecoratorListeningDomEvent] - })); - - tb.createView(MyComp, {context: ctx}).then((view) => { - - var injector = view.rawView.elementInjectors[0]; - - var listener = injector.get(DecoratorListeningDomEvent); - - dispatchEvent(view.rootNodes[0], 'domEvent'); - - expect(listener.eventType).toEqual('domEvent'); - - async.done(); - }); - })); - - it('should support render global events', inject([TestBed, AsyncTestCompleter], (tb, async) => { - tb.overrideView(MyComp, new View({ - template: '
', - directives: [DecoratorListeningDomEvent] - })); - - tb.createView(MyComp, {context: ctx}).then((view) => { - var injector = view.rawView.elementInjectors[0]; - - var listener = injector.get(DecoratorListeningDomEvent); - dispatchEvent(DOM.getGlobalEventTarget("window"), 'domEvent'); - expect(listener.eventType).toEqual('window_domEvent'); - - listener = injector.get(DecoratorListeningDomEvent); - dispatchEvent(DOM.getGlobalEventTarget("document"), 'domEvent'); - expect(listener.eventType).toEqual('document_domEvent'); - - view.destroy(); - listener = injector.get(DecoratorListeningDomEvent); - dispatchEvent(DOM.getGlobalEventTarget("body"), 'domEvent'); - expect(listener.eventType).toEqual(''); - - async.done(); - }); - })); - it('should support preventing default on render events', inject([TestBed, AsyncTestCompleter], (tb, async) => { tb.overrideView(MyComp, new View({ template: '', @@ -608,42 +608,42 @@ export function main() { async.done(); }); })); - - it('should support render global events from multiple directives', inject([TestBed, AsyncTestCompleter], (tb, async) => { - tb.overrideView(MyComp, new View({ - template: '
', - directives: [If, DecoratorListeningDomEvent, DecoratorListeningDomEventOther] - })); - - tb.createView(MyComp, {context: ctx}).then((view) => { - globalCounter = 0; - ctx.ctxBoolProp = true; - view.detectChanges(); - - var subview = view.rawView.viewContainers[0].get(0); - var injector = subview.elementInjectors[0]; - var listener = injector.get(DecoratorListeningDomEvent); - var listenerother = injector.get(DecoratorListeningDomEventOther); - dispatchEvent(DOM.getGlobalEventTarget("window"), 'domEvent'); - expect(listener.eventType).toEqual('window_domEvent'); - expect(listenerother.eventType).toEqual('other_domEvent'); - expect(globalCounter).toEqual(1); - - ctx.ctxBoolProp = false; - view.detectChanges(); - dispatchEvent(DOM.getGlobalEventTarget("window"), 'domEvent'); - expect(globalCounter).toEqual(1); - - ctx.ctxBoolProp = true; - view.detectChanges(); - dispatchEvent(DOM.getGlobalEventTarget("window"), 'domEvent'); - expect(globalCounter).toEqual(2); - - async.done(); - }); - })); } + it('should support render global events from multiple directives', inject([TestBed, AsyncTestCompleter], (tb, async) => { + tb.overrideView(MyComp, new View({ + template: '
', + directives: [If, DecoratorListeningDomEvent, DecoratorListeningDomEventOther] + })); + + tb.createView(MyComp, {context: ctx}).then((view) => { + globalCounter = 0; + ctx.ctxBoolProp = true; + view.detectChanges(); + + var subview = view.rawView.viewContainers[0].get(0); + var injector = subview.elementInjectors[0]; + var listener = injector.get(DecoratorListeningDomEvent); + var listenerother = injector.get(DecoratorListeningDomEventOther); + dispatchEvent(DOM.getGlobalEventTarget("window"), 'domEvent'); + expect(listener.eventType).toEqual('window_domEvent'); + expect(listenerother.eventType).toEqual('other_domEvent'); + expect(globalCounter).toEqual(1); + + ctx.ctxBoolProp = false; + view.detectChanges(); + dispatchEvent(DOM.getGlobalEventTarget("window"), 'domEvent'); + expect(globalCounter).toEqual(1); + + ctx.ctxBoolProp = true; + view.detectChanges(); + dispatchEvent(DOM.getGlobalEventTarget("window"), 'domEvent'); + expect(globalCounter).toEqual(2); + + async.done(); + }); + })); + describe('dynamic ViewContainers', () => { it('should allow to create a ViewContainer at any bound location', diff --git a/modules/angular2/test/forms/integration_spec.js b/modules/angular2/test/forms/integration_spec.js index fdfbd15c9c..f84bfb112e 100644 --- a/modules/angular2/test/forms/integration_spec.js +++ b/modules/angular2/test/forms/integration_spec.js @@ -20,27 +20,320 @@ import {Component, Decorator, View, PropertySetter} from 'angular2/angular2'; import {TestBed} from 'angular2/src/test_lib/test_bed'; -import {ControlGroupDirective, ControlDirective, Control, ControlGroup, OptionalControl, - ControlValueAccessor, RequiredValidatorDirective, CheckboxControlValueAccessor, +import {ControlGroupDirective, ControlDirective, Control, ControlGroup, RequiredValidatorDirective, CheckboxControlValueAccessor, DefaultValueAccessor, Validators} from 'angular2/forms'; export function main() { describe("integration tests", () => { - if (DOM.supportsDOMEvents()) { - it("should initialize DOM elements with the given form object", - inject([TestBed, AsyncTestCompleter], (tb, async) => { - var ctx = new MyComp(new ControlGroup({ - "login": new Control("loginValue") - })); + + it("should initialize DOM elements with the given form object", + inject([TestBed, AsyncTestCompleter], (tb, async) => { + var ctx = new MyComp(new ControlGroup({ + "login": new Control("loginValue") + })); + + var t = `
+ +
`; + + tb.createView(MyComp, {context: ctx, html: t}).then((view) => { + view.detectChanges(); + var input = view.querySelector("input"); + expect(input.value).toEqual("loginValue"); + async.done(); + }); + })); + + it("should update the control group values on DOM change", + inject([TestBed, AsyncTestCompleter], (tb, async) => { + var form = new ControlGroup({ + "login": new Control("oldValue") + }); + var ctx = new MyComp(form); + + var t = `
+ +
`; + + tb.createView(MyComp, {context: ctx, html: t}).then((view) => { + view.detectChanges(); + var input = view.querySelector("input"); + + input.value = "updatedValue"; + dispatchEvent(input, "change"); + + expect(form.value).toEqual({"login": "updatedValue"}); + async.done(); + }); + })); + + it("should work with single controls", inject([TestBed, AsyncTestCompleter], (tb, async) => { + var control = new Control("loginValue"); + var ctx = new MyComp(control); + + var t = `
`; + + tb.createView(MyComp, {context: ctx, html: t}).then((view) => { + view.detectChanges(); + var input = view.querySelector("input") + expect(input.value).toEqual("loginValue"); + + input.value = "updatedValue"; + dispatchEvent(input, "change"); + + expect(control.value).toEqual("updatedValue"); + async.done(); + }); + })); + + it("should update DOM elements when rebinding the control group", + inject([TestBed, AsyncTestCompleter], (tb, async) => { + var form = new ControlGroup({ + "login": new Control("oldValue") + }); + var ctx = new MyComp(form); + + var t = `
+ +
`; + + tb.createView(MyComp, {context: ctx, html: t}).then((view) => { + view.detectChanges(); + ctx.form = new ControlGroup({ + "login": new Control("newValue") + }); + view.detectChanges(); + + var input = view.querySelector("input") + expect(input.value).toEqual("newValue"); + async.done(); + }); + })); + + it("should update DOM element when rebinding the control name", + inject([TestBed, AsyncTestCompleter], (tb, async) => { + var ctx = new MyComp(new ControlGroup({ + "one": new Control("one"), + "two": new Control("two") + }), "one"); + + var t = `
+ +
`; + + tb.createView(MyComp, {context: ctx, html: t}).then((view) => { + view.detectChanges(); + var input = view.querySelector("input") + expect(input.value).toEqual("one"); + + ctx.name = "two"; + view.detectChanges(); + + expect(input.value).toEqual("two"); + async.done(); + }); + })); + + describe("different control types", () => { + it("should support ", inject([TestBed, AsyncTestCompleter], (tb, async) => { + var ctx = new MyComp(new ControlGroup({"text": new Control("old")})); var t = `
- + +
`; + + tb.createView(MyComp, {context: ctx, html: t}).then((view) => { + view.detectChanges(); + var input = view.querySelector("input") + expect(input.value).toEqual("old"); + + input.value = "new"; + dispatchEvent(input, "input"); + + expect(ctx.form.value).toEqual({"text": "new"}); + async.done(); + }); + })); + + it("should support without type", inject([TestBed, AsyncTestCompleter], (tb, async) => { + var ctx = new MyComp(new ControlGroup({"text": new Control("old")})); + + var t = `
+ +
`; + + tb.createView(MyComp, {context: ctx, html: t}).then((view) => { + view.detectChanges(); + var input = view.querySelector("input") + expect(input.value).toEqual("old"); + + input.value = "new"; + dispatchEvent(input, "input"); + + expect(ctx.form.value).toEqual({"text": "new"}); + async.done(); + }); + })); + + it("should support + `; + + tb.createView(MyComp, {context: ctx, html: t}).then((view) => { + view.detectChanges(); + var textarea = view.querySelector("textarea") + expect(textarea.value).toEqual("old"); + + textarea.value = "new"; + dispatchEvent(textarea, "input"); + + expect(ctx.form.value).toEqual({"text": 'new'}); + async.done(); + }); + })); + + it("should support ", inject([TestBed, AsyncTestCompleter], (tb, async) => { + var ctx = new MyComp(new ControlGroup({"checkbox": new Control(true)})); + + var t = `
+ +
`; + + tb.createView(MyComp, {context: ctx, html: t}).then((view) => { + view.detectChanges(); + var input = view.querySelector("input") + expect(input.checked).toBe(true); + + input.checked = false; + dispatchEvent(input, "change"); + + expect(ctx.form.value).toEqual({"checkbox": false}); + async.done(); + }); + })); + + it("should support + + + + `; + + tb.createView(MyComp, {context: ctx, html: t}).then((view) => { + view.detectChanges(); + var select = view.querySelector("select") + var sfOption = view.querySelector("option") + expect(select.value).toEqual('SF'); + if (DOM.supportsDOMEvents()) { + expect(sfOption.selected).toBe(true); + } + + select.value = 'NYC'; + dispatchEvent(select, "change"); + + expect(ctx.form.value).toEqual({"city": 'NYC'}); + if (DOM.supportsDOMEvents()) { + expect(sfOption.selected).toBe(false); + } + async.done(); + }); + })); + + it("should support custom value accessors", inject([TestBed, AsyncTestCompleter], (tb, async) => { + var ctx = new MyComp(new ControlGroup({"name": new Control("aa")})); + + var t = `
+ +
`; + + tb.createView(MyComp, {context: ctx, html: t}).then((view) => { + view.detectChanges(); + var input = view.querySelector("input") + expect(input.value).toEqual("!aa!"); + + input.value = "!bb!"; + dispatchEvent(input, "change"); + + expect(ctx.form.value).toEqual({"name": "bb"}); + async.done(); + }); + })); + }); + + describe("validations", () => { + it("should use validators defined in html", + inject([TestBed, AsyncTestCompleter], (tb, async) => { + var form = new ControlGroup({"login": new Control("aa")}); + var ctx = new MyComp(form); + + var t = `
+ +
`; + + tb.createView(MyComp, {context: ctx, html: t}).then((view) => { + view.detectChanges(); + expect(form.valid).toEqual(true); + + var input = view.querySelector("input"); + + input.value = ""; + dispatchEvent(input, "change"); + + expect(form.valid).toEqual(false); + async.done(); + }); + })); + + it("should use validators defined in the model", + inject([TestBed, AsyncTestCompleter], (tb, async) => { + var form = new ControlGroup({"login": new Control("aa", Validators.required)}); + var ctx = new MyComp(form); + + var t = `
+ +
`; + + tb.createView(MyComp, {context: ctx, html: t}).then((view) => { + view.detectChanges(); + expect(form.valid).toEqual(true); + + var input = view.querySelector("input"); + + input.value = ""; + dispatchEvent(input, "change"); + + expect(form.valid).toEqual(false); + async.done(); + }); + })); + }); + + describe("nested forms", () => { + it("should init DOM with the given form object", + inject([TestBed, AsyncTestCompleter], (tb, async) => { + var form = new ControlGroup({ + "nested": new ControlGroup({ + "login": new Control("value") + }) + }); + var ctx = new MyComp(form); + + var t = `
+
+ +
`; tb.createView(MyComp, {context: ctx, html: t}).then((view) => { view.detectChanges(); - var input = view.querySelector("input"); - expect(input.value).toEqual("loginValue"); + var input = view.querySelector("input") + expect(input.value).toEqual("value"); async.done(); }); })); @@ -48,321 +341,30 @@ export function main() { it("should update the control group values on DOM change", inject([TestBed, AsyncTestCompleter], (tb, async) => { var form = new ControlGroup({ - "login": new Control("oldValue") + "nested": new ControlGroup({ + "login": new Control("value") + }) }); var ctx = new MyComp(form); var t = `
- -
`; - - tb.createView(MyComp, {context: ctx, html: t}).then((view) => { - view.detectChanges(); - var input = view.querySelector("input"); - - input.value = "updatedValue"; - dispatchEvent(input, "change"); - - expect(form.value).toEqual({"login": "updatedValue"}); - async.done(); - }); - })); - - it("should work with single controls", inject([TestBed, AsyncTestCompleter], (tb, async) => { - var control = new Control("loginValue"); - var ctx = new MyComp(control); - - var t = `
`; - - tb.createView(MyComp, {context: ctx, html: t}).then((view) => { - view.detectChanges(); - var input = view.querySelector("input") - expect(input.value).toEqual("loginValue"); - - input.value = "updatedValue"; - dispatchEvent(input, "change"); - - expect(control.value).toEqual("updatedValue"); - async.done(); - }); - })); - - it("should update DOM elements when rebinding the control group", - inject([TestBed, AsyncTestCompleter], (tb, async) => { - var form = new ControlGroup({ - "login": new Control("oldValue") - }); - var ctx = new MyComp(form); - - var t = `
- -
`; - - tb.createView(MyComp, {context: ctx, html: t}).then((view) => { - view.detectChanges(); - ctx.form = new ControlGroup({ - "login": new Control("newValue") - }); - view.detectChanges(); - - var input = view.querySelector("input") - expect(input.value).toEqual("newValue"); - async.done(); - }); - })); - - it("should update DOM element when rebinding the control name", - inject([TestBed, AsyncTestCompleter], (tb, async) => { - var ctx = new MyComp(new ControlGroup({ - "one": new Control("one"), - "two": new Control("two") - }), "one"); - - var t = `
- -
`; - - tb.createView(MyComp, {context: ctx, html: t}).then((view) => { - view.detectChanges(); - var input = view.querySelector("input") - expect(input.value).toEqual("one"); - - ctx.name = "two"; - view.detectChanges(); - - expect(input.value).toEqual("two"); - async.done(); - }); - })); - - describe("different control types", () => { - it("should support ", inject([TestBed, AsyncTestCompleter], (tb, async) => { - var ctx = new MyComp(new ControlGroup({"text": new Control("old")})); - - var t = `
- -
`; - - tb.createView(MyComp, {context: ctx, html: t}).then((view) => { - view.detectChanges(); - var input = view.querySelector("input") - expect(input.value).toEqual("old"); - - input.value = "new"; - dispatchEvent(input, "input"); - - expect(ctx.form.value).toEqual({"text": "new"}); - async.done(); - }); - })); - - it("should support without type", inject([TestBed, AsyncTestCompleter], (tb, async) => { - var ctx = new MyComp(new ControlGroup({"text": new Control("old")})); - - var t = `
- -
`; - - tb.createView(MyComp, {context: ctx, html: t}).then((view) => { - view.detectChanges(); - var input = view.querySelector("input") - expect(input.value).toEqual("old"); - - input.value = "new"; - dispatchEvent(input, "input"); - - expect(ctx.form.value).toEqual({"text": "new"}); - async.done(); - }); - })); - - it("should support - `; - - tb.createView(MyComp, {context: ctx, html: t}).then((view) => { - view.detectChanges(); - var textarea = view.querySelector("textarea") - expect(textarea.value).toEqual("old"); - - textarea.value = "new"; - dispatchEvent(textarea, "input"); - - expect(ctx.form.value).toEqual({"text": 'new'}); - async.done(); - }); - })); - - it("should support ", inject([TestBed, AsyncTestCompleter], (tb, async) => { - var ctx = new MyComp(new ControlGroup({"checkbox": new Control(true)})); - - var t = `
- -
`; - - tb.createView(MyComp, {context: ctx, html: t}).then((view) => { - view.detectChanges(); - var input = view.querySelector("input") - expect(input.checked).toBe(true); - - input.checked = false; - dispatchEvent(input, "change"); - - expect(ctx.form.value).toEqual({"checkbox": false}); - async.done(); - }); - })); - - it("should support - - - - `; - - tb.createView(MyComp, {context: ctx, html: t}).then((view) => { - view.detectChanges(); - var select = view.querySelector("select") - var sfOption = view.querySelector("option") - expect(select.value).toEqual('SF'); - expect(sfOption.selected).toBe(true); - - select.value = 'NYC'; - dispatchEvent(select, "change"); - - expect(ctx.form.value).toEqual({"city": 'NYC'}); - expect(sfOption.selected).toBe(false); - async.done(); - }); - })); - - it("should support custom value accessors", inject([TestBed, AsyncTestCompleter], (tb, async) => { - var ctx = new MyComp(new ControlGroup({"name": new Control("aa")})); - - var t = `
- -
`; - - tb.createView(MyComp, {context: ctx, html: t}).then((view) => { - view.detectChanges(); - var input = view.querySelector("input") - expect(input.value).toEqual("!aa!"); - - input.value = "!bb!"; - dispatchEvent(input, "change"); - - expect(ctx.form.value).toEqual({"name": "bb"}); - async.done(); - }); - })); - }); - - describe("validations", () => { - it("should use validators defined in html", - inject([TestBed, AsyncTestCompleter], (tb, async) => { - var form = new ControlGroup({"login": new Control("aa")}); - var ctx = new MyComp(form); - - var t = `
- -
`; - - tb.createView(MyComp, {context: ctx, html: t}).then((view) => { - view.detectChanges(); - expect(form.valid).toEqual(true); - - var input = view.querySelector("input"); - - input.value = ""; - dispatchEvent(input, "change"); - - expect(form.valid).toEqual(false); - async.done(); - }); - })); - - it("should use validators defined in the model", - inject([TestBed, AsyncTestCompleter], (tb, async) => { - var form = new ControlGroup({"login": new Control("aa", Validators.required)}); - var ctx = new MyComp(form); - - var t = `
- -
`; - - tb.createView(MyComp, {context: ctx, html: t}).then((view) => { - view.detectChanges(); - expect(form.valid).toEqual(true); - - var input = view.querySelector("input"); - - input.value = ""; - dispatchEvent(input, "change"); - - expect(form.valid).toEqual(false); - async.done(); - }); - })); - }); - - describe("nested forms", () => { - it("should init DOM with the given form object", - inject([TestBed, AsyncTestCompleter], (tb, async) => { - var form = new ControlGroup({ - "nested": new ControlGroup({ - "login": new Control("value") - }) - }); - var ctx = new MyComp(form); - - var t = `
`; - tb.createView(MyComp, {context: ctx, html: t}).then((view) => { - view.detectChanges(); - var input = view.querySelector("input") - expect(input.value).toEqual("value"); - async.done(); - }); - })); + tb.createView(MyComp, {context: ctx, html: t}).then((view) => { + view.detectChanges(); + var input = view.querySelector("input") - it("should update the control group values on DOM change", - inject([TestBed, AsyncTestCompleter], (tb, async) => { - var form = new ControlGroup({ - "nested": new ControlGroup({ - "login": new Control("value") - }) - }); - var ctx = new MyComp(form); + input.value = "updatedValue"; + dispatchEvent(input, "change"); - var t = `
-
- -
-
`; - - tb.createView(MyComp, {context: ctx, html: t}).then((view) => { - view.detectChanges(); - var input = view.querySelector("input") - - input.value = "updatedValue"; - dispatchEvent(input, "change"); - - expect(form.value).toEqual({"nested": {"login": "updatedValue"}}); - async.done(); - }); - })); - }); - } + expect(form.value).toEqual({"nested": {"login": "updatedValue"}}); + async.done(); + }); + })); + }); }); } diff --git a/modules/angular2/test/render/dom/events/event_manager_spec.js b/modules/angular2/test/render/dom/events/event_manager_spec.js index b57fb6caa1..3d335d7cc5 100644 --- a/modules/angular2/test/render/dom/events/event_manager_spec.js +++ b/modules/angular2/test/render/dom/events/event_manager_spec.js @@ -2,7 +2,6 @@ import {describe, ddescribe, it, iit, xit, xdescribe, expect, beforeEach, el} fr import {EventManager, EventManagerPlugin, DomEventsPlugin} from 'angular2/src/render/dom/events/event_manager'; import {VmTurnZone} from 'angular2/src/core/zone/vm_turn_zone'; import {List, ListWrapper, Map, MapWrapper} from 'angular2/src/facade/collection'; -import {document} from 'angular2/src/facade/browser'; import {DOM} from 'angular2/src/dom/dom_adapter'; export function main() { @@ -71,7 +70,7 @@ export function main() { it('bubbled events are caught when fired from a child', () => { var element = el('
'); // Workaround for https://bugs.webkit.org/show_bug.cgi?id=122755 - DOM.appendChild(document.body, element); + DOM.appendChild(DOM.defaultDoc().body, element); var child = DOM.firstChild(element); var dispatchedEvent = DOM.createMouseEvent('click'); @@ -86,7 +85,7 @@ export function main() { it('should add and remove global event listeners with correct bubbling', () => { var element = el('
'); - DOM.appendChild(document.body, element); + DOM.appendChild(DOM.defaultDoc().body, element); var dispatchedEvent = DOM.createMouseEvent('click'); var receivedEvent = null; var handler = (e) => { receivedEvent = e; };