diff --git a/src/core/display/DisplayObject.js b/src/core/display/DisplayObject.js index f09c8ae..1f31a70 100644 --- a/src/core/display/DisplayObject.js +++ b/src/core/display/DisplayObject.js @@ -582,7 +582,7 @@ } /** - * Indicates if the sprite is globally visible. + * Indicates if the object is globally visible. * * @member {boolean} * @memberof PIXI.DisplayObject# diff --git a/src/core/display/DisplayObject.js b/src/core/display/DisplayObject.js index f09c8ae..1f31a70 100644 --- a/src/core/display/DisplayObject.js +++ b/src/core/display/DisplayObject.js @@ -582,7 +582,7 @@ } /** - * Indicates if the sprite is globally visible. + * Indicates if the object is globally visible. * * @member {boolean} * @memberof PIXI.DisplayObject# diff --git a/test/core/DisplayObject.js b/test/core/DisplayObject.js index cfdb074..4f10c10 100755 --- a/test/core/DisplayObject.js +++ b/test/core/DisplayObject.js @@ -1,15 +1,104 @@ 'use strict'; -describe('PIXI.DisplayObject', function () +describe('PIXI.DisplayObject', () => { - it('should be able to add itself to a Container', function () + describe('constructor', () => { - var child = new PIXI.DisplayObject(); - var container = new PIXI.Container(); + it('should initialise properties', () => + { + const object = new PIXI.DisplayObject(); - expect(container.children.length).to.equal(0); - child.setParent(container); - expect(container.children.length).to.equal(1); - expect(child.parent).to.equal(container); + expect(object.alpha).to.equal(1); + expect(object.worldAlpha).to.equal(1); + expect(object.renderable).to.be.true; + expect(object.visible).to.be.true; + }); + + it('should set the correct Transform', () => + { + PIXI.TRANSFORM_MODE.DEFAULT = PIXI.TRANSFORM_MODE.DYNAMIC; + + const dynamicTransform = new PIXI.DisplayObject(); + + expect(dynamicTransform.transform).to.be.instanceof(PIXI.Transform); + + PIXI.TRANSFORM_MODE.DEFAULT = PIXI.TRANSFORM_MODE.STATIC; + + const staticTransform = new PIXI.DisplayObject(); + + expect(staticTransform.transform).to.be.instanceof(PIXI.TransformStatic); + }); + }); + + describe('setParent', () => + { + it('should add itself to a Container', () => + { + const child = new PIXI.DisplayObject(); + const container = new PIXI.Container(); + + expect(container.children.length).to.equal(0); + child.setParent(container); + expect(container.children.length).to.equal(1); + expect(child.parent).to.equal(container); + }); + + it('should throw if not Container', () => + { + const child = new PIXI.DisplayObject(); + const notAContainer = {}; + + expect(() => child.setParent()).to.throw('setParent: Argument must be a Container'); + expect(() => child.setParent(notAContainer)).to.throw('setParent: Argument must be a Container'); + }); + }); + + describe('setTransform', () => + { + it('should set correct properties', () => + { + const object = new PIXI.DisplayObject(); + + object.setTransform(1, 2, 3, 4, 5, 6, 7, 8, 9); + + expect(object.position.x).to.be.equal(1); + expect(object.position.y).to.be.equal(2); + expect(object.scale.x).to.be.equal(3); + expect(object.scale.y).to.be.equal(4); + expect(object.rotation).to.be.equal(5); + expect(object.skew.x).to.be.equal(6); + expect(object.skew.y).to.be.equal(7); + expect(object.pivot.x).to.be.equal(8); + expect(object.pivot.y).to.be.equal(9); + }); + + it('should convert zero scale to one', () => + { + const object = new PIXI.DisplayObject(); + + object.setTransform(1, 1, 0, 0, 1, 1, 1, 1, 1); + + expect(object.scale.x).to.be.equal(1); + expect(object.scale.y).to.be.equal(1); + }); + }); + + describe('worldVisible', () => + { + it('should traverse parents', () => + { + const grandParent = new PIXI.Container(); + const parent = new PIXI.Container(); + const child = new PIXI.DisplayObject(); + + grandParent.addChild(parent); + parent.addChild(child); + + expect(child.worldVisible).to.be.true; + + grandParent.visible = false; + + expect(child.worldVisible).to.be.false; + }); }); });