|
1 | | -/* global AFRAME, assert, process, suite, teardown, test, setup, sinon, HTMLElement */ |
| 1 | +/* global AFRAME, assert, process, suite, teardown, test, setup, sinon, HTMLElement, HTMLHeadElement */ |
2 | 2 | var Component = require('core/component'); |
3 | 3 | var components = require('index').components; |
4 | 4 |
|
@@ -192,6 +192,7 @@ suite('Component', function () { |
192 | 192 |
|
193 | 193 | setup(function () { |
194 | 194 | el = entityFactory(); |
| 195 | + components.dummy = undefined; |
195 | 196 | }); |
196 | 197 |
|
197 | 198 | test('emits componentchanged for multi-prop', function (done) { |
@@ -360,6 +361,68 @@ suite('Component', function () { |
360 | 361 | }); |
361 | 362 | el.setAttribute('material', ''); |
362 | 363 | }); |
| 364 | + |
| 365 | + test('a selector property default is not cloned into data', function () { |
| 366 | + registerComponent('dummy', { |
| 367 | + schema: {type: 'selector', default: document.body} |
| 368 | + }); |
| 369 | + var el = document.createElement('a-entity'); |
| 370 | + el.hasLoaded = true; |
| 371 | + el.setAttribute('dummy', 'head'); |
| 372 | + el.components.dummy.updateProperties(''); |
| 373 | + assert.equal(el.components.dummy.data, el.components.dummy.schema.default); |
| 374 | + }); |
| 375 | + |
| 376 | + test('a plain object schema default is cloned into data', function () { |
| 377 | + registerComponent('dummy', { |
| 378 | + schema: {type: 'vec3', default: {x: 1, y: 1, z: 1}} |
| 379 | + }); |
| 380 | + var el = document.createElement('a-entity'); |
| 381 | + el.hasLoaded = true; |
| 382 | + el.setAttribute('dummy', '2 2 2'); |
| 383 | + el.components.dummy.updateProperties(''); |
| 384 | + assert.notEqual(el.components.dummy.data, el.components.dummy.schema.default); |
| 385 | + assert.deepEqual(el.components.dummy.data, {x: 1, y: 1, z: 1}); |
| 386 | + }); |
| 387 | + |
| 388 | + test('do not clone properties from attrValue into data that are not plain objects', function () { |
| 389 | + registerComponent('dummy', { |
| 390 | + schema: { |
| 391 | + color: {default: 'blue'}, |
| 392 | + direction: {type: 'vec3'}, |
| 393 | + el: {type: 'selector', default: 'body'} |
| 394 | + } |
| 395 | + }); |
| 396 | + var el = document.createElement('a-entity'); |
| 397 | + el.hasLoaded = true; |
| 398 | + el.setAttribute('dummy', ''); |
| 399 | + assert.notOk(el.components.dummy.attrValue.el); |
| 400 | + el.components.dummy.updateProperties({ |
| 401 | + color: 'green', |
| 402 | + direction: {x: 1, y: 1, z: 1}, |
| 403 | + el: document.head |
| 404 | + }); |
| 405 | + var data = el.getAttribute('dummy'); |
| 406 | + var attrValue = el.components.dummy.attrValue; |
| 407 | + assert.notEqual(data, attrValue); |
| 408 | + assert.equal(data.color, attrValue.color); |
| 409 | + // The HTMLElement is not cloned in attrValue |
| 410 | + // a reference is shared instead. |
| 411 | + assert.equal(data.el, attrValue.el); |
| 412 | + assert.equal(data.el.constructor, HTMLHeadElement); |
| 413 | + assert.notEqual(data.direction, attrValue.direction); |
| 414 | + assert.deepEqual(data.direction, {x: 1, y: 1, z: 1}); |
| 415 | + assert.deepEqual(attrValue.direction, {x: 1, y: 1, z: 1}); |
| 416 | + el.components.dummy.updateProperties({ |
| 417 | + color: 'red', |
| 418 | + direction: {x: 1, y: 1, z: 1} |
| 419 | + }); |
| 420 | + data = el.getAttribute('dummy'); |
| 421 | + // The HTMLElement is not cloned in attrValue |
| 422 | + // a reference is shared instead. |
| 423 | + assert.equal(data.el.constructor, HTMLHeadElement); |
| 424 | + assert.equal(data.el, el.components.dummy.attrValue.el); |
| 425 | + }); |
363 | 426 | }); |
364 | 427 |
|
365 | 428 | suite('resetProperty', function () { |
|
0 commit comments