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: 3D Error messages #54

Merged
merged 1 commit into from
Apr 6, 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/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