feat: update onclick to close modal + top scroll (#207)
This commit is contained in:
@@ -203,3 +203,15 @@ export const typeRowHooks = ({
|
||||
onClick,
|
||||
};
|
||||
};
|
||||
|
||||
export const confirmSwitchToAdvancedEditor = ({
|
||||
switchToAdvancedEditor,
|
||||
setConfirmOpen,
|
||||
}) => {
|
||||
switchToAdvancedEditor();
|
||||
setConfirmOpen(false);
|
||||
window.scrollTo({
|
||||
top: 0,
|
||||
behavior: 'smooth',
|
||||
});
|
||||
};
|
||||
|
||||
@@ -266,4 +266,18 @@ describe('Problem settings hooks', () => {
|
||||
expect(updateField).toHaveBeenCalledWith({ problemType: typekey });
|
||||
});
|
||||
});
|
||||
describe('Type row hooks', () => {
|
||||
test('test onClick', () => {
|
||||
const switchToAdvancedEditor = jest.fn();
|
||||
const setConfirmOpen = jest.fn();
|
||||
window.scrollTo = jest.fn();
|
||||
hooks.confirmSwitchToAdvancedEditor({
|
||||
switchToAdvancedEditor,
|
||||
setConfirmOpen,
|
||||
});
|
||||
expect(switchToAdvancedEditor).toHaveBeenCalled();
|
||||
expect(setConfirmOpen).toHaveBeenCalledWith(false);
|
||||
expect(window.scrollTo).toHaveBeenCalled();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@@ -6,11 +6,13 @@ import PropTypes from 'prop-types';
|
||||
import messages from '../messages';
|
||||
import { thunkActions } from '../../../../../../data/redux';
|
||||
import BaseModal from '../../../../../TextEditor/components/BaseModal';
|
||||
import { confirmSwitchToAdvancedEditor } from '../hooks';
|
||||
|
||||
export const SwitchToAdvancedEditorCard = ({
|
||||
switchToAdvancedEditor,
|
||||
}) => {
|
||||
const [isConfirmOpen, setConfirmOpen] = React.useState(false);
|
||||
|
||||
return (
|
||||
<Card className="border border-light-700 shadow-none">
|
||||
<BaseModal
|
||||
@@ -19,7 +21,7 @@ export const SwitchToAdvancedEditorCard = ({
|
||||
title={(<FormattedMessage {...messages.ConfirmSwitchMessageTitle} />)}
|
||||
confirmAction={(
|
||||
<Button
|
||||
onClick={switchToAdvancedEditor}
|
||||
onClick={() => confirmSwitchToAdvancedEditor({ switchToAdvancedEditor, setConfirmOpen })}
|
||||
>
|
||||
<FormattedMessage {...messages.ConfirmSwitchButtonLabel} />
|
||||
</Button>
|
||||
|
||||
@@ -8,7 +8,7 @@ exports[`SwitchToAdvancedEditorCard snapshot snapshot: SwitchToAdvancedEditorCar
|
||||
close={[Function]}
|
||||
confirmAction={
|
||||
<Button
|
||||
onClick={[MockFunction switchToAdvancedEditor]}
|
||||
onClick={[Function]}
|
||||
>
|
||||
<FormattedMessage
|
||||
defaultMessage="Switch To Advanced Editor"
|
||||
|
||||
Reference in New Issue
Block a user