| OLD | NEW |
| (Empty) | |
| 1 <!doctype html> |
| 2 <!-- |
| 3 @license |
| 4 Copyright (c) 2015 The Polymer Project Authors. All rights reserved. |
| 5 This code may only be used under the BSD style license found at http://polymer.g
ithub.io/LICENSE.txt |
| 6 The complete set of authors may be found at http://polymer.github.io/AUTHORS.txt |
| 7 The complete set of contributors may be found at http://polymer.github.io/CONTRI
BUTORS.txt |
| 8 Code distributed by Google as part of the polymer project is also |
| 9 subject to an additional IP rights grant found at http://polymer.github.io/PATEN
TS.txt |
| 10 --> |
| 11 <html> |
| 12 <head> |
| 13 <title>test-fixture</title> |
| 14 |
| 15 <script src="../../webcomponentsjs/webcomponents-lite.js"></script> |
| 16 <script src="../../web-component-tester/browser.js"></script> |
| 17 |
| 18 <link rel="import" id="test-fixture-import" href="../test-fixture.html"> |
| 19 <script src="../test-fixture-mocha.js"></script> |
| 20 |
| 21 <script> |
| 22 (function() { |
| 23 function XCustom() { |
| 24 if (window.Reflect) { |
| 25 return Reflect.construct(HTMLElement, [], XCustom); |
| 26 } |
| 27 return HTMLElement.call(this) || this; |
| 28 } |
| 29 |
| 30 XCustom.prototype = Object.create(HTMLElement.prototype); |
| 31 Object.defineProperty(XCustom.prototype, 'constructor', { |
| 32 configurable: true, |
| 33 enumerable: true, |
| 34 writable: true, |
| 35 value: XCustom, |
| 36 }); |
| 37 XCustom.prototype.onDetached = function() {}; |
| 38 XCustom.prototype.disconnectedCallback = |
| 39 XCustom.prototype.detachedCallback = function() { |
| 40 this.onDetached(); |
| 41 }; |
| 42 |
| 43 if (window.customElements) { |
| 44 customElements.define('x-custom', XCustom); |
| 45 } else if (document.registerElement) { |
| 46 document.registerElement('x-custom', { |
| 47 prototype: XCustom.prototype |
| 48 }); |
| 49 } else { |
| 50 throw new Error('No custom elements API was found.'); |
| 51 } |
| 52 })(); |
| 53 </script> |
| 54 </head> |
| 55 <body> |
| 56 <test-fixture id="TrivialFixture"> |
| 57 <template> |
| 58 <div id="Foo"></div> |
| 59 </template> |
| 60 </test-fixture> |
| 61 <test-fixture id="ComplexDomFixture"> |
| 62 <template> |
| 63 <div id="Bar"> |
| 64 <div id="BarChild"></div> |
| 65 </div> |
| 66 <div id="BarSibling"></div> |
| 67 </template> |
| 68 </test-fixture> |
| 69 <test-fixture id="MultiTemplateFixture"> |
| 70 <template> |
| 71 <div id="Baz"></div> |
| 72 </template> |
| 73 <template> |
| 74 <div id="Qux"></div> |
| 75 <div id="QuxSibling"></div> |
| 76 </template> |
| 77 </test-fixture> |
| 78 <test-fixture id="CommentedSingleChildFixture"> |
| 79 <template> |
| 80 <!-- comment --> |
| 81 <!-- comment --> |
| 82 <div id="Foo"></div> |
| 83 <!-- comment --> |
| 84 </template> |
| 85 </test-fixture> |
| 86 <test-fixture id="CommentedMultiChildFixture"> |
| 87 <template> |
| 88 <!-- comment --> |
| 89 <div id="Bar"> |
| 90 <div id="BarChild"></div> |
| 91 </div> |
| 92 <!-- comment --> |
| 93 <!-- comment --> |
| 94 <div id="BarSibling"></div> |
| 95 <!-- comment --> |
| 96 <div id="Baz"></div> |
| 97 </template> |
| 98 </test-fixture> |
| 99 <test-fixture id="AttachedFixture"> |
| 100 <template> |
| 101 <x-custom></x-custom> |
| 102 </template> |
| 103 </test-fixture> |
| 104 <script> |
| 105 describe('test-fixture import', function() { |
| 106 it('loads from test-fixture import', function() { |
| 107 var importNode = document.getElementById('test-fixture-import'); |
| 108 expect(importNode.import).to.not.be.null; |
| 109 }); |
| 110 }); |
| 111 describe('<test-fixture>', function () { |
| 112 var trivialFixture; |
| 113 var complexDomFixture; |
| 114 var multiTemplateFixture; |
| 115 var commentedSingleChildFixture; |
| 116 var commentedMultiChildFixture; |
| 117 |
| 118 beforeEach(function () { |
| 119 trivialFixture = document.getElementById('TrivialFixture'); |
| 120 complexDomFixture = document.getElementById('ComplexDomFixture'); |
| 121 multiTemplateFixture = document.getElementById('MultiTemplateFixture'); |
| 122 commentedSingleChildFixture = document.getElementById('CommentedSingleChildF
ixture'); |
| 123 commentedMultiChildFixture = document.getElementById('CommentedMultiChildFix
ture'); |
| 124 }); |
| 125 |
| 126 afterEach(function () { |
| 127 trivialFixture.restore(); |
| 128 complexDomFixture.restore(); |
| 129 multiTemplateFixture.restore(); |
| 130 commentedSingleChildFixture.restore(); |
| 131 commentedMultiChildFixture.restore(); |
| 132 }); |
| 133 |
| 134 describe('an stamped-out fixture', function () { |
| 135 var attachedFixture; |
| 136 var element; |
| 137 |
| 138 beforeEach(function () { |
| 139 attachedFixture = document.getElementById('AttachedFixture'); |
| 140 element = attachedFixture.create(); |
| 141 }); |
| 142 |
| 143 afterEach(function () { |
| 144 attachedFixture.restore(); |
| 145 }); |
| 146 |
| 147 it('detaches the fixtured DOM when it is restored', function () { |
| 148 var detached = false; |
| 149 |
| 150 element.onDetached = function () { |
| 151 detached = true; |
| 152 }; |
| 153 |
| 154 attachedFixture.restore(); |
| 155 expect(detached).to.be.eql(true); |
| 156 }); |
| 157 }); |
| 158 |
| 159 describe('when create is called', function () { |
| 160 var el; |
| 161 |
| 162 beforeEach(function () { |
| 163 el = trivialFixture.create(); |
| 164 }); |
| 165 |
| 166 it('clones all template fragments within itself', function () { |
| 167 expect(el).to.be.ok; |
| 168 expect(document.getElementById('Foo')).to.be.ok; |
| 169 }); |
| 170 |
| 171 it('detaches all fixture templates from itself', function () { |
| 172 expect(trivialFixture.querySelectorAll('template').length).to.be.equal(0); |
| 173 }); |
| 174 |
| 175 describe('and then restore is called', function () { |
| 176 beforeEach(function () { |
| 177 trivialFixture.restore(); |
| 178 }); |
| 179 |
| 180 it('re-attaches all fixture templates', function () { |
| 181 expect(trivialFixture.querySelectorAll('template').length).to.be.equal(1
); |
| 182 }); |
| 183 |
| 184 it('removes all cloned elements from itself', function () { |
| 185 expect(document.getElementById('Foo')).to.not.be.ok; |
| 186 }); |
| 187 }); |
| 188 |
| 189 describe('for a dom with a single root element', function () { |
| 190 it('returns a reference to the root element', function () { |
| 191 expect(el).to.be.instanceOf(HTMLElement); |
| 192 }); |
| 193 }); |
| 194 |
| 195 describe('for a complex dom', function () { |
| 196 var els; |
| 197 |
| 198 beforeEach(function () { |
| 199 els = complexDomFixture.create(); |
| 200 }); |
| 201 |
| 202 it('fixtures all the dom elements in the template', function () { |
| 203 expect(document.getElementById('Bar')).to.be.ok; |
| 204 expect(document.getElementById('BarSibling')).to.be.ok; |
| 205 expect(document.getElementById('BarChild')).to.be.ok; |
| 206 }); |
| 207 |
| 208 it('returns an array of root elements', function () { |
| 209 expect(els).to.be.instanceOf(Array); |
| 210 expect(els[0]).to.be.instanceOf(HTMLElement); |
| 211 expect(els[1]).to.be.instanceOf(HTMLElement); |
| 212 }); |
| 213 }); |
| 214 |
| 215 describe('when there are multiple templates', function () { |
| 216 var groups; |
| 217 |
| 218 beforeEach(function () { |
| 219 groups = multiTemplateFixture.create(); |
| 220 }); |
| 221 |
| 222 it('fixtures elements from all of the templates', function () { |
| 223 expect(document.getElementById('Baz')).to.be.ok; |
| 224 expect(document.getElementById('Qux')).to.be.ok; |
| 225 }); |
| 226 |
| 227 it('returns an array with elements grouped by template', function () { |
| 228 expect(groups).to.be.instanceOf(Array); |
| 229 expect(groups[0]).to.be.instanceOf(HTMLElement); |
| 230 expect(groups[1]).to.be.instanceOf(Array); |
| 231 expect(groups[1][0]).to.be.instanceOf(HTMLElement); |
| 232 expect(groups[1][1]).to.be.instanceOf(HTMLElement); |
| 233 }); |
| 234 }); |
| 235 |
| 236 describe('when there are comments in the template', function() { |
| 237 var el; |
| 238 var els; |
| 239 |
| 240 beforeEach(function () { |
| 241 el = commentedSingleChildFixture.create(); |
| 242 els = commentedMultiChildFixture.create(); |
| 243 }); |
| 244 |
| 245 it('returns a single element if the template has a single child', function
() { |
| 246 expect(el).to.be.instanceOf(HTMLElement); |
| 247 }); |
| 248 |
| 249 it('returns multiple elements if the template has multiple children', func
tion() { |
| 250 expect(els).to.be.instanceOf(Array); |
| 251 expect(els.length).to.equal(3); |
| 252 }); |
| 253 }); |
| 254 }); |
| 255 |
| 256 describe('when the fixture global is called', function () { |
| 257 var el; |
| 258 |
| 259 beforeEach(function () { |
| 260 el = fixture('TrivialFixture'); |
| 261 }); |
| 262 |
| 263 it('generates a DOM fragment from the associated fixture', function () { |
| 264 expect(el).to.be.equal(document.getElementById('Foo')); |
| 265 }); |
| 266 }); |
| 267 }); |
| 268 </script> |
| 269 |
| 270 </body> |
| 271 </html> |
| OLD | NEW |