var chai = require('chai'), sinon = require("sinon"), sinonChai = require("sinon-chai"), config = require('../config.js'), assert = chai.assert, R3 = require('../build/r3'), CANNON = require('cannon'), THREE = require('three'); chai.use(sinonChai); describe('R3 object creation', function(){ this.timeout(0); before(function(){ }); after(function(){ }); beforeEach(function(done, err) { this.xhr = sinon.useFakeXMLHttpRequest(); this.requests = []; this.xhr.onCreate = function(xhr) { this.requests.push(xhr); }.bind(this); done(); }); afterEach(function(done, err){ this.xhr.restore(); done(); }); it('Should create a Bone object', function (done) { var bone = new R3.D3.Bone( null, 1, 'test bone 1', [2, 3, 4] ); assert(bone.position instanceof R3.D3.Vector3); assert(bone.rotation instanceof R3.D3.Vector3); assert(bone.scale instanceof R3.D3.Vector3); assert(bone.up instanceof R3.D3.Vector3); assert(bone.quaternion instanceof R3.D3.Vector4); assert(bone.parentBoneId == null); assert.deepEqual(bone.childBoneIds, [2,3,4]); done(); }); it('Should create a BoneWeight object', function (done) { var boneWeight = new R3.D3.BoneWeight( 1, 0.5 ); assert(boneWeight.boneIndex == 1); assert(boneWeight.weight == 0.5); done(); }); it('Should create a Broadphase object', function (done) { var engine = new R3.D3.Engine( R3.D3.Engine.ENGINE_TYPE_CANNON, CANNON ); assert(engine.engineType == R3.D3.Engine.ENGINE_TYPE_CANNON); assert(engine.instance instanceof Object); var broadphase = new R3.D3.Broadphase( null, 'broad-phase', R3.D3.Broadphase.BROADPHASE_TYPE_NAIVE, engine, true ); assert(broadphase.id == null); assert(broadphase.instance instanceof CANNON.NaiveBroadphase); assert(broadphase.engine instanceof R3.D3.Engine); assert(broadphase.name == 'broad-phase'); assert(broadphase.broadphaseType == R3.D3.Broadphase.BROADPHASE_TYPE_NAIVE); done(); }); it('Should create a Color object', function (done) { var color = new R3.D3.Color( 0.1, 0.2, 0.3, 0.4 ); assert(color.r == 0.1); assert(color.g == 0.2); assert(color.b == 0.3); assert(color.a == 0.4); done(); }); it('Should create a Color object', function (done) { var color = new R3.D3.Color( 0.1, 0.2, 0.3, 0.4 ); assert(color.r == 0.1); assert(color.g == 0.2); assert(color.b == 0.3); assert(color.a == 0.4); done(); }); it('Should create an Engine object', function (done) { var engine = new R3.D3.Engine( R3.D3.Engine.ENGINE_TYPE_CANNON, CANNON ); assert(engine.engineType == R3.D3.Engine.ENGINE_TYPE_CANNON); assert(engine.instance instanceof Object); done(); }); it('Should create a FlyControls object', function (done) { console.log("Cannot test FlyControls server side"); done(); }); it('Should load the scene via API', function(done) { var scene = new R3.D3.Scene( null, '/gamewheel/root/root/test', 'test' ); var graphics = new R3.D3.Graphics( R3.D3.Graphics.GRAPHICS_TYPE_THREE, THREE ); R3.D3.Scene.LoadSceneFromApi( scene, function(stuff){ done(); }, graphics, '/uploads/gamewheel/root/root/test', null, 'http://api.gamewheel.local' ); }); });