feat: update onclick to close modal + top scroll (#207)

This commit is contained in:
Kristin Aoki
2023-01-24 11:34:55 -05:00
committed by GitHub
parent f135bd2b4a
commit 77afb7465b
4 changed files with 30 additions and 2 deletions

View File

@@ -203,3 +203,15 @@ export const typeRowHooks = ({
onClick,
};
};
export const confirmSwitchToAdvancedEditor = ({
switchToAdvancedEditor,
setConfirmOpen,
}) => {
switchToAdvancedEditor();
setConfirmOpen(false);
window.scrollTo({
top: 0,
behavior: 'smooth',
});
};

View File

@@ -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();
});
});
});

View File

@@ -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>

View File

@@ -8,7 +8,7 @@ exports[`SwitchToAdvancedEditorCard snapshot snapshot: SwitchToAdvancedEditorCar
close={[Function]}
confirmAction={
<Button
onClick={[MockFunction switchToAdvancedEditor]}
onClick={[Function]}
>
<FormattedMessage
defaultMessage="Switch To Advanced Editor"