Skip to content

Commit

Permalink
Fix: OfficeViewer no pdfUrl for .xlsb files
Browse files Browse the repository at this point in the history
  • Loading branch information
Conrad Chan authored and Jeremy Press committed Jun 25, 2019
1 parent 49b1ce0 commit c877dfa
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 2 deletions.
9 changes: 7 additions & 2 deletions src/lib/viewers/office/OfficeViewer.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { getRepresentation } from '../../file';
import { ICON_PRINT_CHECKMARK } from '../../icons/icons';
import api from '../../api';
import { VIEWER_EVENT } from '../../events';
import { getProp } from '../../util';

const LOAD_TIMEOUT_MS = 120000;
const SAFARI_PRINT_TIMEOUT_MS = 1000; // Wait 1s before trying to print
Expand Down Expand Up @@ -161,8 +162,12 @@ class OfficeViewer extends BaseViewer {
setupPDFUrl() {
const { file } = this.options;
const pdfRep = getRepresentation(file, 'pdf');
const { url_template: template } = pdfRep.content;
this.pdfUrl = this.createContentUrlWithAuthParams(template);
const template = getProp(pdfRep, 'content.url_template');

// This occurs in the case of .xlsb files where no pdf rep exists
if (template) {
this.pdfUrl = this.createContentUrlWithAuthParams(template);
}
}

/**
Expand Down
41 changes: 41 additions & 0 deletions src/lib/viewers/office/__tests__/OfficeViewer-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -485,4 +485,45 @@ describe('lib/viewers/office/OfficeViewer', () => {
});
});
});

describe('setupPDFUrl', () => {
beforeEach(() => {
sandbox.restore();
stubs.createContentUrl = sandbox.stub(office, 'createContentUrlWithAuthParams');
});

it('should not attempt to set pdfUrl if no pdf rep exist', () => {
office.options.file.representations = {
entries: []
};

office.setupPDFUrl();

expect(office.pdfUrl).to.be.undefined;
expect(stubs.createContentUrl).not.to.have.been.called;
});

it('should not attempt to set pdfUrl if no content exists', () => {
office.options.file.representations = {
entries: [{ representation: 'pdf' }]
};

office.setupPDFUrl();

expect(office.pdfUrl).to.be.undefined;
expect(stubs.createContentUrl).not.to.have.been.called;
});

it('should set pdfUrl if pdf rep exists', () => {
stubs.createContentUrl.returns('url');
office.options.file.representations = {
entries: [{ representation: 'pdf', content: { url_template: 'template' } }]
};

office.setupPDFUrl();

expect(office.pdfUrl).to.equal('url');
expect(stubs.createContentUrl).to.have.been.called;
});
});
});

0 comments on commit c877dfa

Please sign in to comment.