feat: update styling in advanced problem editor (#216)

This commit is contained in:
Kristin Aoki
2023-01-25 10:42:30 -05:00
committed by GitHub
parent 656e8f8568
commit 2d669cbe3e
9 changed files with 95 additions and 16 deletions

View File

@@ -71,7 +71,9 @@ exports[`SettingsWidget snapshot snapshot: renders Settings widget page 1`] = `
<div <div
className="my-3" className="my-3"
> >
<injectIntl(ShimmedIntlComponent) /> <injectIntl(ShimmedIntlComponent)
problemType="stringresponse"
/>
</div> </div>
</Body> </Body>
</Advanced> </Advanced>
@@ -149,7 +151,9 @@ exports[`SettingsWidget snapshot snapshot: renders Settings widget page advanced
<div <div
className="my-3" className="my-3"
> >
<injectIntl(ShimmedIntlComponent) /> <injectIntl(ShimmedIntlComponent)
problemType="stringresponse"
/>
</div> </div>
</Body> </Body>
</Advanced> </Advanced>

View File

@@ -79,7 +79,7 @@ export const SettingsWidget = ({
<MatlabCard matLabApiKey={settings.matLabApiKey} updateSettings={updateSettings} /> <MatlabCard matLabApiKey={settings.matLabApiKey} updateSettings={updateSettings} />
</div> </div>
<div className="my-3"> <div className="my-3">
<SwitchToAdvancedEditorCard /> <SwitchToAdvancedEditorCard problemType={problemType} />
</div> </div>
</Collapsible.Body> </Collapsible.Body>
</Collapsible.Advanced> </Collapsible.Advanced>

View File

@@ -176,7 +176,7 @@ export const messages = {
}, },
SwitchButtonLabel: { SwitchButtonLabel: {
id: 'authoring.problemeditor.settings.switchtoadvancededitor.label', id: 'authoring.problemeditor.settings.switchtoadvancededitor.label',
defaultMessage: 'Switch To Advanced Editor', defaultMessage: 'Switch to advanced editor',
description: 'button to switch to the advanced mode of the editor.', description: 'button to switch to the advanced mode of the editor.',
}, },
ConfirmSwitchMessage: { ConfirmSwitchMessage: {

View File

@@ -8,12 +8,16 @@ import { thunkActions } from '../../../../../../data/redux';
import BaseModal from '../../../../../TextEditor/components/BaseModal'; import BaseModal from '../../../../../TextEditor/components/BaseModal';
import Button from '../../../../../../sharedComponents/Button'; import Button from '../../../../../../sharedComponents/Button';
import { confirmSwitchToAdvancedEditor } from '../hooks'; import { confirmSwitchToAdvancedEditor } from '../hooks';
import { ProblemTypeKeys } from '../../../../../../data/constants/problem';
export const SwitchToAdvancedEditorCard = ({ export const SwitchToAdvancedEditorCard = ({
problemType,
switchToAdvancedEditor, switchToAdvancedEditor,
}) => { }) => {
const [isConfirmOpen, setConfirmOpen] = React.useState(false); const [isConfirmOpen, setConfirmOpen] = React.useState(false);
if (problemType === ProblemTypeKeys.ADVANCED) { return null; }
return ( return (
<Card className="border border-light-700 shadow-none"> <Card className="border border-light-700 shadow-none">
<BaseModal <BaseModal
@@ -45,6 +49,7 @@ export const SwitchToAdvancedEditorCard = ({
SwitchToAdvancedEditorCard.propTypes = { SwitchToAdvancedEditorCard.propTypes = {
switchToAdvancedEditor: PropTypes.func.isRequired, switchToAdvancedEditor: PropTypes.func.isRequired,
problemType: PropTypes.string.isRequired,
}; };
export const mapStateToProps = () => ({ export const mapStateToProps = () => ({

View File

@@ -1,12 +1,24 @@
import React from 'react'; import React from 'react';
import { shallow } from 'enzyme'; import { shallow } from 'enzyme';
import { SwitchToAdvancedEditorCard } from './SwitchToAdvancedEditorCard'; import { SwitchToAdvancedEditorCard, mapDispatchToProps } from './SwitchToAdvancedEditorCard';
import { thunkActions } from '../../../../../../data/redux';
describe('SwitchToAdvancedEditorCard snapshot', () => { describe('SwitchToAdvancedEditorCard snapshot', () => {
const mockSwitchToAdvancedEditor = jest.fn().mockName('switchToAdvancedEditor'); const mockSwitchToAdvancedEditor = jest.fn().mockName('switchToAdvancedEditor');
test('snapshot: SwitchToAdvancedEditorCard', () => { test('snapshot: SwitchToAdvancedEditorCard', () => {
expect( expect(
shallow(<SwitchToAdvancedEditorCard switchToAdvancedEditor={mockSwitchToAdvancedEditor} />), shallow(<SwitchToAdvancedEditorCard switchToAdvancedEditor={mockSwitchToAdvancedEditor} problemType="stringresponse" />),
).toMatchSnapshot(); ).toMatchSnapshot();
}); });
test('snapshot: SwitchToAdvancedEditorCard returns null', () => {
expect(
shallow(<SwitchToAdvancedEditorCard switchToAdvancedEditor={mockSwitchToAdvancedEditor} problemType="advanced" />),
).toMatchSnapshot();
});
describe('mapDispatchToProps', () => {
test('updateField from actions.problem.updateField', () => {
expect(mapDispatchToProps.switchToAdvancedEditor).toEqual(thunkActions.problem.switchToAdvancedEditor);
});
});
}); });

View File

@@ -45,10 +45,12 @@ exports[`SwitchToAdvancedEditorCard snapshot snapshot: SwitchToAdvancedEditorCar
variant="link" variant="link"
> >
<FormattedMessage <FormattedMessage
defaultMessage="Switch To Advanced Editor" defaultMessage="Switch to advanced editor"
description="button to switch to the advanced mode of the editor." description="button to switch to the advanced mode of the editor."
id="authoring.problemeditor.settings.switchtoadvancededitor.label" id="authoring.problemeditor.settings.switchtoadvancededitor.label"
/> />
</Button> </Button>
</Card> </Card>
`; `;
exports[`SwitchToAdvancedEditorCard snapshot snapshot: SwitchToAdvancedEditorCard returns null 1`] = `""`;

View File

@@ -1,7 +1,19 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP // Jest Snapshot v1, https://goo.gl/fbAQLP
exports[`RawEditor renders as expected with content equal to null 1`] = `
<Fragment>
<Alert
variant="danger"
>
You are using the raw
html
editor.
</Alert>
</Fragment>
`;
exports[`RawEditor renders as expected with default behavior 1`] = ` exports[`RawEditor renders as expected with default behavior 1`] = `
<div> <Fragment>
<Alert <Alert
variant="danger" variant="danger"
> >
@@ -20,5 +32,21 @@ exports[`RawEditor renders as expected with default behavior 1`] = `
lang="html" lang="html"
value="eDiTablE Text" value="eDiTablE Text"
/> />
</div> </Fragment>
`;
exports[`RawEditor renders as expected with lang equal to xml 1`] = `
<Fragment>
<injectIntl(ShimmedIntlComponent)
innerRef={
Object {
"current": Object {
"value": "Ref Value",
},
}
}
lang="xml"
value="eDiTablE Text"
/>
</Fragment>
`; `;

View File

@@ -18,10 +18,12 @@ export const RawEditor = ({
const value = getValue(content); const value = getValue(content);
return ( return (
<div> <>
<Alert variant="danger"> {lang === 'xml' ? null : (
You are using the raw {lang} editor. <Alert variant="danger">
</Alert> You are using the raw {lang} editor.
</Alert>
)}
{ value ? ( { value ? (
<CodeEditor <CodeEditor
innerRef={editorRef} innerRef={editorRef}
@@ -30,7 +32,7 @@ export const RawEditor = ({
/> />
) : null} ) : null}
</div> </>
); );
}; };
RawEditor.defaultProps = { RawEditor.defaultProps = {

View File

@@ -4,15 +4,41 @@ import { shallow } from 'enzyme';
import { RawEditor } from '.'; import { RawEditor } from '.';
describe('RawEditor', () => { describe('RawEditor', () => {
const props = { const defaultProps = {
editorRef: { editorRef: {
current: { current: {
value: 'Ref Value', value: 'Ref Value',
}, },
}, },
content: { data: { data: 'eDiTablE Text' } }, content: { data: { data: 'eDiTablE Text' } },
lang: 'html',
}; };
const xmlProps = {
editorRef: {
current: {
value: 'Ref Value',
},
},
content: { data: { data: 'eDiTablE Text' } },
lang: 'xml',
};
const noContentProps = {
editorRef: {
current: {
value: 'Ref Value',
},
},
content: null,
lang: 'html',
};
test('renders as expected with default behavior', () => { test('renders as expected with default behavior', () => {
expect(shallow(<RawEditor {...props} />)).toMatchSnapshot(); expect(shallow(<RawEditor {...defaultProps} />)).toMatchSnapshot();
});
test('renders as expected with lang equal to xml', () => {
expect(shallow(<RawEditor {...xmlProps} />)).toMatchSnapshot();
});
test('renders as expected with content equal to null', () => {
expect(shallow(<RawEditor {...noContentProps} />)).toMatchSnapshot();
}); });
}); });