fix: failure toast and close modal bugs (#352)
This commit is contained in:
@@ -9,14 +9,7 @@ exports[`EditorContainer component render snapshot: initialized. enable save and
|
|||||||
close={[MockFunction closeCancelConfirmModal]}
|
close={[MockFunction closeCancelConfirmModal]}
|
||||||
confirmAction={
|
confirmAction={
|
||||||
<Button
|
<Button
|
||||||
onClick={
|
onClick={[Function]}
|
||||||
Object {
|
|
||||||
"handleCancel": Object {
|
|
||||||
"onClose": [MockFunction props.onClose],
|
|
||||||
"returnFunction": [MockFunction props.returnFunction],
|
|
||||||
},
|
|
||||||
}
|
|
||||||
}
|
|
||||||
variant="primary"
|
variant="primary"
|
||||||
>
|
>
|
||||||
<FormattedMessage
|
<FormattedMessage
|
||||||
@@ -92,14 +85,7 @@ exports[`EditorContainer component render snapshot: not initialized. disable sav
|
|||||||
close={[MockFunction closeCancelConfirmModal]}
|
close={[MockFunction closeCancelConfirmModal]}
|
||||||
confirmAction={
|
confirmAction={
|
||||||
<Button
|
<Button
|
||||||
onClick={
|
onClick={[Function]}
|
||||||
Object {
|
|
||||||
"handleCancel": Object {
|
|
||||||
"onClose": [MockFunction props.onClose],
|
|
||||||
"returnFunction": [MockFunction props.returnFunction],
|
|
||||||
},
|
|
||||||
}
|
|
||||||
}
|
|
||||||
variant="primary"
|
variant="primary"
|
||||||
>
|
>
|
||||||
<FormattedMessage
|
<FormattedMessage
|
||||||
|
|||||||
@@ -36,7 +36,12 @@ export const EditorContainer = ({
|
|||||||
confirmAction={(
|
confirmAction={(
|
||||||
<Button
|
<Button
|
||||||
variant="primary"
|
variant="primary"
|
||||||
onClick={handleCancel}
|
onClick={() => {
|
||||||
|
handleCancel();
|
||||||
|
if (returnFunction) {
|
||||||
|
closeCancelConfirmModal();
|
||||||
|
}
|
||||||
|
}}
|
||||||
>
|
>
|
||||||
<FormattedMessage {...messages.okButtonLabel} />
|
<FormattedMessage {...messages.okButtonLabel} />
|
||||||
</Button>
|
</Button>
|
||||||
|
|||||||
@@ -64,13 +64,13 @@ export const initialize = (data) => (dispatch) => {
|
|||||||
/**
|
/**
|
||||||
* @param {func} onSuccess
|
* @param {func} onSuccess
|
||||||
*/
|
*/
|
||||||
export const saveBlock = ({ content, returnToUnit }) => (dispatch) => {
|
export const saveBlock = (content, returnToUnit) => (dispatch) => {
|
||||||
dispatch(actions.app.setBlockContent(content));
|
dispatch(actions.app.setBlockContent(content));
|
||||||
dispatch(requests.saveBlock({
|
dispatch(requests.saveBlock({
|
||||||
content,
|
content,
|
||||||
onSuccess: (response) => {
|
onSuccess: (response) => {
|
||||||
dispatch(actions.app.setSaveResponse(response));
|
dispatch(actions.app.setSaveResponse(response));
|
||||||
returnToUnit(response.data)();
|
returnToUnit(response.data);
|
||||||
},
|
},
|
||||||
}));
|
}));
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -138,8 +138,8 @@ describe('app thunkActions', () => {
|
|||||||
let returnToUnit;
|
let returnToUnit;
|
||||||
let calls;
|
let calls;
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
returnToUnit = jest.fn((response) => () => response);
|
returnToUnit = jest.fn();
|
||||||
thunkActions.saveBlock({ content: testValue, returnToUnit })(dispatch);
|
thunkActions.saveBlock(testValue, returnToUnit)(dispatch);
|
||||||
calls = dispatch.mock.calls;
|
calls = dispatch.mock.calls;
|
||||||
});
|
});
|
||||||
it('dispatches actions.app.setBlockContent with content, before dispatching saveBlock', () => {
|
it('dispatches actions.app.setBlockContent with content, before dispatching saveBlock', () => {
|
||||||
|
|||||||
@@ -54,15 +54,15 @@ export const saveBlock = ({
|
|||||||
attemptSave = true;
|
attemptSave = true;
|
||||||
}
|
}
|
||||||
if (attemptSave) {
|
if (attemptSave) {
|
||||||
dispatch(thunkActions.app.saveBlock({
|
dispatch(thunkActions.app.saveBlock(
|
||||||
returnToUnit: module.navigateCallback({
|
content,
|
||||||
|
module.navigateCallback({
|
||||||
destination,
|
destination,
|
||||||
analyticsEvent: analyticsEvt.editorSaveClick,
|
analyticsEvent: analyticsEvt.editorSaveClick,
|
||||||
analytics,
|
analytics,
|
||||||
returnFunction,
|
returnFunction,
|
||||||
}),
|
}),
|
||||||
content,
|
));
|
||||||
}));
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -146,14 +146,14 @@ describe('hooks', () => {
|
|||||||
analytics,
|
analytics,
|
||||||
dispatch,
|
dispatch,
|
||||||
});
|
});
|
||||||
expect(dispatch).toHaveBeenCalledWith(thunkActions.app.saveBlock({
|
expect(dispatch).toHaveBeenCalledWith(thunkActions.app.saveBlock(
|
||||||
returnToUnit: navigateCallback({
|
content,
|
||||||
|
navigateCallback({
|
||||||
destination,
|
destination,
|
||||||
analyticsEvent: analyticsEvt.editorSaveClick,
|
analyticsEvent: analyticsEvt.editorSaveClick,
|
||||||
analytics,
|
analytics,
|
||||||
}),
|
}),
|
||||||
content,
|
));
|
||||||
}));
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user