Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test(jest): Convert the remaining 3D viewer unit tests to Jest #1267

Merged
merged 1 commit into from
Sep 28, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/lib/__tests__/AnnotationControlsFSM-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
8 changes: 4 additions & 4 deletions src/lib/__tests__/Controls-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand All @@ -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);

Expand Down Expand Up @@ -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 });
Expand Down
6 changes: 3 additions & 3 deletions src/lib/__tests__/Preview-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
2 changes: 1 addition & 1 deletion src/lib/__tests__/i18n-test.js
Original file line number Diff line number Diff line change
@@ -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');
Expand Down
4 changes: 2 additions & 2 deletions src/lib/viewers/__tests__/BaseViewer-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down Expand Up @@ -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);
Expand Down
22 changes: 22 additions & 0 deletions src/lib/viewers/box3d/__mocks__/Box3DRuntime.js
Original file line number Diff line number Diff line change
@@ -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;
5 changes: 1 addition & 4 deletions src/lib/viewers/box3d/__tests__/Box3DRenderer-test.js
Original file line number Diff line number Diff line change
@@ -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';
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand Down
22 changes: 11 additions & 11 deletions src/lib/viewers/box3d/model3d/__tests__/Model3DControls-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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);
Expand All @@ -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);
Expand Down Expand Up @@ -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);
});
Expand Down
Loading