Skip to content

Commit

Permalink
test: testing for editor container hook
Browse files Browse the repository at this point in the history
  • Loading branch information
dcoa committed Dec 31, 2024
1 parent b8ecbe2 commit 1355231
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 1 deletion.
29 changes: 29 additions & 0 deletions src/editors/containers/EditorContainer/hooks.test.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -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 }),
Expand All @@ -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();
Expand Down Expand Up @@ -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: {
Expand All @@ -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', () => {
Expand Down
1 change: 0 additions & 1 deletion src/editors/containers/EditorContainer/hooks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@ export const handleSaveClicked = ({
returnFunction,
});
}

return () => saveBlock({
analytics,
content: getContent({ dispatch }),
Expand Down

0 comments on commit 1355231

Please sign in to comment.