From 907661d6630b7242ef1f705d4392bb73491dadcd Mon Sep 17 00:00:00 2001 From: Jared Stoffan Date: Mon, 28 Sep 2020 09:47:07 -0700 Subject: [PATCH] test(jest): Convert the remaining 3D viewer unit tests to Jest (#1267) --- .../__tests__/AnnotationControlsFSM-test.js | 2 +- src/lib/__tests__/Controls-test.js | 8 +- src/lib/__tests__/Preview-test.js | 6 +- src/lib/__tests__/i18n-test.js | 2 +- src/lib/viewers/__tests__/BaseViewer-test.js | 4 +- .../viewers/box3d/__mocks__/Box3DRuntime.js | 22 ++++ .../box3d/__tests__/Box3DRenderer-test.js | 5 +- .../__tests__/Image360Renderer-test.js | 5 +- .../model3d/__tests__/Model3DControls-test.js | 22 ++-- .../model3d/__tests__/Model3DRenderer-test.js | 122 ++++++++++-------- .../model3d/__tests__/Model3DViewer-test.js | 53 ++++---- .../__tests__/Video360Controls-test.js | 22 ++-- .../__tests__/Video360Renderer-test.js | 4 +- .../video360/__tests__/Video360Viewer-test.js | 50 +++---- .../doc/__tests__/DocBaseViewer-test.js | 10 +- .../image/__tests__/ImageBaseViewer-test.js | 8 +- .../image/__tests__/ImageLoader-test.js | 4 +- 17 files changed, 193 insertions(+), 156 deletions(-) create mode 100644 src/lib/viewers/box3d/__mocks__/Box3DRuntime.js diff --git a/src/lib/__tests__/AnnotationControlsFSM-test.js b/src/lib/__tests__/AnnotationControlsFSM-test.js index 36d10b52c..42fb950f0 100644 --- a/src/lib/__tests__/AnnotationControlsFSM-test.js +++ b/src/lib/__tests__/AnnotationControlsFSM-test.js @@ -61,7 +61,7 @@ describe('lib/AnnotationControlsFSM', () => { }); // Should reset state - it('should reset state if input is AnnotationInput.RESET', () => { + test('should reset state if input is AnnotationInput.RESET', () => { const annotationControlsFSM = new AnnotationControlsFSM(); expect(annotationControlsFSM.transition(AnnotationInput.RESET)).toEqual(AnnotationMode.NONE); diff --git a/src/lib/__tests__/Controls-test.js b/src/lib/__tests__/Controls-test.js index 06b5fc023..eebceb4ef 100644 --- a/src/lib/__tests__/Controls-test.js +++ b/src/lib/__tests__/Controls-test.js @@ -45,13 +45,13 @@ describe('lib/Controls', () => { controlsElEventListener = undefined; }); - it('should create the correct DOM structure', () => { + test('should create the correct DOM structure', () => { expect(controls.containerEl).toEqual(document.getElementById('test-controls-container')); expect(controls.controlsEl.classList.contains('bp-controls')).toBe(true); }); - it('should add the correct event listeners', () => { + test('should add the correct event listeners', () => { jest.spyOn(Browser, 'hasTouch').mockReturnValue(false); controls = new Controls(container); @@ -63,7 +63,7 @@ describe('lib/Controls', () => { expect(controlsElEventListener).toBeCalledWith('click', controls.clickHandler); }); - it('should add the correct event listeners when browser has touch', () => { + test('should add the correct event listeners when browser has touch', () => { jest.spyOn(Browser, 'hasTouch').mockReturnValue(true); controls = new Controls(container); @@ -282,7 +282,7 @@ describe('lib/Controls', () => { expect(controls.shouldHide).toBe(true); }); - it('should call stopPropagation on event when called', () => { + test('should call stopPropagation on event when called', () => { const stopPropagation = jest.fn(); controls.clickHandler({ stopPropagation }); diff --git a/src/lib/__tests__/Preview-test.js b/src/lib/__tests__/Preview-test.js index 4d4b230d3..1f4dc08c0 100644 --- a/src/lib/__tests__/Preview-test.js +++ b/src/lib/__tests__/Preview-test.js @@ -798,21 +798,21 @@ describe('lib/Preview', () => { stubs.checkFeature = jest.spyOn(file, 'checkFeature'); }); - it('should return true is file is downloadable and has printing feature', () => { + test('should return true is file is downloadable and has printing feature', () => { stubs.canDownload.mockReturnValue(true); stubs.checkFeature.mockReturnValue(true); expect(preview.canPrint()).toBe(true); }); - it('should return false is file is not downloadable and has printing feature', () => { + test('should return false is file is not downloadable and has printing feature', () => { stubs.canDownload.mockReturnValue(false); stubs.checkFeature.mockReturnValue(true); expect(preview.canPrint()).toBe(false); }); - it('should return false is file is downloadable and but does not have printing feature', () => { + test('should return false is file is downloadable and but does not have printing feature', () => { stubs.canDownload.mockReturnValue(true); stubs.checkFeature.mockReturnValue(false); diff --git a/src/lib/__tests__/i18n-test.js b/src/lib/__tests__/i18n-test.js index 3660a11d3..6e74c6c7a 100644 --- a/src/lib/__tests__/i18n-test.js +++ b/src/lib/__tests__/i18n-test.js @@ -1,7 +1,7 @@ import i18n from '../i18n'; describe('i18n', () => { - it('should return an intl provider object', () => { + test('should return an intl provider object', () => { const intl = i18n.createAnnotatorIntl(); expect(intl.language).toBe('en-US'); expect(intl.locale).toBe('en'); diff --git a/src/lib/viewers/__tests__/BaseViewer-test.js b/src/lib/viewers/__tests__/BaseViewer-test.js index c7fdb85bc..c002bddd3 100644 --- a/src/lib/viewers/__tests__/BaseViewer-test.js +++ b/src/lib/viewers/__tests__/BaseViewer-test.js @@ -1833,7 +1833,7 @@ describe('lib/viewers/BaseViewer', () => { }); }); - it('should reset controls if status is success', () => { + test('should reset controls if status is success', () => { const event = createEvent('success'); base.handleAnnotationCreateEvent(event); @@ -1928,7 +1928,7 @@ describe('lib/viewers/BaseViewer', () => { expect(base.containerEl.classList.remove).not.toBeCalled(); }); - it('should call annotationControls setMode', () => { + test('should call annotationControls setMode', () => { base.processAnnotationModeChange(AnnotationMode.REGION); expect(base.annotationControls.setMode).toBeCalledWith(AnnotationMode.REGION); diff --git a/src/lib/viewers/box3d/__mocks__/Box3DRuntime.js b/src/lib/viewers/box3d/__mocks__/Box3DRuntime.js new file mode 100644 index 000000000..dfe1e1189 --- /dev/null +++ b/src/lib/viewers/box3d/__mocks__/Box3DRuntime.js @@ -0,0 +1,22 @@ +import { MODEL3D_STATIC_ASSETS_VERSION } from '../../../constants'; + +const consoleLog = global.console.log; + +global.console.log = message => { + // Workaround to suppress irrelevant console messages regarding schema compatibility in Box3D/AJV + if (typeof message === 'string' && message.indexOf('$ref: all keywords') >= 0) { + return; + } + + consoleLog(message); +}; + +/* eslint-disable import/no-dynamic-require */ +const Box3DRuntime = require(`../../../../third-party/model3d/${MODEL3D_STATIC_ASSETS_VERSION}/box3d-runtime.min.js`); +const THREE = require(`../../../../third-party/model3d/${MODEL3D_STATIC_ASSETS_VERSION}/three.min.js`); +/* eslint-enable import/no-dynamic-require */ + +global.console.log = consoleLog; + +export { THREE }; +export default Box3DRuntime; diff --git a/src/lib/viewers/box3d/__tests__/Box3DRenderer-test.js b/src/lib/viewers/box3d/__tests__/Box3DRenderer-test.js index ed882aafd..71ffce710 100644 --- a/src/lib/viewers/box3d/__tests__/Box3DRenderer-test.js +++ b/src/lib/viewers/box3d/__tests__/Box3DRenderer-test.js @@ -1,11 +1,8 @@ /* global Box3D */ /* eslint-disable no-unused-expressions */ import Box3DRenderer from '../Box3DRenderer'; +import Box3DRuntime from '../__mocks__/Box3DRuntime'; import { EVENT_SHOW_VR_BUTTON, EVENT_WEBGL_CONTEXT_RESTORED } from '../box3DConstants'; -import { MODEL3D_STATIC_ASSETS_VERSION } from '../../../constants'; - -// eslint-disable-next-line import/no-dynamic-require -const Box3DRuntime = require(`../../../../third-party/model3d/${MODEL3D_STATIC_ASSETS_VERSION}/box3d-runtime.min.js`); const sandbox = sinon.createSandbox(); const PREVIEW_CAMERA_CONTROLLER_ID = 'orbit_camera'; diff --git a/src/lib/viewers/box3d/image360/__tests__/Image360Renderer-test.js b/src/lib/viewers/box3d/image360/__tests__/Image360Renderer-test.js index 2c8495230..74efa678f 100644 --- a/src/lib/viewers/box3d/image360/__tests__/Image360Renderer-test.js +++ b/src/lib/viewers/box3d/image360/__tests__/Image360Renderer-test.js @@ -1,10 +1,7 @@ /* eslint-disable no-unused-expressions */ +import Box3DRuntime from '../../__mocks__/Box3DRuntime'; import Image360Renderer from '../Image360Renderer'; import sceneEntities from '../SceneEntities'; -import { MODEL3D_STATIC_ASSETS_VERSION } from '../../../../constants'; - -// eslint-disable-next-line import/no-dynamic-require -const Box3DRuntime = require(`../../../../../third-party/model3d/${MODEL3D_STATIC_ASSETS_VERSION}/box3d-runtime.min.js`); describe('lib/viewers/box3d/image360/Image360Renderer', () => { let containerEl; diff --git a/src/lib/viewers/box3d/model3d/__tests__/Model3DControls-test.js b/src/lib/viewers/box3d/model3d/__tests__/Model3DControls-test.js index 1fd7dea9f..e6756d9e4 100644 --- a/src/lib/viewers/box3d/model3d/__tests__/Model3DControls-test.js +++ b/src/lib/viewers/box3d/model3d/__tests__/Model3DControls-test.js @@ -19,7 +19,7 @@ import { ICON_3D_RESET, ICON_ANIMATION, ICON_GEAR, ICON_PAUSE, ICON_PLAY } from import { CSS_CLASS_HIDDEN } from '../../box3DConstants'; -describe.skip('lib/viewers/box3d/model3d/Model3DControls', () => { +describe('lib/viewers/box3d/model3d/Model3DControls', () => { let containerEl; let controls; const sandbox = sinon.createSandbox(); @@ -422,20 +422,20 @@ describe.skip('lib/viewers/box3d/model3d/Model3DControls', () => { describe('handleSelectAnimationClip()', () => { test('should invoke setAnimationPlaying() to stop animation playback', () => { - const stub = jest.spyOn(controls, 'setAnimationPlaying'); + const stub = jest.spyOn(controls, 'setAnimationPlaying').mockImplementation(); controls.handleSelectAnimationClip(); expect(stub).toBeCalledWith(false); }); test('should emit a "select animation clip" event', () => { - jest.spyOn(controls, 'setAnimationPlaying'); + jest.spyOn(controls, 'setAnimationPlaying').mockImplementation(); const stub = jest.spyOn(controls, 'emit'); controls.handleSelectAnimationClip(); - expect(stub).toBeCalledWith(EVENT_SELECT_ANIMATION_CLIP); + expect(stub).toBeCalledWith(EVENT_SELECT_ANIMATION_CLIP, undefined); }); test('should emit a "select animation clip" event, with the clip selected', () => { - jest.spyOn(controls, 'setAnimationPlaying'); + jest.spyOn(controls, 'setAnimationPlaying').mockImplementation(); const stub = jest.spyOn(controls, 'emit'); const id = 'p1p1p1p1'; controls.handleSelectAnimationClip(id); @@ -458,19 +458,19 @@ describe.skip('lib/viewers/box3d/model3d/Model3DControls', () => { describe('handleToggleAnimation()', () => { test('should invoke hidePullups()', () => { const hidePullupsStub = jest.spyOn(controls, 'hidePullups'); - jest.spyOn(controls, 'setAnimationPlaying'); + jest.spyOn(controls, 'setAnimationPlaying').mockImplementation(); controls.handleToggleAnimation(); expect(hidePullupsStub).toBeCalled(); }); test('should toggle playback of the current animation via setAnimationPlaying()', () => { - const playStub = jest.spyOn(controls, 'setAnimationPlaying'); + const playStub = jest.spyOn(controls, 'setAnimationPlaying').mockImplementation(); controls.handleToggleAnimation(); expect(playStub).toBeCalled(); }); test('should set toggle animation playback by inverting playback state (.isAnimationPlaying)', () => { - const playStub = jest.spyOn(controls, 'setAnimationPlaying'); + const playStub = jest.spyOn(controls, 'setAnimationPlaying').mockImplementation(); controls.isAnimationPlaying = true; controls.handleToggleAnimation(); expect(playStub).toBeCalledWith(false); @@ -579,20 +579,20 @@ describe.skip('lib/viewers/box3d/model3d/Model3DControls', () => { describe('handleReset()', () => { test('should hide all pullups', () => { - jest.spyOn(controls, 'setAnimationPlaying'); + jest.spyOn(controls, 'setAnimationPlaying').mockImplementation(); const stub = jest.spyOn(controls, 'hidePullups'); controls.handleReset(); expect(stub).toBeCalled(); }); test('should reset the settings pullup', () => { - jest.spyOn(controls, 'setAnimationPlaying'); + jest.spyOn(controls, 'setAnimationPlaying').mockImplementation(); sandbox.mock(controls.settingsPullup).expects('reset'); controls.handleReset(); }); test('should pause animation playback', () => { - const stub = jest.spyOn(controls, 'setAnimationPlaying'); + const stub = jest.spyOn(controls, 'setAnimationPlaying').mockImplementation(); controls.handleReset(); expect(stub).toBeCalledWith(false); }); diff --git a/src/lib/viewers/box3d/model3d/__tests__/Model3DRenderer-test.js b/src/lib/viewers/box3d/model3d/__tests__/Model3DRenderer-test.js index f3d73f618..f03f09f25 100644 --- a/src/lib/viewers/box3d/model3d/__tests__/Model3DRenderer-test.js +++ b/src/lib/viewers/box3d/model3d/__tests__/Model3DRenderer-test.js @@ -1,7 +1,8 @@ -/* global THREE Box3D */ +/* global Box3D */ /* eslint-disable no-unused-expressions */ -import Model3DRenderer from '../Model3DRenderer'; import Box3DRenderer from '../../Box3DRenderer'; +import Box3DRuntime, { THREE } from '../../__mocks__/Box3DRuntime'; +import Model3DRenderer from '../Model3DRenderer'; import Model3dVrControls from '../Model3DVrControls'; import { CAMERA_PROJECTION_PERSPECTIVE, @@ -13,7 +14,7 @@ import { EVENT_SET_WIREFRAMES_VISIBLE, } from '../model3DConstants'; -describe.skip('lib/viewers/box3d/model3d/Model3DRenderer', () => { +describe('lib/viewers/box3d/model3d/Model3DRenderer', () => { const sandbox = sinon.createSandbox(); let containerEl; let renderer; @@ -25,10 +26,15 @@ describe.skip('lib/viewers/box3d/model3d/Model3DRenderer', () => { let animation; let animationComp; + beforeAll(() => { + global.Box3D = Box3DRuntime; + global.THREE = THREE; + }); + beforeEach(() => { fixture.load('viewers/box3d/model3d/__tests__/Model3DRenderer-test.html'); containerEl = document.querySelector('.container'); - stubs.BoxSDK = jest.spyOn(window, 'BoxSDK'); + stubs.BoxSDK = sandbox.stub(window, 'BoxSDK'); renderer = new Model3DRenderer(containerEl, {}); app = { getComponentByScriptId: () => {}, @@ -101,7 +107,7 @@ describe.skip('lib/viewers/box3d/model3d/Model3DRenderer', () => { describe('destroy()', () => { test('should remove event listener from the engine instance canvas', () => { - const removeListener = jest.spyOn(renderer.box3d.canvas, 'removeEventListener'); + const removeListener = jest.spyOn(renderer.box3d.canvas, 'removeEventListener').mockImplementation(); renderer.destroy(); expect(removeListener).toBeCalled(); }); @@ -129,12 +135,12 @@ describe.skip('lib/viewers/box3d/model3d/Model3DRenderer', () => { describe('load()', () => { test('should do nothing with scene entities if location is not present in options', done => { const options = { file: { id: 'dummyId' } }; - jest.spyOn(renderer, 'initBox3d').mockImplementation(opts => { - expect(opts.sceneEntities).not.toBeDefined(); + sandbox.stub(renderer, 'initBox3d').callsFake(opts => { + expect(opts.sceneEntities).toBeUndefined(); done(); return Promise.resolve(); }); - jest.spyOn(renderer, 'loadBox3dFile').mockImplementation(); + sandbox.stub(renderer, 'loadBox3dFile'); renderer.load('', options); }); @@ -143,13 +149,16 @@ describe.skip('lib/viewers/box3d/model3d/Model3DRenderer', () => { location: { staticBaseURI: '', }, + file: { + id: '', + }, }; - jest.spyOn(renderer, 'initBox3d').mockImplementation(opts => { + sandbox.stub(renderer, 'initBox3d').callsFake(opts => { expect(opts.sceneEntities).toBeDefined(); done(); return Promise.resolve(); }); - jest.spyOn(renderer, 'loadBox3dFile').mockImplementation(); + sandbox.stub(renderer, 'loadBox3dFile'); renderer.load('', options); }); @@ -162,15 +171,15 @@ describe.skip('lib/viewers/box3d/model3d/Model3DRenderer', () => { id: '', }, }; - renderMock.expects('initBox3d').mockResolvedValue(undefined); - jest.spyOn(renderer, 'loadBox3dFile').mockImplementation(); + renderMock.expects('initBox3d').returns(Promise.resolve()); + sandbox.stub(renderer, 'loadBox3dFile'); renderer.load('', options); }); test('should load the box3d file after initializing the runtime', done => { const options = { file: { id: '' } }; - renderMock.expects('initBox3d').mockResolvedValue(undefined); - renderMock.expects('loadBox3dFile').mockResolvedValue(undefined); + renderMock.expects('initBox3d').returns(Promise.resolve()); + renderMock.expects('loadBox3dFile').returns(Promise.resolve()); renderer.load('http://derpy.net', options).then(() => { done(); }); @@ -179,7 +188,7 @@ describe.skip('lib/viewers/box3d/model3d/Model3DRenderer', () => { test('should setup the scene via onUnsupportedRepresentation() if it cannot load the model', done => { const options = { file: { id: '' } }; renderMock.expects('onUnsupportedRepresentation'); - jest.spyOn(renderer, 'loadBox3dFile').mockImplementation(() => Promise.reject()); + sandbox.stub(renderer, 'loadBox3dFile').callsFake(() => Promise.reject()); renderer.load('', options).then(() => done()); }); }); @@ -222,25 +231,25 @@ describe.skip('lib/viewers/box3d/model3d/Model3DRenderer', () => { describe('setupScene()', () => { beforeEach(() => { - jest.spyOn(renderer.box3d, 'getAssetsByType').mockReturnValue([]); + sandbox.stub(renderer.box3d, 'getAssetsByType').returns([]); }); test('should do nothing if no scene instance is present', () => { - renderMock.expects('getScene').mockReturnValue(undefined); + renderMock.expects('getScene').returns(undefined); renderer.setupScene(); }); test('should invoke addHelpersToScene() to add the scene grid and axis colour lines to the scene', () => { renderer.instance = instance; - jest.spyOn(renderer, 'getScene').mockReturnValue(scene); + sandbox.stub(renderer, 'getScene').returns(scene); renderMock.expects('addHelpersToScene').once(); renderer.setupScene(); }); test('should invoke onSceneLoad when the scene has been loaded', () => { renderer.instance = instance; - jest.spyOn(renderer, 'getScene').mockReturnValue(scene); - jest.spyOn(scene, 'when').mockImplementation((event, cb) => cb()); + sandbox.stub(renderer, 'getScene').returns(scene); + sandbox.stub(scene, 'when').callsFake((event, cb) => cb()); const stub = jest.spyOn(renderer, 'onSceneLoad').mockImplementation(); renderer.setupScene(); expect(stub).toBeCalled(); @@ -248,7 +257,7 @@ describe.skip('lib/viewers/box3d/model3d/Model3DRenderer', () => { test('should add a listener on the scene instance for it to be loaded', () => { renderer.instance = instance; - jest.spyOn(renderer, 'getScene').mockReturnValue(scene); + sandbox.stub(renderer, 'getScene').returns(scene); sandbox .mock(scene) .expects('when') @@ -280,7 +289,7 @@ describe.skip('lib/viewers/box3d/model3d/Model3DRenderer', () => { describe('reset()', () => { test('should invoke resetModel()', () => { const stub = jest.spyOn(renderer, 'resetModel').mockImplementation(); - jest.spyOn(Box3DRenderer.prototype, 'reset'); + jest.spyOn(Box3DRenderer.prototype, 'reset').mockImplementation(); renderer.reset(); expect(stub).toBeCalled(); }); @@ -323,7 +332,7 @@ describe.skip('lib/viewers/box3d/model3d/Model3DRenderer', () => { setScale: () => {}, unsetProperty: () => {}, }; - jest.spyOn(renderer.instance, 'getChildren').mockReturnValue([child]); + sandbox.stub(renderer.instance, 'getChildren').returns([child]); sandbox .mock(child) .expects('setPosition') @@ -338,7 +347,7 @@ describe.skip('lib/viewers/box3d/model3d/Model3DRenderer', () => { setScale: () => {}, unsetProperty: () => {}, }; - jest.spyOn(renderer.instance, 'getChildren').mockReturnValue([child]); + sandbox.stub(renderer.instance, 'getChildren').returns([child]); sandbox .mock(child) .expects('setQuaternion') @@ -353,7 +362,7 @@ describe.skip('lib/viewers/box3d/model3d/Model3DRenderer', () => { setScale: () => {}, unsetProperty: () => {}, }; - jest.spyOn(renderer.instance, 'getChildren').mockReturnValue([child]); + sandbox.stub(renderer.instance, 'getChildren').returns([child]); sandbox .mock(child) .expects('setScale') @@ -366,9 +375,9 @@ describe.skip('lib/viewers/box3d/model3d/Model3DRenderer', () => { let camera; let orbitComp; beforeEach(() => { - jest.spyOn(Box3DRenderer.prototype, 'resetView').mockImplementation(); - jest.spyOn(THREE.Vector3.prototype, 'subVectors').mockImplementation(); - jest.spyOn(THREE.Vector3.prototype, 'applyMatrix4').mockImplementation(); + sandbox.stub(Box3DRenderer.prototype, 'resetView'); + sandbox.stub(THREE.Vector3.prototype, 'subVectors'); + sandbox.stub(THREE.Vector3.prototype, 'applyMatrix4'); orbitComp = { setPivotPosition: () => {}, setOrbitDistance: () => {}, @@ -391,7 +400,7 @@ describe.skip('lib/viewers/box3d/model3d/Model3DRenderer', () => { updateMatrixWorld: () => {}, }, }; - jest.spyOn(renderer, 'getCamera').mockImplementation(() => camera); + sandbox.stub(renderer, 'getCamera').callsFake(() => camera); }); test('should do nothing if there is no camera', () => { @@ -413,7 +422,7 @@ describe.skip('lib/viewers/box3d/model3d/Model3DRenderer', () => { .mock(renderer.instance) .expects('computeBounds') .never(); - jest.spyOn(camera, 'getComponentByScriptId').mockReturnValue(undefined); + sandbox.stub(camera, 'getComponentByScriptId').returns(undefined); renderer.resetView(); }); @@ -460,7 +469,7 @@ describe.skip('lib/viewers/box3d/model3d/Model3DRenderer', () => { const videos = []; beforeEach(() => { - jest.spyOn(renderer.box3d, 'getEntitiesByType').mockImplementation(type => { + sandbox.stub(renderer.box3d, 'getEntitiesByType').callsFake(type => { switch (type) { case 'animation': return animations; @@ -536,7 +545,7 @@ describe.skip('lib/viewers/box3d/model3d/Model3DRenderer', () => { sandbox .mock(renderer.instance) .expects('getComponentByScriptId') - .mockReturnValue(animComp); + .returns(animComp); renderer.setAnimationAsset({}); }); @@ -633,7 +642,7 @@ describe.skip('lib/viewers/box3d/model3d/Model3DRenderer', () => { }); test('should add an event listener for the instance to load, after animation asset loads', () => { - jest.spyOn(animAsset, 'when').mockImplementation((event, cb) => cb()); + sandbox.stub(animAsset, 'when').callsFake((event, cb) => cb()); sandbox .mock(renderer.instance) .expects('when') @@ -643,8 +652,8 @@ describe.skip('lib/viewers/box3d/model3d/Model3DRenderer', () => { describe('after instance and animation asset loaded', () => { beforeEach(() => { - jest.spyOn(animAsset, 'when').mockImplementation((event, cb) => cb()); - jest.spyOn(renderer.instance, 'when').mockImplementation((event, cb) => cb()); + sandbox.stub(animAsset, 'when').callsFake((event, cb) => cb()); + sandbox.stub(renderer.instance, 'when').callsFake((event, cb) => cb()); }); test('should pause the animation, by default', () => { @@ -699,9 +708,9 @@ describe.skip('lib/viewers/box3d/model3d/Model3DRenderer', () => { sandbox .mock(renderer) .expects('getScene') - .mockReturnValue(undefined); + .returns(undefined); renderer.addHelpersToScene(); - expect(renderer.grid).not.toBeDefined(); + expect(renderer.grid).toBeUndefined(); }); test('should create a GridHelper object', () => { @@ -751,13 +760,13 @@ describe.skip('lib/viewers/box3d/model3d/Model3DRenderer', () => { sandbox .mock(renderer) .expects('getScene') - .mockReturnValue(undefined); + .returns(undefined); renderer.cleanupHelpers(); expect(renderer.grid.material.dispose).not.toBeCalled(); }); test('should not remove the grid if there is none', () => { - jest.spyOn(renderer, 'getScene').mockReturnValue(scene); + sandbox.stub(renderer, 'getScene').returns(scene); renderer.grid = undefined; renderer.axisDisplay = undefined; sandbox @@ -769,7 +778,7 @@ describe.skip('lib/viewers/box3d/model3d/Model3DRenderer', () => { }); test('should remove the grid from the scene', () => { - jest.spyOn(renderer, 'getScene').mockReturnValue(scene); + sandbox.stub(renderer, 'getScene').returns(scene); renderer.axisDisplay = undefined; sandbox .mock(scene.runtimeData) @@ -896,7 +905,7 @@ describe.skip('lib/viewers/box3d/model3d/Model3DRenderer', () => { }); }); - describe('setCameraProjection()', () => { + describe.skip('setCameraProjection()', () => { let camera; beforeEach(() => { camera = { @@ -908,14 +917,14 @@ describe.skip('lib/viewers/box3d/model3d/Model3DRenderer', () => { }); test('should not throw error if no camera is present', () => { - const mock = sandbox.mock(renderer); - mock.expects('getCamera').mockReturnValue(undefined); + jest.spyOn(renderer, 'getCamera').mockReturnValue(undefined); + expect(renderer.setCameraProjection(CAMERA_PROJECTION_PERSPECTIVE)).not.toThrow(); }); test('should set the perspective properties of the camera if perspective mode is selected', done => { - jest.spyOn(renderer, 'getCamera').mockReturnValue(camera); - jest.spyOn(camera, 'setProperty').mockImplementation((prop, value) => { + sandbox.stub(renderer, 'getCamera').returns(camera); + sandbox.stub(camera, 'setProperty').callsFake((prop, value) => { expect(prop).toBe('cameraType'); expect(value).toBe('perspective'); done(); @@ -924,8 +933,8 @@ describe.skip('lib/viewers/box3d/model3d/Model3DRenderer', () => { }); test('should set the orthographic properties of the camera if ortho mode is selected', done => { - jest.spyOn(renderer, 'getCamera').mockReturnValue(camera); - jest.spyOn(camera, 'setProperty').mockImplementation((prop, value) => { + sandbox.stub(renderer, 'getCamera').returns(camera); + sandbox.stub(camera, 'setProperty').callsFake((prop, value) => { expect(prop).toBe('cameraType'); expect(value).toBe('orthographic'); done(); @@ -934,8 +943,8 @@ describe.skip('lib/viewers/box3d/model3d/Model3DRenderer', () => { }); test('should do nothing for unrecognized projection type', () => { - jest.spyOn(renderer, 'getCamera').mockReturnValue(camera); - jest.spyOn(renderer, 'resetView').mockImplementation(); + sandbox.stub(renderer, 'getCamera').returns(camera); + sandbox.stub(renderer, 'resetView'); sandbox .mock(camera) .expects('setProperty') @@ -950,7 +959,7 @@ describe.skip('lib/viewers/box3d/model3d/Model3DRenderer', () => { center = new THREE.Vector3(); renderer.instance = { trigger: () => {}, - getCenter: jest.fn().mockReturnValue(center), + getCenter: sandbox.stub().returns(center), destroy: () => {}, }; }); @@ -985,10 +994,11 @@ describe.skip('lib/viewers/box3d/model3d/Model3DRenderer', () => { }); }); - describe('setAxisRotation()', () => { + describe.skip('setAxisRotation()', () => { test('should do nothing if no instance available', () => { + jest.spyOn(renderer, 'setAxisRotation'); renderer.instance = undefined; - jest.spyOn(renderer.box3d, 'trigger').mockImplementation(); + sandbox.stub(renderer.box3d, 'trigger'); expect(renderer.setAxisRotation('-x', '-y', false)).not.toThrow(); }); @@ -1090,7 +1100,7 @@ describe.skip('lib/viewers/box3d/model3d/Model3DRenderer', () => { renderer.grid = { visible: false, }; - jest.spyOn(renderer.box3d, 'getVrDisplay').mockReturnValue(device); + sandbox.stub(renderer.box3d, 'getVrDisplay').returns(device); renderer.enableVr(); expect(renderer.grid.visible).toBe(true); renderer.grid = undefined; @@ -1099,7 +1109,7 @@ describe.skip('lib/viewers/box3d/model3d/Model3DRenderer', () => { describe('onDisableVr()', () => { beforeEach(() => { - jest.spyOn(Box3DRenderer.prototype, 'onDisableVr'); + sandbox.stub(Box3DRenderer.prototype, 'onDisableVr'); }); test('should stop listening to engine updates if no device position available', () => { @@ -1140,11 +1150,11 @@ describe.skip('lib/viewers/box3d/model3d/Model3DRenderer', () => { sandbox .mock(renderer) .expects('getCamera') - .mockReturnValue(camera); + .returns(camera); }); test('should do nothing if there is no orbit camera component available', () => { - jest.spyOn(camera, 'getComponentByScriptId').mockReturnValue(undefined); + sandbox.stub(camera, 'getComponentByScriptId').returns(undefined); position.expects('set').never(); renderer.updateNonPositionalVrControls(); }); diff --git a/src/lib/viewers/box3d/model3d/__tests__/Model3DViewer-test.js b/src/lib/viewers/box3d/model3d/__tests__/Model3DViewer-test.js index 06b73db8e..8eb1849ea 100644 --- a/src/lib/viewers/box3d/model3d/__tests__/Model3DViewer-test.js +++ b/src/lib/viewers/box3d/model3d/__tests__/Model3DViewer-test.js @@ -1,8 +1,9 @@ /* eslint-disable no-unused-expressions */ -import Model3DViewer from '../Model3DViewer'; import BaseViewer from '../../../BaseViewer'; +import Box3DRuntime from '../../__mocks__/Box3DRuntime'; import Model3DControls from '../Model3DControls'; import Model3DRenderer from '../Model3DRenderer'; +import Model3DViewer from '../Model3DViewer'; import { EVENT_CANVAS_CLICK, EVENT_ROTATE_ON_AXIS, @@ -21,13 +22,17 @@ let containerEl; let model3d; let stubs = {}; -describe.skip('lib/viewers/box3d/model3d/Model3DViewer', () => { +describe('lib/viewers/box3d/model3d/Model3DViewer', () => { const setupFunc = BaseViewer.prototype.setup; + beforeAll(() => { + global.Box3D = Box3DRuntime; + }); + beforeEach(() => { fixture.load('viewers/box3d/model3d/__tests__/Model3DViewer-test.html'); containerEl = document.querySelector('.container'); - stubs.BoxSDK = jest.spyOn(window, 'BoxSDK'); + stubs.BoxSDK = jest.spyOn(window, 'BoxSDK').mockImplementation(); model3d = new Model3DViewer({ file: { id: 0, @@ -47,7 +52,7 @@ describe.skip('lib/viewers/box3d/model3d/Model3DViewer', () => { model3d.containerEl = containerEl; model3d.setup(); - jest.spyOn(model3d, 'createSubModules'); + jest.spyOn(model3d, 'createSubModules').mockImplementation(); model3d.controls = { addAnimationClip: () => {}, addUi: () => {}, @@ -277,7 +282,7 @@ describe.skip('lib/viewers/box3d/model3d/Model3DViewer', () => { getMetadataClient: () => meta, }; - const stub = jest.spyOn(model3d, 'populateAnimationControls'); + const stub = jest.spyOn(model3d, 'populateAnimationControls').mockImplementation(); model3d.handleSceneLoaded().then(() => { expect(stub).toBeCalled(); done(); @@ -312,7 +317,7 @@ describe.skip('lib/viewers/box3d/model3d/Model3DViewer', () => { b3dMock .expects('getEntitiesByType') .once() - .mockReturnValue([]); + .returns([]); model3d.populateAnimationControls(); }); @@ -323,7 +328,7 @@ describe.skip('lib/viewers/box3d/model3d/Model3DViewer', () => { b3dMock .expects('getEntitiesByType') .once() - .mockReturnValue([animation]); + .returns([animation]); model3d.populateAnimationControls(); }); @@ -343,7 +348,7 @@ describe.skip('lib/viewers/box3d/model3d/Model3DViewer', () => { name: 'two', }; const animMock = sandbox.mock(animation); - animMock.expects('getClipIds').mockReturnValue(['1', '2']); + animMock.expects('getClipIds').returns(['1', '2']); animMock .expects('getClip') .withArgs('1') @@ -352,7 +357,7 @@ describe.skip('lib/viewers/box3d/model3d/Model3DViewer', () => { .expects('getClip') .withArgs('2') .returns(clipTwo); - b3dMock.expects('getEntitiesByType').mockReturnValue([animation]); + b3dMock.expects('getEntitiesByType').returns([animation]); controlMock.expects('addAnimationClip').twice(); model3d.populateAnimationControls(); }); @@ -364,7 +369,7 @@ describe.skip('lib/viewers/box3d/model3d/Model3DViewer', () => { b3dMock .expects('getEntitiesByType') .once() - .mockReturnValue([animation]); + .returns([animation]); controlMock.expects('showAnimationControls').never(); model3d.populateAnimationControls(); @@ -377,7 +382,7 @@ describe.skip('lib/viewers/box3d/model3d/Model3DViewer', () => { b3dMock .expects('getEntitiesByType') .once() - .mockReturnValue([animation]); + .returns([animation]); controlMock.expects('selectAnimationClip').never(); model3d.populateAnimationControls(); @@ -394,12 +399,12 @@ describe.skip('lib/viewers/box3d/model3d/Model3DViewer', () => { name: 'one', }; const animMock = sandbox.mock(animation); - animMock.expects('getClipIds').mockReturnValue(['1']); + animMock.expects('getClipIds').returns(['1']); animMock .expects('getClip') .withArgs('1') .returns(clipOne); - b3dMock.expects('getEntitiesByType').mockReturnValue([animation]); + b3dMock.expects('getEntitiesByType').returns([animation]); controlMock.expects('showAnimationControls').once(); model3d.populateAnimationControls(); @@ -416,12 +421,12 @@ describe.skip('lib/viewers/box3d/model3d/Model3DViewer', () => { name: 'one', }; const animMock = sandbox.mock(animation); - animMock.expects('getClipIds').mockReturnValue(['1']); + animMock.expects('getClipIds').returns(['1']); animMock .expects('getClip') .withArgs('1') .returns(clipOne); - b3dMock.expects('getEntitiesByType').mockReturnValue([animation]); + b3dMock.expects('getEntitiesByType').returns([animation]); controlMock .expects('selectAnimationClip') .once() @@ -460,9 +465,9 @@ describe.skip('lib/viewers/box3d/model3d/Model3DViewer', () => { getMetadataClient: () => meta, }; - jest.spyOn(model3d, 'handleReset'); - jest.spyOn(model3d, 'populateAnimationControls'); - jest.spyOn(model3d, 'showWrapper'); + jest.spyOn(model3d, 'handleReset').mockImplementation(); + jest.spyOn(model3d, 'populateAnimationControls').mockImplementation(); + jest.spyOn(model3d, 'showWrapper').mockImplementation(); const axisSetStub = jest.spyOn(model3d, 'handleRotationAxisSet'); model3d.handleSceneLoaded().then(() => { @@ -479,9 +484,9 @@ describe.skip('lib/viewers/box3d/model3d/Model3DViewer', () => { getMetadataClient: () => meta, }; - jest.spyOn(model3d, 'handleReset'); - jest.spyOn(model3d, 'populateAnimationControls'); - jest.spyOn(model3d, 'showWrapper'); + jest.spyOn(model3d, 'handleReset').mockImplementation(); + jest.spyOn(model3d, 'populateAnimationControls').mockImplementation(); + jest.spyOn(model3d, 'showWrapper').mockImplementation(); const axisSetStub = jest.spyOn(model3d, 'handleRotationAxisSet'); model3d.handleSceneLoaded().then(() => { @@ -588,7 +593,7 @@ describe.skip('lib/viewers/box3d/model3d/Model3DViewer', () => { getMetadataClient: () => meta, }; - const onErrorStub = jest.spyOn(model3d, 'onMetadataError'); + const onErrorStub = jest.spyOn(model3d, 'onMetadataError').mockImplementation(); model3d.handleSceneLoaded().catch(() => { expect(onErrorStub).toBeCalled(); @@ -597,7 +602,7 @@ describe.skip('lib/viewers/box3d/model3d/Model3DViewer', () => { }); test('should should invoke onMetadataError() when issues loading metadata', done => { - const errStub = jest.spyOn(model3d, 'onMetadataError'); + const errStub = jest.spyOn(model3d, 'onMetadataError').mockImplementation(); const meta = { get: () => Promise.resolve({ status: 404, response: { status: 'metadata not found' } }), }; @@ -612,7 +617,7 @@ describe.skip('lib/viewers/box3d/model3d/Model3DViewer', () => { }); test('should still advance the promise chain for ui setup after failed metadata load', done => { - jest.spyOn(model3d, 'onMetadataError'); + jest.spyOn(model3d, 'onMetadataError').mockImplementation(); const addUi = jest.spyOn(model3d.controls, 'addUi'); const meta = { get: () => Promise.resolve({ status: 404, response: { status: 'metadata not found' } }), diff --git a/src/lib/viewers/box3d/video360/__tests__/Video360Controls-test.js b/src/lib/viewers/box3d/video360/__tests__/Video360Controls-test.js index d6f5fc178..42af281bf 100644 --- a/src/lib/viewers/box3d/video360/__tests__/Video360Controls-test.js +++ b/src/lib/viewers/box3d/video360/__tests__/Video360Controls-test.js @@ -3,7 +3,7 @@ import Video360Controls from '../Video360Controls'; import { ICON_3D_VR } from '../../../../icons/icons'; import { EVENT_TOGGLE_VR } from '../../box3DConstants'; -describe.skip('lib/viewers/box3d/video360/Video360Controls', () => { +describe('lib/viewers/box3d/video360/Video360Controls', () => { let containerEl; let controls; const CSS_CLASS_HIDDEN = 'bp-is-hidden'; @@ -28,8 +28,8 @@ describe.skip('lib/viewers/box3d/video360/Video360Controls', () => { describe('constructor()', () => { beforeEach(() => { - jest.spyOn(Video360Controls.prototype, 'addUi'); - jest.spyOn(Video360Controls.prototype, 'attachEventHandlers'); + jest.spyOn(Video360Controls.prototype, 'addUi').mockImplementation(); + jest.spyOn(Video360Controls.prototype, 'attachEventHandlers').mockImplementation(); controls = new Video360Controls(containerEl); }); @@ -82,10 +82,10 @@ describe.skip('lib/viewers/box3d/video360/Video360Controls', () => { jest.spyOn(Video360Controls.prototype, 'attachEventHandlers'); jest.spyOn(containerEl, 'querySelector').mockReturnValue(mediaControlsEl); - - const createElement = jest.spyOn(document, 'createElement'); - createElement.withArgs('button').mockReturnValue(vrButtonEl); - createElement.withArgs('span').mockReturnValue(iconSpanEl); + jest.spyOn(document, 'createElement') + .mockImplementation() + .mockReturnValueOnce(vrButtonEl) + .mockReturnValueOnce(iconSpanEl); controls.addUi(); }); @@ -192,10 +192,10 @@ describe.skip('lib/viewers/box3d/video360/Video360Controls', () => { describe('destroy()', () => { beforeEach(() => { - jest.spyOn(Video360Controls.prototype, 'addUi'); - jest.spyOn(Video360Controls.prototype, 'attachEventHandlers'); - jest.spyOn(Video360Controls.prototype, 'removeAllListeners'); - jest.spyOn(Video360Controls.prototype, 'detachEventHandlers'); + jest.spyOn(Video360Controls.prototype, 'addUi').mockImplementation(); + jest.spyOn(Video360Controls.prototype, 'attachEventHandlers').mockImplementation(); + jest.spyOn(Video360Controls.prototype, 'removeAllListeners').mockImplementation(); + jest.spyOn(Video360Controls.prototype, 'detachEventHandlers').mockImplementation(); }); afterEach(() => { diff --git a/src/lib/viewers/box3d/video360/__tests__/Video360Renderer-test.js b/src/lib/viewers/box3d/video360/__tests__/Video360Renderer-test.js index c03959b61..17cdf0d14 100644 --- a/src/lib/viewers/box3d/video360/__tests__/Video360Renderer-test.js +++ b/src/lib/viewers/box3d/video360/__tests__/Video360Renderer-test.js @@ -1,7 +1,7 @@ /* eslint-disable no-unused-expressions */ import Video360Renderer from '../Video360Renderer'; -describe.skip('lib/viewers/box3d/video360/Video360Renderer', () => { +describe('lib/viewers/box3d/video360/Video360Renderer', () => { let containerEl; let renderer; const OPTIONS = { @@ -69,7 +69,7 @@ describe.skip('lib/viewers/box3d/video360/Video360Renderer', () => { describe('destroy()', () => { test('should nullify .inputController', () => { renderer.destroy(); - expect(renderer.inputController).not.toBeDefined(); + expect(renderer.inputController).toBeNull(); }); test('should call super.destroy()', () => { diff --git a/src/lib/viewers/box3d/video360/__tests__/Video360Viewer-test.js b/src/lib/viewers/box3d/video360/__tests__/Video360Viewer-test.js index 6f9b4178d..c17213c29 100644 --- a/src/lib/viewers/box3d/video360/__tests__/Video360Viewer-test.js +++ b/src/lib/viewers/box3d/video360/__tests__/Video360Viewer-test.js @@ -7,7 +7,7 @@ import JS from '../../box3DAssets'; import sceneEntities from '../SceneEntities'; import fullscreen from '../../../../Fullscreen'; -describe.skip('lib/viewers/box3d/video360/Video360Viewer', () => { +describe('lib/viewers/box3d/video360/Video360Viewer', () => { const options = { token: '12345572asdfliuohhr34812348960', file: { @@ -33,13 +33,19 @@ describe.skip('lib/viewers/box3d/video360/Video360Viewer', () => { let viewer; let containerEl; + beforeAll(() => { + global.Box3D = { + isTablet: () => false, + }; + }); + beforeEach(() => { fixture.load('viewers/box3d/video360/__tests__/Video360Viewer-test.html'); containerEl = document.querySelector('.container'); options.container = containerEl; options.location = {}; viewer = new Video360Viewer(options); - jest.spyOn(viewer, 'processMetrics'); + jest.spyOn(viewer, 'processMetrics').mockImplementation(); }); afterEach(() => { @@ -53,7 +59,7 @@ describe.skip('lib/viewers/box3d/video360/Video360Viewer', () => { describe('setup()', () => { beforeEach(() => { - jest.spyOn(viewer, 'finishLoadingSetup'); + jest.spyOn(viewer, 'finishLoadingSetup').mockImplementation(); viewer.setup(); }); @@ -114,7 +120,7 @@ describe.skip('lib/viewers/box3d/video360/Video360Viewer', () => { }); test('should invoke .destroyControls() if it exists', () => { - const destroyStub = jest.spyOn(viewer, 'destroyControls'); + const destroyStub = jest.spyOn(viewer, 'destroyControls').mockImplementation(); viewer.controls = {}; viewer.destroy(); @@ -183,9 +189,9 @@ describe.skip('lib/viewers/box3d/video360/Video360Viewer', () => { }); beforeEach(() => { - stubs.on = jest.spyOn(Video360Renderer.prototype, 'on'); + stubs.on = jest.spyOn(Video360Renderer.prototype, 'on').mockImplementation(); stubs.initBox3d = jest.spyOn(Video360Renderer.prototype, 'initBox3d').mockResolvedValue(undefined); - stubs.initVr = jest.spyOn(Video360Renderer.prototype, 'initVr'); + stubs.initVr = jest.spyOn(Video360Renderer.prototype, 'initVr').mockImplementation(); stubs.create360Environment = jest.spyOn(viewer, 'create360Environment').mockResolvedValue(undefined); }); @@ -245,8 +251,8 @@ describe.skip('lib/viewers/box3d/video360/Video360Viewer', () => { }); test('should invoke .renderer.initVrIfPresent() on successfully creating 360 environment', done => { - jest.spyOn(viewer, 'createControls'); - stubs.initVr.restore(); + jest.spyOn(viewer, 'createControls').mockImplementation(); + stubs.initVr = jest.spyOn(Video360Renderer.prototype, 'initVr').mockImplementation(() => { expect(stubs.initVr).toBeCalled(); done(); @@ -258,9 +264,9 @@ describe.skip('lib/viewers/box3d/video360/Video360Viewer', () => { describe('createControls()', () => { let onStub; beforeEach(() => { - onStub = jest.spyOn(Video360Controls.prototype, 'on'); - jest.spyOn(Video360Controls.prototype, 'addUi'); - jest.spyOn(Video360Controls.prototype, 'attachEventHandlers'); + onStub = jest.spyOn(Video360Controls.prototype, 'on').mockImplementation(); + jest.spyOn(Video360Controls.prototype, 'addUi').mockImplementation(); + jest.spyOn(Video360Controls.prototype, 'attachEventHandlers').mockImplementation(); viewer.renderer = { addListener: jest.fn(), removeListener: jest.fn(), @@ -287,18 +293,18 @@ describe.skip('lib/viewers/box3d/video360/Video360Viewer', () => { }); test('should bind mousemove listener to display video player UI', () => { - const addStub = jest.spyOn(viewer.renderer.getBox3D().canvas, 'addEventListener'); + const addStub = jest.spyOn(viewer.renderer.getBox3D().canvas, 'addEventListener').mockImplementation(); viewer.createControls(); - expect(addStub).toBeCalledWith('mousemove'); + expect(addStub).toBeCalledWith('mousemove', undefined); }); test('should bind touchstart listener to display video player UI, if touch enabled', () => { - const addStub = jest.spyOn(viewer.renderer.getBox3D().canvas, 'addEventListener'); + const addStub = jest.spyOn(viewer.renderer.getBox3D().canvas, 'addEventListener').mockImplementation(); viewer.hasTouch = true; viewer.createControls(); - expect(addStub).toBeCalledWith('touchstart'); + expect(addStub).toBeCalledWith('touchstart', expect.any(Function)); }); }); @@ -341,14 +347,14 @@ describe.skip('lib/viewers/box3d/video360/Video360Viewer', () => { test('should bind mousemove listener to display video player UI', () => { viewer.destroyControls(); - expect(canvas.removeEventListener).toBeCalledWith('mousemove'); + expect(canvas.removeEventListener).toBeCalledWith('mousemove', undefined); }); test('should bind touchstart listener to display video player UI, if touch enabled', () => { viewer.hasTouch = true; viewer.destroyControls(); - expect(canvas.removeEventListener).toBeCalledWith('touchstart'); + expect(canvas.removeEventListener).toBeCalledWith('touchstart', expect.any(Function)); }); }); @@ -392,7 +398,7 @@ describe.skip('lib/viewers/box3d/video360/Video360Viewer', () => { }), createTexture2d: jest.fn().mockReturnValue({ setProperties: jest.fn(), - load: jest.fn(), + load: jest.fn().mockResolvedValue(undefined), id: '12345', }), on: jest.fn(), @@ -403,7 +409,7 @@ describe.skip('lib/viewers/box3d/video360/Video360Viewer', () => { getScene: jest.fn().mockReturnValue(scene), }; - jest.spyOn(viewer, 'finishLoadingSetup'); + jest.spyOn(viewer, 'finishLoadingSetup').mockImplementation(); viewer.setup(); viewer.renderer = renderer; @@ -443,7 +449,7 @@ describe.skip('lib/viewers/box3d/video360/Video360Viewer', () => { expect(box3d.createTexture2d).toBeCalledWith(VIDEO_TEXTURE_PROPS, 'VIDEO_TEX_ID'); }); - describe('load texture asset', () => { + describe.skip('load texture asset', () => { test('should resolve the Promise returned after successfully loading .textureAsset', done => { createPromise.then(done); }); @@ -477,7 +483,7 @@ describe.skip('lib/viewers/box3d/video360/Video360Viewer', () => { describe('toggleFullscreen()', () => { test('should invoke fullscreen.toggle() with .wrapperEl', () => { - jest.spyOn(fullscreen, 'toggle'); + jest.spyOn(fullscreen, 'toggle').mockImplementation(); viewer.toggleFullscreen(); expect(fullscreen.toggle).toBeCalledWith(viewer.wrapperEl); @@ -585,7 +591,7 @@ describe.skip('lib/viewers/box3d/video360/Video360Viewer', () => { getInputController: jest.fn().mockReturnValue(input), }; - jest.spyOn(viewer, 'togglePlay'); + jest.spyOn(viewer, 'togglePlay').mockImplementation(); }); afterEach(() => { diff --git a/src/lib/viewers/doc/__tests__/DocBaseViewer-test.js b/src/lib/viewers/doc/__tests__/DocBaseViewer-test.js index e801a8d94..ec005e350 100644 --- a/src/lib/viewers/doc/__tests__/DocBaseViewer-test.js +++ b/src/lib/viewers/doc/__tests__/DocBaseViewer-test.js @@ -1247,7 +1247,7 @@ describe('src/lib/viewers/doc/DocBaseViewer', () => { }); }); - it('should avoid preflight requests by not adding non-standard headers', done => { + test('should avoid preflight requests by not adding non-standard headers', done => { docBase.options.location = { locale: 'en-US', }; @@ -1268,7 +1268,7 @@ describe('src/lib/viewers/doc/DocBaseViewer', () => { return docBase.initViewer(''); }); - it('should append encoding query parameter for gzip content when range requests are disabled', () => { + test('should append encoding query parameter for gzip content when range requests are disabled', () => { const defaultChunkSize = 524288; // Taken from RANGE_CHUNK_SIZE_NON_US const url = 'www.myTestPDF.com/123456'; const paramsList = `${QUERY_PARAM_ENCODING}=${ENCODING_TYPES.GZIP}`; @@ -1836,7 +1836,7 @@ describe('src/lib/viewers/doc/DocBaseViewer', () => { stubs.stop = jest.spyOn(Timer, 'stop').mockReturnValue({ elapsed: 1000 }); }); - it('should emit render metric event for start page if not already emitted', () => { + test('should emit render metric event for start page if not already emitted', () => { docBase.pagerenderedHandler(docBase.event); expect(stubs.emitMetric).toBeCalledWith({ name: RENDER_EVENT, @@ -1844,13 +1844,13 @@ describe('src/lib/viewers/doc/DocBaseViewer', () => { }); }); - it('should not emit render metric event if it was already emitted', () => { + test('should not emit render metric event if it was already emitted', () => { docBase.startPageRendered = true; docBase.pagerenderedHandler(docBase.event); expect(stubs.emitMetric).not.toBeCalled(); }); - it('should not emit render metric event if rendered page is not start page', () => { + test('should not emit render metric event if rendered page is not start page', () => { docBase.pagerenderedHandler({ pageNumber: 5 }); expect(stubs.emitMetric).not.toBeCalled(); }); diff --git a/src/lib/viewers/image/__tests__/ImageBaseViewer-test.js b/src/lib/viewers/image/__tests__/ImageBaseViewer-test.js index e6d6162d0..887167786 100644 --- a/src/lib/viewers/image/__tests__/ImageBaseViewer-test.js +++ b/src/lib/viewers/image/__tests__/ImageBaseViewer-test.js @@ -316,7 +316,7 @@ describe('lib/viewers/image/ImageBaseViewer', () => { imageBase.isPanning = false; }); - it('should do nothing if incorrect click type', () => { + test('should do nothing if incorrect click type', () => { const event = { button: 3, ctrlKey: null, @@ -336,7 +336,7 @@ describe('lib/viewers/image/ImageBaseViewer', () => { expect(stubs.emitMetric).not.toBeCalled(); }); - it('should zoom in if zoomable but not pannable', () => { + test('should zoom in if zoomable but not pannable', () => { const event = { button: 1, ctrlKey: null, @@ -351,7 +351,7 @@ describe('lib/viewers/image/ImageBaseViewer', () => { expect(stubs.emitMetric).toBeCalledWith('zoom', 'inClick'); }); - it('should reset zoom if mouseup was not due to end of panning', () => { + test('should reset zoom if mouseup was not due to end of panning', () => { const event = { button: 1, ctrlKey: null, @@ -367,7 +367,7 @@ describe('lib/viewers/image/ImageBaseViewer', () => { expect(stubs.emitMetric).toBeCalledWith('zoom', 'resetClick'); }); - it('should not zoom if mouse up was due to end of panning', () => { + test('should not zoom if mouse up was due to end of panning', () => { const event = { button: 1, ctrlKey: null, diff --git a/src/lib/viewers/image/__tests__/ImageLoader-test.js b/src/lib/viewers/image/__tests__/ImageLoader-test.js index 6d49a904b..9f533b43c 100644 --- a/src/lib/viewers/image/__tests__/ImageLoader-test.js +++ b/src/lib/viewers/image/__tests__/ImageLoader-test.js @@ -44,7 +44,7 @@ describe('lib/viewers/image/ImageLoader', () => { }); describe('determineViewer', () => { - it('it should return the MultiImage viewer for a tif file with a jpg representation', () => { + test('it should return the MultiImage viewer for a tif file with a jpg representation', () => { const file = { extension: 'tif', representations: { @@ -72,7 +72,7 @@ describe('lib/viewers/image/ImageLoader', () => { expect(determinedViewer.REP).toBe('jpg'); }); - it('it should return the MultiImage viewer for a tif file with a png representation', () => { + test('it should return the MultiImage viewer for a tif file with a png representation', () => { const file = { extension: 'tif', representations: {