fix(Compiler): fix text nodes after content tags

fixes #2095
This commit is contained in:
Victor Berchet
2015-06-14 19:49:47 +02:00
parent b2e6ad85ea
commit d599fd3434
4 changed files with 59 additions and 30 deletions
@@ -13,7 +13,6 @@ import {DOM} from 'angular2/src/dom/dom_adapter';
import {Content} from 'angular2/src/render/dom/shadow_dom/content_tag';
var _scriptStart = `<script start=""></script>`;
var _scriptEnd = `<script end=""></script>`;
export function main() {
describe('Content', function() {
@@ -21,35 +20,32 @@ export function main() {
var content;
beforeEach(() => {
parent = el(`<div>${_scriptStart}${_scriptEnd}`);
content = DOM.firstChild(parent);
parent = el(`<div>${_scriptStart}</div>`);
let contentStartMarker = DOM.firstChild(parent);
content = new Content(contentStartMarker, '');
});
it("should insert the nodes", () => {
var c = new Content(content, '');
c.init(null);
c.insert([el("<a></a>"), el("<b></b>")])
content.init(null);
content.insert([el("<a>A</a>"), el("<b>B</b>")]);
expect(DOM.getInnerHTML(parent))
.toEqual(`${_scriptStart}<a></a><b></b>${_scriptEnd}`);
expect(parent).toHaveText('AB');
});
it("should remove the nodes from the previous insertion", () => {
var c = new Content(content, '');
c.init(null);
c.insert([el("<a></a>")]);
c.insert([el("<b></b>")]);
content.init(null);
content.insert([el("<a>A</a>")]);
content.insert([el("<b>B</b>")]);
expect(DOM.getInnerHTML(parent)).toEqual(`${_scriptStart}<b></b>${_scriptEnd}`);
expect(parent).toHaveText('B');
});
it("should insert empty list", () => {
var c = new Content(content, '');
c.init(null);
c.insert([el("<a></a>")]);
c.insert([]);
it("should clear nodes on inserting an empty list", () => {
content.init(null);
content.insert([el("<a>A</a>")]);
content.insert([]);
expect(DOM.getInnerHTML(parent)).toEqual(`${_scriptStart}${_scriptEnd}`);
expect(parent).toHaveText('');
});
});
}
@@ -10,7 +10,7 @@ import {
it,
xit,
beforeEachBindings,
SpyObject,
SpyObject
} from 'angular2/test_lib';
import {bind} from 'angular2/di';
@@ -34,6 +34,10 @@ import {StyleInliner} from 'angular2/src/render/dom/shadow_dom/style_inliner';
import {DomTestbed} from './dom_testbed';
import {Injectable} from 'angular2/di';
import {Component, View} from 'angular2/annotations';
export function main() {
describe('ShadowDom integration tests', function() {
var strategies = {
@@ -60,6 +64,26 @@ export function main() {
beforeEachBindings(() => { return [strategyBinding, DomTestbed]; });
describe(`${name} shadow dom strategy`, () => {
// GH-2095 - https://github.com/angular/angular/issues/2095
it('should support text nodes after content tags',
inject([DomTestbed, AsyncTestCompleter], (tb, async) => {
tb.compileAll([
simple,
new ViewDefinition({
componentId: 'simple',
template: '<content></content><p>P,</p>{{a}}',
directives: []
})
])
.then((protoViewDtos) => {
var rootView = tb.createRootView(protoViewDtos[0]);
var cmpView = tb.createComponentView(rootView.viewRef, 0, protoViewDtos[1]);
tb.renderer.setText(cmpView.viewRef, 0, 'text');
expect(tb.rootEl).toHaveText('P,text');
async.done();
});
}));
it('should support simple components',
inject([AsyncTestCompleter, DomTestbed], (async, tb) => {