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.
This commit is contained in:
committed by
Muhammad Faraz Maqsood
parent
154b411ad8
commit
eaee5257bd
@@ -77,6 +77,7 @@ const SettingsWidget = ({
|
||||
updateSettings={updateSettings}
|
||||
answers={answers}
|
||||
tolerance={settings.tolerance}
|
||||
correctAnswerCount={correctAnswerCount}
|
||||
/>
|
||||
</div>
|
||||
)}
|
||||
|
||||
@@ -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 (
|
||||
<SettingsOption
|
||||
title={intl.formatMessage(messages.toleranceSettingTitle)}
|
||||
@@ -70,6 +78,16 @@ const ToleranceCard = ({
|
||||
<FormattedMessage {...messages.toleranceAnswerRangeWarning} />
|
||||
</Alert>
|
||||
)}
|
||||
{
|
||||
hasMultipleCorrectAnswers
|
||||
&& (
|
||||
<Alert
|
||||
variant="info"
|
||||
>
|
||||
<FormattedMessage {...messages.toleranceMultipleAnswersWarning} />
|
||||
</Alert>
|
||||
)
|
||||
}
|
||||
<div className="mb-3">
|
||||
<span>
|
||||
<FormattedMessage {...messages.toleranceSettingText} />
|
||||
@@ -79,7 +97,7 @@ const ToleranceCard = ({
|
||||
<Form.Control
|
||||
as="select"
|
||||
onChange={handleToleranceTypeChange({ updateSettings, tolerance, answers })}
|
||||
disabled={isAnswerRange}
|
||||
disabled={isAnswerRange || hasMultipleCorrectAnswers}
|
||||
value={tolerance.type}
|
||||
>
|
||||
{Object.keys(ToleranceTypes).map((toleranceType) => (
|
||||
@@ -91,7 +109,7 @@ const ToleranceCard = ({
|
||||
</option>
|
||||
))}
|
||||
</Form.Control>
|
||||
{ tolerance?.type !== ToleranceTypes.none.type && !isAnswerRange
|
||||
{ tolerance?.type !== ToleranceTypes.none.type && (!isAnswerRange || !hasMultipleCorrectAnswers)
|
||||
&& (
|
||||
<Form.Control
|
||||
className="mt-4"
|
||||
@@ -114,6 +132,7 @@ ToleranceCard.propTypes = {
|
||||
type: PropTypes.string,
|
||||
value: PropTypes.oneOfType([PropTypes.number, PropTypes.any]),
|
||||
}).isRequired,
|
||||
correctAnswerCount: PropTypes.number.isRequired,
|
||||
answers: PropTypes.arrayOf(PropTypes.shape({
|
||||
correct: PropTypes.bool,
|
||||
id: PropTypes.string,
|
||||
|
||||
@@ -110,6 +110,40 @@ describe('ToleranceCard', () => {
|
||||
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(<ToleranceCard
|
||||
tolerance={mockToleranceNumber}
|
||||
correctAnswerCount={2}
|
||||
{...rangeprops}
|
||||
/>);
|
||||
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 () => {
|
||||
|
||||
@@ -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',
|
||||
|
||||
Reference in New Issue
Block a user