Skip to content

Commit

Permalink
test: adding test for insertlinkmodaltoggle hook
Browse files Browse the repository at this point in the history
  • Loading branch information
johnvente committed Jan 18, 2024
1 parent e9dee15 commit 15f00a8
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,9 @@ const BlockLink = ({ path, onCloseLink }) => {
);
};

BlockLink.defaultProps = {
onCloseLink: () => {},
};

BlockLink.propTypes = {
path: PropTypes.string.isRequired,
onCloseLink: PropTypes.func,
onCloseLink: PropTypes.func.isRequired,
};

export default BlockLink;
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,6 @@ const FilterBlock = ({ block, onBlockFilterClick }) => {
);
};

FilterBlock.defaultProps = {
onBlockFilterClick: () => {},
};

const blockShape = PropTypes.shape({
id: PropTypes.string.isRequired,
blockId: PropTypes.string.isRequired,
Expand All @@ -41,7 +37,7 @@ const blockShape = PropTypes.shape({

FilterBlock.propTypes = {
block: PropTypes.objectOf(blockShape).isRequired,
onBlockFilterClick: PropTypes.func,
onBlockFilterClick: PropTypes.func.isRequired,
};

export default FilterBlock;
19 changes: 19 additions & 0 deletions src/editors/sharedComponents/TinyMceWidget/hooks.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ describe('TinyMceEditor hooks', () => {
state.testGetter(state.keys.isImageModalOpen);
state.testGetter(state.keys.isSourceCodeModalOpen);
state.testGetter(state.keys.imageSelection);
state.testGetter(state.keys.isInsertLinkModalOpen);
});

describe('non-state hooks', () => {
Expand Down Expand Up @@ -404,6 +405,24 @@ describe('TinyMceEditor hooks', () => {
});
});

describe('insertLinkModalToggle', () => {
const hookKey = state.keys.isInsertLinkModalOpen;
beforeEach(() => {
hook = module.insertLinkModalToggle();
});
test('isInsertLinkOpen: state value', () => {
expect(hook.isInsertLinkOpen).toEqual(state.stateVals[hookKey]);
});
test('openInsertLinkModal: calls setter with true', () => {
hook.openInsertLinkModal();
expect(state.setState[hookKey]).toHaveBeenCalledWith(true);
});
test('closeInsertLinkModal: calls setter with false', () => {
hook.closeInsertLinkModal();
expect(state.setState[hookKey]).toHaveBeenCalledWith(false);
});
});

describe('openModalWithSelectedImage', () => {
const setImage = jest.fn();
const openImgModal = jest.fn();
Expand Down

0 comments on commit 15f00a8

Please sign in to comment.