Skip to content

Commit

Permalink
feat(viewer): use unsupported file type error message for .boxdicom (#…
Browse files Browse the repository at this point in the history
…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
  • Loading branch information
JChan106 authored Nov 19, 2021
1 parent 8b9a4a8 commit 7af11c4
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 15 deletions.
15 changes: 10 additions & 5 deletions src/lib/viewers/iframe/IFrameLoader.js
Original file line number Diff line number Diff line change
Expand Up @@ -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'],
},
];

Expand All @@ -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);
Expand Down
29 changes: 19 additions & 10 deletions src/lib/viewers/iframe/__tests__/IFrameLoader-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 }) => {
Expand All @@ -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);
},
);
});

0 comments on commit 7af11c4

Please sign in to comment.