1
0
Fork 0
spacetac/src/ui/common/Animations.spec.ts

69 lines
2.7 KiB
TypeScript
Raw Normal View History

2017-09-24 22:23:22 +00:00
module TK.SpaceTac.UI.Specs {
describe("Animations", () => {
let testgame = setupEmptyView();
it("shows and hides objects", function () {
let obj = { visible: false, alpha: 0.5 };
2017-10-09 21:13:56 +00:00
expect(testgame.view.animations.simulate(obj, 'alpha')).toEqual([]);
2017-10-09 21:13:56 +00:00
testgame.view.animations.show(obj);
expect(obj.visible).toBe(true);
expect(obj.alpha).toBe(0);
2017-10-09 21:13:56 +00:00
expect(testgame.view.animations.simulate(obj, 'alpha')).toEqual([0, 0.25, 0.5, 0.75, 1]);
obj.alpha = 1;
2017-10-09 21:13:56 +00:00
testgame.view.animations.hide(obj);
expect(obj.visible).toBe(true);
expect(obj.alpha).toBe(1);
2017-10-09 21:13:56 +00:00
expect(testgame.view.animations.simulate(obj, 'alpha')).toEqual([1, 0.75, 0.5, 0.25, 0]);
obj.alpha = 0.2;
2017-10-09 21:13:56 +00:00
testgame.view.animations.setVisible(obj, true, 1000, 0.6);
expect(obj.visible).toBe(true);
expect(obj.alpha).toBe(0.2);
2017-10-09 21:13:56 +00:00
expect(testgame.view.animations.simulate(obj, 'alpha')).toEqual([0.2, 0.3, 0.4, 0.5, 0.6]);
obj.alpha = 0.6;
2017-10-09 21:13:56 +00:00
testgame.view.animations.setVisible(obj, false, 1000, 0.6, 0.2);
expect(obj.visible).toBe(true);
expect(obj.alpha).toBe(0.6);
2017-10-09 21:13:56 +00:00
expect(testgame.view.animations.simulate(obj, 'alpha')).toEqual([0.6, 0.5, 0.4, 0.3, 0.2]);
});
it("blocks input while object is hidden", function () {
let obj = { visible: true, alpha: 1, input: { enabled: true }, changeStateFrame: jasmine.createSpy("changeStateFrame"), freezeFrames: false };
2017-10-09 21:13:56 +00:00
testgame.view.animations.setVisible(obj, false, 0);
expect(obj.visible).toBe(false);
expect(obj.alpha).toBe(0);
expect(obj.input.enabled).toBe(false);
expect(obj.changeStateFrame).toHaveBeenCalledWith("Out");
expect(obj.freezeFrames).toBe(true);
2017-10-09 21:13:56 +00:00
testgame.view.animations.setVisible(obj, true, 0);
expect(obj.visible).toBe(true);
expect(obj.alpha).toBe(1);
expect(obj.input.enabled).toBe(true);
expect(obj.changeStateFrame).toHaveBeenCalledTimes(1);
expect(obj.freezeFrames).toBe(false);
});
it("animates rotation", function () {
let obj = { rotation: -Math.PI * 2.5 };
let tween = testgame.ui.tweens.create(obj);
let result = Animations.rotationTween(tween, Math.PI * 0.25, 1, Phaser.Easing.Linear.None);
expect(result).toEqual(750);
expect(tween.generateData(4)).toEqual([
{ rotation: -Math.PI * 0.25 },
{ rotation: 0 },
{ rotation: Math.PI * 0.25 },
]);
});
});
}