Skip to content

Commit

Permalink
Fix: Instant Preview when thumbnail is pending (#473)
Browse files Browse the repository at this point in the history
  • Loading branch information
tonyjin authored Nov 7, 2017
1 parent e758871 commit a2f4f8b
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 4 deletions.
1 change: 1 addition & 0 deletions src/lib/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ export const PRELOAD_REP_NAME = 'jpg';
export const STATUS_ERROR = 'error';
export const STATUS_SUCCESS = 'success';
export const STATUS_VIEWABLE = 'viewable';
export const STATUS_PENDING = 'pending';

// X-Rep-Hints for Representations API
export const X_REP_HINT_BASE = '[3d][pdf][text][mp3]';
Expand Down
7 changes: 3 additions & 4 deletions src/lib/viewers/doc/DocBaseViewer.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import {
DOC_STATIC_ASSETS_VERSION,
PERMISSION_DOWNLOAD,
PRELOAD_REP_NAME,
STATUS_ERROR
STATUS_SUCCESS
} from '../../constants';
import { checkPermission, getRepresentation } from '../../file';
import { get, createAssetUrlCreator } from '../../util';
Expand Down Expand Up @@ -201,10 +201,9 @@ 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
// Don't show preload if there is no preload rep, the 'preload' viewer option isn't set, or the rep isn't ready
const preloadRep = getRepresentation(file, PRELOAD_REP_NAME);
if (!preloadRep || !this.getViewerOption('preload') || RepStatus.getStatus(preloadRep) === STATUS_ERROR) {
if (!preloadRep || !this.getViewerOption('preload') || RepStatus.getStatus(preloadRep) !== STATUS_SUCCESS) {
return;
}

Expand Down
14 changes: 14 additions & 0 deletions src/lib/viewers/doc/__tests__/DocBaseViewer-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import {
CLASS_HIDDEN,
PERMISSION_DOWNLOAD,
STATUS_ERROR,
STATUS_PENDING,
STATUS_SUCCESS,
} from '../../../constants';

Expand Down Expand Up @@ -291,6 +292,19 @@ describe('src/lib/viewers/doc/DocBaseViewer', () => {
docBase.showPreload();
});

it('should not do anything if preload rep is pending', () => {
sandbox.stub(docBase, 'getCachedPage').returns(1);
sandbox.stub(docBase, 'getViewerOption').withArgs('preload').returns(true);
sandbox.stub(file, 'getRepresentation').returns({
status: {
state: STATUS_PENDING
}
});
sandbox.mock(docBase.preloader).expects('showPreload').never();

docBase.showPreload();
});

it('should show preload with correct authed URL', () => {
const preloadUrl = 'someUrl';
docBase.options.file = {};
Expand Down

0 comments on commit a2f4f8b

Please sign in to comment.