-
Notifications
You must be signed in to change notification settings - Fork 2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix impl of _contentForTemplate. Add template-stamp tests.
Fixes #4597
- Loading branch information
1 parent
7d5e448
commit 06190c9
Showing
3 changed files
with
101 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,99 @@ | ||
<!DOCTYPE html> | ||
<!-- | ||
@license | ||
Copyright (c) 2017 The Polymer Project Authors. All rights reserved. | ||
This code may only be used under the BSD style license found at http://polymer.github.io/LICENSE.txt | ||
The complete set of authors may be found at http://polymer.github.io/AUTHORS.txt | ||
The complete set of contributors may be found at http://polymer.github.io/CONTRIBUTORS.txt | ||
Code distributed by Google as part of the polymer project is also | ||
subject to an additional IP rights grant found at http://polymer.github.io/PATENTS.txt | ||
--> | ||
<html> | ||
<head> | ||
<meta charset="UTF-8"> | ||
|
||
<script src="../../../webcomponentsjs/webcomponents-lite.js"></script> | ||
<script src="../../../web-component-tester/browser.js"></script> | ||
|
||
<link rel="import" href="../../lib/mixins/template-stamp.html"> | ||
</head> | ||
<body> | ||
|
||
<template id="test-template"> | ||
<div id="a">a</div> | ||
<div id="eventHandler" on-click="handleClick"></div> | ||
<div id="b">b</div> | ||
<template id="nestedTemplate"> | ||
<div on-click="handleClick"></div> | ||
</template> | ||
<template id="preservedTemplate" preserve-content> | ||
<div on-click="shouldNotBeRemoved"></div> | ||
</template> | ||
</template> | ||
|
||
<script> | ||
HTMLImports.whenReady(() => { | ||
class TemplateStamper extends Polymer.TemplateStamp(HTMLElement) { | ||
connectedCallback() { | ||
this.handleClick = sinon.spy(event => { | ||
this.handleClickTarget = event.target; | ||
}); | ||
let template = document.getElementById('test-template'); | ||
this.dom = this._stampTemplate(template); | ||
this.attachShadow({mode:'open'}).appendChild(this.dom); | ||
} | ||
} | ||
customElements.define('template-stamper', TemplateStamper); | ||
}); | ||
</script> | ||
|
||
<script> | ||
|
||
suite('template-stamp', () => { | ||
|
||
test('id map', () => { | ||
let el = document.createElement('template-stamper'); | ||
document.body.appendChild(el); | ||
assert.equal(el.dom.$.a.textContent, 'a'); | ||
assert.equal(el.dom.$.b.textContent, 'b'); | ||
document.body.removeChild(el); | ||
}); | ||
|
||
test('declarative events', () => { | ||
let el = document.createElement('template-stamper'); | ||
document.body.appendChild(el); | ||
el.dom.$.eventHandler.click(); | ||
assert.equal(el.handleClick.callCount, 1); | ||
assert.equal(el.handleClick.firstCall.args[0].type, 'click'); | ||
assert.equal(el.handleClickTarget, el.dom.$.eventHandler); | ||
document.body.removeChild(el); | ||
}); | ||
|
||
test('cached template content', () => { | ||
let el = document.createElement('template-stamper'); | ||
document.body.appendChild(el); | ||
let content = el.constructor._contentForTemplate(el.dom.$.nestedTemplate); | ||
assert.isTrue(content instanceof DocumentFragment); | ||
assert.equal(content.ownerDocument, el.dom.$.nestedTemplate.content.ownerDocument); | ||
assert.equal(content.firstElementChild.getAttribute('on-click'), null); | ||
document.body.removeChild(el); | ||
}); | ||
|
||
test('preserved template content', () => { | ||
let el = document.createElement('template-stamper'); | ||
document.body.appendChild(el); | ||
let content = el.dom.$.preservedTemplate.content; | ||
assert.isTrue(content instanceof DocumentFragment); | ||
assert.equal(content.firstElementChild.getAttribute('on-click'), 'shouldNotBeRemoved'); | ||
document.body.removeChild(el); | ||
}); | ||
|
||
}); | ||
|
||
// Note template parsing API is tested in `property-effects-template.html`, | ||
// combined with adding property effects | ||
|
||
</script> | ||
|
||
</body> | ||
</html> |