diff --git a/src/editors/containers/ProblemEditor/components/EditProblemView/hooks.js b/src/editors/containers/ProblemEditor/components/EditProblemView/hooks.js index 31134b0666..39b184edb4 100644 --- a/src/editors/containers/ProblemEditor/components/EditProblemView/hooks.js +++ b/src/editors/containers/ProblemEditor/components/EditProblemView/hooks.js @@ -110,7 +110,8 @@ export const checkForNoAnswers = ({ openSaveWarningModal, problem }) => { const hasTitle = () => { const titles = []; answers.forEach(answer => { - const title = simpleTextAreaProblems.includes(problemType) ? answer.title : answerTitles[answer.id]; + const rawVal = simpleTextAreaProblems.includes(problemType) ? answer.title : answerTitles[answer.id]; + const title = String(rawVal ?? ''); if (title?.length > 0) { titles.push(title); } @@ -125,8 +126,9 @@ export const checkForNoAnswers = ({ openSaveWarningModal, problem }) => { let correctAnswer; answers.forEach(answer => { if (answer.correct) { - const title = simpleTextAreaProblems.includes(problemType) ? answer.title : answerTitles[answer.id]; - if (title?.length > 0) { + const rawVal = simpleTextAreaProblems.includes(problemType) ? answer.title : answerTitles[answer.id]; + const title = String(rawVal ?? ''); + if (title.length > 0) { correctAnswer = true; } } diff --git a/src/editors/containers/ProblemEditor/components/EditProblemView/hooks.test.js b/src/editors/containers/ProblemEditor/components/EditProblemView/hooks.test.js index a94bdca92f..b411096f82 100644 --- a/src/editors/containers/ProblemEditor/components/EditProblemView/hooks.test.js +++ b/src/editors/containers/ProblemEditor/components/EditProblemView/hooks.test.js @@ -391,6 +391,22 @@ describe('EditProblemView hooks parseState', () => { expect(openSaveWarningModal).toHaveBeenCalled(); expect(content).toEqual(null); }); + it('should return the correct content if the user entered a number as the correct answer for a dropdown type problem', () => { + const problem = { ...problemState, answers: [{ id: 'A', title: 1234, correct: true }] }; + const content = hooks.getContent({ + isAdvancedProblemType: false, + problemState: problem, + editorRef, + assets, + lmsEndpointUrl, + openSaveWarningModal, + }); + expect(openSaveWarningModal).toHaveBeenCalled(); + expect(content).toEqual({ + olx: mockBuiltOLX, + settings: expectedSettings, + }); + }); }); });