Skip to content

Commit

Permalink
FIX Get JS tests passing again
Browse files Browse the repository at this point in the history
  • Loading branch information
GuySartorelli committed Feb 9, 2023
1 parent 1bb852e commit e3cec27
Show file tree
Hide file tree
Showing 38 changed files with 774 additions and 114 deletions.
6 changes: 6 additions & 0 deletions babel.config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"presets": [
"@babel/preset-env",
"@babel/preset-react"
]
}
2 changes: 1 addition & 1 deletion client/dist/js/TinyMCE_sslink-file.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion client/dist/js/TinyMCE_ssmedia.js

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions client/dist/js/bundle.js

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* global jest, jasmine, describe, it, expect, beforeEach, FormData */
/* global jest, describe, it, expect, beforeEach, FormData */

import React from 'react';
import ReactTestUtils from 'react-dom/test-utils';
Expand All @@ -24,15 +24,10 @@ describe('AssetDropzone', () => {
let item = null;

beforeEach(() => {
item = ReactTestUtils.renderIntoDocument(
<AssetDropzone {...props} />
);
item = new AssetDropzone();
});

it('should set this.dropzone to null', () => {
item.dropzone = 1;
item.constructor(props);

expect(item.dropzone).toBe(null);
});
});
Expand Down
2 changes: 1 addition & 1 deletion client/src/components/BackButton/tests/BackButton-test.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* global jest, jasmine, describe, it, expect, beforeEach */
/* global jest, describe, it, expect, beforeEach */

import React from 'react';
import ReactTestUtils from 'react-dom/test-utils';
Expand Down
8 changes: 4 additions & 4 deletions client/src/components/BulkActions/tests/BulkActions-test.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* global jest, jasmine, describe, it, expect, beforeEach */
/* global jest, describe, it, expect, beforeEach */

