From 1c203ffbfe8df94bb4d6d29f8c8ab9c5c4c1f46f Mon Sep 17 00:00:00 2001 From: Ihor Romaniuk Date: Fri, 28 Aug 2026 12:38:55 +0200 Subject: [PATCH] fix: leave new dropdown answers empty instead of "undefined" Adding a dropdown problem in Studio filled all three answers with the word "undefined" instead of leaving them empty behind their "Enter an answer" placeholder, so an author had to clear each field before typing. The blank template writes empty option tags, and the parser turned a missing text node into a string with String(). Single select and multi-select escape it because they are rich text and their titles are rebuilt right after; dropdown answers are plain text, so the string survived into the field. --- src/editors/containers/ProblemEditor/data/OLXParser.js | 4 ++-- .../containers/ProblemEditor/data/OLXParser.test.js | 8 ++++++++ 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/src/editors/containers/ProblemEditor/data/OLXParser.js b/src/editors/containers/ProblemEditor/data/OLXParser.js index 43817b91d9..46a578812d 100644 --- a/src/editors/containers/ProblemEditor/data/OLXParser.js +++ b/src/editors/containers/ProblemEditor/data/OLXParser.js @@ -261,7 +261,7 @@ export class OLXParser { const preservedFeedback = preservedAnswers[index].filter(answer => Object.keys(answer).includes(`${option}hint`) ); - let title = String(element['#text']); + let title = String(element['#text'] ?? ''); if (isComplexAnswer && preservedAnswer) { title = this.richTextBuilder.build(preservedAnswer); @@ -281,7 +281,7 @@ export class OLXParser { } else { const preservedAnswer = preservedAnswers[0].filter(answer => !Object.keys(answer).includes(`${option}hint`)); const preservedFeedback = preservedAnswers[0].filter(answer => Object.keys(answer).includes(`${option}hint`)); - let title = String(choice['#text']); + let title = String(choice['#text'] ?? ''); if (isComplexAnswer && preservedAnswer) { title = this.richTextBuilder.build(preservedAnswer); diff --git a/src/editors/containers/ProblemEditor/data/OLXParser.test.js b/src/editors/containers/ProblemEditor/data/OLXParser.test.js index fceb9de2c4..993c66b77a 100644 --- a/src/editors/containers/ProblemEditor/data/OLXParser.test.js +++ b/src/editors/containers/ProblemEditor/data/OLXParser.test.js @@ -1,3 +1,4 @@ +import dropdownTemplate from '@src/editors/data/constants/basicProblemTemplates/dropdown'; import { OLXParser } from './OLXParser'; import { checkboxesOLXWithFeedbackAndHintsOLX, @@ -134,6 +135,13 @@ describe('OLXParser', () => { expect(problemType).toEqual(ProblemTypeKeys.NUMERIC); }); }); + describe('given the blank dropdown template', () => { + const olxparser = new OLXParser(dropdownTemplate.olx); + const { answers } = olxparser.parseMultipleChoiceAnswers('optionresponse', 'optioninput', 'option'); + it('should leave every answer empty, so the editor shows its placeholder', () => { + expect(answers.map(answer => answer.title)).toEqual(['', '', '']); + }); + }); describe('given dropdown olx with feedback and hints', () => { const problemType = dropdownOlxParser.getProblemType(); it('should equal ProblemTypeKeys.DROPDOWN', () => {