From 85b8ee458844237e0a22c03d65e1ecd949546788 Mon Sep 17 00:00:00 2001 From: Tony Jin Date: Wed, 28 Mar 2018 09:33:14 -0700 Subject: [PATCH] Fix: Only check flash for SWF files (#747) --- .gitignore | 1 + src/lib/viewers/swf/SWFLoader.js | 5 ++-- .../viewers/swf/__tests__/SWFLoader-test.js | 27 ++++++++++++++++--- 3 files changed, 28 insertions(+), 5 deletions(-) diff --git a/.gitignore b/.gitignore index 172d8f210..49d4629f5 100644 --- a/.gitignore +++ b/.gitignore @@ -10,3 +10,4 @@ dist src/i18n/json jsconfig.json functional-tests/output +yarn-error.log diff --git a/src/lib/viewers/swf/SWFLoader.js b/src/lib/viewers/swf/SWFLoader.js index fdbc7b013..ecec5ce8e 100644 --- a/src/lib/viewers/swf/SWFLoader.js +++ b/src/lib/viewers/swf/SWFLoader.js @@ -29,11 +29,12 @@ class SWFLoader extends AssetLoader { * @inheritdoc */ determineViewer(file, disabledViewers = []) { - if (!Browser.hasFlash()) { + const viewer = super.determineViewer(file, disabledViewers); + if (viewer && !Browser.hasFlash()) { throw new PreviewError(ERROR_CODE.FLASH_NOT_ENABLED, __('error_flash_not_enabled')); } - return super.determineViewer(file, disabledViewers); + return viewer; } } diff --git a/src/lib/viewers/swf/__tests__/SWFLoader-test.js b/src/lib/viewers/swf/__tests__/SWFLoader-test.js index 6ba209ae4..98072182a 100644 --- a/src/lib/viewers/swf/__tests__/SWFLoader-test.js +++ b/src/lib/viewers/swf/__tests__/SWFLoader-test.js @@ -1,9 +1,11 @@ +/* eslint-disable no-unused-expressions */ import SWFLoader from '../SWFLoader'; import AssetLoader from '../../AssetLoader'; import Browser from '../../../Browser'; import PreviewError from '../../../PreviewError'; const sandbox = sinon.sandbox.create(); +let file; describe('lib/viewers/SWFLoader', () => { afterEach(() => { @@ -11,16 +13,35 @@ describe('lib/viewers/SWFLoader', () => { }); describe('determineViewer()', () => { + beforeEach(() => { + file = { + extension: 'swf', + representations: { + entries: [ + { + representation: 'ORIGINAL' + } + ] + } + }; + }); + it('should throw a preview error if flash is not supported', () => { sandbox.stub(Browser, 'hasFlash').returns(false); - expect(() => SWFLoader.determineViewer()).to.throw(PreviewError); + expect(() => SWFLoader.determineViewer(file)).to.throw(PreviewError); }); it('should call the superclass determineViewer if flash is suported', () => { sandbox.stub(Browser, 'hasFlash').returns(true); const stub = sandbox.stub(AssetLoader.prototype, 'determineViewer'); - SWFLoader.determineViewer(); - expect(stub).to.have.been.called; // eslint-disable-line no-unused-expressions + SWFLoader.determineViewer(file); + expect(stub).to.be.called; + }); + + it('should not check Flash if file is not SWF', () => { + sandbox.stub(Browser, 'hasFlash'); + file.extension = 'jpg'; + expect(Browser.hasFlash).to.not.be.called; }); }); });