2015-02-05 16:08:05 -05:00
|
|
|
import {describe, xit, it, expect, beforeEach, ddescribe, iit, el} from 'angular2/test_lib';
|
|
|
|
import {DOM} from 'angular2/src/facade/dom';
|
|
|
|
import {Injector} from 'angular2/di';
|
|
|
|
import {Lexer, Parser, ChangeDetector, dynamicChangeDetection} from 'angular2/change_detection';
|
|
|
|
import {Compiler, CompilerCache} from 'angular2/src/core/compiler/compiler';
|
|
|
|
import {DirectiveMetadataReader} from 'angular2/src/core/compiler/directive_metadata_reader';
|
2015-01-30 03:43:21 -05:00
|
|
|
import {NativeShadowDomStrategy} from 'angular2/src/core/compiler/shadow_dom_strategy';
|
2015-02-05 16:08:05 -05:00
|
|
|
import {Decorator, Component} from 'angular2/src/core/annotations/annotations';
|
2015-02-12 08:44:59 -05:00
|
|
|
import {Template} from 'angular2/src/core/annotations/template';
|
|
|
|
import {TemplateLoader} from 'angular2/src/core/compiler/template_loader';
|
2015-02-05 16:08:05 -05:00
|
|
|
import {NgElement} from 'angular2/src/core/dom/element';
|
2015-02-04 16:27:31 -05:00
|
|
|
import {NonBindable} from 'angular2/src/directives/non_bindable';
|
2015-02-24 09:32:44 -05:00
|
|
|
import {MockTemplateResolver} from 'angular2/src/mock/template_resolver_mock';
|
2015-01-08 07:57:41 -05:00
|
|
|
|
|
|
|
export function main() {
|
2015-02-04 16:27:31 -05:00
|
|
|
describe('non-bindable', () => {
|
2015-02-12 08:44:59 -05:00
|
|
|
var view, cd, compiler, component, tplResolver;
|
2015-01-08 07:57:41 -05:00
|
|
|
beforeEach(() => {
|
2015-02-24 09:32:44 -05:00
|
|
|
tplResolver = new MockTemplateResolver();
|
2015-02-12 08:44:59 -05:00
|
|
|
compiler = new Compiler(dynamicChangeDetection, new TemplateLoader(null),
|
|
|
|
new DirectiveMetadataReader(), new Parser(new Lexer()), new CompilerCache(),
|
|
|
|
new NativeShadowDomStrategy(), tplResolver);
|
2015-01-08 07:57:41 -05:00
|
|
|
});
|
|
|
|
|
|
|
|
function createView(pv) {
|
|
|
|
component = new TestComponent();
|
2015-02-09 09:11:31 -05:00
|
|
|
view = pv.instantiate(null, null);
|
2015-01-08 07:57:41 -05:00
|
|
|
view.hydrate(new Injector([]), null, component);
|
2015-01-14 16:51:16 -05:00
|
|
|
cd = view.changeDetector;
|
2015-01-08 07:57:41 -05:00
|
|
|
}
|
|
|
|
|
2015-02-12 08:44:59 -05:00
|
|
|
function compileWithTemplate(html) {
|
|
|
|
var template = new Template({
|
|
|
|
inline: html,
|
|
|
|
directives: [NonBindable, TestDecorator]
|
|
|
|
});
|
|
|
|
tplResolver.setTemplate(TestComponent, template);
|
|
|
|
return compiler.compile(TestComponent);
|
2015-01-08 07:57:41 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
it('should not interpolate children', (done) => {
|
2015-02-04 16:27:31 -05:00
|
|
|
var template = '<div>{{text}}<span non-bindable>{{text}}</span></div>';
|
2015-01-08 07:57:41 -05:00
|
|
|
compileWithTemplate(template).then((pv) => {
|
|
|
|
createView(pv);
|
|
|
|
cd.detectChanges();
|
|
|
|
expect(DOM.getText(view.nodes[0])).toEqual('foo{{text}}');
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should ignore directives on child nodes', (done) => {
|
2015-02-04 16:27:31 -05:00
|
|
|
var template = '<div non-bindable><span id=child test-dec>{{text}}</span></div>';
|
2015-01-08 07:57:41 -05:00
|
|
|
compileWithTemplate(template).then((pv) => {
|
|
|
|
createView(pv);
|
|
|
|
cd.detectChanges();
|
|
|
|
var span = DOM.querySelector(view.nodes[0], '#child');
|
|
|
|
expect(DOM.hasClass(span, 'compiled')).toBeFalsy();
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should trigger directives on the same node', (done) => {
|
2015-02-04 16:27:31 -05:00
|
|
|
var template = '<div><span id=child non-bindable test-dec>{{text}}</span></div>';
|
2015-01-08 07:57:41 -05:00
|
|
|
compileWithTemplate(template).then((pv) => {
|
|
|
|
createView(pv);
|
|
|
|
cd.detectChanges();
|
|
|
|
var span = DOM.querySelector(view.nodes[0], '#child');
|
|
|
|
expect(DOM.hasClass(span, 'compiled')).toBeTruthy();
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2015-02-12 08:44:59 -05:00
|
|
|
@Component({selector: 'test-cmp'})
|
2015-01-08 07:57:41 -05:00
|
|
|
class TestComponent {
|
|
|
|
text: string;
|
|
|
|
constructor() {
|
|
|
|
this.text = 'foo';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Decorator({
|
|
|
|
selector: '[test-dec]'
|
|
|
|
})
|
|
|
|
class TestDecorator {
|
|
|
|
constructor(el: NgElement) {
|
|
|
|
DOM.addClass(el.domElement, 'compiled');
|
|
|
|
}
|
|
|
|
}
|