feat: update returnToUnit to include api response (#346)

This commit is contained in:
Kristin Aoki
2023-06-13 15:29:04 -04:00
committed by GitHub
parent 82b0f67f11
commit 8eb10b7b12
4 changed files with 5 additions and 5 deletions

View File

@@ -70,7 +70,7 @@ export const saveBlock = ({ content, returnToUnit }) => (dispatch) => {
content,
onSuccess: (response) => {
dispatch(actions.app.setSaveResponse(response));
returnToUnit();
returnToUnit(response.data)();
},
}));
};

View File

@@ -138,7 +138,7 @@ describe('app thunkActions', () => {
let returnToUnit;
let calls;
beforeEach(() => {
returnToUnit = jest.fn();
returnToUnit = jest.fn((response) => () => response);
thunkActions.saveBlock({ content: testValue, returnToUnit })(dispatch);
calls = dispatch.mock.calls;
});

View File

@@ -21,12 +21,12 @@ export const navigateCallback = ({
destination,
analyticsEvent,
analytics,
}) => () => {
}) => (response) => {
if (process.env.NODE_ENV !== 'development' && analyticsEvent && analytics) {
sendTrackEvent(analyticsEvent, analytics);
}
if (returnFunction) {
returnFunction();
returnFunction()(response);
return;
}
module.navigateTo(destination);

View File

@@ -74,7 +74,6 @@ describe('hooks', () => {
let output;
const SAVED_ENV = process.env;
const destination = 'hOmE';
const returnFunction = jest.fn();
beforeEach(() => {
jest.resetModules();
process.env = { ...SAVED_ENV };
@@ -102,6 +101,7 @@ describe('hooks', () => {
expect(spy).toHaveBeenCalledWith(destination);
});
it('should call returnFunction and return null', () => {
const returnFunction = jest.fn(() => (response) => response);
output = hooks.navigateCallback({
destination,
returnFunction,