Skip to content

Commit

Permalink
Fix: Don't load preload if the rep has an error (#92)
Browse files Browse the repository at this point in the history
  • Loading branch information
tonyjin authored Apr 25, 2017
1 parent 41560d6 commit ab5c65a
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 10 deletions.
1 change: 1 addition & 0 deletions src/lib/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ export const APP_HOST = 'https://app.box.com';
export const ORIGINAL_REP_NAME = 'ORIGINAL';
export const PRELOAD_REP_NAME = 'jpg';

export const STATUS_ERROR = 'error';
export const STATUS_SUCCESS = 'success';
export const STATUS_VIEWABLE = 'viewable';

Expand Down
10 changes: 8 additions & 2 deletions src/lib/viewers/doc/DocBaseViewer.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,15 @@ import Controls from '../../Controls';
import DocFindBar from './DocFindBar';
import fullscreen from '../../Fullscreen';
import Popup from '../../Popup';
import RepStatus from '../../RepStatus';
import {
CLASS_BOX_PREVIEW_FIND_BAR,
CLASS_HIDDEN,
CLASS_IS_SCROLLABLE,
DOC_STATIC_ASSETS_VERSION,
PERMISSION_DOWNLOAD,
PRELOAD_REP_NAME
PRELOAD_REP_NAME,
STATUS_ERROR
} from '../../constants';
import { checkPermission, getRepresentation } from '../../file';
import { get, createAssetUrlCreator, decodeKeydown } from '../../util';
Expand Down Expand Up @@ -176,8 +178,12 @@ class DocBaseViewer extends BaseViewer {
return;
}

// Don't show preload if there is no preload rep, the 'preload' viewer option isn't set,
// or the rep has an error
const preloadRep = getRepresentation(file, PRELOAD_REP_NAME);
if (!preloadRep || !this.getViewerOption('preload')) {
if (!preloadRep ||
!this.getViewerOption('preload') ||
RepStatus.getStatus(preloadRep) === STATUS_ERROR) {
return;
}

Expand Down
34 changes: 26 additions & 8 deletions src/lib/viewers/doc/__tests__/DocBaseViewer-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@ import * as util from '../../../util';
import {
CLASS_BOX_PREVIEW_FIND_BAR,
CLASS_HIDDEN,
PERMISSION_DOWNLOAD
PERMISSION_DOWNLOAD,
STATUS_ERROR,
STATUS_SUCCESS
} from '../../../constants';

import {
Expand Down Expand Up @@ -241,6 +243,20 @@ describe('src/lib/viewers/doc/DocBaseViewer', () => {
docBase.showPreload();
});

it('should not do anything if file is watermarked', () => {
docBase.options.file = {
watermark_info: {
is_watermarked: true
}
};
sandbox.stub(docBase, 'getCachedPage').returns(1);
sandbox.stub(docBase, 'getViewerOption').withArgs('preload').returns(true);
sandbox.stub(file, 'getRepresentation').returns({});
sandbox.mock(docBase.preloader).expects('showPreload').never();

docBase.showPreload();
});

it('should not do anything if no preload rep is found', () => {
docBase.options.file = {};
sandbox.stub(docBase, 'getCachedPage').returns(1);
Expand All @@ -261,15 +277,14 @@ describe('src/lib/viewers/doc/DocBaseViewer', () => {
docBase.showPreload();
});

it('should not do anything if file is watermarked', () => {
docBase.options.file = {
watermark_info: {
is_watermarked: true
}
};
it('should not do anything if preload rep has an error', () => {
sandbox.stub(docBase, 'getCachedPage').returns(1);
sandbox.stub(docBase, 'getViewerOption').withArgs('preload').returns(true);
sandbox.stub(file, 'getRepresentation').returns({});
sandbox.stub(file, 'getRepresentation').returns({
status: {
state: STATUS_ERROR
}
});
sandbox.mock(docBase.preloader).expects('showPreload').never();

docBase.showPreload();
Expand All @@ -282,6 +297,9 @@ describe('src/lib/viewers/doc/DocBaseViewer', () => {
sandbox.stub(file, 'getRepresentation').returns({
content: {
url_template: ''
},
status: {
state: STATUS_SUCCESS
}
});
sandbox.stub(docBase, 'getViewerOption').withArgs('preload').returns(true);
Expand Down

0 comments on commit ab5c65a

Please sign in to comment.