From eaee5257bd3856b5e5ec072157974b7fe5a03607 Mon Sep 17 00:00:00 2001 From: Muhammad Faraz Maqsood Date: Mon, 16 Jun 2025 11:00:18 +0500 Subject: [PATCH] fix: disable tolerance for multiple answers As tolerance was being only applied to first correct answer. So, disable tolerance and do not apply it in case of multiple correct answers for Numerical input problem type according to the given documentation: https://docs.openedx.org/en/latest/educators/how-tos/course_development/exercise_tools/manage_numerical_input_problem.html#add-a-tolerance:~:text=hints%20to%20problems.-,Add%20Multiple%20Correct%20Responses%20via%20the%20Advanced%20Editor,text%20string%20as%20correct%20answers. --- .../EditProblemView/SettingsWidget/index.jsx | 1 + .../settingsComponents/Tolerance/index.jsx | 23 +++++++++++-- .../Tolerance/index.test.jsx | 34 +++++++++++++++++++ .../settingsComponents/Tolerance/messages.js | 7 +++- 4 files changed, 62 insertions(+), 3 deletions(-) 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',