From 74b2b76beb39e3a8a8b81928d365288b2e51f4bc Mon Sep 17 00:00:00 2001 From: Kristin Aoki <42981026+KristinAoki@users.noreply.github.com> Date: Wed, 1 Feb 2023 15:00:03 -0500 Subject: [PATCH] fix: add check for question length for parser (#226) --- src/editors/containers/ProblemEditor/hooks.js | 48 ++++++++++--------- .../containers/ProblemEditor/hooks.test.js | 10 +++- 2 files changed, 34 insertions(+), 24 deletions(-) diff --git a/src/editors/containers/ProblemEditor/hooks.js b/src/editors/containers/ProblemEditor/hooks.js index fb063528d..499048b54 100644 --- a/src/editors/containers/ProblemEditor/hooks.js +++ b/src/editors/containers/ProblemEditor/hooks.js @@ -12,30 +12,32 @@ export const state = StrictDict({ export const parseContentForLabels = ({ editor, updateQuestion }) => { let content = editor.getContent(); - const parsedLabels = content.split(/
${nextLabel}`; - updatedContent = content.replace(parsedLabels[i + 1], nextLabel); - content = updatedContent; - } - } - }); + }); + } updateQuestion(content); }; diff --git a/src/editors/containers/ProblemEditor/hooks.test.js b/src/editors/containers/ProblemEditor/hooks.test.js index 9bac2b788..6795749c2 100644 --- a/src/editors/containers/ProblemEditor/hooks.test.js +++ b/src/editors/containers/ProblemEditor/hooks.test.js @@ -58,7 +58,7 @@ describe('Problem editor hooks', () => { }); describe('parseContentForLabels', () => { - test('it calls getContent and setContent', () => { + test('it calls getContent and updateQuestion for some content', () => { const editor = { getContent: jest.fn(() => '
some content
') };
const updateQuestion = jest.fn();
const content = 'some content
followed by more text
';
@@ -66,6 +66,14 @@ describe('Problem editor hooks', () => {
expect(editor.getContent).toHaveBeenCalled();
expect(updateQuestion).toHaveBeenCalledWith(content);
});
+ test('it calls getContent and updateQuestion for empty content', () => {
+ const editor = { getContent: jest.fn(() => '') };
+ const updateQuestion = jest.fn();
+ const content = '';
+ module.parseContentForLabels({ editor, updateQuestion });
+ expect(editor.getContent).toHaveBeenCalled();
+ expect(updateQuestion).toHaveBeenCalledWith(content);
+ });
});
describe('problemEditorConfig', () => {