Commit 519b9cef authored by Saturnino Abril's avatar Saturnino Abril

fix JS error after editing a post (#2080)

parent 0a1acaaa
......@@ -272,7 +272,10 @@ export default class EditPostModal extends React.PureComponent {
}
setEditboxRef = (ref) => {
this.editbox = ref.getWrappedInstance();
if (ref && ref.getWrappedInstance) {
this.editbox = ref.getWrappedInstance();
}
if (this.editbox) {
this.editbox.focus();
}
......
......@@ -437,4 +437,18 @@ describe('components/EditPostModal', () => {
instance.handleKeyDown({key: Constants.KeyCodes.ESCAPE[0], keyCode: Constants.KeyCodes.ESCAPE[1]});
expect(instance.handleHide).not.toBeCalled();
});
it('should set instance.editbox on setEditboxRef', () => {
const wrapper = shallow(createEditPost());
wrapper.instance().setEditboxRef();
expect(wrapper.instance().editbox).toEqual(undefined);
const focus = jest.fn();
const ref = {getWrappedInstance: () => ({focus})};
wrapper.instance().setEditboxRef(ref);
wrapper.update();
expect(wrapper.instance().editbox).toEqual({focus});
expect(wrapper.instance().editbox.focus).toHaveBeenCalledTimes(1);
});
});
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment