From 5aca835a4b021a9796e9fe4cb7ba62e65911567c Mon Sep 17 00:00:00 2001
From: Jesper Hodge <19345795+jesperhodge@users.noreply.github.com>
Date: Fri, 20 Jan 2023 15:59:30 -0500
Subject: [PATCH] Fix problem editor margins and borders (#203)
* fix: fix border and allow customizing of tinymce style
* fix: make tinymce widget look like on figma
* fix: update settingsoptions card border
* fix: header typography
* fix: spacings
* chore: update snapshots
* Update src/editors/containers/ProblemEditor/components/EditProblemView/SettingsWidget/index.jsx
Co-authored-by: Kristin Aoki <42981026+KristinAoki@users.noreply.github.com>
* Update src/editors/containers/ProblemEditor/components/EditProblemView/SettingsWidget/index.jsx
Co-authored-by: Kristin Aoki <42981026+KristinAoki@users.noreply.github.com>
* Update src/editors/containers/ProblemEditor/components/EditProblemView/index.jsx
Co-authored-by: Kristin Aoki <42981026+KristinAoki@users.noreply.github.com>
* Update src/editors/containers/ProblemEditor/components/EditProblemView/QuestionWidget/index.jsx
Co-authored-by: Kristin Aoki <42981026+KristinAoki@users.noreply.github.com>
* Update src/editors/containers/ProblemEditor/components/EditProblemView/QuestionWidget/index.jsx
Co-authored-by: Kristin Aoki <42981026+KristinAoki@users.noreply.github.com>
* Update src/editors/containers/ProblemEditor/components/EditProblemView/QuestionWidget/index.jsx
Co-authored-by: Kristin Aoki <42981026+KristinAoki@users.noreply.github.com>
* fix: html and react problems in problem editor
* chore: update snapshots
* chore: apply pr suggestions
* chore: fix test coverage
* chore: fix lint
* chore: fix tests
* chore: fix lint
Co-authored-by: Kristin Aoki <42981026+KristinAoki@users.noreply.github.com>
---
package-lock.json | 2 +-
package.json | 2 +-
src/colors.scss | 1 -
.../AnswerWidget/AnswersContainer.jsx | 9 +-
.../AnswerWidget/AnswersContainer.test.jsx | 44 +-
.../AnswersContainer.test.jsx.snap | 26 +-
.../EditProblemView/AnswerWidget/hook.test.js | 12 +
.../EditProblemView/AnswerWidget/hooks.js | 21 +-
.../EditProblemView/AnswerWidget/index.jsx | 2 +-
.../EditProblemView/AnswerWidget/index.scss | 6 +-
.../EditProblemView/QuestionWidget/index.jsx | 15 +-
.../EditProblemView/QuestionWidget/index.scss | 28 ++
.../SettingsWidget/SettingsOption.jsx | 2 +-
.../SettingsOption.test.jsx.snap | 4 +-
.../__snapshots__/index.test.jsx.snap | 334 +++++++-------
.../EditProblemView/SettingsWidget/index.jsx | 111 +++--
.../SwitchToAdvancedEditorCard.jsx | 2 +-
.../SwitchToAdvancedEditorCard.test.jsx.snap | 4 +-
.../__snapshots__/index.test.jsx.snap | 2 +
.../components/EditProblemView/index.jsx | 2 +-
src/editors/containers/ProblemEditor/hooks.js | 13 -
src/editors/data/constants/tinyMCEStyles.js | 428 +++++++++---------
src/index.scss | 1 -
23 files changed, 592 insertions(+), 479 deletions(-)
delete mode 100644 src/colors.scss
create mode 100644 src/editors/containers/ProblemEditor/components/EditProblemView/QuestionWidget/index.scss
diff --git a/package-lock.json b/package-lock.json
index 930a72c40..27075c386 100644
--- a/package-lock.json
+++ b/package-lock.json
@@ -38,7 +38,7 @@
"@edx/frontend-platform": "2.4.0",
"@edx/paragon": "^20.27.0",
"@testing-library/dom": "^8.13.0",
- "@testing-library/react": "12.1.1",
+ "@testing-library/react": "^12.1.1",
"@testing-library/user-event": "^13.5.0",
"codecov": "3.8.3",
"enzyme": "3.11.0",
diff --git a/package.json b/package.json
index bc07d0ddb..fc5f9b095 100644
--- a/package.json
+++ b/package.json
@@ -38,7 +38,7 @@
"@edx/frontend-platform": "2.4.0",
"@edx/paragon": "^20.27.0",
"@testing-library/dom": "^8.13.0",
- "@testing-library/react": "12.1.1",
+ "@testing-library/react": "^12.1.1",
"@testing-library/user-event": "^13.5.0",
"codecov": "3.8.3",
"enzyme": "3.11.0",
diff --git a/src/colors.scss b/src/colors.scss
deleted file mode 100644
index f3c642859..000000000
--- a/src/colors.scss
+++ /dev/null
@@ -1 +0,0 @@
-$black: #000;
\ No newline at end of file
diff --git a/src/editors/containers/ProblemEditor/components/EditProblemView/AnswerWidget/AnswersContainer.jsx b/src/editors/containers/ProblemEditor/components/EditProblemView/AnswerWidget/AnswersContainer.jsx
index eea060eb5..42c079a4f 100644
--- a/src/editors/containers/ProblemEditor/components/EditProblemView/AnswerWidget/AnswersContainer.jsx
+++ b/src/editors/containers/ProblemEditor/components/EditProblemView/AnswerWidget/AnswersContainer.jsx
@@ -6,7 +6,7 @@ import { Add } from '@edx/paragon/icons';
import { FormattedMessage } from '@edx/frontend-platform/i18n';
import messages from './messages';
-import { initializeAnswerContainer } from '../../../hooks';
+import { useAnswerContainer, isSingleAnswerProblem } from './hooks';
import { actions, selectors } from '../../../../../data/redux';
import { answerOptionProps } from '../../../../../data/services/cms/types';
import AnswerOption from './AnswerOption';
@@ -18,9 +18,12 @@ export const AnswersContainer = ({
addAnswer,
updateField,
}) => {
- const { hasSingleAnswer } = initializeAnswerContainer({ answers, problemType, updateField });
+ const hasSingleAnswer = isSingleAnswerProblem(problemType);
+
+ useAnswerContainer({ answers, problemType, updateField });
+
return (
-
+
{answers.map((answer) => (
({
+ FormattedMessage: ({ defaultMessage }) => ({defaultMessage}
),
+ injectIntl: (args) => args,
+ intlShape: {},
+}));
+
+jest.mock('./AnswerOption', () => () => MockAnswerOption
);
+
jest.mock('../../../../../data/redux', () => ({
actions: {
problem: {
@@ -25,10 +38,37 @@ describe('AnswersContainer', () => {
};
describe('render', () => {
test('snapshot: renders correct default', () => {
- expect(shallow()).toMatchSnapshot();
+ act(() => {
+ expect(shallow()).toMatchSnapshot();
+ });
});
test('snapshot: renders correctly with answers', () => {
- expect(shallow()).toMatchSnapshot();
+ act(() => {
+ expect(shallow(
+ ,
+ )).toMatchSnapshot();
+ });
+ });
+
+ test('with react-testing-library', async () => {
+ let container = null;
+ await act(async () => {
+ const wrapper = render(
+ ,
+ );
+ container = wrapper.container;
+ });
+
+ await waitFor(() => expect(container.querySelector('button')).toBeTruthy());
+ await new Promise(resolve => setTimeout(resolve, 500));
+
+ expect(props.updateField).toHaveBeenCalledWith(expect.objectContaining({ correctAnswerCount: 2 }));
});
});
describe('mapStateToProps', () => {
diff --git a/src/editors/containers/ProblemEditor/components/EditProblemView/AnswerWidget/__snapshots__/AnswersContainer.test.jsx.snap b/src/editors/containers/ProblemEditor/components/EditProblemView/AnswerWidget/__snapshots__/AnswersContainer.test.jsx.snap
index fef7eb828..07078350c 100644
--- a/src/editors/containers/ProblemEditor/components/EditProblemView/AnswerWidget/__snapshots__/AnswersContainer.test.jsx.snap
+++ b/src/editors/containers/ProblemEditor/components/EditProblemView/AnswerWidget/__snapshots__/AnswersContainer.test.jsx.snap
@@ -2,7 +2,7 @@
exports[`AnswersContainer render snapshot: renders correct default 1`] = `