Skip to content

Commit

Permalink
update tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
Steven Orvell committed Jul 15, 2015
1 parent 348896a commit 8922323
Show file tree
Hide file tree
Showing 6 changed files with 380 additions and 3 deletions.
86 changes: 86 additions & 0 deletions test/smoke/dom-bind-async.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
<!doctype html>
<html>
<head>

<title>dom-bind</title>

<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">

<script src="../../../webcomponentsjs/webcomponents-lite.js"></script>
<link rel="import" href="../../polymer.html" async>

<script>
document.querySelector('link').addEventListener('load', function() {
app.render();
});
</script>

</head>
<body>

<template is="dom-bind" id="app">

<h3>Repeat index</h3>
<template is="dom-repeat" items="{{employees}}">
<div style="padding: 3px 0px;">
<button on-tap="modify">Modify</button>
<span>{{index}}</span>
<span>{{item.first}}</span>
<span>{{item.last}}</span>
</div>
</template>

<h3>Show person by index, demonstrate "dom-if" expressions</h3>
<template is="dom-repeat" items="{{employees}}">
<div>
<template is="dom-if" if="{{testit(index)}}">
<div style="padding: 3px 0px;">
<button on-tap="modify">Modify</button>
<span>{{index}}</span>
<span>{{item.first}}</span>
<span>{{item.last}}</span>
</div>
</template>
</div>
</template>

<h3>Show person by index, demonstrate filter</h3>
<template is="dom-repeat" items="{{employees}}" filter="onlyRob">
<div>
<div style="padding: 3px 0px;">
<button on-tap="modify">Modify</button>
<span>{{index}}</span>
<span>{{item.first}}</span>
<span>{{item.last}}</span>
</div>
</div>
</template>

</template>

<script>
var logEl = document.getElementById('log');
var app = document.getElementById('app');
app.testit = function(i) {
return i > 1;
};
app.modify = function(e) {
e.model.set('item.last', e.model.item.last + '*');
};
app.onlyRob = function(item) {
return item.first == 'Rob';
};
app.bar = true;
app.employees = [
{first: 'Bob', last: 'Smith'},
{first: 'Sally', last: 'Johnson'},
{first: 'Rob', last: 'Instructs'},
{first: 'Scott', last: 'Explains'},
{first: 'Taylor', last: 'Blogs'}
];

</script>

</body>
</html>
55 changes: 55 additions & 0 deletions test/smoke/dynamic-dom-bind.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
<!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
-->
<script src="../../../webcomponentsjs/webcomponents-lite.js"></script>
<link rel="import" href="../../polymer.html">

<body>
<x-test></x-test>

<dom-module id="x-foo">
<template>
<content></content>
</template>
<script>
HTMLImports.whenReady(function() {
Polymer({
is: 'x-foo'
});
});
</script>
</dom-module>

<dom-module id="x-test">
<template>
Greeting:
<x-foo id="myCustomElement"></x-foo>
</template>
<script>
HTMLImports.whenReady(function() {
Polymer({
is: 'x-test',
attached: function() {
var appendTo = this.$.myCustomElement,
t = document.createElement('template', 'dom-bind'),
span = document.createElement('span');
span.innerHTML = '{{hello}}';
t.content.appendChild(span);
t.hello = 'hey';
Polymer.dom(appendTo).appendChild(t);
}
});
});
</script>
</dom-module>


</body>

73 changes: 73 additions & 0 deletions test/smoke/dynamic-dom-bind2.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
<!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
-->
<script src="../../../webcomponentsjs/webcomponents-lite.js"></script>
<link rel="import" href="../../polymer.html">

<body>
<x-outer></x-outer>

<dom-module id="x-outer">
<template>
<x-test id="test1"></x-test>
<button on-tap="_addDomBindDirectly">Add dom-bind directly</button>
<span>&lt;&lt;&lt; Doesn't work the first time</span>
<br /><br />
<x-test id="test2"></x-test>
<button on-tap="_addDomBindIndirectly">Add dom-bind indirectly</button>
<span>&lt;&lt;&lt; Works every time</span>
</template>
</dom-module>

<dom-module id="x-test">
<template>
<content></content>
</template>
</dom-module>

