From 5258e9397248434f20d1ef3e6ca77257d7f32f77 Mon Sep 17 00:00:00 2001
From: connorhaugh <49422820+connorhaugh@users.noreply.github.com>
Date: Mon, 7 Mar 2022 19:43:46 -0500
Subject: [PATCH] Test add requests redux tests (#24)
Add redux tests as well as get save functionality working.
---
src/editors/Editor.test.jsx | 6 +-
.../__snapshots__/index.test.jsx.snap | 6 +-
src/editors/components/EditorFooter/index.jsx | 9 +-
.../components/EditorFooter/index.test.jsx | 11 +-
.../EditorHeader/EditableHeader.jsx | 2 +-
.../EditorHeader/EditableHeader.test.jsx | 2 +-
.../components/EditorHeader/HeaderTitle.jsx | 1 -
.../EditableHeader.test.jsx.snap | 2 +-
.../containers/TextEditor/TextEditor.test.jsx | 4 +
.../__snapshots__/TextEditor.test.jsx.snap | 4 +-
.../components/SelectImageModal.jsx | 4 +-
src/editors/containers/TextEditor/hooks.js | 8 +-
.../containers/TextEditor/hooks.test.jsx | 4 +-
src/editors/data/constants/mockData.js | 2 -
src/editors/data/redux/app/reducer.js | 6 +-
src/editors/data/redux/app/reducer.test.js | 1 -
src/editors/data/redux/app/selectors.js | 1 +
.../data/redux/requests/reducer.test.js | 49 +++++++
.../data/redux/thunkActions/requests.js | 2 +-
.../data/redux/thunkActions/requests.test.js | 120 ++++++++----------
src/editors/data/services/cms/api.test.js | 16 +--
www/src/Gallery.jsx | 2 +-
www/src/index.jsx | 1 +
23 files changed, 158 insertions(+), 105 deletions(-)
create mode 100644 src/editors/data/redux/requests/reducer.test.js
diff --git a/src/editors/Editor.test.jsx b/src/editors/Editor.test.jsx
index 8fe08893e..3bc349f5b 100644
--- a/src/editors/Editor.test.jsx
+++ b/src/editors/Editor.test.jsx
@@ -1,5 +1,5 @@
import React from 'react';
-import { mount, shallow } from 'enzyme';
+import { shallow } from 'enzyme';
import { Editor, mapDispatchToProps, supportedEditors } from './Editor';
import { thunkActions } from './data/redux';
import * as hooks from './hooks';
@@ -36,9 +36,9 @@ describe('Editor', () => {
() => ({ editorRef: { current: 'ref' }, refReady: true, setEditorRef: jest.fn().mockName('setEditorRef') }),
);
const wrapper = shallow();
- if(blockType == 'html'){ // snap just one editor to make viewing easier
+ if (blockType === 'html') { // snap just one editor to make viewing easier
expect(wrapper).toMatchSnapshot();
- };
+ }
expect(wrapper.children().children().at(1).is(supportedEditors[blockType])).toBe(true);
});
test('presents error message if no relevant editor found and ref ready', () => {
diff --git a/src/editors/components/EditorFooter/__snapshots__/index.test.jsx.snap b/src/editors/components/EditorFooter/__snapshots__/index.test.jsx.snap
index 0fa0c9e66..283003ba2 100644
--- a/src/editors/components/EditorFooter/__snapshots__/index.test.jsx.snap
+++ b/src/editors/components/EditorFooter/__snapshots__/index.test.jsx.snap
@@ -38,7 +38,7 @@ exports[`EditorFooter snapshots Save Failed, error message raised 1`] = `
"handleSaveClicked": Object {
"editorRef": [MockFunction args.editorRef],
"returnUrl": "hocuspocus.ca",
- "saveBlock": [MockFunction args.saveBlock],
+ "saveBlockContent": [MockFunction args.saveBlock],
},
}
}
@@ -82,7 +82,7 @@ exports[`EditorFooter snapshots not intialized, Spinner appears and button is di
"handleSaveClicked": Object {
"editorRef": [MockFunction args.editorRef],
"returnUrl": "hocuspocus.ca",
- "saveBlock": [MockFunction args.saveBlock],
+ "saveBlockContent": [MockFunction args.saveBlock],
},
}
}
@@ -125,7 +125,7 @@ exports[`EditorFooter snapshots renders as expected with default behavior 1`] =
"handleSaveClicked": Object {
"editorRef": [MockFunction args.editorRef],
"returnUrl": "hocuspocus.ca",
- "saveBlock": [MockFunction args.saveBlock],
+ "saveBlockContent": [MockFunction args.saveBlock],
},
}
}
diff --git a/src/editors/components/EditorFooter/index.jsx b/src/editors/components/EditorFooter/index.jsx
index fa918f3df..56bf7d45f 100644
--- a/src/editors/components/EditorFooter/index.jsx
+++ b/src/editors/components/EditorFooter/index.jsx
@@ -27,7 +27,7 @@ export const EditorFooter = ({
isInitialized,
returnUrl,
saveFailed,
- saveBlock,
+ saveBlockContent,
}) => (
{saveFailed && (
@@ -49,7 +49,7 @@ export const EditorFooter = ({
onClick={module.handleSaveClicked({
editorRef,
returnUrl,
- saveBlock,
+ saveBlockContent,
})}
disabled={!isInitialized}
>
@@ -74,17 +74,18 @@ EditorFooter.propTypes = {
isInitialized: PropTypes.bool.isRequired,
returnUrl: PropTypes.string,
saveFailed: PropTypes.bool.isRequired,
- saveBlock: PropTypes.func.isRequired,
+ saveBlockContent: PropTypes.func.isRequired,
};
export const mapStateToProps = (state) => ({
+ returnUrl: selectors.app.returnUrl(state),
isInitialized: selectors.app.isInitialized(state),
saveFailed: selectors.requests.isFailed(state, { requestKey: RequestKeys.saveBlock }),
studioEndpointUrl: selectors.app.studioEndpointUrl(state),
});
export const mapDispatchToProps = {
- saveBlock: thunkActions.app.saveBlock,
+ saveBlockContent: thunkActions.app.saveBlock,
};
export default connect(mapStateToProps, mapDispatchToProps)(EditorFooter);
diff --git a/src/editors/components/EditorFooter/index.test.jsx b/src/editors/components/EditorFooter/index.test.jsx
index 98073d3ce..a975fe990 100644
--- a/src/editors/components/EditorFooter/index.test.jsx
+++ b/src/editors/components/EditorFooter/index.test.jsx
@@ -9,12 +9,14 @@ jest.mock('../../data/redux', () => ({
thunkActions: {
app: {
saveBlock: jest.fn().mockName('thunkActions.app.saveBlock'),
+ fetchImages: jest.fn().mockName('thunkActions.app.fetchImages'),
},
},
selectors: {
app: {
isInitialized: jest.fn(state => ({ isInitialized: state })),
studioEndpointUrl: jest.fn(state => ({ studioEndpointUrl: state })),
+ returnUrl: jest.fn(state => ({ returnUrl: state })),
},
requests: {
isFailed: jest.fn((state, params) => ({ isFailed: { state, params } })),
@@ -41,7 +43,7 @@ describe('EditorFooter', () => {
isInitialized: true,
returnUrl: 'hocuspocus.ca',
saveFailed: false,
- saveBlock: jest.fn().mockName('args.saveBlock'),
+ saveBlockContent: jest.fn().mockName('args.saveBlock'),
};
describe('behavior', () => {
const realmodule = jest.requireActual('./index');
@@ -68,6 +70,11 @@ describe('EditorFooter', () => {
});
describe('mapStateToProps', () => {
const testState = { A: 'pple', B: 'anana', C: 'ucumber' };
+ test('isInitialized from app.returnUrl', () => {
+ expect(
+ module.mapStateToProps(testState).returnUrl,
+ ).toEqual(selectors.app.returnUrl(testState));
+ });
test('isInitialized from app.isInitialized', () => {
expect(
module.mapStateToProps(testState).isInitialized,
@@ -86,7 +93,7 @@ describe('EditorFooter', () => {
});
describe('mapDispatchToProps', () => {
test('saveBlock from thunkActions.app.saveBlock', () => {
- expect(module.mapDispatchToProps.saveBlock).toEqual(thunkActions.app.saveBlock);
+ expect(module.mapDispatchToProps.saveBlockContent).toEqual(thunkActions.app.saveBlock);
});
});
});
diff --git a/src/editors/components/EditorHeader/EditableHeader.jsx b/src/editors/components/EditorHeader/EditableHeader.jsx
index c0db15ca2..39e18f6a8 100644
--- a/src/editors/components/EditorHeader/EditableHeader.jsx
+++ b/src/editors/components/EditorHeader/EditableHeader.jsx
@@ -19,7 +19,7 @@ export const EditableHeader = ({
onKeyDown={handleKeyDown}
placeholder="Title"
ref={inputRef}
- trailingInputElement={}
+ trailingElement={}
value={localTitle}
/>
diff --git a/src/editors/components/EditorHeader/EditableHeader.test.jsx b/src/editors/components/EditorHeader/EditableHeader.test.jsx
index 31cad7204..1987eb59a 100644
--- a/src/editors/components/EditorHeader/EditableHeader.test.jsx
+++ b/src/editors/components/EditorHeader/EditableHeader.test.jsx
@@ -23,7 +23,7 @@ describe('EditableHeader', () => {
});
test('displays Edit Icon', () => {
const formControl = el.find(Form.Control);
- expect(formControl.props().trailingInputElement).toMatchObject();
+ expect(formControl.props().trailingElement).toMatchObject();
});
});
});
diff --git a/src/editors/components/EditorHeader/HeaderTitle.jsx b/src/editors/components/EditorHeader/HeaderTitle.jsx
index 7d0ac0939..d78572dad 100644
--- a/src/editors/components/EditorHeader/HeaderTitle.jsx
+++ b/src/editors/components/EditorHeader/HeaderTitle.jsx
@@ -18,7 +18,6 @@ export const HeaderTitle = ({
typeHeader,
}) => {
if (!isInitialized) { return ; }
-
const {
inputRef,
isEditing,
diff --git a/src/editors/components/EditorHeader/__snapshots__/EditableHeader.test.jsx.snap b/src/editors/components/EditorHeader/__snapshots__/EditableHeader.test.jsx.snap
index 8fd13fba0..ec5dffea7 100644
--- a/src/editors/components/EditorHeader/__snapshots__/EditableHeader.test.jsx.snap
+++ b/src/editors/components/EditorHeader/__snapshots__/EditableHeader.test.jsx.snap
@@ -8,7 +8,7 @@ exports[`EditableHeader snapshot snapshot 1`] = `
onChange={[MockFunction args.handleChange]}
onKeyDown={[MockFunction args.handleKeyDown]}
placeholder="Title"
- trailingInputElement={
+ trailingElement={
diff --git a/src/editors/containers/TextEditor/TextEditor.test.jsx b/src/editors/containers/TextEditor/TextEditor.test.jsx
index 5b3e1fade..6f8866815 100644
--- a/src/editors/containers/TextEditor/TextEditor.test.jsx
+++ b/src/editors/containers/TextEditor/TextEditor.test.jsx
@@ -16,6 +16,9 @@ jest.mock('@tinymce/tinymce-react', () => {
,
};
});
+jest.mock('./components/ImageUploadModal', () => 'ImageUploadModal');
+jest.mock('./components/SelectImageModal', () => 'SelectImageModal');
+jest.mock('./components/ImageSettingsModal', () => 'ImageSettingsModal');
jest.mock('./hooks', () => ({
editorConfig: jest.fn(args => ({ editorConfig: args })),
@@ -27,6 +30,7 @@ jest.mock('../../data/redux', () => ({
actions: {
app: {
initializeEditor: jest.fn().mockName('actions.app.initializeEditor'),
+ fetchImages: jest.fn().mockName('actions.app.fetchImages'),
},
},
selectors: {
diff --git a/src/editors/containers/TextEditor/__snapshots__/TextEditor.test.jsx.snap b/src/editors/containers/TextEditor/__snapshots__/TextEditor.test.jsx.snap
index f5fe54334..0eb01d0e7 100644
--- a/src/editors/containers/TextEditor/__snapshots__/TextEditor.test.jsx.snap
+++ b/src/editors/containers/TextEditor/__snapshots__/TextEditor.test.jsx.snap
@@ -22,7 +22,7 @@ exports[`TextEditor snapshots block failed to load, Toast is shown 1`] = `
editorConfig={
Object {
"blockValue": Object {
- "data": "HYleTsEditTeaxt",
+ "data": "eDiTablE Text",
},
"initializeEditor": [MockFunction args.intializeEditor],
"openModal": [MockFunction modal.openModal],
@@ -85,7 +85,7 @@ exports[`TextEditor snapshots renders as expected with default behavior 1`] = `
editorConfig={
Object {
"blockValue": Object {
- "data": "HYleTsEditTeaxt",
+ "data": "eDiTablE Text",
},
"initializeEditor": [MockFunction args.intializeEditor],
"openModal": [MockFunction modal.openModal],
diff --git a/src/editors/containers/TextEditor/components/SelectImageModal.jsx b/src/editors/containers/TextEditor/components/SelectImageModal.jsx
index 2dc540c4d..3d9f4c779 100644
--- a/src/editors/containers/TextEditor/components/SelectImageModal.jsx
+++ b/src/editors/containers/TextEditor/components/SelectImageModal.jsx
@@ -4,7 +4,7 @@ import PropTypes from 'prop-types';
import { Button, Image } from '@edx/paragon';
-import { thunkActions } from '../../../data/redux';
+import { actions } from '../../../data/redux';
import BaseModal from './BaseModal';
import * as module from './SelectImageModal';
@@ -60,7 +60,7 @@ SelectImageModal.propTypes = {
export const mapStateToProps = () => ({});
export const mapDispatchToProps = {
- fetchImages: thunkActions.app.fetchImages,
+ fetchImages: actions.app.fetchImages,
};
export default connect(mapStateToProps, mapDispatchToProps)(SelectImageModal);
diff --git a/src/editors/containers/TextEditor/hooks.js b/src/editors/containers/TextEditor/hooks.js
index e432b0843..4e73a4b51 100644
--- a/src/editors/containers/TextEditor/hooks.js
+++ b/src/editors/containers/TextEditor/hooks.js
@@ -8,7 +8,9 @@ export const addImageUploadButton = (openModal) => (editor) => {
});
};
-export const initializeEditorRef = (setRef) => (evt, editor) => { setRef(editor); };
+export const initializeEditorRef = (setRef) => (evt, editor) => {
+ setRef(editor);
+};
// for toast onClose to avoid console warnings
export const nullMethod = () => {};
@@ -19,8 +21,8 @@ export const editorConfig = ({
openModal,
initializeEditor,
}) => ({
- onInit: () => {
- module.initializeEditorRef(setEditorRef);
+ onInit: (evt, editor) => {
+ module.initializeEditorRef(setEditorRef)(evt, editor);
initializeEditor();
},
initialValue: blockValue ? blockValue.data.data : '',
diff --git a/src/editors/containers/TextEditor/hooks.test.jsx b/src/editors/containers/TextEditor/hooks.test.jsx
index 762af3e2d..f1109ddfd 100644
--- a/src/editors/containers/TextEditor/hooks.test.jsx
+++ b/src/editors/containers/TextEditor/hooks.test.jsx
@@ -58,11 +58,11 @@ describe('TextEditor hooks', () => {
initializeEditor: jest.fn(),
};
let output;
- test('It creates an onInit which calls initializeEditor, but not setEditorRef', () => {
+ test('It creates an onInit which calls initializeEditor and setEditorRef', () => {
output = module.editorConfig(props);
output.onInit();
expect(props.initializeEditor).toHaveBeenCalled();
- expect(props.setEditorRef).not.toHaveBeenCalled();
+ expect(props.setEditorRef).toHaveBeenCalled();
});
test('It sets the blockvalue to be empty string by default', () => {
output = module.editorConfig(props);
diff --git a/src/editors/data/constants/mockData.js b/src/editors/data/constants/mockData.js
index 954a4fb65..d00d4f7d6 100644
--- a/src/editors/data/constants/mockData.js
+++ b/src/editors/data/constants/mockData.js
@@ -1,5 +1,3 @@
-import { blockTypes } from './app';
-
export const mockImageData = [
{
displayName: 'shahrukh.jpg',
diff --git a/src/editors/data/redux/app/reducer.js b/src/editors/data/redux/app/reducer.js
index ab64e11bf..478de3557 100644
--- a/src/editors/data/redux/app/reducer.js
+++ b/src/editors/data/redux/app/reducer.js
@@ -29,7 +29,11 @@ const app = createSlice({
blockType: payload.blockType,
}),
setUnitUrl: (state, { payload }) => ({ ...state, unitUrl: payload }),
- setBlockValue: (state, { payload }) => ({ ...state, blockValue: payload }),
+ setBlockValue: (state, { payload }) => ({
+ ...state,
+ blockValue: payload,
+ blockTitle: payload.data.display_name,
+ }),
setBlockContent: (state, { payload }) => ({ ...state, blockContent: payload }),
setBlockTitle: (state, { payload }) => ({ ...state, blockTitle: payload }),
setSaveResponse: (state, { payload }) => ({ ...state, saveResponse: payload }),
diff --git a/src/editors/data/redux/app/reducer.test.js b/src/editors/data/redux/app/reducer.test.js
index 7986db6ff..ac820eb19 100644
--- a/src/editors/data/redux/app/reducer.test.js
+++ b/src/editors/data/redux/app/reducer.test.js
@@ -42,7 +42,6 @@ describe('app reducer', () => {
};
[
['setUnitUrl', 'unitUrl'],
- ['setBlockValue', 'blockValue'],
['setBlockContent', 'blockContent'],
['setBlockTitle', 'blockTitle'],
['setSaveResponse', 'saveResponse'],
diff --git a/src/editors/data/redux/app/selectors.js b/src/editors/data/redux/app/selectors.js
index 41ce6e83c..5ade3ae4d 100644
--- a/src/editors/data/redux/app/selectors.js
+++ b/src/editors/data/redux/app/selectors.js
@@ -19,6 +19,7 @@ export const simpleSelectors = {
saveResponse: mkSimpleSelector(app => app.saveResponse),
studioEndpointUrl: mkSimpleSelector(app => app.studioEndpointUrl),
unitUrl: mkSimpleSelector(app => app.unitUrl),
+ blockTitle: mkSimpleSelector(app => app.blockTitle),
};
export const returnUrl = createSelector(
diff --git a/src/editors/data/redux/requests/reducer.test.js b/src/editors/data/redux/requests/reducer.test.js
new file mode 100644
index 000000000..62872a47d
--- /dev/null
+++ b/src/editors/data/redux/requests/reducer.test.js
@@ -0,0 +1,49 @@
+import { initialState, actions, reducer } from './reducer';
+import { RequestStates, RequestKeys } from '../../constants/requests';
+
+describe('requests reducer', () => {
+ test('intial state generated on create', () => {
+ expect(reducer(undefined, {})).toEqual(initialState);
+ });
+
+ describe('handling actions', () => {
+ const arbitraryKey = 'ArbItrAryKey';
+ const requestsList = [RequestKeys.fetchUnit, RequestKeys.fetchBlock, RequestKeys.saveBlock, arbitraryKey];
+
+ requestsList.forEach(requestKey => {
+ describe(`${requestKey} lifecycle`, () => {
+ const testAction = (action, args, expected) => {
+ const testingState = {
+ ...initialState,
+ arbitraryField: 'arbitrary',
+ [requestKey]: { arbitrary: 'state' },
+ };
+ expect(reducer(testingState, actions[action](args))).toEqual({
+ ...testingState,
+ [requestKey]: expected,
+ });
+ };
+ test('startRequest sets pending status', () => {
+ testAction('startRequest', requestKey, { status: RequestStates.pending });
+ });
+ test('completeRequest sets completed status and loads response', () => {
+ testAction(
+ 'completeRequest',
+ { requestKey },
+ { status: RequestStates.completed },
+ );
+ });
+ test('failRequest sets failed state and loads error', () => {
+ testAction(
+ 'failRequest',
+ { requestKey },
+ { status: RequestStates.failed },
+ );
+ });
+ test('clearRequest clears request state', () => {
+ testAction('clearRequest', { requestKey }, {});
+ });
+ });
+ });
+ });
+});
diff --git a/src/editors/data/redux/thunkActions/requests.js b/src/editors/data/redux/thunkActions/requests.js
index 3dbd0bc5b..8e0062095 100644
--- a/src/editors/data/redux/thunkActions/requests.js
+++ b/src/editors/data/redux/thunkActions/requests.js
@@ -82,7 +82,7 @@ export const saveBlock = ({ content, ...rest }) => (dispatch, getState) => {
courseId: selectors.app.courseId(getState()),
content,
studioEndpointUrl: selectors.app.studioEndpointUrl(getState()),
- title: selectors.app.title(getState()),
+ title: selectors.app.blockTitle(getState()),
}),
...rest,
}));
diff --git a/src/editors/data/redux/thunkActions/requests.test.js b/src/editors/data/redux/thunkActions/requests.test.js
index 5f2242f77..3711b445d 100644
--- a/src/editors/data/redux/thunkActions/requests.test.js
+++ b/src/editors/data/redux/thunkActions/requests.test.js
@@ -1,15 +1,24 @@
-import { actions } from '..';
import { RequestKeys } from '../../constants/requests';
import api from '../../services/cms/api';
import * as requests from './requests';
+import { actions, selectors } from '../index';
-jest.mock('data/services/lms/api', () => ({
- initializeApp: (locationId) => ({ initializeApp: locationId }),
- fetchSubmissionStatus: (submissionUUID) => ({ fetchSubmissionStatus: submissionUUID }),
- fetchSubmission: (submissionUUID) => ({ fetchSubmission: submissionUUID }),
- lockSubmission: ({ submissionUUID }) => ({ lockSubmission: { submissionUUID } }),
- unlockSubmission: ({ submissionUUID }) => ({ unlockSubmission: { submissionUUID } }),
- updateGrade: (submissionUUID, gradeData) => ({ updateGrade: { submissionUUID, gradeData } }),
+const testState = {
+ some: 'data',
+};
+
+jest.mock('../app/selectors', () => ({
+ studioEndpointUrl: (state) => ({ studioEndpointUrl: state }),
+ blockId: (state) => ({ blockId: state }),
+ blockType: (state) => ({ blockType: state }),
+ courseId: (state) => ({ courseId: state }),
+ blockTitle: (state) => ({ title: state }),
+}));
+
+jest.mock('../../services/cms/api', () => ({
+ fetchBlockById: ({ id, url }) => ({ id, url }),
+ fetchByUnitId: ({ id, url }) => ({ id, url }),
+ saveBlock: (args) => args,
}));
let dispatch;
@@ -24,7 +33,7 @@ describe('requests thunkActions module', () => {
describe('networkRequest', () => {
const requestKey = 'test-request';
- const testData = { some: 'test data' };
+ const testData = ({ some: 'test data' });
let resolveFn;
let rejectFn;
beforeEach(() => {
@@ -83,7 +92,7 @@ describe('requests thunkActions module', () => {
}) => {
let dispatchedAction;
beforeEach(() => {
- action({ ...args, onSuccess, onFailure })(dispatch);
+ action({ ...args, onSuccess, onFailure })(dispatch, () => testState);
[[dispatchedAction]] = dispatch.mock.calls;
});
it('dispatches networkRequest', () => {
@@ -101,77 +110,58 @@ describe('requests thunkActions module', () => {
});
});
};
-
describe('network request actions', () => {
- const submissionUUID = 'test-submission-id';
- const locationId = 'test-location-id';
+ const fetchParams = { fetchParam1: 'param1', fetchParam2: 'param2' };
beforeEach(() => {
requests.networkRequest = jest.fn(args => ({ networkRequest: args }));
});
- describe('initializeApp', () => {
+ describe('fetchBlock', () => {
testNetworkRequestAction({
- action: requests.initializeApp,
- args: { locationId },
- expectedString: 'with initialize key, initializeApp promise',
+ action: requests.fetchBlock,
+ args: fetchParams,
+ expectedString: 'with fetchBlock promise',
expectedData: {
- requestKey: RequestKeys.initialize,
- promise: api.initializeApp(locationId),
+ ...fetchParams,
+ requestKey: RequestKeys.fetchBlock,
+ promise: api.fetchBlockById({
+ studioEndpointUrl: selectors.app.studioEndpointUrl(testState),
+ blockId: selectors.app.blockId(testState),
+ }),
},
});
});
- describe('fetchSubmissionStatus', () => {
+ describe('fetchUnit', () => {
testNetworkRequestAction({
- action: requests.fetchSubmissionStatus,
- args: { submissionUUID },
- expectedString: 'with fetchSubmissionStatus promise',
+ action: requests.fetchUnit,
+ args: fetchParams,
+ expectedString: 'with fetchUnit promise',
expectedData: {
- requestKey: RequestKeys.fetchSubmissionStatus,
- promise: api.fetchSubmissionStatus(submissionUUID),
+ ...fetchParams,
+ requestKey: RequestKeys.fetchUnit,
+ promise: api.fetchByUnitId({
+ studioEndpointUrl: selectors.app.studioEndpointUrl(testState),
+ blockId: selectors.app.blockId(testState),
+ }),
},
});
});
- describe('fetchSubmission', () => {
+ describe('saveBlock', () => {
+ const content = 'SoME HtMl CoNtent As String';
testNetworkRequestAction({
- action: requests.fetchSubmission,
- args: { submissionUUID },
- expectedString: 'with fetchSubmission promise',
+ action: requests.saveBlock,
+ args: { content, some: 'data' },
+ expectedString: 'with saveBlock promise',
expectedData: {
- requestKey: RequestKeys.fetchSubmission,
- promise: api.fetchSubmission(submissionUUID),
- },
- });
- });
- describe('setLock: true', () => {
- testNetworkRequestAction({
- action: requests.setLock,
- args: { submissionUUID, value: true },
- expectedString: 'with setLock promise',
- expectedData: {
- requestKey: RequestKeys.setLock,
- promise: api.lockSubmission(submissionUUID),
- },
- });
- });
- describe('setLock: false', () => {
- testNetworkRequestAction({
- action: requests.setLock,
- args: { submissionUUID, value: false },
- expectedString: 'with setLock promise',
- expectedData: {
- requestKey: RequestKeys.setLock,
- promise: api.unlockSubmission(submissionUUID),
- },
- });
- });
- describe('submitGrade', () => {
- const gradeData = 'test-grade-data';
- testNetworkRequestAction({
- action: requests.submitGrade,
- args: { submissionUUID, gradeData },
- expectedString: 'with submitGrade promise',
- expectedData: {
- requestKey: RequestKeys.submitGrade,
- promise: api.updateGrade(submissionUUID, gradeData),
+ ...testState,
+ requestKey: RequestKeys.saveBlock,
+ promise: api.saveBlock({
+ blockId: selectors.app.blockId(testState),
+ blockType: selectors.app.blockType(testState),
+ courseId: selectors.app.courseId(testState),
+ content,
+ studioEndpointUrl: selectors.app.studioEndpointUrl(testState),
+ title: selectors.app.blockTitle(testState),
+ }),
},
});
});
diff --git a/src/editors/data/services/cms/api.test.js b/src/editors/data/services/cms/api.test.js
index 94d81306d..a656419a5 100644
--- a/src/editors/data/services/cms/api.test.js
+++ b/src/editors/data/services/cms/api.test.js
@@ -1,6 +1,4 @@
-import {
- fetchBlockById, fetchByUnitId, normalizeContent, saveBlock,
-} from './api';
+import { apiMethods } from './api';
import * as urls from './urls';
import { get, post } from './utils';
@@ -23,21 +21,21 @@ const title = 'remember this needs to go into metadata to save';
describe('cms api', () => {
describe('fetchBlockId', () => {
it('should call get with url.blocks', () => {
- fetchBlockById({ blockId, studioEndpointUrl });
+ apiMethods.fetchBlockById({ blockId, studioEndpointUrl });
expect(get).toHaveBeenCalledWith(urls.block({ blockId, studioEndpointUrl }));
});
});
describe('fetchByUnitId', () => {
it('should call get with url.blockAncestor', () => {
- fetchByUnitId({ blockId, studioEndpointUrl });
+ apiMethods.fetchByUnitId({ blockId, studioEndpointUrl });
expect(get).toHaveBeenCalledWith(urls.blockAncestor({ studioEndpointUrl, blockId }));
});
});
describe('normalizeContent', () => {
test('return value for blockType: html', () => {
- expect(normalizeContent({
+ expect(apiMethods.normalizeContent({
blockId,
blockType: 'html',
content,
@@ -53,14 +51,14 @@ describe('cms api', () => {
});
});
test('throw error for invalid blockType', () => {
- expect(() => { normalizeContent({ blockType: 'somethingINVALID' }); })
+ expect(() => { apiMethods.normalizeContent({ blockType: 'somethingINVALID' }); })
.toThrow(TypeError);
});
});
describe('saveBlock', () => {
it('should call post with urls.block and normalizeContent', () => {
- saveBlock({
+ apiMethods.saveBlock({
blockId,
blockType: 'html',
content,
@@ -70,7 +68,7 @@ describe('cms api', () => {
});
expect(post).toHaveBeenCalledWith(
urls.block({ studioEndpointUrl }),
- normalizeContent({
+ apiMethods.normalizeContent({
blockType: 'html',
content,
blockId,
diff --git a/www/src/Gallery.jsx b/www/src/Gallery.jsx
index daa2728ae..714a8ec7e 100644
--- a/www/src/Gallery.jsx
+++ b/www/src/Gallery.jsx
@@ -1,7 +1,7 @@
import React from 'react';
import { Form } from '@edx/paragon';
-
+// eslint-disable-next-line
import { EditorPage } from '@edx/frontend-lib-content-components';
// eslint-disable-next-line
import { blockTypes } from '@edx/frontend-lib-content-components/editors/data/constants/app';
diff --git a/www/src/index.jsx b/www/src/index.jsx
index 69d97806a..df7500be2 100644
--- a/www/src/index.jsx
+++ b/www/src/index.jsx
@@ -1,3 +1,4 @@
+// eslint-disable-next-line
import 'core-js/stable';
import 'regenerator-runtime/runtime';