diff --git a/src/lib/viewers/box3d/Box3d.js b/src/lib/viewers/box3d/Box3d.js index 157de04fd..0bec957b4 100644 --- a/src/lib/viewers/box3d/Box3d.js +++ b/src/lib/viewers/box3d/Box3d.js @@ -15,7 +15,7 @@ import { EVENT_TOGGLE_FULLSCREEN, EVENT_TOGGLE_VR } from './Box3dConstants'; -import JS from './Box3dAssets'; +import JS from './box3dAssets'; import './Box3d.scss'; // Milliseconds to wait for model to load before cancelling Preview diff --git a/src/lib/viewers/box3d/__tests__/Box3dRenderer-test.js b/src/lib/viewers/box3d/__tests__/Box3dRenderer-test.js index b72a6133f..7a5129ae3 100644 --- a/src/lib/viewers/box3d/__tests__/Box3dRenderer-test.js +++ b/src/lib/viewers/box3d/__tests__/Box3dRenderer-test.js @@ -289,13 +289,15 @@ describe('lib/viewers/box3d/Box3dRenderer', () => { it('should produce an XhrResourceLoader which supports token, sharedLink and sharedLinkPassword', (done) => { const creatBox3DStub = sandbox.stub(renderer, 'createBox3d', (loader) => { sandbox.stub(loader.queue, 'add', (fn) => fn()); + const resource = { + once: (event, cb) => cb() + }; + sandbox.stub(loader, 'load', () => resource); - const resource = loader.load('path/to/texture.jpg', window.Box3D.LoadingType.IMAGE, {}); + loader.load('path/to/texture.jpg', window.Box3D.LoadingType.IMAGE, {}); - resource.once('done', () => { - expect(creatBox3DStub).to.be.called; - done(); - }); + expect(creatBox3DStub).to.be.called; + done(); }); renderer.initBox3d({ diff --git a/src/lib/viewers/box3d/Box3dAssets.js b/src/lib/viewers/box3d/box3dAssets.js similarity index 85% rename from src/lib/viewers/box3d/Box3dAssets.js rename to src/lib/viewers/box3d/box3dAssets.js index 31ea076c8..defaa4449 100644 --- a/src/lib/viewers/box3d/Box3dAssets.js +++ b/src/lib/viewers/box3d/box3dAssets.js @@ -1,9 +1,9 @@ const STATIC_URI = 'third-party/model3d/'; -const BOX3D = [ +const JS = [ `${STATIC_URI}boxsdk.min.js`, `${STATIC_URI}three.min.js`, `${STATIC_URI}box3d-runtime.min.js`, `${STATIC_URI}webvr-polyfill.js`, `${STATIC_URI}WebVR/VRConfig.js` ]; -export default BOX3D; +export default JS; diff --git a/src/lib/viewers/box3d/model3d/__tests__/Model3d-test.js b/src/lib/viewers/box3d/model3d/__tests__/Model3d-test.js index 26d8ca0f6..c809c6139 100644 --- a/src/lib/viewers/box3d/model3d/__tests__/Model3d-test.js +++ b/src/lib/viewers/box3d/model3d/__tests__/Model3d-test.js @@ -526,8 +526,8 @@ describe('lib/viewers/box3d/model3d/Model3d', () => { }); }); - it('should should invoke console.error() when issues loading metadata', (done) => { - const errStub = sandbox.stub(console, 'error'); + it('should should invoke onMetadataError() when issues loading metadata', (done) => { + const errStub = sandbox.stub(model3d, 'onMetadataError'); const meta = { get: () => Promise.resolve({ status: 404, response: { status: 'metadata not found' } }) }; @@ -542,6 +542,7 @@ describe('lib/viewers/box3d/model3d/Model3d', () => { }); it('should still advance the promise chain for ui setup after failed metadata load', (done) => { + sandbox.stub(model3d, 'onMetadataError'); const addUi = sandbox.stub(model3d.controls, 'addUi'); const meta = { get: () => Promise.resolve({ status: 404, response: { status: 'metadata not found' } }) diff --git a/src/lib/viewers/box3d/model3d/__tests__/Model3dRenderer-test.js b/src/lib/viewers/box3d/model3d/__tests__/Model3dRenderer-test.js index fd7e1255e..fc4903a83 100644 --- a/src/lib/viewers/box3d/model3d/__tests__/Model3dRenderer-test.js +++ b/src/lib/viewers/box3d/model3d/__tests__/Model3dRenderer-test.js @@ -608,6 +608,7 @@ describe('lib/viewers/box3d/model3d/Model3dRenderer', () => { const animations = []; const images = []; const videos = []; + let startOptimizerStub; beforeEach(() => { sandbox.stub(renderer.box3d, 'getEntitiesByType', (type) => { @@ -622,6 +623,7 @@ describe('lib/viewers/box3d/model3d/Model3dRenderer', () => { return []; } }); + startOptimizerStub = sandbox.stub(renderer, 'startOptimizer'); }); afterEach(() => { @@ -631,21 +633,26 @@ describe('lib/viewers/box3d/model3d/Model3dRenderer', () => { }); it('should reset the scene via reset()', () => { + sandbox.stub(Promise, 'all').returns({ then: () => {} }); renderMock.expects('reset'); renderer.onSceneLoad(); }); it('should collect all assets that are loading', () => { + sandbox.stub(Promise, 'all').returns({ then: () => {} }); const anim = { - isLoading: sandbox.stub().returns(true) + isLoading: sandbox.stub().returns(true), + when: sandbox.stub() }; animations.push(anim); const image = { - isLoading: sandbox.stub().returns(false) + isLoading: sandbox.stub().returns(false), + when: sandbox.stub() }; images.push(image); const video = { - isLoading: sandbox.stub().returns(false) + isLoading: sandbox.stub().returns(false), + when: sandbox.stub() }; videos.push(video); sandbox.mock(animations).expects('concat').withArgs(images, videos) @@ -658,6 +665,7 @@ describe('lib/viewers/box3d/model3d/Model3dRenderer', () => { }); it('should add listeners for filtered assets to load', () => { + sandbox.stub(Promise, 'all').returns({ then: () => {} }); const anim = { isLoading: sandbox.stub().returns(true), when: sandbox.stub() @@ -671,14 +679,13 @@ describe('lib/viewers/box3d/model3d/Model3dRenderer', () => { }); it('should invoke resize', () => { + sandbox.stub(Promise, 'all').returns({ then: () => {} }); renderMock.expects('resize'); renderer.onSceneLoad(); }); describe('when assets fully loaded', () => { - let startStub; beforeEach(() => { - startStub = sandbox.stub(renderer, 'startOptimizer'); sandbox.stub(Promise, 'all').returns({ then: (callback) => callback() }); @@ -686,7 +693,7 @@ describe('lib/viewers/box3d/model3d/Model3dRenderer', () => { it('should invoke startOptimizer()', () => { renderer.onSceneLoad(); - expect(startStub).to.be.called; + expect(startOptimizerStub).to.be.called; }); it('should set the current animation to the first animation asset', () => { @@ -1018,6 +1025,7 @@ describe('lib/viewers/box3d/model3d/Model3dRenderer', () => { }); it('should not remove the grid if there is none', () => { + sandbox.stub(renderer, 'getScene').returns(scene); renderer.grid = undefined; renderer.axisDisplay = undefined; sandbox.mock(scene.runtimeData).expects('remove').withArgs(grid).never(); @@ -1025,6 +1033,7 @@ describe('lib/viewers/box3d/model3d/Model3dRenderer', () => { }); it('should remove the grid from the scene', () => { + sandbox.stub(renderer, 'getScene').returns(scene); renderer.axisDisplay = undefined; sandbox.mock(scene.runtimeData).expects('remove').withArgs(grid); renderer.cleanupHelpers(); diff --git a/src/lib/viewers/box3d/video360/Video360.js b/src/lib/viewers/box3d/video360/Video360.js index e9f0e60b4..816b256ef 100644 --- a/src/lib/viewers/box3d/video360/Video360.js +++ b/src/lib/viewers/box3d/video360/Video360.js @@ -6,7 +6,7 @@ import Video360Controls from './Video360Controls'; import Video360Renderer from './Video360Renderer'; import sceneEntities from './SceneEntities'; import { EVENT_TOGGLE_VR, EVENT_SHOW_VR_BUTTON } from '../Box3dConstants'; -import JS from '../Box3dAssets'; +import JS from '../box3dAssets'; import './Video360.scss'; const CSS_CLASS_VIDEO_360 = 'bp-video-360'; diff --git a/src/lib/viewers/box3d/video360/__tests__/Video360-test.js b/src/lib/viewers/box3d/video360/__tests__/Video360-test.js index 9035cee9d..c3c78d4ac 100644 --- a/src/lib/viewers/box3d/video360/__tests__/Video360-test.js +++ b/src/lib/viewers/box3d/video360/__tests__/Video360-test.js @@ -7,7 +7,7 @@ import { EVENT_TOGGLE_VR, EVENT_SHOW_VR_BUTTON } from '../../Box3dConstants'; -import JS from '../../Box3dAssets'; +import JS from '../../box3dAssets'; import sceneEntities from '../SceneEntities'; import fullscreen from '../../../../Fullscreen';