<script>
HTMLImports.whenReady(function() {
Polymer({
is: 'x-test'
});

Polymer({
is: 'x-outer',
_addDomBindDirectly: function() {
var domBind = this._createDomBind();
Polymer.dom(this.$.test1).appendChild(domBind);
},
_addDomBindIndirectly: function() {
var domBind = this._createDomBind();

var tempContainer = document.createElement("div");
tempContainer.appendChild(domBind);

Polymer.dom(this.$.test2).appendChild(tempContainer);
},
_createDomBind: function() {
var domBind = document.createElement("template", "dom-bind");
domBind.test = "hello";

var doc = domBind.content.ownerDocument;
var div = doc.createElement("div");
div.textContent = "{{test}}";

domBind.content.appendChild(div);

return domBind;
}
});
});
</script>


</body>

37 changes: 36 additions & 1 deletion test/unit/dom-bind-elements1.html
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,39 @@
}
}
});
</script>
</script>

<dom-module id="x-content">
<template><div id="container"><content></content></div></template>
<script>
Polymer({
is: 'x-content'
});
</script>
</dom-module>

<dom-module id="x-attach-dom-bind">
<template><x-content id="local"></x-content></template>
<script>
Polymer({
is: 'x-attach-dom-bind',
attached: function() {
var t = document.createElement('template', 'dom-bind'),
span = document.createElement('span');
span.innerHTML = '{{hello}}';
t.content.appendChild(span);
t.hello = 'hey';
Polymer.dom(this.$.local).appendChild(t);
}
});
</script>
</dom-module>

<dom-module id="x-compose">
<template><x-content id="local"></x-content></template>
<script>
Polymer({
is: 'x-compose'
});
</script>
</dom-module>
114 changes: 112 additions & 2 deletions test/unit/polymer-dom-elements.html
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@
Polymer({
is: 'x-test-no-distribute'
});
</script>
</script>

<dom-module id="x-distribute">
<template>
Expand All @@ -72,7 +72,7 @@
</div>
</div>
</template>
</dom-element>
</dom-module>

<script>
Polymer({
Expand Down Expand Up @@ -184,4 +184,114 @@
<script>Polymer({
is: 'x-clonate'
});</script>
</dom-module>

<dom-module id="x-attach3">
<style>
:host {
display: block;
border: 1px dashed orange;
padding: 4px;
box-sizing: border-box;
}

:host ::content .add3 {
box-sizing: border-box;
height: 20px;
background: #333;
border: 2px solid yellow;
}
</style>
<template>
<content></content>
<template is="dom-if" if="{{shouldIf(done.count)}}">
<x-attach2></x-attach2>
</template>
</template>
<script>Polymer({
is: 'x-attach3',
properties: {
done: {value: {count: 0}}
},
ready: function() {
this.done.count++;
},
attached: function() {
var d = document.createElement('div');
d.className = 'add3';
Polymer.dom(this).appendChild(d);
},
shouldIf: function(x) {
return x < 3;
}
});</script>
</dom-module>

<dom-module id="x-attach2">
<style>
:host {
display: block;
border: 1px dashed tomato;
padding: 4px;
}

:host ::content .add2 {
box-sizing: border-box;
height: 20px;
background: gray;
border: 2px solid yellow;
}
</style>
<template>
<x-attach3><content></content></x-attach3>
<template is="dom-if" if="{{shouldIf(done.count)}}">
<x-attach1></x-attach1>
</template>
</template>
<script>
Polymer({
is: 'x-attach2',
properties: {
done: {value: {count: 0}}
},
ready: function() {
this.done.count++;
},
attached: function() {
var d = document.createElement('div');
d.className = 'add2';
Polymer.dom(this).appendChild(d);
},
shouldIf: function(x) {
return x < 3;
}
});</script>
</dom-module>

<dom-module id="x-attach1">
<style>
:host {
display: block;
border: 1px dashed seagreen;
padding: 4px;
}

:host ::content .add1 {
box-sizing: border-box;
height: 20px;
background: lightgray;
border: 2px solid yellow;
}
</style>
<template>
<x-attach2><content></content></x-attach2>
</template>
<script>Polymer({
is: 'x-attach1',
attached: function() {
var d = document.createElement('div');
d.className = 'add1';
Polymer.dom(this).appendChild(d);
}
});</script>
</dom-module>
Loading

0 comments on commit 8922323

Please sign in to comment.