diff --git a/common/test/acceptance/pages/lms/discussion.py b/common/test/acceptance/pages/lms/discussion.py index c266395629..42e2966682 100644 --- a/common/test/acceptance/pages/lms/discussion.py +++ b/common/test/acceptance/pages/lms/discussion.py @@ -723,3 +723,17 @@ class DiscussionTabHomePage(CoursePage, DiscussionPageMixin): """ elements = self.q(css=".forum-new-post-form") return elements[0] if elements.visible and len(elements) == 1 else None + + def set_new_post_editor_value(self, new_body): + """ + Set the Discussions new post editor (wmd) with the content in new_body + """ + self.q(css=".wmd-input").fill(new_body) + + def get_new_post_preview_value(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 > *", "WMD preview pane has contents", timeout=10) + return self.q(css=".wmd-preview").html[0] diff --git a/common/test/acceptance/tests/discussion/test_discussion.py b/common/test/acceptance/tests/discussion/test_discussion.py index 84dc9111d7..1ced069189 100644 --- a/common/test/acceptance/tests/discussion/test_discussion.py +++ b/common/test/acceptance/tests/discussion/test_discussion.py @@ -837,6 +837,40 @@ class DiscussionCommentEditTest(BaseDiscussionTestCase): page.a11y_audit.check_for_accessibility_errors() +@attr(shard=2) +class DiscussionEditorPreviewTest(UniqueCourseTest): + def setUp(self): + super(DiscussionEditorPreviewTest, self).setUp() + CourseFixture(**self.course_info).install() + AutoAuthPage(self.browser, course_id=self.course_id).visit() + self.page = DiscussionTabHomePage(self.browser, self.course_id) + self.page.visit() + self.page.click_new_post_button() + + def test_text_rendering(self): + """When I type plain text into the editor, it should be rendered as plain text in the preview box""" + self.page.set_new_post_editor_value("Some plain text") + self.assertEqual(self.page.get_new_post_preview_value(), "

Some plain text

") + + def test_markdown_rendering(self): + """When I type Markdown into the editor, it should be rendered as formatted Markdown in the preview box""" + self.page.set_new_post_editor_value( + "Some markdown\n" + "\n" + "- line 1\n" + "- line 2" + ) + + self.assertEqual(self.page.get_new_post_preview_value(), ( + "

Some markdown

\n" + "\n" + "" + )) + + @attr(shard=2) class InlineDiscussionTest(UniqueCourseTest, DiscussionResponsePaginationTestMixin): """