Merge pull request #8179 from edx/aj/tnl2223-expand-inline-discussion-jumps-to-the-bottom-of-page

TNL-2223 Inline discussion jumps to the bottom of the page when threa…
This commit is contained in:
Awais Jibran
2015-05-27 22:50:28 +05:00
4 changed files with 61 additions and 2 deletions

View File

@@ -135,6 +135,20 @@ class MultipleThreadFixture(DiscussionContentFixture):
threads_list = {thread['id']: thread for thread in self.threads}
return {"threads": json.dumps(threads_list), "comments": '{}'}
def add_response(self, response, comments, thread):
"""
Add responses to the thread
"""
response['children'] = comments
if thread["thread_type"] == "discussion":
response_list_attr = "children"
elif response["endorsed"]:
response_list_attr = "endorsed_responses"
else:
response_list_attr = "non_endorsed_responses"
thread.setdefault(response_list_attr, []).append(response)
thread['comments_count'] += len(comments) + 1
class UserProfileViewFixture(DiscussionContentFixture):

View File

@@ -464,6 +464,13 @@ class InlineDiscussionThreadPage(DiscussionThreadPage):
def is_thread_anonymous(self):
return not self.q(css=".posted-details > .username").present
@wait_for_js
def check_if_selector_is_focused(self, selector):
"""
Check if selector is focused
"""
return self.browser.execute_script("return $('{}').is(':focus')".format(selector))
class DiscussionUserProfilePage(CoursePage):

View File

@@ -582,6 +582,7 @@ class InlineDiscussionTest(UniqueCourseTest, DiscussionResponsePaginationTestMix
def setUp(self):
super(InlineDiscussionTest, self).setUp()
self.thread_ids = []
self.discussion_id = "test_discussion_{}".format(uuid4().hex)
self.additional_discussion_id = "test_discussion_{}".format(uuid4().hex)
self.course_fix = CourseFixture(**self.course_info).add_children(
@@ -616,6 +617,38 @@ class InlineDiscussionTest(UniqueCourseTest, DiscussionResponsePaginationTestMix
self.thread_page = InlineDiscussionThreadPage(self.browser, thread_id) # pylint: disable=attribute-defined-outside-init
self.thread_page.expand()
def setup_multiple_inline_threads(self, thread_count):
"""
Set up multiple treads on the page by passing 'thread_count'
"""
threads = []
for i in range(thread_count):
thread_id = "test_thread_{}_{}".format(i, uuid4().hex)
threads.append(
Thread(id=thread_id, commentable_id=self.discussion_id),
)
self.thread_ids.append(thread_id)
thread_fixture = MultipleThreadFixture(threads)
thread_fixture.add_response(
Response(id="response1"),
[Comment(id="comment1", user_id="other"), Comment(id="comment2", user_id=self.user_id)],
threads[0]
)
thread_fixture.push()
def test_page_while_expanding_inline_discussion(self):
"""
Tests for the Inline Discussion page with multiple treads. Page should not focus 'thread-wrapper'
after loading responses.
"""
self.setup_multiple_inline_threads(thread_count=3)
self.discussion_page.expand_discussion()
thread_page = InlineDiscussionThreadPage(self.browser, self.thread_ids[0])
thread_page.expand()
# Check if 'thread-wrapper' is focused after expanding thread
self.assertFalse(thread_page.check_if_selector_is_focused(selector='.thread-wrapper'))
def test_initial_render(self):
self.assertFalse(self.discussion_page.is_discussion_expanded())