diff --git a/common/static/common/js/discussion/utils.js b/common/static/common/js/discussion/utils.js index 69ef9d5ff1..44755e98d7 100644 --- a/common/static/common/js/discussion/utils.js +++ b/common/static/common/js/discussion/utils.js @@ -384,10 +384,9 @@ } else if (RE_DISPLAYMATH.test(htmlString)) { htmlString = htmlString.replace(RE_DISPLAYMATH, function($0, $1, $2, $3) { /* - bug fix, ordering is off + corrected mathjax rendering in preview */ - processedHtmlString = processor('$$' + $2 + '$$', 'display') + processedHtmlString; - processedHtmlString = $1 + processedHtmlString; + processedHtmlString += $1 + processor('$$' + $2 + '$$', 'display'); return $3; }); } else { diff --git a/common/test/acceptance/pages/lms/discussion.py b/common/test/acceptance/pages/lms/discussion.py index 092d4e1656..e912d74b07 100644 --- a/common/test/acceptance/pages/lms/discussion.py +++ b/common/test/acceptance/pages/lms/discussion.py @@ -758,3 +758,11 @@ class DiscussionTabHomePage(CoursePage, DiscussionPageMixin): """ self.wait_for_element_visibility(".wmd-preview > *", "WMD preview pane has contents", timeout=10) return self.q(css=".wmd-preview").html[0] + + def get_new_post_preview_text(self): + """ + Get the rendered preview of the contents of the Discussions new post editor + Waits for content to appear, as the preview is triggered on debounced/delayed onchange + """ + self.wait_for_element_visibility(".wmd-preview > div", "WMD preview pane has contents", timeout=10) + return self.q(css=".wmd-preview").text[0] diff --git a/common/test/acceptance/tests/discussion/test_discussion.py b/common/test/acceptance/tests/discussion/test_discussion.py index 8a17e19dcf..ee6eca1bde 100644 --- a/common/test/acceptance/tests/discussion/test_discussion.py +++ b/common/test/acceptance/tests/discussion/test_discussion.py @@ -959,6 +959,22 @@ class DiscussionEditorPreviewTest(UniqueCourseTest): "" )) + def test_mathjax_rendering_in_order(self): + """ + Tests that mathjax is rendered in proper order. + + When user types mathjax expressions into discussion editor, it should render in the proper + order. + """ + self.page.set_new_post_editor_value( + 'Text line 1 \n' + '$$e[n]=d_1$$ \n' + 'Text line 2 \n' + '$$e[n]=d_2$$' + ) + + self.assertEqual(self.page.get_new_post_preview_text(), 'Text line 1\nText line 2') + @attr(shard=2) class InlineDiscussionTest(UniqueCourseTest, DiscussionResponsePaginationTestMixin):