import { AsyncTestCompleter, beforeEach, ddescribe, xdescribe, describe, dispatchEvent, expect, iit, inject, IS_DARTIUM, beforeEachBindings, it, xit, TestComponentBuilder, By, Scope } from 'angular2/test_lib'; import {DOM} from 'angular2/src/dom/dom_adapter'; import {List, ListWrapper} from 'angular2/src/facade/collection'; import {PromiseWrapper, EventEmitter, ObservableWrapper} from 'angular2/src/facade/async'; import {Injectable} from 'angular2/di'; import { Directive, Component, View, } from 'angular2/annotations'; import {NgFor} from 'angular2/src/directives/ng_for'; @Injectable() class Logger { log: List; constructor() { this.log = []; } add(thing: string) { this.log.push(thing); } } @Directive({selector: '[message]', properties: ['message']}) @Injectable() class MessageDir { logger: Logger; constructor(logger: Logger) { this.logger = logger; } set message(newMessage) { this.logger.add(newMessage); } } @Component({selector: 'child-comp'}) @View({ template: `
Child
{{childBinding}}`, directives: [MessageDir] }) @Injectable() class ChildComp { childBinding: string; constructor() { this.childBinding = 'Original'; } } @Component({selector: 'parent-comp', appInjector: [Logger]}) @View({ template: `
Parent
{{parentBinding}} `, directives: [ChildComp, MessageDir] }) @Injectable() class ParentComp { parentBinding: string; constructor() { this.parentBinding = 'OriginalParent'; } } @Directive({selector: 'custom-emitter', events: ['myevent']}) @Injectable() class CustomEmitter { myevent: EventEmitter; constructor() { this.myevent = new EventEmitter(); } } @Component({selector: 'events-comp'}) @View({ template: ` `, directives: [CustomEmitter] }) @Injectable() class EventsComp { clicked: boolean; customed: boolean; constructor() { this.clicked = false; this.customed = false; } handleClick() { this.clicked = true; } handleCustom() { this.customed = true; } } @Component({selector: 'using-for', appInjector: [Logger]}) @View({ template: `{{thing}} `, directives: [NgFor, MessageDir] }) @Injectable() class UsingFor { stuff: List; constructor() { this.stuff = ['one', 'two', 'three']; } } export function main() { describe('debug element', function() { it('should list component child elements', inject([TestComponentBuilder, AsyncTestCompleter], (tcb, async) => { tcb.createAsync(ParentComp) .then((rootTestComponent) => { rootTestComponent.detectChanges(); var childEls = rootTestComponent.children; // The root is a lone component, and has no children in the light dom. expect(childEls.length).toEqual(0); var rootCompChildren = rootTestComponent.componentViewChildren; // The root component has 3 elements in its shadow view. expect(rootCompChildren.length).toEqual(3); expect(DOM.hasClass(rootCompChildren[0].domElement, 'parent')).toBe(true); expect(DOM.hasClass(rootCompChildren[1].domElement, 'parent')).toBe(true); expect(DOM.hasClass(rootCompChildren[2].domElement, 'child-comp-class')).toBe(true); var nested = rootCompChildren[0].children; expect(nested.length).toEqual(1); expect(DOM.hasClass(nested[0].domElement, 'parentnested')).toBe(true); var childComponent = rootCompChildren[2]; expect(childComponent.children.length).toEqual(0); var childCompChildren = childComponent.componentViewChildren; expect(childCompChildren.length).toEqual(2); expect(DOM.hasClass(childCompChildren[0].domElement, 'child')).toBe(true); expect(DOM.hasClass(childCompChildren[1].domElement, 'child')).toBe(true); var childNested = childCompChildren[0].children; expect(childNested.length).toEqual(1); expect(DOM.hasClass(childNested[0].domElement, 'childnested')).toBe(true); async.done(); }); })); it('should list child elements within viewports', inject([TestComponentBuilder, AsyncTestCompleter], (tcb, async) => { tcb.createAsync(UsingFor).then((rootTestComponent) => { rootTestComponent.detectChanges(); var childEls = rootTestComponent.componentViewChildren; // TODO should this count include the