From 3e407b9d7f1c18ed85d570a17d45a2cb1fcb179e Mon Sep 17 00:00:00 2001 From: Eric Fischer Date: Tue, 25 Aug 2015 10:53:34 -0400 Subject: [PATCH 1/2] Revert "Fix for flaky TeamDiscussionView js tests" This reverts commit d64c2b299f5f847272483ddd5ffb845d66d3b2bf. --- .../js/spec/views/team_discussion_spec.js | 300 +++++++----------- 1 file changed, 115 insertions(+), 185 deletions(-) diff --git a/lms/djangoapps/teams/static/teams/js/spec/views/team_discussion_spec.js b/lms/djangoapps/teams/static/teams/js/spec/views/team_discussion_spec.js index 59dc359b84..889577224b 100644 --- a/lms/djangoapps/teams/static/teams/js/spec/views/team_discussion_spec.js +++ b/lms/djangoapps/teams/static/teams/js/spec/views/team_discussion_spec.js @@ -38,109 +38,84 @@ define([ }; createPost = function(requests, view, title, body, threadID) { - runs(function() { - title = title || "Test title"; - body = body || "Test body"; - threadID = threadID || "999"; - view.$('.new-post-button').click(); - view.$('.js-post-title').val(title); - view.$('.js-post-body textarea').val(body); + title = title || "Test title"; + body = body || "Test body"; + threadID = threadID || "999"; + view.$('.new-post-button').click(); + view.$('.js-post-title').val(title); + view.$('.js-post-body textarea').val(body); + view.$('.submit').click(); + AjaxHelpers.expectRequest( + requests, 'POST', + interpolate( + '/courses/%(courseID)s/discussion/%(discussionID)s/threads/create?ajax=1', + { + courseID: TeamSpecHelpers.testCourseID, + discussionID: TeamSpecHelpers.testTeamDiscussionID + }, + true + ), + interpolate( + 'thread_type=discussion&title=%(title)s&body=%(body)s&anonymous=false&anonymous_to_peers=false&auto_subscribe=true', + { + title: title.replace(/ /g, '+'), + body: body.replace(/ /g, '+') + }, + true + ) + ); + AjaxHelpers.respondWithJson(requests, { + content: TeamSpecHelpers.createMockPostResponse({ + id: threadID, + title: title, + body: body + }), + annotated_content_info: TeamSpecHelpers.createAnnotatedContentInfo() }); - - waitsFor(function() { - return $('.submit').length; - }, "Submit button never appeared", 1000); - - runs(function() { - view.$('.submit').click(); - AjaxHelpers.expectRequest( - requests, 'POST', - interpolate( - '/courses/%(courseID)s/discussion/%(discussionID)s/threads/create?ajax=1', - { - courseID: TeamSpecHelpers.testCourseID, - discussionID: TeamSpecHelpers.testTeamDiscussionID - }, - true - ), - interpolate( - 'thread_type=discussion&title=%(title)s&body=%(body)s&anonymous=false&anonymous_to_peers=false&auto_subscribe=true', - { - title: title.replace(/ /g, '+'), - body: body.replace(/ /g, '+') - }, - true - ) - ); - AjaxHelpers.respondWithJson(requests, { - content: TeamSpecHelpers.createMockPostResponse({ - id: threadID, - title: title, - body: body - }), - annotated_content_info: TeamSpecHelpers.createAnnotatedContentInfo() - }); - }); }; expandReplies = function(requests, view, threadID) { - waitsFor(function() { - return $('.forum-thread-expand').length; - }, "Forum expando link never appeared", 1000); - - runs(function() { - view.$('.forum-thread-expand').first().click(); - AjaxHelpers.expectRequest( - requests, 'GET', - interpolate( - '/courses/%(courseID)s/discussion/forum/%(discussionID)s/threads/%(threadID)s?ajax=1&resp_skip=0&resp_limit=25', - { - courseID: TeamSpecHelpers.testCourseID, - discussionID: TeamSpecHelpers.testTeamDiscussionID, - threadID: threadID || "999" - }, - true - ) - ); - AjaxHelpers.respondWithJson(requests, { - content: TeamSpecHelpers.createMockThreadResponse(), - annotated_content_info: TeamSpecHelpers.createAnnotatedContentInfo() - }); - }); + view.$('.forum-thread-expand').first().click(); + AjaxHelpers.expectRequest( + requests, 'GET', + interpolate( + '/courses/%(courseID)s/discussion/forum/%(discussionID)s/threads/%(threadID)s?ajax=1&resp_skip=0&resp_limit=25', + { + courseID: TeamSpecHelpers.testCourseID, + discussionID: TeamSpecHelpers.testTeamDiscussionID, + threadID: threadID || "999" + }, + true + ) + ); + AjaxHelpers.respondWithJson(requests, { + content: TeamSpecHelpers.createMockThreadResponse(), + annotated_content_info: TeamSpecHelpers.createAnnotatedContentInfo() + }); }; postReply = function(requests, view, reply, threadID) { - var replyForm; - runs(function() { - replyForm = view.$('.discussion-reply-new').first(); - }); - - waitsFor(function() { - return replyForm.find('.discussion-submit-post').length; - }, "submit reply button never appeared", 1000); - - runs(function() { - replyForm.find('.reply-body textarea').val(reply); - replyForm.find('.discussion-submit-post').click(); - AjaxHelpers.expectRequest( - requests, 'POST', - interpolate( - '/courses/%(courseID)s/discussion/threads/%(threadID)s/reply?ajax=1', - { - courseID: TeamSpecHelpers.testCourseID, - threadID: threadID || "999" - }, - true - ), - 'body=' + reply.replace(/ /g, '+') - ); - AjaxHelpers.respondWithJson(requests, { - content: TeamSpecHelpers.createMockThreadResponse({ - body: reply, - comments_count: 1 - }), - "annotated_content_info": TeamSpecHelpers.createAnnotatedContentInfo() - }); + var replyForm = view.$('.discussion-reply-new').first(); + replyForm.find('.reply-body textarea').val(reply); + replyForm.find('.discussion-submit-post').click(); + AjaxHelpers.expectRequest( + requests, 'POST', + interpolate( + '/courses/%(courseID)s/discussion/threads/%(threadID)s/reply?ajax=1', + { + courseID: TeamSpecHelpers.testCourseID, + threadID: threadID || "999" + }, + true + ), + 'body=' + reply.replace(/ /g, '+') + ); + AjaxHelpers.respondWithJson(requests, { + content: TeamSpecHelpers.createMockThreadResponse({ + body: reply, + comments_count: 1 + }), + "annotated_content_info": TeamSpecHelpers.createAnnotatedContentInfo() }); }; @@ -152,26 +127,17 @@ define([ it('can create a new post', function() { var requests = AjaxHelpers.requests(this), - view, + view = createDiscussionView(requests), testTitle = 'New Post', testBody = 'New post body', newThreadElement; - runs(function() { - view = createDiscussionView(requests); - createPost(requests, view, testTitle, testBody); - }); - - waitsFor(function() { - return $('.discussion-thread').length; - }, "Discussion thread never appeared", 1000); + createPost(requests, view, testTitle, testBody); - runs(function() { - // Expect the first thread to be the new post - expect(view.$('.discussion-thread').length).toEqual(4); - newThreadElement = view.$('.discussion-thread').first(); - expect(newThreadElement.find('.post-header-content h1').text().trim()).toEqual(testTitle); - expect(newThreadElement.find('.post-body').text().trim()).toEqual(testBody); - }); + // Expect the first thread to be the new post + expect(view.$('.discussion-thread').length).toEqual(4); + newThreadElement = view.$('.discussion-thread').first(); + expect(newThreadElement.find('.post-header-content h1').text().trim()).toEqual(testTitle); + expect(newThreadElement.find('.post-body').text().trim()).toEqual(testBody); }); it('can post a reply', function() { @@ -179,95 +145,59 @@ define([ view = createDiscussionView(requests), testReply = "Test reply", testThreadID = "1"; - runs(function() { - expandReplies(requests, view, testThreadID); - postReply(requests, view, testReply, testThreadID); - }); - - waitsFor(function() { - return view.$('.discussion-response .response-body').length; - }, "Discussion response never made visible", 1000); - - runs(function() { - expect(view.$('.discussion-response .response-body').text().trim()).toBe(testReply); - }); + expandReplies(requests, view, testThreadID); + postReply(requests, view, testReply, testThreadID); + expect(view.$('.discussion-response .response-body').text().trim()).toBe(testReply); }); it('can post a reply to a new post', function() { var requests = AjaxHelpers.requests(this), view = createDiscussionView(requests, []), testReply = "Test reply"; - runs(function() { - createPost(requests, view); - expandReplies(requests, view); - postReply(requests, view, testReply); - }); - - waitsFor(function() { - return view.$('.discussion-response .response-body').length; - }, "Discussion response never made visible", 1000); - - runs(function() { - expect(view.$('.discussion-response .response-body').text().trim()).toBe(testReply); - }); + createPost(requests, view); + expandReplies(requests, view); + postReply(requests, view, testReply); + expect(view.$('.discussion-response .response-body').text().trim()).toBe(testReply); }); it('cannot move an existing thread to a different topic', function() { var requests = AjaxHelpers.requests(this), - view, + view = createDiscussionView(requests), postTopicButton, updatedThreadElement, updatedTitle = 'Updated title', updatedBody = 'Updated body', testThreadID = "1"; - runs(function() { - view = createDiscussionView(requests); - expandReplies(requests, view, testThreadID); + expandReplies(requests, view, testThreadID); + view.$('.action-more .icon').first().click(); + view.$('.action-edit').first().click(); + postTopicButton = view.$('.post-topic'); + expect(postTopicButton.length).toBe(0); + view.$('.js-post-post-title').val(updatedTitle); + view.$('.js-post-body textarea').val(updatedBody); + view.$('.submit').click(); + AjaxHelpers.expectRequest( + requests, 'POST', + interpolate( + '/courses/%(courseID)s/discussion/%(discussionID)s/threads/create?ajax=1', + { + courseID: TeamSpecHelpers.testCourseID, + discussionID: TeamSpecHelpers.testTeamDiscussionID + }, + true + ), + 'thread_type=discussion&title=&body=Updated+body&anonymous=false&anonymous_to_peers=false&auto_subscribe=true' + ); + AjaxHelpers.respondWithJson(requests, { + content: TeamSpecHelpers.createMockPostResponse({ + id: "999", title: updatedTitle, body: updatedBody + }), + annotated_content_info: TeamSpecHelpers.createAnnotatedContentInfo() }); - waitsFor(function() { - return view.$('.action-more .icon').length; - }, "Expanding replies never finished", 1000); - - runs(function() { - view.$('.action-more .icon').first().click(); - view.$('.action-edit').first().click(); - postTopicButton = view.$('.post-topic'); - expect(postTopicButton.length).toBe(0); - view.$('.js-post-post-title').val(updatedTitle); - view.$('.js-post-body textarea').val(updatedBody); - }); - - waitsFor(function() { - return $('.submit').length; - }, "submit button never appeared", 1000); - - runs(function() { - view.$('.submit').click(); - AjaxHelpers.expectRequest( - requests, 'POST', - interpolate( - '/courses/%(courseID)s/discussion/%(discussionID)s/threads/create?ajax=1', - { - courseID: TeamSpecHelpers.testCourseID, - discussionID: TeamSpecHelpers.testTeamDiscussionID - }, - true - ), - 'thread_type=discussion&title=&body=Updated+body&anonymous=false&anonymous_to_peers=false&auto_subscribe=true' - ); - AjaxHelpers.respondWithJson(requests, { - content: TeamSpecHelpers.createMockPostResponse({ - id: "999", title: updatedTitle, body: updatedBody - }), - annotated_content_info: TeamSpecHelpers.createAnnotatedContentInfo() - }); - - - // Expect the thread to have been updated - updatedThreadElement = view.$('.discussion-thread').first(); - expect(updatedThreadElement.find('.post-header-content h1').text().trim()).toEqual(updatedTitle); - expect(updatedThreadElement.find('.post-body').text().trim()).toEqual(updatedBody); - }); + // Expect the thread to have been updated + updatedThreadElement = view.$('.discussion-thread').first(); + expect(updatedThreadElement.find('.post-header-content h1').text().trim()).toEqual(updatedTitle); + expect(updatedThreadElement.find('.post-body').text().trim()).toEqual(updatedBody); }); it('cannot move a new thread to a different topic', function() { From 4d974730bf216ec9c73d368bdf7dac8cce716b9b Mon Sep 17 00:00:00 2001 From: Eric Fischer Date: Wed, 26 Aug 2015 12:16:55 -0400 Subject: [PATCH 2/2] Removing extraneous render from team_discussion.js On the advice of https://github.com/edx/edx-platform/pull/9470, the render call here is not needed and should be removed in order to allow the view's owner to determine when it needs to be rendered. This will hopefully also fix the flaky tests we've been seeing, we'll need to continue to monitor the builds to be sure. --- lms/djangoapps/teams/static/teams/js/views/team_discussion.js | 1 - 1 file changed, 1 deletion(-) diff --git a/lms/djangoapps/teams/static/teams/js/views/team_discussion.js b/lms/djangoapps/teams/static/teams/js/views/team_discussion.js index 2549f17124..0245a522bf 100644 --- a/lms/djangoapps/teams/static/teams/js/views/team_discussion.js +++ b/lms/djangoapps/teams/static/teams/js/views/team_discussion.js @@ -8,7 +8,6 @@ var TeamDiscussionView = Backbone.View.extend({ initialize: function () { window.$$course_id = this.$el.data("course-id"); - this.render(); }, render: function () {