fix: failure toast and close modal bugs (#352)

This commit is contained in:
Kristin Aoki
2023-06-21 13:48:54 -04:00
committed by GitHub
parent 8a2c725eda
commit c8e85fae0b
6 changed files with 20 additions and 29 deletions

View File

@@ -9,14 +9,7 @@ exports[`EditorContainer component render snapshot: initialized. enable save and
close={[MockFunction closeCancelConfirmModal]}
confirmAction={
<Button
onClick={
Object {
"handleCancel": Object {
"onClose": [MockFunction props.onClose],
"returnFunction": [MockFunction props.returnFunction],
},
}
}
onClick={[Function]}
variant="primary"
>
<FormattedMessage
@@ -92,14 +85,7 @@ exports[`EditorContainer component render snapshot: not initialized. disable sav
close={[MockFunction closeCancelConfirmModal]}
confirmAction={
<Button
onClick={
Object {
"handleCancel": Object {
"onClose": [MockFunction props.onClose],
"returnFunction": [MockFunction props.returnFunction],
},
}
}
onClick={[Function]}
variant="primary"
>
<FormattedMessage

View File

@@ -36,7 +36,12 @@ export const EditorContainer = ({
confirmAction={(
<Button
variant="primary"
onClick={handleCancel}
onClick={() => {
handleCancel();
if (returnFunction) {
closeCancelConfirmModal();
}
}}
>
<FormattedMessage {...messages.okButtonLabel} />
</Button>

View File

@@ -64,13 +64,13 @@ export const initialize = (data) => (dispatch) => {
/**
* @param {func} onSuccess
*/
export const saveBlock = ({ content, returnToUnit }) => (dispatch) => {
export const saveBlock = (content, returnToUnit) => (dispatch) => {
dispatch(actions.app.setBlockContent(content));
dispatch(requests.saveBlock({
content,
onSuccess: (response) => {
dispatch(actions.app.setSaveResponse(response));
returnToUnit(response.data)();
returnToUnit(response.data);
},
}));
};

View File

@@ -138,8 +138,8 @@ describe('app thunkActions', () => {
let returnToUnit;
let calls;
beforeEach(() => {
returnToUnit = jest.fn((response) => () => response);
thunkActions.saveBlock({ content: testValue, returnToUnit })(dispatch);
returnToUnit = jest.fn();
thunkActions.saveBlock(testValue, returnToUnit)(dispatch);
calls = dispatch.mock.calls;
});
it('dispatches actions.app.setBlockContent with content, before dispatching saveBlock', () => {

View File

@@ -54,15 +54,15 @@ export const saveBlock = ({
attemptSave = true;
}
if (attemptSave) {
dispatch(thunkActions.app.saveBlock({
returnToUnit: module.navigateCallback({
dispatch(thunkActions.app.saveBlock(
content,
module.navigateCallback({
destination,
analyticsEvent: analyticsEvt.editorSaveClick,
analytics,
returnFunction,
}),
content,
}));
));
}
};

View File

@@ -146,14 +146,14 @@ describe('hooks', () => {
analytics,
dispatch,
});
expect(dispatch).toHaveBeenCalledWith(thunkActions.app.saveBlock({
returnToUnit: navigateCallback({
expect(dispatch).toHaveBeenCalledWith(thunkActions.app.saveBlock(
content,
navigateCallback({
destination,
analyticsEvent: analyticsEvt.editorSaveClick,
analytics,
}),
content,
}));
));
});
});