Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -122,8 +122,8 @@ 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 title = simpleTextAreaProblems.includes(problemType) ? answer.title.toString() : answerTitles[answer.id];
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This fixes the problem, but it seems like the real problem is that answer.title is a number in the first place. Shouldn't we try to prevent title from being set to a non-string value in the first place, rather than fixing it here?

I think the root problem might be on this line where the XML parser sometimes returns a number for the #text value. Could we coerce it to a string there instead?

if (title.length > 0) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are we certain that title is always going to be defined? There's no type information here so I don't really know, but it seems safer to leave it as title?.length just in case.

correctAnswer = true;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -383,6 +383,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,
});
});
});
});

Expand Down