|
1 | 1 | /* global AFRAME, assert, CustomEvent, process, screen, sinon, setup, suite, teardown, test, THREE, EventTarget */ |
2 | 2 | var AScene = require('core/scene/a-scene').AScene; |
| 3 | +var AEntity = require('core/a-entity').AEntity; |
| 4 | +var ANode = require('core/a-node').ANode; |
3 | 5 | var components = require('core/component').components; |
4 | 6 | var scenes = require('core/scene/scenes'); |
5 | 7 | var setupCanvas = require('core/scene/a-scene').setupCanvas; |
@@ -498,6 +500,84 @@ suite('a-scene (without renderer) - WebXR', function () { |
498 | 500 | assert.notOk(setSizeSpy.called); |
499 | 501 | }); |
500 | 502 | }); |
| 503 | + |
| 504 | + suite('setAttribute', function () { |
| 505 | + var sceneEl; |
| 506 | + setup(function (done) { |
| 507 | + sceneEl = this.el; |
| 508 | + sceneEl.addEventListener('loaded', function () { |
| 509 | + done(); |
| 510 | + }); |
| 511 | + }); |
| 512 | + |
| 513 | + test('can set a component with a string', function () { |
| 514 | + sceneEl.setAttribute('fog', 'type: exponential; density: 0.75'); |
| 515 | + var fog = sceneEl.getAttribute('fog'); |
| 516 | + assert.equal(fog.type, 'exponential'); |
| 517 | + assert.equal(fog.density, 0.75); |
| 518 | + }); |
| 519 | + |
| 520 | + test('can set a component with an object', function () { |
| 521 | + var value = {type: 'exponential', density: 0.75}; |
| 522 | + sceneEl.setAttribute('fog', value); |
| 523 | + var fog = sceneEl.getAttribute('fog'); |
| 524 | + assert.equal(fog.type, 'exponential'); |
| 525 | + assert.equal(fog.density, 0.75); |
| 526 | + }); |
| 527 | + |
| 528 | + test('can clobber component attributes with an object and flag', function () { |
| 529 | + sceneEl.setAttribute('fog', 'type: exponential; density: 0.75'); |
| 530 | + sceneEl.setAttribute('fog', {type: 'exponential'}, true); |
| 531 | + var fog = sceneEl.getAttribute('fog'); |
| 532 | + assert.equal(fog.type, 'exponential'); |
| 533 | + assert.equal(fog.density, 0.00025); |
| 534 | + assert.equal(sceneEl.getDOMAttribute('fog').density, undefined); |
| 535 | + }); |
| 536 | + |
| 537 | + test('can set a single component via a single attribute', function () { |
| 538 | + sceneEl.setAttribute('fog', 'type', 'exponential'); |
| 539 | + assert.equal(sceneEl.getAttribute('fog').type, 'exponential'); |
| 540 | + }); |
| 541 | + |
| 542 | + test('can set system attribute with a string', function () { |
| 543 | + sceneEl.setAttribute('renderer', 'anisotropy: 4; toneMapping: ACESFilmic'); |
| 544 | + assert.equal(sceneEl.getAttribute('renderer').anisotropy, 4); |
| 545 | + assert.equal(sceneEl.getAttribute('renderer').toneMapping, 'ACESFilmic'); |
| 546 | + }); |
| 547 | + |
| 548 | + test('can set system attribute with an object', function () { |
| 549 | + sceneEl.setAttribute('renderer', {anisotropy: 4, toneMapping: 'ACESFilmic'}); |
| 550 | + assert.equal(sceneEl.getAttribute('renderer').anisotropy, 4); |
| 551 | + assert.equal(sceneEl.getAttribute('renderer').toneMapping, 'ACESFilmic'); |
| 552 | + }); |
| 553 | + |
| 554 | + test('can set system attribute value before system initializes', function () { |
| 555 | + delete sceneEl.systems['renderer']; |
| 556 | + sceneEl.setAttribute('renderer', 'anisotropy: 4'); |
| 557 | + assert.equal(sceneEl.getAttribute('renderer'), 'anisotropy: 4'); |
| 558 | + sceneEl.initSystem('renderer'); |
| 559 | + assert.equal(sceneEl.getAttribute('renderer').anisotropy, 4); |
| 560 | + }); |
| 561 | + |
| 562 | + test('calls a-entity setAttribute for non-systems (component)', function () { |
| 563 | + var spy = this.sinon.spy(AEntity.prototype, 'setAttribute'); |
| 564 | + sceneEl.setAttribute('fog', 'type', 'exponential'); |
| 565 | + assert.ok(spy.calledOnce); |
| 566 | + }); |
| 567 | + |
| 568 | + test('calls a-entity setAttribute for non-systems (HTML attribute)', function () { |
| 569 | + var spy = this.sinon.spy(AEntity.prototype, 'setAttribute'); |
| 570 | + sceneEl.setAttribute('data-custom-attr', 'value'); |
| 571 | + assert.ok(spy.calledOnce); |
| 572 | + }); |
| 573 | + |
| 574 | + test('calls a-node setAttribute for systems', function () { |
| 575 | + var spy = this.sinon.spy(ANode.prototype, 'setAttribute'); |
| 576 | + sceneEl.setAttribute('renderer', 'anisotropy: 4'); |
| 577 | + assert.ok(spy.calledOnce); |
| 578 | + assert.equal(sceneEl.getAttribute('renderer').anisotropy, 4); |
| 579 | + }); |
| 580 | + }); |
501 | 581 | }); |
502 | 582 |
|
503 | 583 | /** |
|
0 commit comments