From 2d669cbe3efc98561c797f3d74f02e873827ab12 Mon Sep 17 00:00:00 2001 From: Kristin Aoki <42981026+KristinAoki@users.noreply.github.com> Date: Wed, 25 Jan 2023 10:42:30 -0500 Subject: [PATCH] feat: update styling in advanced problem editor (#216) --- .../__snapshots__/index.test.jsx.snap | 8 +++-- .../EditProblemView/SettingsWidget/index.jsx | 2 +- .../SettingsWidget/messages.js | 2 +- .../SwitchToAdvancedEditorCard.jsx | 5 +++ .../SwitchToAdvancedEditorCard.test.jsx | 16 ++++++++-- .../SwitchToAdvancedEditorCard.test.jsx.snap | 4 ++- .../__snapshots__/index.test.jsx.snap | 32 +++++++++++++++++-- .../sharedComponents/RawEditor/index.jsx | 12 ++++--- .../sharedComponents/RawEditor/index.test.jsx | 30 +++++++++++++++-- 9 files changed, 95 insertions(+), 16 deletions(-) diff --git a/src/editors/containers/ProblemEditor/components/EditProblemView/SettingsWidget/__snapshots__/index.test.jsx.snap b/src/editors/containers/ProblemEditor/components/EditProblemView/SettingsWidget/__snapshots__/index.test.jsx.snap index 84ff5f54b..e0cedda10 100644 --- a/src/editors/containers/ProblemEditor/components/EditProblemView/SettingsWidget/__snapshots__/index.test.jsx.snap +++ b/src/editors/containers/ProblemEditor/components/EditProblemView/SettingsWidget/__snapshots__/index.test.jsx.snap @@ -71,7 +71,9 @@ exports[`SettingsWidget snapshot snapshot: renders Settings widget page 1`] = `
- +
@@ -149,7 +151,9 @@ exports[`SettingsWidget snapshot snapshot: renders Settings widget page advanced
- +
diff --git a/src/editors/containers/ProblemEditor/components/EditProblemView/SettingsWidget/index.jsx b/src/editors/containers/ProblemEditor/components/EditProblemView/SettingsWidget/index.jsx index 871fda5e7..b2caf9a8d 100644 --- a/src/editors/containers/ProblemEditor/components/EditProblemView/SettingsWidget/index.jsx +++ b/src/editors/containers/ProblemEditor/components/EditProblemView/SettingsWidget/index.jsx @@ -79,7 +79,7 @@ export const SettingsWidget = ({
- +
diff --git a/src/editors/containers/ProblemEditor/components/EditProblemView/SettingsWidget/messages.js b/src/editors/containers/ProblemEditor/components/EditProblemView/SettingsWidget/messages.js index ce597208a..f8bf23431 100644 --- a/src/editors/containers/ProblemEditor/components/EditProblemView/SettingsWidget/messages.js +++ b/src/editors/containers/ProblemEditor/components/EditProblemView/SettingsWidget/messages.js @@ -176,7 +176,7 @@ export const messages = { }, SwitchButtonLabel: { 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.', }, ConfirmSwitchMessage: { diff --git a/src/editors/containers/ProblemEditor/components/EditProblemView/SettingsWidget/settingsComponents/SwitchToAdvancedEditorCard.jsx b/src/editors/containers/ProblemEditor/components/EditProblemView/SettingsWidget/settingsComponents/SwitchToAdvancedEditorCard.jsx index 7d058235f..03882ee8d 100644 --- a/src/editors/containers/ProblemEditor/components/EditProblemView/SettingsWidget/settingsComponents/SwitchToAdvancedEditorCard.jsx +++ b/src/editors/containers/ProblemEditor/components/EditProblemView/SettingsWidget/settingsComponents/SwitchToAdvancedEditorCard.jsx @@ -8,12 +8,16 @@ import { thunkActions } from '../../../../../../data/redux'; import BaseModal from '../../../../../TextEditor/components/BaseModal'; import Button from '../../../../../../sharedComponents/Button'; import { confirmSwitchToAdvancedEditor } from '../hooks'; +import { ProblemTypeKeys } from '../../../../../../data/constants/problem'; export const SwitchToAdvancedEditorCard = ({ + problemType, switchToAdvancedEditor, }) => { const [isConfirmOpen, setConfirmOpen] = React.useState(false); + if (problemType === ProblemTypeKeys.ADVANCED) { return null; } + return ( ({ diff --git a/src/editors/containers/ProblemEditor/components/EditProblemView/SettingsWidget/settingsComponents/SwitchToAdvancedEditorCard.test.jsx b/src/editors/containers/ProblemEditor/components/EditProblemView/SettingsWidget/settingsComponents/SwitchToAdvancedEditorCard.test.jsx index 96d0b4a5c..9a91044f3 100644 --- a/src/editors/containers/ProblemEditor/components/EditProblemView/SettingsWidget/settingsComponents/SwitchToAdvancedEditorCard.test.jsx +++ b/src/editors/containers/ProblemEditor/components/EditProblemView/SettingsWidget/settingsComponents/SwitchToAdvancedEditorCard.test.jsx @@ -1,12 +1,24 @@ import React from 'react'; import { shallow } from 'enzyme'; -import { SwitchToAdvancedEditorCard } from './SwitchToAdvancedEditorCard'; +import { SwitchToAdvancedEditorCard, mapDispatchToProps } from './SwitchToAdvancedEditorCard'; +import { thunkActions } from '../../../../../../data/redux'; describe('SwitchToAdvancedEditorCard snapshot', () => { const mockSwitchToAdvancedEditor = jest.fn().mockName('switchToAdvancedEditor'); test('snapshot: SwitchToAdvancedEditorCard', () => { expect( - shallow(), + shallow(), ).toMatchSnapshot(); }); + test('snapshot: SwitchToAdvancedEditorCard returns null', () => { + expect( + shallow(), + ).toMatchSnapshot(); + }); + + describe('mapDispatchToProps', () => { + test('updateField from actions.problem.updateField', () => { + expect(mapDispatchToProps.switchToAdvancedEditor).toEqual(thunkActions.problem.switchToAdvancedEditor); + }); + }); }); diff --git a/src/editors/containers/ProblemEditor/components/EditProblemView/SettingsWidget/settingsComponents/__snapshots__/SwitchToAdvancedEditorCard.test.jsx.snap b/src/editors/containers/ProblemEditor/components/EditProblemView/SettingsWidget/settingsComponents/__snapshots__/SwitchToAdvancedEditorCard.test.jsx.snap index 037706263..745e27c47 100644 --- a/src/editors/containers/ProblemEditor/components/EditProblemView/SettingsWidget/settingsComponents/__snapshots__/SwitchToAdvancedEditorCard.test.jsx.snap +++ b/src/editors/containers/ProblemEditor/components/EditProblemView/SettingsWidget/settingsComponents/__snapshots__/SwitchToAdvancedEditorCard.test.jsx.snap @@ -45,10 +45,12 @@ exports[`SwitchToAdvancedEditorCard snapshot snapshot: SwitchToAdvancedEditorCar variant="link" > `; + +exports[`SwitchToAdvancedEditorCard snapshot snapshot: SwitchToAdvancedEditorCard returns null 1`] = `""`; diff --git a/src/editors/sharedComponents/RawEditor/__snapshots__/index.test.jsx.snap b/src/editors/sharedComponents/RawEditor/__snapshots__/index.test.jsx.snap index 056066354..f7b70ddf5 100644 --- a/src/editors/sharedComponents/RawEditor/__snapshots__/index.test.jsx.snap +++ b/src/editors/sharedComponents/RawEditor/__snapshots__/index.test.jsx.snap @@ -1,7 +1,19 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP +exports[`RawEditor renders as expected with content equal to null 1`] = ` + + + You are using the raw + html + editor. + + +`; + exports[`RawEditor renders as expected with default behavior 1`] = ` -
+ @@ -20,5 +32,21 @@ exports[`RawEditor renders as expected with default behavior 1`] = ` lang="html" value="eDiTablE Text" /> -
+ +`; + +exports[`RawEditor renders as expected with lang equal to xml 1`] = ` + + + `; diff --git a/src/editors/sharedComponents/RawEditor/index.jsx b/src/editors/sharedComponents/RawEditor/index.jsx index 05bbc9401..2d1d3347a 100644 --- a/src/editors/sharedComponents/RawEditor/index.jsx +++ b/src/editors/sharedComponents/RawEditor/index.jsx @@ -18,10 +18,12 @@ export const RawEditor = ({ const value = getValue(content); return ( -
- - You are using the raw {lang} editor. - + <> + {lang === 'xml' ? null : ( + + You are using the raw {lang} editor. + + )} { value ? ( ) : null} -
+ ); }; RawEditor.defaultProps = { diff --git a/src/editors/sharedComponents/RawEditor/index.test.jsx b/src/editors/sharedComponents/RawEditor/index.test.jsx index 868f7b47d..86f0cc765 100644 --- a/src/editors/sharedComponents/RawEditor/index.test.jsx +++ b/src/editors/sharedComponents/RawEditor/index.test.jsx @@ -4,15 +4,41 @@ import { shallow } from 'enzyme'; import { RawEditor } from '.'; describe('RawEditor', () => { - const props = { + const defaultProps = { editorRef: { current: { value: 'Ref Value', }, }, 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', () => { - expect(shallow()).toMatchSnapshot(); + expect(shallow()).toMatchSnapshot(); + }); + test('renders as expected with lang equal to xml', () => { + expect(shallow()).toMatchSnapshot(); + }); + test('renders as expected with content equal to null', () => { + expect(shallow()).toMatchSnapshot(); }); });