diff --git a/src/lib/viewers/office/OfficeViewer.js b/src/lib/viewers/office/OfficeViewer.js index 43a7ff413..975d234be 100644 --- a/src/lib/viewers/office/OfficeViewer.js +++ b/src/lib/viewers/office/OfficeViewer.js @@ -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 @@ -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); + } } /** diff --git a/src/lib/viewers/office/__tests__/OfficeViewer-test.js b/src/lib/viewers/office/__tests__/OfficeViewer-test.js index 12cc4c463..399df1e33 100644 --- a/src/lib/viewers/office/__tests__/OfficeViewer-test.js +++ b/src/lib/viewers/office/__tests__/OfficeViewer-test.js @@ -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; + }); + }); });