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`] = `