diff --git a/src/editors/containers/ProblemEditor/components/EditProblemView/SettingsWidget/index.jsx b/src/editors/containers/ProblemEditor/components/EditProblemView/SettingsWidget/index.jsx index 763cc5151..8a1ba201e 100644 --- a/src/editors/containers/ProblemEditor/components/EditProblemView/SettingsWidget/index.jsx +++ b/src/editors/containers/ProblemEditor/components/EditProblemView/SettingsWidget/index.jsx @@ -77,6 +77,7 @@ const SettingsWidget = ({ updateSettings={updateSettings} answers={answers} tolerance={settings.tolerance} + correctAnswerCount={correctAnswerCount} /> )} diff --git a/src/editors/containers/ProblemEditor/components/EditProblemView/SettingsWidget/settingsComponents/Tolerance/index.jsx b/src/editors/containers/ProblemEditor/components/EditProblemView/SettingsWidget/settingsComponents/Tolerance/index.jsx index 96d732657..6ad6709d4 100644 --- a/src/editors/containers/ProblemEditor/components/EditProblemView/SettingsWidget/settingsComponents/Tolerance/index.jsx +++ b/src/editors/containers/ProblemEditor/components/EditProblemView/SettingsWidget/settingsComponents/Tolerance/index.jsx @@ -50,12 +50,20 @@ const ToleranceCard = ({ tolerance, answers, updateSettings, + correctAnswerCount, // inject intl, }) => { const isAnswerRange = isAnswerRangeSet({ answers }); + const hasMultipleCorrectAnswers = correctAnswerCount > 1; let summary = getSummary({ tolerance, intl }); useEffect(() => { summary = getSummary({ tolerance, intl }); }, [tolerance]); + useEffect(() => { + if (hasMultipleCorrectAnswers) { + updateSettings({ tolerance: { value: null, type: ToleranceTypes.none.type } }); + } + }, [tolerance, hasMultipleCorrectAnswers]); + return ( )} + { + hasMultipleCorrectAnswers + && ( + + + + ) + }
@@ -79,7 +97,7 @@ const ToleranceCard = ({ {Object.keys(ToleranceTypes).map((toleranceType) => ( @@ -91,7 +109,7 @@ const ToleranceCard = ({ ))} - { tolerance?.type !== ToleranceTypes.none.type && !isAnswerRange + { tolerance?.type !== ToleranceTypes.none.type && (!isAnswerRange || !hasMultipleCorrectAnswers) && ( { expect(NumberText).toBeDefined(); expect(screen.getByTestId('select').getAttributeNames().includes('disabled')).toBeTruthy(); }); + it('If there are multiple correct answers, show multiple correct answers warning message and disable dropdown.', () => { + const rangeprops = { + answers: [{ + id: 'A', + correct: true, + selectedFeedback: '', + title: 'An Answer A', + isAnswerRange: false, + unselectedFeedback: '', + }, + { + id: 'B', + correct: true, + selectedFeedback: '', + title: 'An Answer B', + isAnswerRange: false, + unselectedFeedback: '', + }, + ], + updateSettings: jest.fn(), + intl: { + formatMessage, + }, + }; + + render(); + const warningMessage = screen.getByText(messages.toleranceMultipleAnswersWarning.defaultMessage); + expect(warningMessage).toBeDefined(); + expect(screen.getByTestId('select').getAttributeNames().includes('disabled')).toBeTruthy(); + }); }); describe('Type Select', () => { it('Renders the types for selection', async () => { diff --git a/src/editors/containers/ProblemEditor/components/EditProblemView/SettingsWidget/settingsComponents/Tolerance/messages.js b/src/editors/containers/ProblemEditor/components/EditProblemView/SettingsWidget/settingsComponents/Tolerance/messages.js index 1b16c0cfb..0f929473b 100644 --- a/src/editors/containers/ProblemEditor/components/EditProblemView/SettingsWidget/settingsComponents/Tolerance/messages.js +++ b/src/editors/containers/ProblemEditor/components/EditProblemView/SettingsWidget/settingsComponents/Tolerance/messages.js @@ -24,7 +24,12 @@ const messages = defineMessages({ toleranceAnswerRangeWarning: { id: 'problemEditor.settings.tolerance.answerrangewarning', defaultMessage: 'Tolerance cannot be applied to an answer range', - description: 'a warning to users that tolerance cannot be aplied to an answer range.', + description: 'a warning to users that tolerance cannot be applied to an answer range.', + }, + toleranceMultipleAnswersWarning: { + id: 'problemEditor.settings.tolerance.toleranceMultipleAnswersWarning', + defaultMessage: 'Tolerance cannot be applied to multiple correct answers', + description: 'a warning to users that tolerance cannot be applied to multiple correct answers.', }, typesPercentage: { id: 'problemEditor.settings.tolerance.type.percent',