diff --git a/src/editors/containers/EditorContainer/hooks.test.jsx b/src/editors/containers/EditorContainer/hooks.test.jsx index 815a4cc12..23817bc56 100644 --- a/src/editors/containers/EditorContainer/hooks.test.jsx +++ b/src/editors/containers/EditorContainer/hooks.test.jsx @@ -16,6 +16,7 @@ jest.mock('../../data/redux', () => ({ app: { isInitialized: (state) => ({ isInitialized: state }), images: (state) => ({ images: state }), + isCreateBlock: (state) => ({ isCreateBlock: state }), }, requests: { isFailed: (...args) => ({ requestFailed: args }), @@ -26,6 +27,7 @@ jest.mock('../../hooks', () => ({ ...jest.requireActual('../../hooks'), navigateCallback: jest.fn((args) => ({ navigateCallback: args })), saveBlock: jest.fn((args) => ({ saveBlock: args })), + createBlock: jest.fn((args) => ({ createBlock: args })), })); const dispatch = jest.fn(); @@ -53,6 +55,8 @@ describe('EditorContainer hooks', () => { const getContent = () => 'myTestContentValue'; const setAssetToStaticUrl = () => 'myTestContentValue'; const validateEntry = () => 'vaLIdAteENTry'; + reactRedux.useSelector.mockReturnValue(false); + const output = hooks.handleSaveClicked({ getContent, images: { @@ -73,6 +77,31 @@ describe('EditorContainer hooks', () => { validateEntry, }); }); + it('returns callback to createBlock with dispatch and content if isCreateBlock is true', () => { + const getContent = () => 'myTestContentValue'; + const setAssetToStaticUrl = () => 'myTestContentValue'; + const validateEntry = () => 'vaLIdAteENTry'; + reactRedux.useSelector.mockReturnValue(true); + + const output = hooks.handleSaveClicked({ + getContent, + images: { + portableUrl: '/static/sOmEuiMAge.jpeg', + displayName: 'sOmEuiMAge', + }, + destination: 'testDEsTURL', + analytics: 'soMEanALytics', + dispatch, + validateEntry, + }); + output(); + expect(appHooks.createBlock).toHaveBeenCalledWith({ + content: setAssetToStaticUrl(reactRedux.useSelector(selectors.app.images), getContent), + destination: reactRedux.useSelector(selectors.app.returnUrl), + analytics: reactRedux.useSelector(selectors.app.analytics), + dispatch, + }); + }); }); describe('cancelConfirmModalToggle', () => { diff --git a/src/editors/containers/EditorContainer/hooks.ts b/src/editors/containers/EditorContainer/hooks.ts index de37327a2..626f6e284 100644 --- a/src/editors/containers/EditorContainer/hooks.ts +++ b/src/editors/containers/EditorContainer/hooks.ts @@ -42,7 +42,6 @@ export const handleSaveClicked = ({ returnFunction, }); } - return () => saveBlock({ analytics, content: getContent({ dispatch }),