Skip to content

Commit

Permalink
Chore: Mock super.setup() in all Viewer unit tests (#81)
Browse files Browse the repository at this point in the history
  • Loading branch information
pramodsum authored Apr 18, 2017
1 parent 8285e39 commit fec384c
Show file tree
Hide file tree
Showing 21 changed files with 182 additions and 5 deletions.
11 changes: 11 additions & 0 deletions src/lib/viewers/box3d/__tests__/Box3DViewer-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ let box3d;
let stubs = {};

describe('lib/viewers/box3d/Box3DViewer', () => {
const setupFunc = BaseViewer.prototype.setup;

before(() => {
fixture.setBase('src/lib');
});
Expand All @@ -45,6 +47,9 @@ describe('lib/viewers/box3d/Box3DViewer', () => {
}
}
});

Object.defineProperty(BaseViewer.prototype, 'setup', { value: sandbox.mock() });
box3d.containerEl = containerEl;
box3d.setup();

sandbox.stub(box3d, 'createSubModules');
Expand All @@ -67,6 +72,8 @@ describe('lib/viewers/box3d/Box3DViewer', () => {
sandbox.verifyAndRestore();
fixture.cleanup();

Object.defineProperty(BaseViewer.prototype, 'setup', { value: setupFunc });

if (box3d && typeof box3d.destroy === 'function') {
box3d.destroy();
}
Expand All @@ -91,6 +98,8 @@ describe('lib/viewers/box3d/Box3DViewer', () => {
}
}
});
Object.defineProperty(BaseViewer.prototype, 'setup', { value: sandbox.mock() });
box3d.containerEl = containerEl;
box3d.setup();

box3d.createSubModules();
Expand Down Expand Up @@ -325,6 +334,8 @@ describe('lib/viewers/box3d/Box3DViewer', () => {
});

it('should call renderer.load()', () => {
Object.defineProperty(BaseViewer.prototype, 'setup', { value: sandbox.mock() });
box3d.containerEl = containerEl;
Object.defineProperty(BaseViewer.prototype, 'load', { value: sandbox.mock() });
sandbox.stub(box3d, 'loadAssets').returns(Promise.resolve());
sandbox.stub(box3d, 'getRepStatus').returns({ getPromise: () => Promise.resolve() });
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
/* eslint-disable no-unused-expressions */
import Image360Viewer from '../Image360Viewer';
import BaseViewer from '../../../BaseViewer';
import Box3DControls from '../../Box3DControls';
import Image360Renderer from '../Image360Renderer';

Expand All @@ -9,6 +10,7 @@ const CSS_CLASS_IMAGE_360 = 'bp-image-360';
describe('lib/viewers/box3d/image360/Image360Viewer', () => {
let containerEl;
let viewer;
const setupFunc = BaseViewer.prototype.setup;

before(() => {
fixture.setBase('src/lib');
Expand All @@ -24,12 +26,16 @@ describe('lib/viewers/box3d/image360/Image360Viewer', () => {
id: '0'
}
});
Object.defineProperty(BaseViewer.prototype, 'setup', { value: sandbox.mock() });
viewer.containerEl = containerEl;
});

afterEach(() => {
sandbox.verifyAndRestore();
fixture.cleanup();

Object.defineProperty(BaseViewer.prototype, 'setup', { value: setupFunc });

if (viewer && typeof viewer.destroy === 'function') {
viewer.destroy();
}
Expand Down
10 changes: 10 additions & 0 deletions src/lib/viewers/box3d/model3d/__tests__/Model3DViewer-test.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
/* eslint-disable no-unused-expressions */
import Model3DViewer from '../Model3DViewer';
import BaseViewer from '../../../BaseViewer';
import Model3DControls from '../Model3DControls';
import Model3DRenderer from '../Model3DRenderer';
import {
Expand All @@ -21,6 +22,8 @@ let model3d;
let stubs = {};

describe('lib/viewers/box3d/model3d/Model3DViewer', () => {
const setupFunc = BaseViewer.prototype.setup;

before(() => {
fixture.setBase('src/lib');
});
Expand All @@ -43,6 +46,9 @@ describe('lib/viewers/box3d/model3d/Model3DViewer', () => {
}
}
});

Object.defineProperty(BaseViewer.prototype, 'setup', { value: sandbox.mock() });
model3d.containerEl = containerEl;
model3d.setup();

sandbox.stub(model3d, 'createSubModules');
Expand Down Expand Up @@ -92,6 +98,8 @@ describe('lib/viewers/box3d/model3d/Model3DViewer', () => {
fixture.cleanup();
stubs = {};

Object.defineProperty(BaseViewer.prototype, 'setup', { value: setupFunc });

if (model3d && typeof model3d.destroy === 'function') {
model3d.destroy();
}
Expand All @@ -115,6 +123,8 @@ describe('lib/viewers/box3d/model3d/Model3DViewer', () => {
}
}
});
Object.defineProperty(BaseViewer.prototype, 'setup', { value: sandbox.mock() });
m3d.containerEl = containerEl;
m3d.setup();

m3d.createSubModules();
Expand Down
6 changes: 6 additions & 0 deletions src/lib/viewers/doc/__tests__/DocBaseViewer-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ let containerEl;
let stubs = {};

describe('src/lib/viewers/doc/DocBaseViewer', () => {
const setupFunc = BaseViewer.prototype.setup;

before(() => {
fixture.setBase('src/lib');
});
Expand All @@ -54,6 +56,8 @@ describe('src/lib/viewers/doc/DocBaseViewer', () => {
id: '0'
}
});
Object.defineProperty(BaseViewer.prototype, 'setup', { value: sandbox.mock() });
docBase.containerEl = containerEl;
docBase.setup();
stubs = {};
});
Expand All @@ -62,6 +66,8 @@ describe('src/lib/viewers/doc/DocBaseViewer', () => {
sandbox.verifyAndRestore();
fixture.cleanup();

Object.defineProperty(BaseViewer.prototype, 'setup', { value: setupFunc });

docBase.pdfViewer = undefined;
if (typeof docBase.destroy === 'function') {
docBase.destroy();
Expand Down
8 changes: 8 additions & 0 deletions src/lib/viewers/doc/__tests__/DocumentViewer-test.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
/* eslint-disable no-unused-expressions */
import DocumentViewer from '../DocumentViewer';
import DocBaseViewer from '../DocBaseViewer';
import BaseViewer from '../../BaseViewer';
import DocPreloader from '../DocPreloader';
import fullscreen from '../../../Fullscreen';
import {
Expand All @@ -19,6 +20,8 @@ let doc;
let stubs = {};

describe('lib/viewers/doc/DocumentViewer', () => {
const setupFunc = BaseViewer.prototype.setup;

before(() => {
fixture.setBase('src/lib');
});
Expand All @@ -33,6 +36,9 @@ describe('lib/viewers/doc/DocumentViewer', () => {
id: '0'
}
});

Object.defineProperty(BaseViewer.prototype, 'setup', { value: sandbox.mock() });
doc.containerEl = containerEl;
doc.setup();

doc.pdfViewer = {
Expand All @@ -48,6 +54,8 @@ describe('lib/viewers/doc/DocumentViewer', () => {
sandbox.verifyAndRestore();
fixture.cleanup();

Object.defineProperty(BaseViewer.prototype, 'setup', { value: setupFunc });

if (doc && typeof doc.destroy === 'function') {
doc.destroy();
}
Expand Down
8 changes: 8 additions & 0 deletions src/lib/viewers/doc/__tests__/PresentationViewer-test.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
/* eslint-disable no-unused-expressions */
import PresentationViewer from '../PresentationViewer';
import BaseViewer from '../../BaseViewer';
import Browser from '../../../Browser';
import DocBaseViewer from '../DocBaseViewer';
import PresentationPreloader from '../PresentationPreloader';
Expand All @@ -22,6 +23,8 @@ let presentation;
let stubs = {};

describe('lib/viewers/doc/PresentationViewer', () => {
const setupFunc = BaseViewer.prototype.setup;

before(() => {
fixture.setBase('src/lib');
});
Expand All @@ -33,6 +36,9 @@ describe('lib/viewers/doc/PresentationViewer', () => {
presentation = new PresentationViewer({
container: containerEl
});

Object.defineProperty(BaseViewer.prototype, 'setup', { value: sandbox.mock() });
presentation.containerEl = containerEl;
presentation.setup();

presentation.pdfViewer = {
Expand All @@ -54,6 +60,8 @@ describe('lib/viewers/doc/PresentationViewer', () => {
sandbox.verifyAndRestore();
fixture.cleanup();

Object.defineProperty(BaseViewer.prototype, 'setup', { value: setupFunc });

if (presentation && typeof presentation.destroy === 'function') {
presentation.pdfViewer = undefined;
presentation.destroy();
Expand Down
11 changes: 10 additions & 1 deletion src/lib/viewers/error/__tests__/PreviewErrorViewer-test.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
/* eslint-disable no-unused-expressions */
import PreviewErrorViewer from '../PreviewErrorViewer';
import BaseViewer from '../../BaseViewer';
import Browser from '../../../Browser';
import * as file from '../../../file';
import { PERMISSION_DOWNLOAD } from '../../../constants';
Expand All @@ -11,26 +12,34 @@ import {

const sandbox = sinon.sandbox.create();
let error;
let containerEl;

describe('lib/viewers/error/PreviewErrorViewer', () => {
const setupFunc = BaseViewer.prototype.setup;

before(() => {
fixture.setBase('src/lib');
});

beforeEach(() => {
fixture.load('viewers/error/__tests__/PreviewErrorViewer-test.html');
containerEl = document.querySelector('.container');
error = new PreviewErrorViewer({
file: {
id: '1'
},
container: '.container'
container: containerEl
});
Object.defineProperty(BaseViewer.prototype, 'setup', { value: sandbox.mock() });
error.containerEl = containerEl;
});

afterEach(() => {
fixture.cleanup();
sandbox.verifyAndRestore();

Object.defineProperty(BaseViewer.prototype, 'setup', { value: setupFunc });

if (error && typeof error.destroy === 'function') {
error.destroy();
}
Expand Down
8 changes: 8 additions & 0 deletions src/lib/viewers/iframe/__tests__/IFrameViewer-test.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
import IFrameViewer from '../IFrameViewer';
import BaseViewer from '../../BaseViewer';

const sandbox = sinon.sandbox.create();
let containerEl;
let iframe;

describe('lib/viewers/iframe/IFrameViewer', () => {
const setupFunc = BaseViewer.prototype.setup;

before(() => {
fixture.setBase('src/lib');
});
Expand All @@ -19,12 +22,17 @@ describe('lib/viewers/iframe/IFrameViewer', () => {
extension: 'boxnote'
}
});

Object.defineProperty(BaseViewer.prototype, 'setup', { value: sandbox.mock() });
iframe.containerEl = containerEl;
});

afterEach(() => {
sandbox.verifyAndRestore();
fixture.cleanup();

Object.defineProperty(BaseViewer.prototype, 'setup', { value: setupFunc });

if (iframe && typeof iframe.destroy === 'function') {
iframe.destroy();
}
Expand Down
10 changes: 10 additions & 0 deletions src/lib/viewers/image/__tests__/ImageViewer-test.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
/* eslint-disable no-unused-expressions */
import ImageViewer from '../ImageViewer';
import BaseViewer from '../../BaseViewer';
import Browser from '../../../Browser';
import * as file from '../../../file';
import * as util from '../../../util';
Expand All @@ -16,6 +17,8 @@ let containerEl;
let clock;

describe('lib/viewers/image/ImageViewer', () => {
const setupFunc = BaseViewer.prototype.setup;

before(() => {
fixture.setBase('src/lib');
});
Expand Down Expand Up @@ -45,6 +48,9 @@ describe('lib/viewers/image/ImageViewer', () => {
}
}
});

Object.defineProperty(BaseViewer.prototype, 'setup', { value: sandbox.stub() });
image.containerEl = containerEl;
image.setup();
});

Expand All @@ -53,6 +59,8 @@ describe('lib/viewers/image/ImageViewer', () => {
fixture.cleanup();
clock.restore();

Object.defineProperty(BaseViewer.prototype, 'setup', { value: setupFunc });

if (image && typeof image.destroy === 'function') {
image.destroy();
}
Expand All @@ -70,6 +78,8 @@ describe('lib/viewers/image/ImageViewer', () => {
});
sandbox.stub(image, 'initAnnotations');

Object.defineProperty(BaseViewer.prototype, 'setup', { value: sandbox.stub() });
image.containerEl = containerEl;
image.setup();

expect(image.wrapperEl).to.have.class('bp-image');
Expand Down
8 changes: 8 additions & 0 deletions src/lib/viewers/image/__tests__/MultiImageViewer-test.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
/* eslint-disable no-unused-expressions */
import MultiImageViewer from '../MultiImageViewer';
import fullscreen from '../../../Fullscreen';
import BaseViewer from '../../BaseViewer';
import Browser from '../../../Browser';

const CLASS_INVISIBLE = 'bp-is-invisible';
Expand All @@ -15,6 +16,8 @@ let containerEl;

describe('lib/viewers/image/MultiImageViewer', () => {
stubs.errorHandler = MultiImageViewer.prototype.errorHandler;
const setupFunc = BaseViewer.prototype.setup;

before(() => {
fixture.setBase('src/lib');
});
Expand Down Expand Up @@ -45,9 +48,14 @@ describe('lib/viewers/image/MultiImageViewer', () => {
};

multiImage = new MultiImageViewer(options);

Object.defineProperty(BaseViewer.prototype, 'setup', { value: sandbox.stub() });
multiImage.containerEl = containerEl;
});

afterEach(() => {
Object.defineProperty(BaseViewer.prototype, 'setup', { value: setupFunc });

if (multiImage && multiImage.imagesEl) {
multiImage.destroy();
}
Expand Down
Loading

0 comments on commit fec384c

Please sign in to comment.