diff --git a/src/editors/containers/EditorContainer/index.test.tsx b/src/editors/containers/EditorContainer/index.test.tsx index a35e4d74b..d5cf30173 100644 --- a/src/editors/containers/EditorContainer/index.test.tsx +++ b/src/editors/containers/EditorContainer/index.test.tsx @@ -17,17 +17,6 @@ jest.spyOn(editorCmsApi, 'fetchCourseImages').mockImplementation(async () => ( / { data: { assets: [], start: 0, end: 0, page: 0, pageSize: 50, totalCount: 0 } } )); // Mock out the 'get ancestors' API: -jest.spyOn(editorCmsApi, 'fetchByUnitId').mockImplementation(async () => ({ - status: 200, - data: { - ancestors: [{ - id: 'block-v1:Org+TS100+24+type@vertical+block@parent', - display_name: 'You-Knit? The Test Unit', - category: 'vertical', - has_children: true, - }], - }, -})); const isDirtyMock = jest.fn(); jest.mock('../TextEditor/hooks', () => ({ @@ -60,6 +49,17 @@ describe('EditorContainer', () => { jest.spyOn(window, 'removeEventListener'); jest.spyOn(mockEvent, 'preventDefault'); Object.defineProperty(mockEvent, 'returnValue', { writable: true }); + jest.spyOn(editorCmsApi, 'fetchByUnitId').mockImplementation(async () => ({ + status: 200, + data: { + ancestors: [{ + id: 'block-v1:Org+TS100+24+type@vertical+block@parent', + display_name: 'You-Knit? The Test Unit', + category: 'vertical', + has_children: true, + }], + }, + })); }); afterEach(() => { diff --git a/src/editors/containers/EditorContainer/index.tsx b/src/editors/containers/EditorContainer/index.tsx index 7bc04597a..eb9e08ab2 100644 --- a/src/editors/containers/EditorContainer/index.tsx +++ b/src/editors/containers/EditorContainer/index.tsx @@ -94,7 +94,6 @@ const EditorContainer: React.FC = ({ const onSave = () => { setSaved(true); handleSave(); - dispatch({ type: 'resetEditor' }); }; // Stops user from navigating away if they have unsaved changes. usePromptIfDirty(() => { @@ -110,7 +109,6 @@ const EditorContainer: React.FC = ({ openCancelConfirmModal(); } else { handleCancel(); - dispatch({ type: 'resetEditor' }); } }; return ( @@ -130,7 +128,6 @@ const EditorContainer: React.FC = ({ if (returnFunction) { closeCancelConfirmModal(); } - dispatch({ type: 'resetEditor' }); }} > diff --git a/src/editors/containers/TextEditor/index.test.jsx b/src/editors/containers/TextEditor/index.test.jsx index ea3bffc94..5e17dc544 100644 --- a/src/editors/containers/TextEditor/index.test.jsx +++ b/src/editors/containers/TextEditor/index.test.jsx @@ -55,6 +55,7 @@ jest.mock('../../data/redux', () => ({ selectors: { app: { blockValue: jest.fn(state => ({ blockValue: state })), + isCreateBlock: jest.fn(state => ({ isCreateBlock: state })), lmsEndpointUrl: jest.fn(state => ({ lmsEndpointUrl: state })), studioEndpointUrl: jest.fn(state => ({ studioEndpointUrl: state })), showRawEditor: jest.fn(state => ({ showRawEditor: state })), @@ -126,7 +127,8 @@ describe('TextEditor', () => { test('blockFinished from requests.isFinished', () => { expect( mapStateToProps(testState).blockFinished, - ).toEqual(selectors.requests.isFinished(testState, { requestKey: RequestKeys.fetchBlock })); + ).toEqual(selectors.app.isCreateBlock(testState) + || selectors.requests.isFinished(testState, { requestKey: RequestKeys.fetchBlock })); }); test('learningContextId from app.learningContextId', () => { expect( diff --git a/src/editors/data/redux/thunkActions/app.js b/src/editors/data/redux/thunkActions/app.js index 5d99027b6..f9e8b2561 100644 --- a/src/editors/data/redux/thunkActions/app.js +++ b/src/editors/data/redux/thunkActions/app.js @@ -88,6 +88,7 @@ export const fetchCourseDetails = () => (dispatch) => { */ export const initialize = (data) => (dispatch) => { const editorType = data.blockType; + dispatch({ type: 'resetEditor' }); dispatch(actions.app.initialize(data)); if (data.blockId === '' && editorType) { dispatch(actions.app.initializeEditor()); @@ -139,6 +140,10 @@ export const createBlock = (content, returnToUnit) => (dispatch) => { dispatch(actions.app.setBlockId(response.id)); dispatch(saveBlock(content, returnToUnit)); }, + onFailure: (error) => dispatch(actions.requests.failRequest({ + requestKey: RequestKeys.createBlock, + error, + })), })); }; diff --git a/src/editors/data/redux/thunkActions/app.test.js b/src/editors/data/redux/thunkActions/app.test.js index a3c098ef6..c1c179987 100644 --- a/src/editors/data/redux/thunkActions/app.test.js +++ b/src/editors/data/redux/thunkActions/app.test.js @@ -186,6 +186,7 @@ describe('app thunkActions', () => { thunkActions.fetchCourseDetails = () => 'fetchCourseDetails'; thunkActions.initialize(testValue)(dispatch); expect(dispatch.mock.calls).toEqual([ + [{ type: 'resetEditor' }], [actions.app.initialize(testValue)], [thunkActions.fetchBlock()], ]); @@ -207,6 +208,7 @@ describe('app thunkActions', () => { }; thunkActions.initialize(data)(dispatch); expect(dispatch.mock.calls).toEqual([ + [{ type: 'resetEditor' }], [actions.app.initialize(data)], [actions.app.initializeEditor()], ]); @@ -236,6 +238,7 @@ describe('app thunkActions', () => { }; thunkActions.initialize(data)(dispatch); expect(dispatch.mock.calls).toEqual([ + [{ type: 'resetEditor' }], [actions.app.initialize(data)], [thunkActions.fetchBlock()], [thunkActions.fetchUnit()], @@ -273,6 +276,7 @@ describe('app thunkActions', () => { }; thunkActions.initialize(data)(dispatch); expect(dispatch.mock.calls).toEqual([ + [{ type: 'resetEditor' }], [actions.app.initialize(data)], [thunkActions.fetchBlock()], [thunkActions.fetchUnit()], @@ -310,6 +314,7 @@ describe('app thunkActions', () => { }; thunkActions.initialize(data)(dispatch); expect(dispatch.mock.calls).toEqual([ + [{ type: 'resetEditor' }], [actions.app.initialize(data)], [thunkActions.fetchBlock()], [thunkActions.fetchUnit()], diff --git a/src/editors/data/redux/thunkActions/requests.js b/src/editors/data/redux/thunkActions/requests.js index d0564996f..1e68bc101 100644 --- a/src/editors/data/redux/thunkActions/requests.js +++ b/src/editors/data/redux/thunkActions/requests.js @@ -376,6 +376,7 @@ export default StrictDict({ fetchBlock, fetchStudioView, fetchUnit, + createBlock, saveBlock, fetchImages, fetchVideos,