import { AsyncTestCompleter, beforeEach, ddescribe, xdescribe, describe, el, dispatchEvent, expect, iit, inject, IS_DARTIUM, beforeEachBindings, it, xit, containsRegexp, stringifyElement, TestComponentBuilder } from 'angular2/test_lib'; import {DOM} from 'angular2/src/dom/dom_adapter'; import { Type, isPresent, BaseException, assertionsEnabled, isJsObject, global, stringify, CONST, CONST_EXPR } from 'angular2/src/facade/lang'; import {PromiseWrapper, EventEmitter, ObservableWrapper} from 'angular2/src/facade/async'; import { Injector, bind, Injectable, Binding, forwardRef, OpaqueToken, Inject, Parent, Ancestor, Unbounded, UnboundedMetadata } from 'angular2/di'; import { PipeFactory, Pipes, defaultPipes, ChangeDetection, DynamicChangeDetection, Pipe, ChangeDetectorRef, ON_PUSH } from 'angular2/change_detection'; import {Directive, Component, View, Attribute, Query} from 'angular2/annotations'; import * as viewAnn from 'angular2/src/core/annotations_impl/view'; import {QueryList} from 'angular2/src/core/compiler/query_list'; import {NgIf} from 'angular2/src/directives/ng_if'; import {NgFor} from 'angular2/src/directives/ng_for'; import {ViewContainerRef} from 'angular2/src/core/compiler/view_container_ref'; import {ProtoViewRef, ViewRef} from 'angular2/src/core/compiler/view_ref'; import {Compiler} from 'angular2/src/core/compiler/compiler'; import {ElementRef} from 'angular2/src/core/compiler/element_ref'; import {DomRenderer} from 'angular2/src/render/dom/dom_renderer'; import {AppViewManager} from 'angular2/src/core/compiler/view_manager'; const ANCHOR_ELEMENT = CONST_EXPR(new OpaqueToken('AnchorElement')); export function main() { describe('integration tests', function() { beforeEachBindings(() => [bind(ANCHOR_ELEMENT).toValue(el('
'))]); describe('react to record changes', function() { it('should consume text node changes', inject([TestComponentBuilder, AsyncTestCompleter], (tcb: TestComponentBuilder, async) => { tcb.overrideView(MyComp, new viewAnn.View({template: '
Component with an injected parent
', directives: [SomeDirective]}) @Injectable() class CompWithParent { myParent: SomeDirective; constructor(@Parent() someComp: SomeDirective) { this.myParent = someComp; } } @Component({selector: 'cmp-with-ancestor'}) @View({template: 'Component with an injected ancestor
', directives: [SomeDirective]}) @Injectable() class CompWithAncestor { myAncestor: SomeDirective; constructor(@Ancestor() someComp: SomeDirective) { this.myAncestor = someComp; } } @Component({selector: '[child-cmp2]', viewInjector: [MyService]}) @Injectable() class ChildComp2 { ctxProp: string; dirProp: string; constructor(service: MyService) { this.ctxProp = service.greeting; this.dirProp = null; } } @Directive({selector: '[some-viewport]'}) @Injectable() class SomeViewport { constructor(container: ViewContainerRef, protoView: ProtoViewRef) { container.create(protoView).setLocal('some-tmpl', 'hello'); container.create(protoView).setLocal('some-tmpl', 'again'); } } @Injectable() class DoublePipe implements Pipe { onDestroy() {} supports(obj) { return true; } transform(value, args = null) { return `${value}${value}`; } } @Injectable() class DoublePipeFactory implements PipeFactory { supports(obj) { return true; } create(cdRef) { return new DoublePipe(); } } @Directive({selector: '[emitter]', events: ['event']}) @Injectable() class DirectiveEmitingEvent { msg: string; event: EventEmitter; constructor() { this.msg = ''; this.event = new EventEmitter(); } fireEvent(msg: string) { ObservableWrapper.callNext(this.event, msg); } } @Directive({selector: '[update-host-attributes]', host: {'role': 'button'}}) @Injectable() class DirectiveUpdatingHostAttributes { } @Directive({selector: '[update-host-properties]', host: {'[id]': 'id'}}) @Injectable() class DirectiveUpdatingHostProperties { id: string; constructor() { this.id = "one"; } } @Directive({selector: '[update-host-actions]', host: {'@setAttr': 'setAttribute'}}) @Injectable() class DirectiveUpdatingHostActions { setAttr: EventEmitter; constructor() { this.setAttr = new EventEmitter(); } triggerSetAttr(attrValue) { ObservableWrapper.callNext(this.setAttr, ["key", attrValue]); } } @Directive({selector: '[listener]', host: {'(event)': 'onEvent($event)'}}) @Injectable() class DirectiveListeningEvent { msg: string; constructor() { this.msg = ''; } onEvent(msg: string) { this.msg = msg; } } @Directive({ selector: '[listener]', host: { '(domEvent)': 'onEvent($event.type)', '(window:domEvent)': 'onWindowEvent($event.type)', '(document:domEvent)': 'onDocumentEvent($event.type)', '(body:domEvent)': 'onBodyEvent($event.type)' } }) @Injectable() class DirectiveListeningDomEvent { eventType: string; constructor() { this.eventType = ''; } onEvent(eventType: string) { this.eventType = eventType; } onWindowEvent(eventType: string) { this.eventType = "window_" + eventType; } onDocumentEvent(eventType: string) { this.eventType = "document_" + eventType; } onBodyEvent(eventType: string) { this.eventType = "body_" + eventType; } } var globalCounter = 0; @Directive({selector: '[listenerother]', host: {'(window:domEvent)': 'onEvent($event.type)'}}) @Injectable() class DirectiveListeningDomEventOther { eventType: string; counter: int; constructor() { this.eventType = ''; } onEvent(eventType: string) { globalCounter++; this.eventType = "other_" + eventType; } } @Directive({selector: '[listenerprevent]', host: {'(click)': 'onEvent($event)'}}) @Injectable() class DirectiveListeningDomEventPrevent { onEvent(event) { return false; } } @Directive({selector: '[listenernoprevent]', host: {'(click)': 'onEvent($event)'}}) @Injectable() class DirectiveListeningDomEventNoPrevent { onEvent(event) { return true; } } @Directive({selector: '[id]', properties: ['id']}) @Injectable() class IdDir { id: string; } @Directive({selector: '[static]'}) @Injectable() class NeedsAttribute { typeAttribute; titleAttribute; fooAttribute; constructor(@Attribute('type') typeAttribute: String, @Attribute('title') titleAttribute: String, @Attribute('foo') fooAttribute: String) { this.typeAttribute = typeAttribute; this.titleAttribute = titleAttribute; this.fooAttribute = fooAttribute; } } @Directive({selector: '[public-api]'}) @Injectable() class PublicApi { } @Directive({selector: '[private-impl]'}) @Injectable() class PrivateImpl extends PublicApi { } @Directive({selector: '[needs-public-api]'}) @Injectable() class NeedsPublicApi { constructor(@Parent() api: PublicApi) { expect(api instanceof PrivateImpl).toBe(true); } } @Directive({selector: '[toolbarpart]'}) @Injectable() class ToolbarPart { protoViewRef: ProtoViewRef; elementRef: ElementRef; constructor(protoViewRef: ProtoViewRef, elementRef: ElementRef) { this.elementRef = elementRef; this.protoViewRef = protoViewRef; } } @Directive({selector: '[toolbar-vc]', properties: ['toolbarVc']}) @Injectable() class ToolbarViewContainer { vc: ViewContainerRef; constructor(vc: ViewContainerRef) { this.vc = vc; } set toolbarVc(part: ToolbarPart) { var view = this.vc.create(part.protoViewRef, 0, part.elementRef); view.setLocal('toolbarProp', 'From toolbar'); } } @Component({selector: 'toolbar'}) @View({ template: 'TOOLBAR()', directives: [ToolbarViewContainer, NgFor] }) @Injectable() class ToolbarComponent { query: QueryList