| <!DOCTYPE html> |
| <!-- |
| Copyright (c) 2014 The Chromium Authors. All rights reserved. |
| Use of this source code is governed by a BSD-style license that can be |
| found in the LICENSE file. |
| --> |
| <link rel="import" href="/base/utils.html"> |
| <polymer-element name="instantiate-template-polymer-element-test"> |
| <template></template> |
| <script> |
| 'use strict'; |
| Polymer({ |
| testProperty: 'Test' |
| }); |
| </script> |
| </polymer-element> |
| |
| <template id="instantiate-template-polymer-test"> |
| <instantiate-template-polymer-element-test> |
| </instantiate-template-polymer-element-test> |
| </template> |
| |
| <template id="multiple-template-test"> |
| <template> |
| <instantiate-template-polymer-element-test> |
| </instantiate-template-polymer-element-test> |
| <span test-attribute='TestAttribute'>Foo</span> |
| </template> |
| <instantiate-template-polymer-element-test> |
| </instantiate-template-polymer-element-test> |
| </template> |
| <script> |
| 'use strict'; |
| |
| tv.b.unittest.testSuite(function() { |
| var THIS_DOC = document._currentScript.ownerDocument; |
| |
| test('clamping', function() { |
| assert.equal(tv.b.clamp(2, 1, 3), 2); |
| assert.equal(tv.b.clamp(1, 1, 3), 1); |
| assert.equal(tv.b.clamp(0, 1, 3), 1); |
| assert.equal(tv.b.clamp(3, 1, 3), 3); |
| assert.equal(tv.b.clamp(4, 1, 3), 3); |
| }); |
| |
| test('getUsingPath', function() { |
| var z = tv.b.getUsingPath('x.y.z', {'x': {'y': {'z': 3}}}); |
| assert.equal(z, 3); |
| |
| var w = tv.b.getUsingPath('x.w', {'x': {'y': {'z': 3}}}); |
| assert.isUndefined(w); |
| }); |
| |
| test('instantiateTemplatePolymer', function() { |
| var e = tv.b.instantiateTemplate( |
| '#instantiate-template-polymer-test', |
| THIS_DOC); |
| assert.equal(e.children.length, 1); |
| assert.equal(e.children[0].testProperty, 'Test'); |
| }); |
| |
| test('instantiateTemplateMultipleTemplates', function() { |
| var outerElement = tv.b.instantiateTemplate( |
| '#multiple-template-test', |
| THIS_DOC); |
| assert.equal(outerElement.children.length, 2); |
| assert.equal(outerElement.children[1].testProperty, 'Test'); |
| |
| // Make sure we can still instantiate inner templates, if we need them. |
| var innerElement = outerElement.children[0].createInstance(); |
| assert.equal(innerElement.children.length, 2); |
| assert.equal(innerElement.children[0].testProperty, 'Test'); |
| assert.equal( |
| innerElement.children[1].getAttribute('test-attribute'), |
| 'TestAttribute'); |
| assert.equal(innerElement.children[1].textContent, 'Foo'); |
| }); |
| }); |
| </script> |