Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix uncaught exceptions box3d #8

Merged
merged 2 commits into from
Mar 22, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/lib/viewers/box3d/Box3d.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
12 changes: 7 additions & 5 deletions src/lib/viewers/box3d/__tests__/Box3dRenderer-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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({
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
5 changes: 3 additions & 2 deletions src/lib/viewers/box3d/model3d/__tests__/Model3d-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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' } })
};
Expand All @@ -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' } })
Expand Down
21 changes: 15 additions & 6 deletions src/lib/viewers/box3d/model3d/__tests__/Model3dRenderer-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) => {
Expand All @@ -622,6 +623,7 @@ describe('lib/viewers/box3d/model3d/Model3dRenderer', () => {
return [];
}
});
startOptimizerStub = sandbox.stub(renderer, 'startOptimizer');
});

afterEach(() => {
Expand All @@ -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)
Expand All @@ -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()
Expand All @@ -671,22 +679,21 @@ 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()
});
});

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', () => {
Expand Down Expand Up @@ -1018,13 +1025,15 @@ 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();
renderer.cleanupHelpers();
});

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();
Expand Down
2 changes: 1 addition & 1 deletion src/lib/viewers/box3d/video360/Video360.js
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand Down