fix: check for if an answer changes to false (#250)
This commit is contained in:
@@ -206,12 +206,19 @@ export const typeRowHooks = ({
|
||||
updateField,
|
||||
updateAnswer,
|
||||
}) => {
|
||||
const clearPreviouslySelectedAnswers = () => {
|
||||
answers.forEach(answer => {
|
||||
if (answer.correct) {
|
||||
updateAnswer({ ...answer, correct: false });
|
||||
}
|
||||
});
|
||||
};
|
||||
const onClick = () => {
|
||||
// Dropdown problems can only have one correct answer. When there is more than one correct answer
|
||||
// from a previous problem type, the correct attribute for selected answers need to be set to false.
|
||||
if (typeKey === ProblemTypeKeys.DROPDOWN) {
|
||||
if (correctAnswerCount > 1) {
|
||||
answers.forEach(answer => {
|
||||
updateAnswer({ ...answer, correct: false });
|
||||
});
|
||||
clearPreviouslySelectedAnswers();
|
||||
}
|
||||
}
|
||||
if (blockTitle === ProblemTypes[problemType].title) {
|
||||
|
||||
@@ -263,6 +263,10 @@ describe('Problem settings hooks', () => {
|
||||
{
|
||||
correct: true,
|
||||
id: 'b',
|
||||
},
|
||||
{
|
||||
correct: false,
|
||||
id: 'c',
|
||||
}];
|
||||
output = hooks.typeRowHooks({
|
||||
answers,
|
||||
@@ -278,6 +282,7 @@ describe('Problem settings hooks', () => {
|
||||
expect(setBlockTitle).toHaveBeenCalledWith('Dropdown');
|
||||
expect(updateAnswer).toHaveBeenNthCalledWith(1, { ...answers[0], correct: false });
|
||||
expect(updateAnswer).toHaveBeenNthCalledWith(2, { ...answers[1], correct: false });
|
||||
expect(updateAnswer).not.toHaveBeenNthCalledWith(3, { ...answers[2], correct: false });
|
||||
expect(updateField).toHaveBeenCalledWith({ problemType: typekey });
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user