Skip to content

Commit

Permalink
Fix: 3D Error messages (#54)
Browse files Browse the repository at this point in the history
Preventing a 3D support error from being thrown if the file is not a 3D file
  • Loading branch information
Jeremy Press authored Apr 6, 2017
1 parent 0b4787c commit b7b3c95
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 18 deletions.
2 changes: 1 addition & 1 deletion src/lib/viewers/box3d/model3d/Model3DLoader.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ class Model3DLoader extends AssetLoader {
determineViewer(file, disabledViewers = []) {
const viewer = super.determineViewer(file, disabledViewers);

if (!Browser.supportsModel3D()) {
if (viewer && !Browser.supportsModel3D()) {
const message = replacePlaceholders(__('error_unsupported'), [__('3d_models')]);
throw new Error(message);
}
Expand Down
42 changes: 25 additions & 17 deletions src/lib/viewers/box3d/model3d/__tests__/Model3DLoader-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,39 +3,47 @@ import Model3DLoader from '../Model3DLoader';
import Browser from '../../../../Browser';

const sandbox = sinon.sandbox.create();

let file;
describe('lib/viewers/box3d/model3d/Model3DLoader', () => {
beforeEach(() => {
file = {
extension: 'box3d',
name: 'blah.box3d',
representations: {
entries: [{
representation: '3d'
}]
}
};
});

afterEach(() => {
file = undefined;
sandbox.verifyAndRestore();
});

describe('determineViewer()', () => {
it('should throw an error if browser doesn\'t support 3D', () => {
const file = {
extension: 'box3d',
name: 'blah.box3d',
representations: {
entries: [{
representation: '3d'
}]
}
};

it('should throw an error if browser doesn\'t support 3D and it is a 3d file', () => {
sandbox.stub(Browser, 'supportsModel3D').returns(false);
expect(() => Model3DLoader.determineViewer(file)).to.throw(Error, /browser doesn't support preview for 3D models/);
});

it('should return viewer if browser supports 3D', () => {
const file = {
extension: 'box3d',
name: 'blah.box3d',
it('should not throw an error if browser doesn\'t support 3D and it is a non 3d file', () => {
file = {
extension: 'pdf',
name: 'blah.pdf',
representations: {
entries: [{
representation: '3d'
representation: 'pdf'
}]
}
};

sandbox.stub(Browser, 'supportsModel3D').returns(false);
expect(() => Model3DLoader.determineViewer(file)).to.not.throw(Error, /browser doesn't support preview for 3D models/);
});

it('should return viewer if browser supports 3D', () => {
sandbox.stub(Browser, 'supportsModel3D').returns(true);
expect(Model3DLoader.determineViewer(file)).to.equal(Model3DLoader.viewers[0]);
});
Expand Down

0 comments on commit b7b3c95

Please sign in to comment.