2014-11-12 14:40:36 -05:00
|
|
|
import {describe, xit, it, expect, beforeEach, ddescribe, iit} from 'test_lib/test_lib';
|
2014-10-28 02:16:31 -04:00
|
|
|
import {ProtoView, ElementPropertyMemento, DirectivePropertyMemento} from 'core/compiler/view';
|
2014-10-10 23:44:55 -04:00
|
|
|
import {ProtoElementInjector, ElementInjector} from 'core/compiler/element_injector';
|
2014-11-20 15:07:48 -05:00
|
|
|
import {DirectiveMetadataReader} from 'core/compiler/directive_metadata_reader';
|
2014-11-21 18:13:01 -05:00
|
|
|
import {Component, Decorator, Template} from 'core/annotations/annotations';
|
2014-11-19 18:52:01 -05:00
|
|
|
import {ProtoRecordRange} from 'change_detection/record_range';
|
2014-10-29 18:41:50 -04:00
|
|
|
import {ChangeDetector} from 'change_detection/change_detector';
|
2014-11-12 14:40:36 -05:00
|
|
|
import {TemplateConfig} from 'core/annotations/template_config';
|
2014-11-11 20:33:47 -05:00
|
|
|
import {Parser} from 'change_detection/parser/parser';
|
|
|
|
import {Lexer} from 'change_detection/parser/lexer';
|
2014-10-10 23:44:55 -04:00
|
|
|
import {DOM, Element} from 'facade/dom';
|
2014-10-28 02:16:31 -04:00
|
|
|
import {FIELD} from 'facade/lang';
|
2014-11-12 14:40:36 -05:00
|
|
|
import {Injector} from 'di/di';
|
|
|
|
import {View} from 'core/compiler/view';
|
2014-11-21 18:13:01 -05:00
|
|
|
import {ViewPort} from 'core/compiler/viewport';
|
2014-11-20 15:07:48 -05:00
|
|
|
import {reflector} from 'reflection/reflection';
|
2014-09-28 23:02:32 -04:00
|
|
|
|
|
|
|
export function main() {
|
2014-09-28 16:55:01 -04:00
|
|
|
describe('view', function() {
|
2014-11-21 18:13:01 -05:00
|
|
|
var parser, someComponentDirective, someTemplateDirective;
|
2014-10-28 02:16:31 -04:00
|
|
|
|
2014-11-07 17:30:04 -05:00
|
|
|
beforeEach(() => {
|
2014-11-20 15:07:48 -05:00
|
|
|
parser = new Parser(new Lexer());
|
|
|
|
someComponentDirective = new DirectiveMetadataReader().annotatedType(SomeComponent);
|
2014-11-21 18:13:01 -05:00
|
|
|
someTemplateDirective = new DirectiveMetadataReader().annotatedType(SomeTemplate);
|
2014-11-11 20:33:47 -05:00
|
|
|
});
|
2014-10-30 17:41:19 -04:00
|
|
|
|
2014-11-07 17:30:04 -05:00
|
|
|
|
2014-11-11 20:33:47 -05:00
|
|
|
describe('ProtoView.instantiate', function() {
|
2014-10-30 17:41:19 -04:00
|
|
|
|
2014-11-12 14:40:36 -05:00
|
|
|
function createCollectDomNodesTestCases(useTemplateElement:boolean) {
|
2014-10-29 18:41:50 -04:00
|
|
|
|
2014-11-12 14:40:36 -05:00
|
|
|
function templateAwareCreateElement(html) {
|
|
|
|
return createElement(useTemplateElement ? `<template>${html}</template>` : html);
|
|
|
|
}
|
|
|
|
|
|
|
|
it('should collect the root node in the ProtoView element', () => {
|
2014-11-19 18:52:01 -05:00
|
|
|
var pv = new ProtoView(templateAwareCreateElement('<div id="1"></div>'), new ProtoRecordRange());
|
2014-11-12 14:40:36 -05:00
|
|
|
var view = pv.instantiate(null, null, null);
|
2014-11-11 21:36:44 -05:00
|
|
|
expect(view.nodes.length).toBe(1);
|
|
|
|
expect(view.nodes[0].getAttribute('id')).toEqual('1');
|
|
|
|
});
|
2014-10-27 11:47:13 -04:00
|
|
|
|
2014-11-12 14:40:36 -05:00
|
|
|
describe('collect elements with property bindings', () => {
|
|
|
|
|
|
|
|
it('should collect property bindings on the root element if it has the ng-binding class', () => {
|
2014-11-19 18:52:01 -05:00
|
|
|
var pv = new ProtoView(templateAwareCreateElement('<div [prop]="a" class="ng-binding"></div>'), new ProtoRecordRange());
|
2014-11-12 14:40:36 -05:00
|
|
|
pv.bindElement(null);
|
2014-11-18 19:38:36 -05:00
|
|
|
pv.bindElementProperty('prop', parser.parseBinding('a').ast);
|
2014-11-12 14:40:36 -05:00
|
|
|
|
|
|
|
var view = pv.instantiate(null, null, null);
|
|
|
|
expect(view.bindElements.length).toEqual(1);
|
|
|
|
expect(view.bindElements[0]).toBe(view.nodes[0]);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should collect property bindings on child elements with ng-binding class', () => {
|
|
|
|
var pv = new ProtoView(templateAwareCreateElement('<div><span></span><span class="ng-binding"></span></div>'),
|
2014-11-19 18:52:01 -05:00
|
|
|
new ProtoRecordRange());
|
2014-11-12 14:40:36 -05:00
|
|
|
pv.bindElement(null);
|
2014-11-18 19:38:36 -05:00
|
|
|
pv.bindElementProperty('a', parser.parseBinding('b').ast);
|
2014-11-12 14:40:36 -05:00
|
|
|
|
|
|
|
var view = pv.instantiate(null, null, null);
|
|
|
|
expect(view.bindElements.length).toEqual(1);
|
|
|
|
expect(view.bindElements[0]).toBe(view.nodes[0].childNodes[1]);
|
|
|
|
});
|
|
|
|
|
2014-11-11 20:33:47 -05:00
|
|
|
});
|
2014-10-27 11:47:13 -04:00
|
|
|
|
2014-11-12 14:40:36 -05:00
|
|
|
describe('collect text nodes with bindings', () => {
|
2014-11-11 20:33:47 -05:00
|
|
|
|
2014-11-12 14:40:36 -05:00
|
|
|
it('should collect text nodes under the root element', () => {
|
2014-11-19 18:52:01 -05:00
|
|
|
var pv = new ProtoView(templateAwareCreateElement('<div class="ng-binding">{{}}<span></span>{{}}</div>'), new ProtoRecordRange());
|
2014-11-12 14:40:36 -05:00
|
|
|
pv.bindElement(null);
|
2014-11-18 19:38:36 -05:00
|
|
|
pv.bindTextNode(0, parser.parseBinding('a').ast);
|
|
|
|
pv.bindTextNode(2, parser.parseBinding('b').ast);
|
2014-10-27 11:47:13 -04:00
|
|
|
|
2014-11-12 14:40:36 -05:00
|
|
|
var view = pv.instantiate(null, null, null);
|
|
|
|
expect(view.textNodes.length).toEqual(2);
|
|
|
|
expect(view.textNodes[0]).toBe(view.nodes[0].childNodes[0]);
|
|
|
|
expect(view.textNodes[1]).toBe(view.nodes[0].childNodes[2]);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should collect text nodes with bindings on child elements with ng-binding class', () => {
|
|
|
|
var pv = new ProtoView(templateAwareCreateElement('<div><span> </span><span class="ng-binding">{{}}</span></div>'),
|
2014-11-19 18:52:01 -05:00
|
|
|
new ProtoRecordRange());
|
2014-11-12 14:40:36 -05:00
|
|
|
pv.bindElement(null);
|
2014-11-18 19:38:36 -05:00
|
|
|
pv.bindTextNode(0, parser.parseBinding('b').ast);
|
2014-11-12 14:40:36 -05:00
|
|
|
|
|
|
|
var view = pv.instantiate(null, null, null);
|
|
|
|
expect(view.textNodes.length).toEqual(1);
|
|
|
|
expect(view.textNodes[0]).toBe(view.nodes[0].childNodes[1].childNodes[0]);
|
|
|
|
});
|
2014-10-27 11:47:13 -04:00
|
|
|
|
2014-11-11 21:36:44 -05:00
|
|
|
});
|
2014-11-12 14:40:36 -05:00
|
|
|
}
|
2014-10-27 11:47:13 -04:00
|
|
|
|
2014-11-07 17:30:04 -05:00
|
|
|
describe('inplace instantiation', () => {
|
|
|
|
it('should be supported.', () => {
|
|
|
|
var template = createElement('<div></div>')
|
2014-11-19 18:52:01 -05:00
|
|
|
var view = new ProtoView(template, new ProtoRecordRange())
|
2014-11-07 17:30:04 -05:00
|
|
|
.instantiate(null, null, null, true);
|
|
|
|
expect(view.nodes[0]).toBe(template);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should be off by default.', () => {
|
|
|
|
var template = createElement('<div></div>')
|
2014-11-19 18:52:01 -05:00
|
|
|
var view = new ProtoView(template, new ProtoRecordRange())
|
2014-11-07 17:30:04 -05:00
|
|
|
.instantiate(null, null, null);
|
|
|
|
expect(view.nodes[0]).not.toBe(template);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2014-11-12 14:40:36 -05:00
|
|
|
describe('collect dom nodes with a regular element as root', () => {
|
|
|
|
createCollectDomNodesTestCases(false);
|
|
|
|
});
|
2014-11-11 20:33:47 -05:00
|
|
|
|
2014-11-12 14:40:36 -05:00
|
|
|
describe('collect dom nodes with a template element as root', () => {
|
|
|
|
createCollectDomNodesTestCases(true);
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('create ElementInjectors', () => {
|
|
|
|
it('should use the directives of the ProtoElementInjector', () => {
|
2014-11-19 18:52:01 -05:00
|
|
|
var pv = new ProtoView(createElement('<div class="ng-binding"></div>'), new ProtoRecordRange());
|
2014-11-12 14:40:36 -05:00
|
|
|
pv.bindElement(new ProtoElementInjector(null, 1, [SomeDirective]));
|
|
|
|
|
|
|
|
var view = pv.instantiate(null, null, null);
|
|
|
|
expect(view.elementInjectors.length).toBe(1);
|
|
|
|
expect(view.elementInjectors[0].get(SomeDirective) instanceof SomeDirective).toBe(true);
|
2014-11-11 20:33:47 -05:00
|
|
|
});
|
2014-10-27 11:47:13 -04:00
|
|
|
|
2014-11-12 14:40:36 -05:00
|
|
|
it('should use the correct parent', () => {
|
|
|
|
var pv = new ProtoView(createElement('<div class="ng-binding"><span class="ng-binding"></span></div>'),
|
2014-11-19 18:52:01 -05:00
|
|
|
new ProtoRecordRange());
|
2014-11-12 14:40:36 -05:00
|
|
|
var protoParent = new ProtoElementInjector(null, 0, [SomeDirective]);
|
|
|
|
pv.bindElement(protoParent);
|
|
|
|
pv.bindElement(new ProtoElementInjector(protoParent, 1, [AnotherDirective]));
|
|
|
|
|
|
|
|
var view = pv.instantiate(null, null, null);
|
|
|
|
expect(view.elementInjectors.length).toBe(2);
|
|
|
|
expect(view.elementInjectors[0].get(SomeDirective) instanceof SomeDirective).toBe(true);
|
|
|
|
expect(view.elementInjectors[1].parent).toBe(view.elementInjectors[0]);
|
|
|
|
});
|
2014-11-11 21:36:44 -05:00
|
|
|
});
|
2014-10-27 11:47:13 -04:00
|
|
|
|
2014-11-12 14:40:36 -05:00
|
|
|
describe('collect root element injectors', () => {
|
2014-11-11 20:33:47 -05:00
|
|
|
|
2014-11-12 14:40:36 -05:00
|
|
|
it('should collect a single root element injector', () => {
|
|
|
|
var pv = new ProtoView(createElement('<div class="ng-binding"><span class="ng-binding"></span></div>'),
|
2014-11-19 18:52:01 -05:00
|
|
|
new ProtoRecordRange());
|
2014-11-12 14:40:36 -05:00
|
|
|
var protoParent = new ProtoElementInjector(null, 0, [SomeDirective]);
|
|
|
|
pv.bindElement(protoParent);
|
|
|
|
pv.bindElement(new ProtoElementInjector(protoParent, 1, [AnotherDirective]));
|
2014-10-27 11:47:13 -04:00
|
|
|
|
2014-11-12 14:40:36 -05:00
|
|
|
var view = pv.instantiate(null, null, null);
|
|
|
|
expect(view.rootElementInjectors.length).toBe(1);
|
|
|
|
expect(view.rootElementInjectors[0].get(SomeDirective) instanceof SomeDirective).toBe(true);
|
2014-11-11 21:36:44 -05:00
|
|
|
});
|
2014-10-27 11:47:13 -04:00
|
|
|
|
2014-11-12 14:40:36 -05:00
|
|
|
it('should collect multiple root element injectors', () => {
|
|
|
|
var pv = new ProtoView(createElement('<div><span class="ng-binding"></span><span class="ng-binding"></span></div>'),
|
2014-11-19 18:52:01 -05:00
|
|
|
new ProtoRecordRange());
|
2014-11-12 14:40:36 -05:00
|
|
|
pv.bindElement(new ProtoElementInjector(null, 1, [SomeDirective]));
|
|
|
|
pv.bindElement(new ProtoElementInjector(null, 2, [AnotherDirective]));
|
2014-11-11 20:33:47 -05:00
|
|
|
|
2014-11-12 14:40:36 -05:00
|
|
|
var view = pv.instantiate(null, null, null);
|
|
|
|
expect(view.rootElementInjectors.length).toBe(2)
|
|
|
|
expect(view.rootElementInjectors[0].get(SomeDirective) instanceof SomeDirective).toBe(true);
|
|
|
|
expect(view.rootElementInjectors[1].get(AnotherDirective) instanceof AnotherDirective).toBe(true);
|
2014-11-11 20:33:47 -05:00
|
|
|
});
|
2014-10-27 11:47:13 -04:00
|
|
|
|
2014-10-10 23:44:55 -04:00
|
|
|
});
|
2014-10-28 02:16:31 -04:00
|
|
|
|
2014-11-12 14:40:36 -05:00
|
|
|
describe('recurse over child component views', () => {
|
2014-12-01 13:19:07 -05:00
|
|
|
var ctx;
|
2014-11-11 21:36:44 -05:00
|
|
|
|
2014-11-12 14:40:36 -05:00
|
|
|
function createComponentWithSubPV(subProtoView) {
|
2014-11-19 18:52:01 -05:00
|
|
|
var pv = new ProtoView(createElement('<cmp class="ng-binding"></cmp>'), new ProtoRecordRange());
|
2014-11-12 14:40:36 -05:00
|
|
|
var binder = pv.bindElement(new ProtoElementInjector(null, 0, [SomeComponent], true));
|
2014-11-18 19:38:36 -05:00
|
|
|
binder.componentDirective = someComponentDirective;
|
2014-11-12 14:40:36 -05:00
|
|
|
binder.nestedProtoView = subProtoView;
|
|
|
|
return pv;
|
|
|
|
}
|
|
|
|
|
|
|
|
function createNestedView(protoView) {
|
2014-11-11 21:36:44 -05:00
|
|
|
ctx = new MyEvaluationContext();
|
2014-11-12 14:40:36 -05:00
|
|
|
return protoView.instantiate(ctx, new Injector([]), null);
|
2014-11-11 21:36:44 -05:00
|
|
|
}
|
2014-10-28 02:16:31 -04:00
|
|
|
|
2014-11-12 14:40:36 -05:00
|
|
|
it('should create shadow dom', () => {
|
2014-11-19 18:52:01 -05:00
|
|
|
var subpv = new ProtoView(createElement('<span>hello shadow dom</span>'), new ProtoRecordRange());
|
2014-11-12 14:40:36 -05:00
|
|
|
var pv = createComponentWithSubPV(subpv);
|
2014-11-11 21:36:44 -05:00
|
|
|
|
2014-11-12 14:40:36 -05:00
|
|
|
var view = createNestedView(pv);
|
|
|
|
|
|
|
|
expect(view.nodes[0].shadowRoot.childNodes[0].childNodes[0].nodeValue).toEqual('hello shadow dom');
|
2014-10-28 02:16:31 -04:00
|
|
|
});
|
|
|
|
|
2014-11-12 14:40:36 -05:00
|
|
|
it('should expose component services to the component', () => {
|
2014-11-19 18:52:01 -05:00
|
|
|
var subpv = new ProtoView(createElement('<span></span>'), new ProtoRecordRange());
|
2014-11-12 14:40:36 -05:00
|
|
|
var pv = createComponentWithSubPV(subpv);
|
2014-11-11 21:36:44 -05:00
|
|
|
|
2014-11-12 14:40:36 -05:00
|
|
|
var view = createNestedView(pv);
|
|
|
|
|
|
|
|
var comp = view.rootElementInjectors[0].get(SomeComponent);
|
|
|
|
expect(comp.service).toBeAnInstanceOf(SomeService);
|
2014-10-28 02:16:31 -04:00
|
|
|
});
|
|
|
|
|
2014-11-12 14:40:36 -05:00
|
|
|
it('should expose component services and component instance to directives in the shadow Dom',
|
|
|
|
() => {
|
|
|
|
var subpv = new ProtoView(
|
2014-11-19 18:52:01 -05:00
|
|
|
createElement('<div dec class="ng-binding">hello shadow dom</div>'), new ProtoRecordRange());
|
2014-12-01 13:19:07 -05:00
|
|
|
subpv.bindElement(
|
2014-11-12 14:40:36 -05:00
|
|
|
new ProtoElementInjector(null, 0, [ServiceDependentDecorator]));
|
|
|
|
var pv = createComponentWithSubPV(subpv);
|
2014-11-11 20:33:47 -05:00
|
|
|
|
2014-11-12 14:40:36 -05:00
|
|
|
var view = createNestedView(pv);
|
|
|
|
|
2014-11-21 18:13:01 -05:00
|
|
|
var subView = view.componentChildViews[0];
|
2014-11-12 14:40:36 -05:00
|
|
|
var subInj = subView.rootElementInjectors[0];
|
|
|
|
var subDecorator = subInj.get(ServiceDependentDecorator);
|
|
|
|
var comp = view.rootElementInjectors[0].get(SomeComponent);
|
|
|
|
|
|
|
|
expect(subDecorator).toBeAnInstanceOf(ServiceDependentDecorator);
|
|
|
|
expect(subDecorator.service).toBe(comp.service);
|
|
|
|
expect(subDecorator.component).toBe(comp);
|
2014-11-11 21:36:44 -05:00
|
|
|
});
|
2014-10-28 02:16:31 -04:00
|
|
|
});
|
2014-10-29 18:41:50 -04:00
|
|
|
|
2014-11-21 18:13:01 -05:00
|
|
|
describe('recurse over child templateViews', () => {
|
2014-12-01 13:19:07 -05:00
|
|
|
var ctx, view;
|
2014-11-21 18:13:01 -05:00
|
|
|
function createView(protoView) {
|
|
|
|
ctx = new MyEvaluationContext();
|
|
|
|
view = protoView.instantiate(ctx, null, null);
|
|
|
|
}
|
|
|
|
|
|
|
|
it('should create a viewPort for the template directive', () => {
|
|
|
|
var templateProtoView = new ProtoView(
|
|
|
|
createElement('<div id="1"></div>'), new ProtoRecordRange());
|
|
|
|
var pv = new ProtoView(createElement('<someTmpl class="ng-binding"></someTmpl>'), new ProtoRecordRange());
|
|
|
|
var binder = pv.bindElement(new ProtoElementInjector(null, 0, [SomeTemplate]));
|
|
|
|
binder.templateDirective = someTemplateDirective;
|
|
|
|
binder.nestedProtoView = templateProtoView;
|
|
|
|
|
|
|
|
createView(pv);
|
|
|
|
|
|
|
|
var tmplComp = view.rootElementInjectors[0].get(SomeTemplate);
|
|
|
|
expect(tmplComp.viewPort).not.toBe(null);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2014-11-19 18:52:01 -05:00
|
|
|
describe('react to record changes', () => {
|
2014-10-29 18:41:50 -04:00
|
|
|
var view, cd, ctx;
|
|
|
|
|
2014-11-11 21:36:44 -05:00
|
|
|
function createView(protoView) {
|
2014-10-29 18:41:50 -04:00
|
|
|
ctx = new MyEvaluationContext();
|
2014-11-12 14:40:36 -05:00
|
|
|
view = protoView.instantiate(ctx, null, null);
|
2014-11-19 18:52:01 -05:00
|
|
|
cd = new ChangeDetector(view.recordRange);
|
2014-10-29 18:41:50 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
it('should consume text node changes', () => {
|
2014-11-11 20:33:47 -05:00
|
|
|
var pv = new ProtoView(createElement('<div class="ng-binding">{{}}</div>'),
|
2014-11-19 18:52:01 -05:00
|
|
|
new ProtoRecordRange());
|
2014-11-11 20:33:47 -05:00
|
|
|
pv.bindElement(null);
|
2014-11-18 19:38:36 -05:00
|
|
|
pv.bindTextNode(0, parser.parseBinding('foo').ast);
|
2014-11-11 20:33:47 -05:00
|
|
|
createView(pv);
|
2014-10-29 18:41:50 -04:00
|
|
|
|
|
|
|
ctx.foo = 'buz';
|
|
|
|
cd.detectChanges();
|
|
|
|
expect(view.textNodes[0].nodeValue).toEqual('buz');
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should consume element binding changes', () => {
|
2014-11-11 20:33:47 -05:00
|
|
|
var pv = new ProtoView(createElement('<div class="ng-binding"></div>'),
|
2014-11-19 18:52:01 -05:00
|
|
|
new ProtoRecordRange());
|
2014-11-11 20:33:47 -05:00
|
|
|
pv.bindElement(null);
|
2014-11-18 19:38:36 -05:00
|
|
|
pv.bindElementProperty('id', parser.parseBinding('foo').ast);
|
2014-11-11 20:33:47 -05:00
|
|
|
createView(pv);
|
2014-10-29 18:41:50 -04:00
|
|
|
|
|
|
|
ctx.foo = 'buz';
|
|
|
|
cd.detectChanges();
|
2014-11-11 20:33:47 -05:00
|
|
|
expect(view.bindElements[0].id).toEqual('buz');
|
2014-10-29 18:41:50 -04:00
|
|
|
});
|
|
|
|
|
|
|
|
it('should consume directive watch expression change.', () => {
|
2014-11-11 20:33:47 -05:00
|
|
|
var pv = new ProtoView(createElement('<div class="ng-binding"></div>'),
|
2014-11-19 18:52:01 -05:00
|
|
|
new ProtoRecordRange());
|
2014-11-12 14:40:36 -05:00
|
|
|
pv.bindElement(new ProtoElementInjector(null, 0, [SomeDirective]));
|
2014-11-20 15:07:48 -05:00
|
|
|
pv.bindDirectiveProperty( 0, parser.parseBinding('foo').ast, 'prop', reflector.setter('prop'));
|
2014-11-11 20:33:47 -05:00
|
|
|
createView(pv);
|
2014-10-29 18:41:50 -04:00
|
|
|
|
|
|
|
ctx.foo = 'buz';
|
|
|
|
cd.detectChanges();
|
2014-11-12 14:40:36 -05:00
|
|
|
expect(view.elementInjectors[0].get(SomeDirective).prop).toEqual('buz');
|
2014-10-29 18:41:50 -04:00
|
|
|
});
|
|
|
|
});
|
2014-11-07 17:30:04 -05:00
|
|
|
});
|
|
|
|
|
|
|
|
describe('protoView createRootProtoView', () => {
|
|
|
|
var el, pv;
|
|
|
|
beforeEach(() => {
|
|
|
|
el = DOM.createElement('div');
|
2014-11-19 18:52:01 -05:00
|
|
|
pv = new ProtoView(createElement('<div>hi</div>'), new ProtoRecordRange());
|
2014-11-07 17:30:04 -05:00
|
|
|
});
|
2014-11-12 14:40:36 -05:00
|
|
|
|
2014-11-07 17:30:04 -05:00
|
|
|
it('should create the root component when instantiated', () => {
|
|
|
|
var rootProtoView = ProtoView.createRootProtoView(pv, el, someComponentDirective);
|
|
|
|
var view = rootProtoView.instantiate(null, new Injector([]), null, true);
|
|
|
|
expect(view.rootElementInjectors[0].get(SomeComponent)).not.toBe(null);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should inject the protoView into the shadowDom', () => {
|
|
|
|
var rootProtoView = ProtoView.createRootProtoView(pv, el, someComponentDirective);
|
2014-12-01 13:19:07 -05:00
|
|
|
rootProtoView.instantiate(null, new Injector([]), null, true);
|
2014-11-07 17:30:04 -05:00
|
|
|
expect(el.shadowRoot.childNodes[0].childNodes[0].nodeValue).toEqual('hi');
|
|
|
|
});
|
2014-09-28 23:02:32 -04:00
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
2014-10-29 18:41:50 -04:00
|
|
|
|
2014-11-12 14:40:36 -05:00
|
|
|
class SomeDirective {
|
2014-11-22 00:19:23 -05:00
|
|
|
prop;
|
2014-11-11 20:33:47 -05:00
|
|
|
constructor() {
|
|
|
|
this.prop = 'foo';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-11-12 14:40:36 -05:00
|
|
|
class SomeService {}
|
|
|
|
|
|
|
|
@Component({
|
|
|
|
componentServices: [SomeService]
|
|
|
|
})
|
|
|
|
class SomeComponent {
|
2014-11-22 00:19:23 -05:00
|
|
|
service: SomeService;
|
2014-11-12 14:40:36 -05:00
|
|
|
constructor(service: SomeService) {
|
|
|
|
this.service = service;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Decorator({
|
|
|
|
selector: '[dec]'
|
|
|
|
})
|
|
|
|
class ServiceDependentDecorator {
|
2014-11-22 00:19:23 -05:00
|
|
|
component: SomeComponent;
|
|
|
|
service: SomeService;
|
2014-11-12 14:40:36 -05:00
|
|
|
constructor(component: SomeComponent, service: SomeService) {
|
|
|
|
this.component = component;
|
|
|
|
this.service = service;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-11-21 18:13:01 -05:00
|
|
|
@Template({
|
|
|
|
selector: 'someTmpl'
|
|
|
|
})
|
|
|
|
class SomeTemplate {
|
|
|
|
viewPort: ViewPort;
|
|
|
|
constructor(viewPort: ViewPort) {
|
|
|
|
this.viewPort = viewPort;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-11-11 20:33:47 -05:00
|
|
|
class AnotherDirective {
|
2014-11-22 00:19:23 -05:00
|
|
|
prop:string;
|
2014-11-11 20:33:47 -05:00
|
|
|
constructor() {
|
|
|
|
this.prop = 'anotherFoo';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-10-29 18:41:50 -04:00
|
|
|
class MyEvaluationContext {
|
2014-11-22 00:19:23 -05:00
|
|
|
foo:string;
|
2014-10-29 18:41:50 -04:00
|
|
|
constructor() {
|
|
|
|
this.foo = 'bar';
|
|
|
|
};
|
|
|
|
}
|
2014-11-11 20:33:47 -05:00
|
|
|
|
|
|
|
function createElement(html) {
|
|
|
|
return DOM.createTemplate(html).content.firstChild;
|
|
|
|
}
|