-
Notifications
You must be signed in to change notification settings - Fork 2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Perform dom-bind work in attached/detached. Add tests. #1591
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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,241 @@ | ||
<!doctype html> | ||
<!-- | ||
@license | ||
Copyright (c) 2014 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="../../polymer.html"> | ||
</head> | ||
<body> | ||
|
||
<script> | ||
HTMLImports.whenReady(function() { | ||
Polymer({ | ||
is: 'x-basic', | ||
properties: { | ||
notifyingvalue: { | ||
notify: true | ||
} | ||
} | ||
}); | ||
}); | ||
</script> | ||
|
||
<template is="dom-bind" id="decDomBind"> | ||
<x-basic id="decEl1" value="{{value}}" notifyingvalue="{{nvalue}}" on-custom="handleEvent" computed="{{compute(dep)}}"></x-basic> | ||
<x-basic id="decEl2" value="{{value}}" notifyingvalue="{{nvalue}}"></x-basic> | ||
</template> | ||
|
||
<div id="container"> | ||
</div> | ||
|
||
<script> | ||
|
||
suite('declarative dom-bind', function() { | ||
|
||
var domBind; | ||
var el1; | ||
var el2; | ||
|
||
setup(function() { | ||
domBind = decDomBind; | ||
el1 = decEl1; | ||
el2 = decEl2; | ||
}); | ||
|
||
test('value binds top-down', function() { | ||
domBind.value = 'foo'; | ||
assert.equal(el1.value, 'foo'); | ||
assert.equal(el2.value, 'foo'); | ||
}); | ||
|
||
test('notifyingvalue binds from child to child', function() { | ||
el1.notifyingvalue = 'bar'; | ||
assert.equal(domBind.nvalue, 'bar'); | ||
assert.equal(el2.notifyingvalue, 'bar'); | ||
}); | ||
|
||
test('event listener fires', function() { | ||
var count = 0; | ||
domBind.handleEvent = function() { | ||
count++; | ||
}; | ||
el1.fire('custom'); | ||
assert.equal(count, 1); | ||
}); | ||
|
||
test('inline function runs', function() { | ||
domBind.compute = function(val) { | ||
return val * 10; | ||
}; | ||
domBind.dep = 5; | ||
assert.equal(el1.computed, 50); | ||
}); | ||
|
||
}); | ||
|
||
suite('imperative dom-bind', function() { | ||
|
||
var domBind; | ||
var el1; | ||
var el2; | ||
|
||
setup(function() { | ||
domBind = document.createElement('template', 'dom-bind'); | ||
var doc = domBind.content.ownerDocument; | ||
el1 = doc.createElement('x-basic'); | ||
el1.setAttribute('id', 'impEl1'); | ||
el1.setAttribute('value', '{{value}}'); | ||
el1.setAttribute('notifyingvalue', '{{nvalue}}'); | ||
el1.setAttribute('on-custom', 'handleEvent'); | ||
el1.setAttribute('computed', '{{compute(dep)}}'); | ||
el2 = doc.createElement('x-basic'); | ||
el2.setAttribute('id', 'impEl2'); | ||
el2.setAttribute('value', '{{value}}'); | ||
el2.setAttribute('notifyingvalue', '{{nvalue}}'); | ||
domBind.content.appendChild(el1); | ||
domBind.content.appendChild(el2); | ||
document.body.appendChild(domBind); | ||
CustomElements.takeRecords(); | ||
el1 = domBind.$.impEl1; | ||
el2 = domBind.$.impEl2; | ||
}); | ||
|
||
teardown(function() { | ||
if (domBind.parentElement) { | ||
domBind.parentElement.removeChild(domBind); | ||
} | ||
}); | ||
|
||
test('value binds top-down', function() { | ||
domBind.value = 'foo'; | ||
assert.equal(el1.value, 'foo'); | ||
assert.equal(el2.value, 'foo'); | ||
}); | ||
|
||
test('notifyingvalue binds from child to child', function() { | ||
el1.notifyingvalue = 'bar'; | ||
assert.equal(domBind.nvalue, 'bar'); | ||
assert.equal(el2.notifyingvalue, 'bar'); | ||
}); | ||
|
||
test('event listener fires', function() { | ||
var count = 0; | ||
domBind.handleEvent = function() { | ||
count++; | ||
}; | ||
el1.fire('custom'); | ||
assert.equal(count, 1); | ||
}); | ||
|
||
test('inline function runs', function() { | ||
domBind.compute = function(val) { | ||
return val * 10; | ||
}; | ||
domBind.dep = 5; | ||
assert.equal(el1.computed, 50); | ||
}); | ||
|
||
test('move dom-bind', function() { | ||
domBind.parentElement.removeChild(domBind); | ||
// TODO(kschaaf): detached/attached not called if takeRecords isn't | ||
// called between remove & insert on polyfill... seems bad? | ||
CustomElements.takeRecords(); | ||
container.appendChild(domBind); | ||
CustomElements.takeRecords(); | ||
assert.equal(container.firstElementChild, el1); | ||
assert.equal(container.firstElementChild.nextElementSibling, el2); | ||
}); | ||
|
||
test('remove dom-bind', function() { | ||
domBind.parentElement.removeChild(domBind); | ||
CustomElements.takeRecords(); | ||
assert(!document.contains(el1)); | ||
assert(!document.contains(el2)); | ||
}); | ||
|
||
}); | ||
|
||
suite('innerHTML dom-bind', function() { | ||
|
||
var domBind; | ||
var el1; | ||
var el2; | ||
|
||
setup(function() { | ||
domBind = document.createElement('template', 'dom-bind'); | ||
domBind.innerHTML = | ||
'<x-basic id="impEl1" value="{{value}}" notifyingvalue="{{nvalue}}" on-custom="handleEvent" computed="{{compute(dep)}}"></x-basic>' + | ||
'<x-basic id="impEl2" value="{{value}}" notifyingvalue="{{nvalue}}"></x-basic>'; | ||
document.body.appendChild(domBind); | ||
CustomElements.takeRecords(); | ||
el1 = domBind.$.impEl1; | ||
el2 = domBind.$.impEl2; | ||
}); | ||
|
||
teardown(function() { | ||
if (domBind.parentElement) { | ||
domBind.parentElement.removeChild(domBind); | ||
} | ||
}); | ||
|
||
test('value binds top-down', function() { | ||
domBind.value = 'foo'; | ||
assert.equal(el1.value, 'foo'); | ||
assert.equal(el2.value, 'foo'); | ||
}); | ||
|
||
test('notifyingvalue binds from child to child', function() { | ||
el1.notifyingvalue = 'bar'; | ||
assert.equal(domBind.nvalue, 'bar'); | ||
assert.equal(el2.notifyingvalue, 'bar'); | ||
}); | ||
|
||
test('event listener fires', function() { | ||
var count = 0; | ||
domBind.handleEvent = function() { | ||
count++; | ||
}; | ||
el1.fire('custom'); | ||
assert.equal(count, 1); | ||
}); | ||
|
||
test('inline function runs', function() { | ||
domBind.compute = function(val) { | ||
return val * 10; | ||
}; | ||
domBind.dep = 5; | ||
assert.equal(el1.computed, 50); | ||
}); | ||
|
||
test('move dom-bind', function() { | ||
domBind.parentElement.removeChild(domBind); | ||
CustomElements.takeRecords(); | ||
container.appendChild(domBind); | ||
CustomElements.takeRecords(); | ||
assert.equal(container.firstElementChild, el1); | ||
assert.equal(container.firstElementChild.nextElementSibling, el2); | ||
}); | ||
|
||
test('remove dom-bind', function() { | ||
domBind.parentElement.removeChild(domBind); | ||
CustomElements.takeRecords(); | ||
assert(!document.contains(el1)); | ||
assert(!document.contains(el2)); | ||
}); | ||
|
||
}); | ||
|
||
</script> | ||
|
||
</body> | ||
</html> |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@sorvell If I don't call
CustomElements.takeRecords()
betweenremove
andinsert
, I don't get detached/attached callbacks when moving a node in the DOM on polyfill... expected?