chore(build): run event tests in Node

Closes #1476
This commit is contained in:
Marc Laval 2015-04-21 19:30:55 +02:00 committed by Misko Hevery
parent e70a2f21dd
commit 22c6c09daf
6 changed files with 443 additions and 405 deletions

View File

@ -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

View File

@ -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

View File

@ -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]'

View File

@ -545,7 +545,6 @@ export function main() {
});
}));
if (DOM.supportsDOMEvents()) {
it('should support render events', inject([TestBed, AsyncTestCompleter], (tb, async) => {
tb.overrideView(MyComp, new View({
template: '<div listener></div>',
@ -592,6 +591,7 @@ export function main() {
});
}));
if (DOM.supportsDOMEvents()) {
it('should support preventing default on render events', inject([TestBed, AsyncTestCompleter], (tb, async) => {
tb.overrideView(MyComp, new View({
template: '<input type="checkbox" listenerprevent></input><input type="checkbox" listenernoprevent></input>',
@ -608,6 +608,7 @@ export function main() {
async.done();
});
}));
}
it('should support render global events from multiple directives', inject([TestBed, AsyncTestCompleter], (tb, async) => {
tb.overrideView(MyComp, new View({
@ -642,7 +643,6 @@ export function main() {
async.done();
});
}));
}
describe('dynamic ViewContainers', () => {

View File

@ -20,13 +20,12 @@ 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({
@ -231,13 +230,17 @@ export function main() {
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();
});
}));
@ -362,7 +365,6 @@ export function main() {
});
}));
});
}
});
}

View File

@ -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('<div><div></div></div>');
// 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('<div><div></div></div>');
DOM.appendChild(document.body, element);
DOM.appendChild(DOM.defaultDoc().body, element);
var dispatchedEvent = DOM.createMouseEvent('click');
var receivedEvent = null;
var handler = (e) => { receivedEvent = e; };