jest.mock('jquery', () => {
const jqueryMock = {
Expand Down Expand Up @@ -131,7 +131,7 @@ describe('BulkActions', () => {
const callbackMockFn = jest.fn();

bulkActions.getOptionByValue
.mockReturnValueOnce({ confirm: Promise.resolve(), callback: callbackMockFn });
.mockReturnValueOnce({ confirm: () => Promise.resolve(), callback: callbackMockFn });
return bulkActions.handleChangeValue(event).then(() => {
expect(callbackMockFn).toBeCalled();
});
Expand All @@ -141,9 +141,9 @@ describe('BulkActions', () => {
const callbackMockFn = jest.fn();

bulkActions.getOptionByValue
.mockReturnValueOnce({ confirm: Promise.reject(), callback: callbackMockFn });
.mockReturnValueOnce({ confirm: () => Promise.reject('cancelled'), callback: callbackMockFn });
return bulkActions.handleChangeValue(event).then(() => {
expect(callbackMockFn).toBeCalled();
expect(callbackMockFn).not.toBeCalled();
});
});
});
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* global jest, jasmine, describe, it, expect, beforeEach, Event */
/* global jest, describe, it, expect, beforeEach, Event */

import React from 'react';
import ReactTestUtils from 'react-dom/test-utils';
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* global jest, jasmine, describe, it, expect, beforeEach */
/* global jest, describe, it, expect, beforeEach */

// FormBuilderLoader mock was not mocking properly
// manually override with a stateless null component
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* global jest, jasmine, describe, it, expect, beforeEach */
/* global jest, describe, it, expect, beforeEach */

jest.mock('components/AssetDropzone/AssetDropzone');

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* global jest, jasmine, describe, it, expect, beforeEach */
/* global jest, describe, it, expect, beforeEach */

import React from 'react';
import ImageSizePresetList from '../ImageSizePresetList';
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* global jest, jasmine, describe, it, expect, beforeEach */
/* global jest, describe, it, expect, beforeEach */

import React from 'react';
import ReactTestUtils from 'react-dom/test-utils';
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* global jest, jasmine, describe, it, expect, beforeEach */
/* global jest, describe, it, expect, beforeEach */

import React from 'react';
import ReactTestUtils from 'react-dom/test-utils';
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* global jest, jasmine, describe, it, expect, beforeEach */
/* global jest, describe, it, expect, beforeEach */

import React from 'react';
import ReactTestUtils from 'react-dom/test-utils';
Expand Down
9 changes: 2 additions & 7 deletions client/src/containers/AssetAdmin/AssetAdmin.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,6 @@ import AssetAdminBreadcrumb from './AssetAdminBreadcrumb';
class AssetAdmin extends Component {
constructor(props) {
super(props);
// Needed to avoid warnings about missing state when getDerivedStateFromProps is called
if (!this.state) {
this.state = {};
}

this.handleOpenFile = this.handleOpenFile.bind(this);
this.handleCloseFile = this.handleCloseFile.bind(this);
Expand All @@ -58,11 +54,10 @@ class AssetAdmin extends Component {
this.handleMoveFilesSuccess = this.handleMoveFilesSuccess.bind(this);
}

static getDerivedStateFromProps(props) {
if (!props.loading && props.folder && props.folderId !== props.folder.id) {
componentWillReceiveProps(props) {
if ((typeof props.onReplaceUrl === 'function') && !props.loading && props.folder && props.folderId !== props.folder.id) {
props.onReplaceUrl(props.folder.id, props.fileId, props.query, props.viewAction);
}
return null;
}

/**
Expand Down
2 changes: 1 addition & 1 deletion client/src/containers/AssetAdmin/tests/AssetAdmin-test.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* global jest, describe, it, pit, expect, beforeEach, jasmine */
/* global jest, describe, it, pit, expect, beforeEach */

// mock sub-components, as they could rely on a Redux store context and not necessary for unit test
jest.mock('containers/Editor/Editor');
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* global jest, describe, it, pit, expect, beforeEach, jasmine */
/* global jest, describe, it, pit, expect, beforeEach */
import Breadcrumb from '../AssetAdminBreadcrumb';
import ShallowRenderer from 'react-test-renderer/shallow';
import React from 'react';
Expand Down
23 changes: 9 additions & 14 deletions client/src/containers/AssetAdmin/tests/AssetAdminRouter-test.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* global jest, describe, it, pit, expect, beforeEach, jasmine */
/* global jest, describe, it, pit, expect, beforeEach */

// mock sub-components, as they could rely on a Redux store context and not necessary for unit test
jest.mock('containers/AssetAdmin/AssetAdmin');
Expand All @@ -17,19 +17,14 @@ describe('AssetAdminRouter', () => {
limit: 10,
form: {},
},
location: {
pathname: '',
query: {},
search: '',
},
match: {
params: {
fileId: '0',
folderId: '0',
router: {
location: {
pathname: '',
query: {},
search: '',
},
},
history: {
push: jest.fn(),
navigate: jest.fn(),
params: {},
},
};
});
Expand All @@ -42,7 +37,7 @@ describe('AssetAdminRouter', () => {
});

it('should retain page query parameter when not changing folders', () => {
const newUrl = component.getUrl(props.match.params.folderId, null, { page: 2 });
const newUrl = component.getUrl(props.router.params.folderId, null, { page: 2 });
expect(newUrl).toContain('page=2');
});

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* global jest, jasmine, describe, it, expect, beforeEach, Event */
/* global jest, describe, it, expect, beforeEach, Event */

import React from 'react';
import { Component } from '../BulkDeleteConfirmation';
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* global jest, jasmine, describe, it, expect, beforeEach, Event */
/* global jest, describe, it, expect, beforeEach, Event */

import React from 'react';
import Component from '../BulkDeleteMessage';
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* global jest, describe, it, pit, expect, beforeEach, jasmine */
/* global jest, describe, it, pit, expect, beforeEach */
import { getFolderDescendantFileTotals, getFileTotalItems } from '../helpers';
import { mockfiles as files } from './mockfiles';

Expand Down
2 changes: 1 addition & 1 deletion client/src/containers/Editor/tests/Editor-test.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* global jest, jasmine, describe, it, expect, beforeEach, FormData */
/* global jest, describe, it, expect, beforeEach, FormData */
jest.mock('containers/FormBuilderLoader/FormBuilderLoader');
jest.mock('components/FormBuilderModal/FormBuilderModal');

Expand Down
2 changes: 1 addition & 1 deletion client/src/containers/Editor/tests/EditorHeader-test.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* global jest, jasmine, describe, it, expect, beforeEach, FormData */
/* global jest, describe, it, expect, beforeEach, FormData */
jest.mock('containers/FormBuilderLoader/FormBuilderLoader');
jest.mock('components/FormBuilderModal/FormBuilderModal');

Expand Down
15 changes: 0 additions & 15 deletions client/src/containers/Gallery/tests/Gallery-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -471,21 +471,6 @@ describe('Gallery', () => {
});
});

describe('handleCreateFolder()', () => {
let gallery = null;

beforeEach(() => {
props.onCreateFolder = jest.fn();

gallery = ReactTestUtils.renderIntoDocument(
<Gallery {...props} />
);
gallery.handleCreateFolder();

expect(props.onCreateFolder).toBeCalled();
});
});

describe('bulkActions', () => {
let gallery = null;

Expand Down
2 changes: 1 addition & 1 deletion client/src/lib/tests/getFormSchema-test.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* global jest, jasmine, describe, it, expect, beforeEach, FormData */
/* global jest, describe, it, expect, beforeEach, FormData */

import getFormSchema from '../getFormSchema';
import CONSTANTS from 'constants/index';
Expand Down
2 changes: 1 addition & 1 deletion client/src/lib/tests/getStatusCodeMessage-test.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* global jest, jasmine, describe, it, expect, beforeEach, FormData */
/* global jest, describe, it, expect, beforeEach, FormData */

import getStatusCodeMessage from '../getStatusCodeMessage';

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* global jest, describe, it, pit, expect, beforeEach, jasmine */
/* global jest, describe, it, pit, expect, beforeEach */
import reducer, { initialState } from '../ConfirmDeletionReducer';
import ACTION_TYPES from '../ConfirmDeletionActionTypes';
import * as TRANSITIONS from '../ConfirmDeletionTransitions';
Expand Down
2 changes: 1 addition & 1 deletion client/src/state/files/tests/readFilesQuery-test.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* global jest, describe, it, pit, expect, beforeEach, jasmine */
/* global jest, describe, it, pit, expect, beforeEach */

import query from '../readFilesQuery';

Expand Down
20 changes: 13 additions & 7 deletions client/src/state/imageLoad/tests/ImageLoadActionHandler-test.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* global jest, describe, it, expect, beforeEach, jasmine */
/* global jest, describe, it, expect, beforeEach */

import ImageLoadActionHandler from '../ImageLoadActionHandler';
import IMAGE_STATUS from '../ImageLoadStatus';
Expand Down Expand Up @@ -36,7 +36,9 @@ describe('ImageLoadActionHandler', () => {
});

it('eternally failing images end up failed', () => {
jest.useFakeTimers();
jest.useFakeTimers({
legacyFakeTimers: true,
});

const options = {
minRetry: 4,
Expand All @@ -49,7 +51,7 @@ describe('ImageLoadActionHandler', () => {
// Create handler which always fails
const loadImageHandler = new ImageLoadActionHandler(
options,
(url, resolve, reject) => { reject(); }
(url, resolve, reject) => { reject(4); }
);

// Attempts three times, after a 4 second then 8 second retry delay
Expand All @@ -73,7 +75,9 @@ describe('ImageLoadActionHandler', () => {
});

it('initially failing download can eventually succeed', () => {
jest.useFakeTimers();
jest.useFakeTimers({
legacyFakeTimers: true,
});

const options = {
minRetry: 4,
Expand All @@ -88,7 +92,7 @@ describe('ImageLoadActionHandler', () => {
if (attempts > 2) {
resolve();
} else {
reject();
reject(2);
}
};

Expand All @@ -110,7 +114,9 @@ describe('ImageLoadActionHandler', () => {
});

it('failed download with expiry will eventually expire', () => {
jest.useFakeTimers();
jest.useFakeTimers({
legacyFakeTimers: true,
});

const options = {
minRetry: 4,
Expand All @@ -121,7 +127,7 @@ describe('ImageLoadActionHandler', () => {
// ensure all future timers advance automatically
onTimeout: () => jest.runAllTimers(),
};
const handler = (url, resolve, reject) => { reject(); };
const handler = (url, resolve, reject) => { reject(3); };
// Create handler which always fails
const loadImageHandler = new ImageLoadActionHandler(
options,
Expand Down
2 changes: 1 addition & 1 deletion client/src/state/imageLoad/tests/ImageLoadActions-test.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* global jest, describe, it, expect, beforeEach, jasmine */
/* global jest, describe, it, expect, beforeEach */

jest.mock('../ImageLoadActionHandler', () => jest.fn());

Expand Down
2 changes: 1 addition & 1 deletion client/src/state/imageLoad/tests/ImageLoadLocker-test.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* global jest, describe, it, expect, beforeEach, jasmine */
/* global jest, describe, it, expect, beforeEach */

jest.unmock('../ImageLoadLocker');

Expand Down
2 changes: 1 addition & 1 deletion client/src/state/modal/tests/ModalReducer-test.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* global jest, describe, it, pit, expect, beforeEach, jasmine */
/* global jest, describe, it, pit, expect, beforeEach */
import reducer, { initialState } from '../ModalReducer';
import {
defineImageSizePresets,
Expand Down
2 changes: 1 addition & 1 deletion client/src/state/modal/tests/helpers-test.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* global jest, describe, it, pit, expect, beforeEach, jasmine */
/* global jest, describe, it, pit, expect, beforeEach */
import isStashableField, { findField } from '../helpers';

const stashable = {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* global jest, describe, it, expect, beforeEach, jasmine */
/* global jest, describe, it, expect, beforeEach */

import previewFieldReducer from '../PreviewFieldReducer';
import ACTION_TYPES from '../PreviewFieldActionTypes';
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* global jest, jasmine, describe, it, expect, beforeEach */
/* global jest, describe, it, expect, beforeEach */

import queuedFilesReducer from '../QueuedFilesReducer';

Expand Down
4 changes: 2 additions & 2 deletions client/src/state/uploadField/tests/UploadFieldReducer-test.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* global jest, describe, it, expect, beforeEach, jasmine */
/* global jest, describe, it, expect, beforeEach */

import uploadFieldReducer from '../UploadFieldReducer';
import fileStructure from '../../../lib/fileStructure';
Expand Down Expand Up @@ -122,7 +122,7 @@ describe('uploadFieldReducer', () => {
});
expect(nextState.fields.anotherfield.files.length).toBe(2);
expect(nextState.fields.anotherfield.files[1]).toEqual(
jasmine.objectContaining({
expect.objectContaining({
id: 10,
queuedId: 'xyz',
name: 'InProgressFile.jpg',
Expand Down
Loading

0 comments on commit e3cec27

Please sign in to comment.