From 9188dbdb47e2a08ebc431d04a345fe9e239c1857 Mon Sep 17 00:00:00 2001 From: attiyaishaque Date: Mon, 8 May 2017 18:43:57 +0500 Subject: [PATCH] EDUCATOR-283 Old mathjax not load in preview box. --- .../js/discussion/views/new_post_view.js | 2 +- .../test/acceptance/pages/lms/discussion.py | 4 ++-- .../tests/discussion/test_discussion.py | 23 ++++++++++++++++++- 3 files changed, 25 insertions(+), 4 deletions(-) diff --git a/common/static/common/js/discussion/views/new_post_view.js b/common/static/common/js/discussion/views/new_post_view.js index cfb851808a..87c5e58705 100644 --- a/common/static/common/js/discussion/views/new_post_view.js +++ b/common/static/common/js/discussion/views/new_post_view.js @@ -202,7 +202,7 @@ var $general; this.$('.forum-new-post-form')[0].reset(); DiscussionUtil.clearFormErrors(this.$('.post-errors')); - this.$('.wmd-preview p').html(''); + this.$('.wmd-preview').html(''); if (this.isTabMode()) { $general = this.$('.post-topic option:contains(General)'); this.topicView.setTopic($general || this.$('button.topic-title').first()); diff --git a/common/test/acceptance/pages/lms/discussion.py b/common/test/acceptance/pages/lms/discussion.py index bda38702de..dcb1d83275 100644 --- a/common/test/acceptance/pages/lms/discussion.py +++ b/common/test/acceptance/pages/lms/discussion.py @@ -718,12 +718,12 @@ class DiscussionTabHomePage(CoursePage, DiscussionPageMixin): """ self.q(css=".wmd-input").fill(new_body) - def get_new_post_preview_value(self): + def get_new_post_preview_value(self, selector=".wmd-preview > *"): """ 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 > *", "WMD preview pane has contents", timeout=10) + self.wait_for_element_visibility(selector, "WMD preview pane has contents", timeout=10) return self.q(css=".wmd-preview").html[0] def get_new_post_preview_text(self): diff --git a/common/test/acceptance/tests/discussion/test_discussion.py b/common/test/acceptance/tests/discussion/test_discussion.py index 923e563765..65096562a8 100644 --- a/common/test/acceptance/tests/discussion/test_discussion.py +++ b/common/test/acceptance/tests/discussion/test_discussion.py @@ -11,7 +11,7 @@ from pytz import UTC from flaky import flaky from common.test.acceptance.tests.discussion.helpers import BaseDiscussionTestCase -from common.test.acceptance.tests.helpers import UniqueCourseTest +from common.test.acceptance.tests.helpers import UniqueCourseTest, get_modal_alert from common.test.acceptance.pages.lms.auto_auth import AutoAuthPage from common.test.acceptance.pages.lms.courseware import CoursewarePage from common.test.acceptance.pages.lms.discussion import ( @@ -997,6 +997,27 @@ class DiscussionEditorPreviewTest(UniqueCourseTest): self.assertEqual(self.page.get_new_post_preview_text(), 'Text line 1\nText line 2') + def test_mathjax_not_rendered_after_post_cancel(self): + """ + Tests that mathjax is not rendered when we cancel the post + + When user types the mathjax expression into discussion editor, it will appear in te preview + box, and when user cancel it and again click the "Add new post" button, mathjax will not + appear in the preview box + """ + self.page.set_new_post_editor_value( + '\\begin{equation}' + '\\tau_g(\omega) = - \\frac{d}{d\omega}\phi(\omega) \hspace{2em} (1) ' + '\\end{equation}' + ) + self.assertIsNotNone(self.page.get_new_post_preview_text()) + self.page.click_element(".cancel") + alert = get_modal_alert(self.browser) + alert.accept() + self.assertIsNotNone(self.page.new_post_button) + self.page.click_new_post_button() + self.assertEqual(self.page.get_new_post_preview_value('.wmd-preview'), "") + @attr(shard=2) class InlineDiscussionTest(UniqueCourseTest, DiscussionResponsePaginationTestMixin):