Skip to content

Commit

Permalink
fixed issue with content in light dom exceptioning (#329)
Browse files Browse the repository at this point in the history
* fixed issue with content in light dom exceptioning

* comments++ to polymer.dom and simpler traversal

* deleted commented code
  • Loading branch information
e111077 authored Jun 23, 2016
1 parent 1aff4fb commit 0a56c4d
Show file tree
Hide file tree
Showing 8 changed files with 94 additions and 29 deletions.
2 changes: 1 addition & 1 deletion bower.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
"stacky": "^1.3.0",
"test-fixture": "polymerelements/test-fixture#^1.0.0"
},
"version": "4.3.0",
"version": "4.3.1",
"devDependencies": {
"polymer": "Polymer/polymer#^1.5.0",
"webcomponentsjs": "webcomponents/webcomponentsjs#^0.7.22"
Expand Down
29 changes: 16 additions & 13 deletions browser.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion browser.js.map

Large diffs are not rendered by default.

29 changes: 16 additions & 13 deletions browser/mocha/replace.js
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,17 @@ extendInterfaces('replace', function(context, teardown) {
}

if (instanceParent) {
// Polymer's shady dom implementation goes through the insertion
// points and checks their parents. If the parent of a content
// tag has been stamped already, then Polymer.dom has to be aware
// of this content tag's parent. Additionally,
// Polymer.dom.appendChild does not seem to actually append the
// content nodes into the document fragment, so node.appendChild
// must also be called to actually insert the node.
if (instanceNode.tagName == 'CONTENT') {
Polymer.dom(instanceParent).appendChild(instanceNode);
}

instanceParent.appendChild(instanceNode);
}

Expand All @@ -84,26 +95,18 @@ extendInterfaces('replace', function(context, teardown) {
instanceParent = instanceNode;
templateNode = templateNode.firstChild;

// traverse laterally if you cannot traverse down
} else if (templateNode.nextSibling) {
templateNode = templateNode.nextSibling;

// if the parent is the dom, we are done
} else if (templateNode.parentNode === dom) {
instanceParent = instanceNode.parentNode;
return instanceParent;

// traverse up
} else {
// traverse up until you can move laterally
while (!templateNode.nextSibling) {
templateNode = templateNode.parentNode;
instanceParent = instanceParent.parentNode;

// stop traversing up if we are at the top
if (templateNode === dom) {
if (templateNode.parentNode === dom) {
return instanceParent;
} else {
instanceParent = instanceParent.parentNode;
}

templateNode = templateNode.parentNode;
}

// traverse laterally
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "web-component-tester",
"version": "4.3.0",
"version": "4.3.1",
"description": "web-component-tester makes testing your web components a breeze!",
"keywords": [
"browser",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<dom-module id="projection-element-2">
<template>
<content></content>
</template>
<script>
Polymer({
is: 'projection-element-2'
});
</script>
</dom-module>
14 changes: 14 additions & 0 deletions test/fixtures/integration/multiple-replace/projection-element.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<link rel="import" href="projection-element-2.html">

<dom-module id="projection-element">
<template>
<projection-element-2 id="customElement">
<content></content>
</projection-element-2>
</template>
<script>
Polymer({
is: 'projection-element'
});
</script>
</dom-module>
35 changes: 35 additions & 0 deletions test/fixtures/integration/multiple-replace/tests.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
<script src="../../../../browser.js"></script>
<link rel="import" href="dom-if-element.html">
<link rel="import" href="exception-fixture.html">
<link rel="import" href="projection-element.html">
<link rel="import" href="../../../../../paper-input/paper-input.html">
</head>
<body>
<test-fixture id="DomIfTemplate">
Expand All @@ -19,6 +21,14 @@
</template>
</test-fixture>

<test-fixture id="ProjectionFixture">
<template>
<projection-element>
<div id="helloWorld">Hello World</div>
</projection-element>
</template>
</test-fixture>

<script>
'use strict';

Expand Down Expand Up @@ -89,6 +99,31 @@
assert.equal(element4.nodeName, 'F');
});
});

describe('testing projected element replacement', function() {
var setupCorrectly = true;
var customElementChildren;

before(function() {
try {
replace('non-present-element').with('a-a');
} catch (err) {
setupCorrectly = false;
}

var template = fixture('ProjectionFixture');
customElementChildren = template.$.customElement.children;
});

after(function () {

});

it('double replace test', function() {
assert.isOk(setupCorrectly);
assert.equal(customElementChildren.length, 1);
});
});
</script>

</body>
Expand Down

0 comments on commit 0a56c4d

Please sign in to comment.