From 8b9a4a87dbb922ec4c27c78297b3904a6424e9f3 Mon Sep 17 00:00:00 2001 From: Jackie Chan Date: Wed, 17 Nov 2021 15:53:32 -0800 Subject: [PATCH] feat(viewer): Add support for disabling .boxdicom file type (#1436) * feat(viewer): Add support for disabling .boxdicom file type * feat(viewer): use test.each for tests, check boxdicom by file extension * feat(viewer): Move tests to IFrameLoader * feat(viewer): use template literal syntax for test.each --- src/lib/viewers/iframe/IFrameLoader.js | 15 ++++++++ .../iframe/__tests__/IFrameLoader-test.js | 37 ++++++++++++++++--- 2 files changed, 47 insertions(+), 5 deletions(-) diff --git a/src/lib/viewers/iframe/IFrameLoader.js b/src/lib/viewers/iframe/IFrameLoader.js index 303fd33da..ad64495c5 100644 --- a/src/lib/viewers/iframe/IFrameLoader.js +++ b/src/lib/viewers/iframe/IFrameLoader.js @@ -1,3 +1,4 @@ +import getProp from 'lodash/get'; import AssetLoader from '../AssetLoader'; import IFrameViewer from './IFrameViewer'; import { ORIGINAL_REP_NAME } from '../../constants'; @@ -22,6 +23,20 @@ class IFrameLoader extends AssetLoader { super(); this.viewers = VIEWERS; } + + /** + * @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'); + } + + return super.determineViewer(file, disabledViewers); + } } export default new IFrameLoader(); diff --git a/src/lib/viewers/iframe/__tests__/IFrameLoader-test.js b/src/lib/viewers/iframe/__tests__/IFrameLoader-test.js index ff0fc6ff4..b0eb5410e 100644 --- a/src/lib/viewers/iframe/__tests__/IFrameLoader-test.js +++ b/src/lib/viewers/iframe/__tests__/IFrameLoader-test.js @@ -1,12 +1,19 @@ -/* eslint-disable no-unused-expressions */ import IFrameLoader from '../IFrameLoader'; import IFrameViewer from '../IFrameViewer'; -const sandbox = sinon.createSandbox(); - describe('lib/viewers/iframe/IFrameLoader', () => { - afterEach(() => { - sandbox.verifyAndRestore(); + const iframe = new IFrameViewer({ + file: { + id: '123', + extension: 'boxnote', + representations: { + entries: [ + { + representation: 'ORIGINAL', + }, + ], + }, + }, }); test('should have the correct viewer', () => { @@ -18,4 +25,24 @@ describe('lib/viewers/iframe/IFrameLoader', () => { EXT: ['boxnote', 'boxdicom'], }); }); + + test.each` + disableDicom | fileType | viewerInstance + ${true} | ${'boxdicom'} | ${undefined} + ${true} | ${'boxnote'} | ${IFrameLoader.viewers[0]} + ${false} | ${'boxdicom'} | ${IFrameLoader.viewers[0]} + `( + 'should return correct result depending on the disableDicom viewer option and file type', + ({ disableDicom, fileType, viewerInstance }) => { + iframe.options.file.extension = fileType; + + const viewerOptions = { + IFrame: { + disableDicom, + }, + }; + const viewer = IFrameLoader.determineViewer(iframe.options.file, [], viewerOptions); + expect(viewer).toEqual(viewerInstance); + }, + ); });