Skip to content

Commit 2530b01

Browse files
fix: restrict single select questions to one correct answer (#2618)
1 parent 13c51ce commit 2530b01

3 files changed

Lines changed: 4 additions & 4 deletions

File tree

src/editors/containers/ProblemEditor/components/EditProblemView/AnswerWidget/hooks.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ export const useFeedback = (answer) => {
9090
};
9191

9292
export const isSingleAnswerProblem = (problemType) => (
93-
problemType === ProblemTypeKeys.DROPDOWN
93+
problemType === ProblemTypeKeys.SINGLESELECT || problemType === ProblemTypeKeys.DROPDOWN
9494
);
9595

9696
export const useAnswerContainer = ({ answers, updateField }) => {

src/editors/containers/ProblemEditor/components/EditProblemView/AnswerWidget/hooks.test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,7 @@ describe('Answer Options Hooks', () => {
200200
});
201201
describe('isSingleAnswerProblem()', () => {
202202
test('singleSelect', () => {
203-
expect(module.isSingleAnswerProblem(ProblemTypeKeys.SINGLESELECT)).toBe(false);
203+
expect(module.isSingleAnswerProblem(ProblemTypeKeys.SINGLESELECT)).toBe(true);
204204
});
205205
test('multiSelect', () => {
206206
expect(module.isSingleAnswerProblem(ProblemTypeKeys.MULTISELECT)).toBe(false);

src/editors/containers/ProblemEditor/components/EditProblemView/SettingsWidget/hooks.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -299,9 +299,9 @@ export const typeRowHooks = ({
299299
if (typeKey === ProblemTypeKeys.TEXTINPUT && RichTextProblems.includes(problemType)) {
300300
convertToPlainText();
301301
}
302-
// Dropdown problems can only have one correct answer. When there is more than one correct answer
302+
// Dropdown and single-select problems can only have one correct answer. When there is more than one correct answer
303303
// from a previous problem type, the correct attribute for selected answers need to be set to false.
304-
if (typeKey === ProblemTypeKeys.DROPDOWN) {
304+
if (typeKey === ProblemTypeKeys.DROPDOWN || typeKey === ProblemTypeKeys.SINGLESELECT) {
305305
if (correctAnswerCount > 1) {
306306
clearPreviouslySelectedAnswers();
307307
} else if (RichTextProblems.includes(problemType)) {

0 commit comments

Comments
 (0)