From 7af11c402f889d7e9f4e53a6bb282579c5c556e1 Mon Sep 17 00:00:00 2001 From: Jackie Chan Date: Fri, 19 Nov 2021 13:12:40 -0800 Subject: [PATCH] feat(viewer): use unsupported file type error message for .boxdicom (#1437) * feat(viewer): use unsupported file type error message for boxdicom * feat(viewer): modify tests and simplify viewer logic * feat(viewer): remove unneeded conditional * feat(viewer): update comment --- src/lib/viewers/iframe/IFrameLoader.js | 15 ++++++---- .../iframe/__tests__/IFrameLoader-test.js | 29 ++++++++++++------- 2 files changed, 29 insertions(+), 15 deletions(-) diff --git a/src/lib/viewers/iframe/IFrameLoader.js b/src/lib/viewers/iframe/IFrameLoader.js index ad64495c5..3a6864468 100644 --- a/src/lib/viewers/iframe/IFrameLoader.js +++ b/src/lib/viewers/iframe/IFrameLoader.js @@ -9,7 +9,13 @@ const VIEWERS = [ NAME: 'IFrame', CONSTRUCTOR: IFrameViewer, REP: ORIGINAL_REP_NAME, - EXT: ['boxnote', 'boxdicom'], + EXT: ['boxdicom'], + }, + { + NAME: 'IFrame', + CONSTRUCTOR: IFrameViewer, + REP: ORIGINAL_REP_NAME, + EXT: ['boxnote'], }, ]; @@ -28,11 +34,10 @@ class IFrameLoader extends AssetLoader { * @inheritdoc */ determineViewer(file, disabledViewers = [], viewerOptions = {}) { - const isDicomFile = file.extension === 'boxdicom'; const disableDicom = getProp(viewerOptions, 'IFrame.disableDicom'); - // The IFrame viewer is disabled when the file is a Boxdicom file and the disableDicom viewer option is enabled - if (disableDicom && isDicomFile) { - disabledViewers.push('IFrame'); + // Removes boxdicom as a supported extension when the disableDicom viewer option is enabled + if (disableDicom) { + this.viewers = this.viewers.filter(viewer => !viewer.EXT.includes('boxdicom')); } return super.determineViewer(file, disabledViewers); diff --git a/src/lib/viewers/iframe/__tests__/IFrameLoader-test.js b/src/lib/viewers/iframe/__tests__/IFrameLoader-test.js index b0eb5410e..1a199a6cd 100644 --- a/src/lib/viewers/iframe/__tests__/IFrameLoader-test.js +++ b/src/lib/viewers/iframe/__tests__/IFrameLoader-test.js @@ -16,21 +16,29 @@ describe('lib/viewers/iframe/IFrameLoader', () => { }, }); - test('should have the correct viewer', () => { - const iframeViewer = IFrameLoader.viewers[0]; - expect(iframeViewer).toEqual({ - NAME: 'IFrame', - CONSTRUCTOR: IFrameViewer, - REP: 'ORIGINAL', - EXT: ['boxnote', 'boxdicom'], - }); + test('should have the correct viewers', () => { + const iframeViewers = IFrameLoader.viewers; + expect(iframeViewers).toEqual([ + { + NAME: 'IFrame', + CONSTRUCTOR: IFrameViewer, + REP: 'ORIGINAL', + EXT: ['boxdicom'], + }, + { + NAME: 'IFrame', + CONSTRUCTOR: IFrameViewer, + REP: 'ORIGINAL', + EXT: ['boxnote'], + }, + ]); }); test.each` disableDicom | fileType | viewerInstance + ${false} | ${'boxdicom'} | ${IFrameLoader.viewers.find(v => v.EXT.includes('boxdicom'))} ${true} | ${'boxdicom'} | ${undefined} - ${true} | ${'boxnote'} | ${IFrameLoader.viewers[0]} - ${false} | ${'boxdicom'} | ${IFrameLoader.viewers[0]} + ${true} | ${'boxnote'} | ${IFrameLoader.viewers.find(v => v.EXT.includes('boxnote'))} `( 'should return correct result depending on the disableDicom viewer option and file type', ({ disableDicom, fileType, viewerInstance }) => { @@ -43,6 +51,7 @@ describe('lib/viewers/iframe/IFrameLoader', () => { }; const viewer = IFrameLoader.determineViewer(iframe.options.file, [], viewerOptions); expect(viewer).toEqual(viewerInstance); + expect(IFrameLoader.getViewers().some(v => v.EXT.includes('boxdicom'))).toEqual(!disableDicom); }, ); });