Skip to content
Closed
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 @@ -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);
}
Expand All @@ -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) {
Copy link
Copy Markdown
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 @@ -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,
});
});
});
});

Expand Down
Loading