Skip to content

Commit

Permalink
feat(viewer): Move tests to IFrameLoader
Browse files Browse the repository at this point in the history
  • Loading branch information
JChan106 committed Nov 17, 2021
1 parent 6b9ff39 commit abc58ae
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 69 deletions.
35 changes: 34 additions & 1 deletion src/lib/viewers/iframe/__tests__/IFrameLoader-test.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,23 @@
/* eslint-disable no-unused-expressions */
import IFrameLoader from '../IFrameLoader';
import IFrameViewer from '../IFrameViewer';

const sandbox = sinon.createSandbox();

describe('lib/viewers/iframe/IFrameLoader', () => {
const iframe = new IFrameViewer({
file: {
id: '123',
extension: 'boxnote',
representations: {
entries: [
{
representation: 'ORIGINAL',
},
],
},
},
});

afterEach(() => {
sandbox.verifyAndRestore();
});
Expand All @@ -18,4 +31,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);
},
);
});
68 changes: 0 additions & 68 deletions src/lib/viewers/iframe/__tests__/IFrameViewer-test.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import IFrameLoader from '../IFrameLoader';
import IFrameViewer from '../IFrameViewer';
import BaseViewer from '../../BaseViewer';

Expand All @@ -16,13 +15,6 @@ describe('lib/viewers/iframe/IFrameViewer', () => {
file: {
id: '123',
extension: 'boxnote',
representations: {
entries: [
{
representation: 'ORIGINAL',
},
],
},
},
});

Expand Down Expand Up @@ -90,66 +82,6 @@ describe('lib/viewers/iframe/IFrameViewer', () => {
iframe.load();
});

test('should not return a viewer if file is a boxdicom and the open_with_ambra FF is enabled', () => {
iframe.options.file.extension = 'boxdicom';

const viewerOptions = {
IFrame: {
disableDicom: true,
},
};
const viewer = IFrameLoader.determineViewer(iframe, [], viewerOptions);
expect(viewer).toBeUndefined();
});

test('should return a viewer if file is a boxnote and open_with_ambra FF is enabled', () => {
iframe.options.file.extension = 'boxnote';

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

test('should return a viewer if open_with_ambra FF is disabled', () => {
iframe.options.file.extension = 'boxdicom';

const viewerOptions = {
IFrame: {
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 abc58ae

Please sign in to comment.