Skip to content

Commit

Permalink
feat(viewer): use test.each for tests, check boxdicom by file extension
Browse files Browse the repository at this point in the history
  • Loading branch information
JChan106 committed Nov 17, 2021
1 parent de2dd56 commit 6b9ff39
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 8 deletions.
8 changes: 4 additions & 4 deletions src/lib/viewers/iframe/IFrameLoader.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,10 @@ class IFrameLoader extends AssetLoader {
* @inheritdoc
*/
determineViewer(file, disabledViewers = [], viewerOptions = {}) {
const isDicomFile = file.name === 'Dicom.boxdicom' || file.extension === 'boxdicom';
const openWithAmbraEnabled = getProp(viewerOptions, 'IFrame.openWithAmbra');
// The IFrame viewer is disabled when the file is a Boxdicom file and Open_with_Ambra FF is enabled
if (openWithAmbraEnabled && isDicomFile) {
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');
}

Expand Down
32 changes: 28 additions & 4 deletions src/lib/viewers/iframe/__tests__/IFrameViewer-test.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import IFrameLoader from '../IFrameLoader';
import IFrameViewer from '../IFrameViewer';
import BaseViewer from '../../BaseViewer';
import IFrameLoader from '../IFrameLoader';

let containerEl;
let iframe;
Expand Down Expand Up @@ -95,7 +95,7 @@ describe('lib/viewers/iframe/IFrameViewer', () => {

const viewerOptions = {
IFrame: {
openWithAmbra: true,
disableDicom: true,
},
};
const viewer = IFrameLoader.determineViewer(iframe, [], viewerOptions);
Expand All @@ -107,7 +107,7 @@ describe('lib/viewers/iframe/IFrameViewer', () => {

const viewerOptions = {
IFrame: {
openWithAmbra: true,
disableDicom: true,
},
};
const viewer = IFrameLoader.determineViewer(iframe.options.file, [], viewerOptions);
Expand All @@ -119,13 +119,37 @@ describe('lib/viewers/iframe/IFrameViewer', () => {

const viewerOptions = {
IFrame: {
openWithAmbra: false,
disableDicom: false,
},
};
const viewer = IFrameLoader.determineViewer(iframe.options.file, [], viewerOptions);
expect(viewer).toBeDefined();
});

test.each([
// disableDicom, fileType, viewerDefined
[true, 'boxdicom', false],
[true, 'boxnote', true],
[false, 'boxdicom', true],
])(
'should return correct result depending on the disableDicom viewer option and file type',
(disableDicom, fileType, viewerDefined) => {
iframe.options.file.extension = fileType;

const viewerOptions = {
IFrame: {
disableDicom,
},
};
const viewer = IFrameLoader.determineViewer(iframe.options.file, [], viewerOptions);
if (viewerDefined) {
expect(viewer).toBeDefined();
} else {
expect(viewer).toBeUndefined();
}
},
);

test('should invoke startLoadTimer()', () => {
const stub = jest.spyOn(iframe, 'startLoadTimer');
iframe.load();
Expand Down

0 comments on commit 6b9ff39

Please sign in to comment.