2015-01-08 09:11:33 -08:00
|
|
|
import {describe, xit, it, expect, beforeEach, ddescribe, iit, el} from 'test_lib/test_lib';
|
2014-11-11 17:33:47 -08:00
|
|
|
|
|
|
|
import {DOM} from 'facade/dom';
|
|
|
|
|
2014-11-12 11:40:36 -08:00
|
|
|
import {Injector} from 'di/di';
|
2014-12-29 09:51:52 -08:00
|
|
|
import {Lexer, Parser, ChangeDetector} from 'change_detection/change_detection';
|
2014-11-11 17:33:47 -08:00
|
|
|
|
2014-12-02 13:21:39 -08:00
|
|
|
import {Compiler, CompilerCache} from 'core/compiler/compiler';
|
2014-11-20 12:07:48 -08:00
|
|
|
import {DirectiveMetadataReader} from 'core/compiler/directive_metadata_reader';
|
2015-01-02 14:23:59 -08:00
|
|
|
import {ShadowDomEmulated} from 'core/compiler/shadow_dom';
|
2014-11-11 17:33:47 -08:00
|
|
|
|
2014-12-01 15:26:53 -08:00
|
|
|
import {Decorator, Component, Template} from 'core/annotations/annotations';
|
2014-11-11 17:33:47 -08:00
|
|
|
import {TemplateConfig} from 'core/annotations/template_config';
|
|
|
|
|
2014-12-01 15:26:53 -08:00
|
|
|
import {ViewPort} from 'core/compiler/viewport';
|
2014-12-01 18:41:55 -08:00
|
|
|
import {MapWrapper} from 'facade/collection';
|
2014-12-01 15:26:53 -08:00
|
|
|
|
2014-11-11 17:33:47 -08:00
|
|
|
export function main() {
|
|
|
|
describe('integration tests', function() {
|
|
|
|
var compiler;
|
|
|
|
|
|
|
|
beforeEach( () => {
|
2014-12-02 13:21:39 -08:00
|
|
|
compiler = new Compiler(null, new DirectiveMetadataReader(), new Parser(new Lexer()), new CompilerCache());
|
2014-11-11 17:33:47 -08:00
|
|
|
});
|
|
|
|
|
2014-11-19 15:52:01 -08:00
|
|
|
describe('react to record changes', function() {
|
2014-11-11 17:33:47 -08:00
|
|
|
var view, ctx, cd;
|
|
|
|
function createView(pv) {
|
|
|
|
ctx = new MyComp();
|
2014-12-01 18:41:55 -08:00
|
|
|
view = pv.instantiate(null);
|
|
|
|
view.hydrate(new Injector([]), null, ctx);
|
2014-11-19 15:52:01 -08:00
|
|
|
cd = new ChangeDetector(view.recordRange);
|
2014-11-11 17:33:47 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
it('should consume text node changes', (done) => {
|
2015-01-08 09:11:33 -08:00
|
|
|
compiler.compile(MyComp, el('<div>{{ctxProp}}</div>')).then((pv) => {
|
2014-11-11 17:33:47 -08:00
|
|
|
createView(pv);
|
|
|
|
ctx.ctxProp = 'Hello World!';
|
|
|
|
|
|
|
|
cd.detectChanges();
|
|
|
|
expect(DOM.getInnerHTML(view.nodes[0])).toEqual('Hello World!');
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should consume element binding changes', (done) => {
|
2015-01-08 09:11:33 -08:00
|
|
|
compiler.compile(MyComp, el('<div [id]="ctxProp"></div>')).then((pv) => {
|
2014-11-11 17:33:47 -08:00
|
|
|
createView(pv);
|
|
|
|
|
|
|
|
ctx.ctxProp = 'Hello World!';
|
|
|
|
cd.detectChanges();
|
|
|
|
|
|
|
|
expect(view.nodes[0].id).toEqual('Hello World!');
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should consume directive watch expression change.', (done) => {
|
2015-01-08 09:11:33 -08:00
|
|
|
compiler.compile(MyComp, el('<div my-dir [elprop]="ctxProp"></div>')).then((pv) => {
|
2014-11-11 17:33:47 -08:00
|
|
|
createView(pv);
|
|
|
|
|
|
|
|
ctx.ctxProp = 'Hello World!';
|
|
|
|
cd.detectChanges();
|
|
|
|
|
|
|
|
var elInj = view.elementInjectors[0];
|
|
|
|
expect(elInj.get(MyDir).dirProp).toEqual('Hello World!');
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
2014-11-12 11:40:36 -08:00
|
|
|
|
|
|
|
it('should support nested components.', (done) => {
|
2015-01-08 09:11:33 -08:00
|
|
|
compiler.compile(MyComp, el('<child-cmp></child-cmp>')).then((pv) => {
|
2014-11-12 11:40:36 -08:00
|
|
|
createView(pv);
|
|
|
|
|
|
|
|
cd.detectChanges();
|
|
|
|
|
|
|
|
expect(view.nodes[0].shadowRoot.childNodes[0].nodeValue).toEqual('hello');
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
2014-12-01 15:26:53 -08:00
|
|
|
|
|
|
|
it('should support template directives via `<template>` elements.', (done) => {
|
2015-01-08 09:11:33 -08:00
|
|
|
compiler.compile(MyComp, el('<div><template let-some-tmpl="greeting"><copy-me>{{greeting}}</copy-me></template></div>')).then((pv) => {
|
2014-12-01 15:26:53 -08:00
|
|
|
createView(pv);
|
|
|
|
|
|
|
|
cd.detectChanges();
|
|
|
|
|
|
|
|
var childNodesOfWrapper = view.nodes[0].childNodes;
|
|
|
|
// 1 template + 2 copies.
|
|
|
|
expect(childNodesOfWrapper.length).toBe(3);
|
|
|
|
expect(childNodesOfWrapper[1].childNodes[0].nodeValue).toEqual('hello');
|
2014-12-01 18:41:55 -08:00
|
|
|
expect(childNodesOfWrapper[2].childNodes[0].nodeValue).toEqual('again');
|
2014-12-01 15:26:53 -08:00
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should support template directives via `template` attribute.', (done) => {
|
2015-01-08 09:11:33 -08:00
|
|
|
compiler.compile(MyComp, el('<div><copy-me template="some-tmpl #greeting">{{greeting}}</copy-me></div>')).then((pv) => {
|
2014-12-01 15:26:53 -08:00
|
|
|
createView(pv);
|
|
|
|
|
|
|
|
cd.detectChanges();
|
|
|
|
|
|
|
|
var childNodesOfWrapper = view.nodes[0].childNodes;
|
|
|
|
// 1 template + 2 copies.
|
|
|
|
expect(childNodesOfWrapper.length).toBe(3);
|
|
|
|
expect(childNodesOfWrapper[1].childNodes[0].nodeValue).toEqual('hello');
|
2014-12-01 18:41:55 -08:00
|
|
|
expect(childNodesOfWrapper[2].childNodes[0].nodeValue).toEqual('again');
|
2014-12-01 15:26:53 -08:00
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
2014-11-11 17:33:47 -08:00
|
|
|
});
|
2015-01-02 14:23:59 -08:00
|
|
|
|
|
|
|
it('should emulate content tag', (done) => {
|
2015-01-08 09:11:33 -08:00
|
|
|
var temp = `<emulated-shadow-dom-component>` +
|
2015-01-02 14:23:59 -08:00
|
|
|
`<div>Light</div>` +
|
|
|
|
`<div template="trivial-template">DOM</div>` +
|
|
|
|
`</emulated-shadow-dom-component>`;
|
|
|
|
|
|
|
|
function createView(pv) {
|
|
|
|
var view = pv.instantiate(null);
|
|
|
|
view.hydrate(new Injector([]), null, {});
|
|
|
|
return view;
|
|
|
|
}
|
|
|
|
|
2015-01-08 09:11:33 -08:00
|
|
|
compiler.compile(MyComp, el(temp)).
|
2015-01-02 14:23:59 -08:00
|
|
|
then(createView).
|
|
|
|
then((view) => {
|
|
|
|
expect(DOM.getText(view.nodes[0])).toEqual('Before LightDOM After');
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
2014-11-11 17:33:47 -08:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2015-01-02 14:23:59 -08:00
|
|
|
@Template({
|
|
|
|
selector: '[trivial-template]'
|
|
|
|
})
|
|
|
|
class TrivialTemplateDirective {
|
|
|
|
constructor(viewPort:ViewPort) {
|
|
|
|
viewPort.create();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Component({
|
|
|
|
selector: 'emulated-shadow-dom-component',
|
|
|
|
template: new TemplateConfig({
|
|
|
|
inline: 'Before <content></content> After',
|
|
|
|
directives: []
|
|
|
|
}),
|
|
|
|
shadowDom: ShadowDomEmulated
|
|
|
|
})
|
|
|
|
class EmulatedShadowDomCmp {
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2014-11-11 17:33:47 -08:00
|
|
|
@Decorator({
|
|
|
|
selector: '[my-dir]',
|
|
|
|
bind: {'elprop':'dirProp'}
|
|
|
|
})
|
|
|
|
class MyDir {
|
2014-11-21 21:19:23 -08:00
|
|
|
dirProp:string;
|
2014-11-11 17:33:47 -08:00
|
|
|
constructor() {
|
|
|
|
this.dirProp = '';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Component({
|
|
|
|
template: new TemplateConfig({
|
2015-01-02 14:23:59 -08:00
|
|
|
directives: [MyDir, ChildComp, SomeTemplate, EmulatedShadowDomCmp, TrivialTemplateDirective]
|
2014-11-11 17:33:47 -08:00
|
|
|
})
|
|
|
|
})
|
|
|
|
class MyComp {
|
2014-11-21 21:19:23 -08:00
|
|
|
ctxProp:string;
|
2014-11-11 17:33:47 -08:00
|
|
|
constructor() {
|
|
|
|
this.ctxProp = 'initial value';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-11-12 11:40:36 -08:00
|
|
|
@Component({
|
|
|
|
selector: 'child-cmp',
|
|
|
|
componentServices: [MyService],
|
|
|
|
template: new TemplateConfig({
|
|
|
|
directives: [MyDir],
|
|
|
|
inline: '{{ctxProp}}'
|
|
|
|
})
|
|
|
|
})
|
|
|
|
class ChildComp {
|
2014-11-21 21:19:23 -08:00
|
|
|
ctxProp:string;
|
2014-11-12 11:40:36 -08:00
|
|
|
constructor(service: MyService) {
|
|
|
|
this.ctxProp = service.greeting;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-12-01 15:26:53 -08:00
|
|
|
@Template({
|
|
|
|
selector: '[some-tmpl]'
|
|
|
|
})
|
|
|
|
class SomeTemplate {
|
|
|
|
constructor(viewPort: ViewPort) {
|
2014-12-01 18:41:55 -08:00
|
|
|
viewPort.create().setLocal('some-tmpl', 'hello');
|
|
|
|
viewPort.create().setLocal('some-tmpl', 'again');
|
2014-12-01 15:26:53 -08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-11-12 11:40:36 -08:00
|
|
|
class MyService {
|
2014-11-21 21:19:23 -08:00
|
|
|
greeting:string;
|
2014-11-12 11:40:36 -08:00
|
|
|
constructor() {
|
|
|
|
this.greeting = 'hello';
|
|
|
|
}
|
|
|
|
}
|