diff --git a/common/static/common/js/discussion/views/discussion_inline_view.js b/common/static/common/js/discussion/views/discussion_inline_view.js index 276c82cbee..7e731eaa3e 100644 --- a/common/static/common/js/discussion/views/discussion_inline_view.js +++ b/common/static/common/js/discussion/views/discussion_inline_view.js @@ -121,7 +121,7 @@ this.newPostView.render(); - this.listenTo(this.newPostView, 'newPost:createPost', this.hideNewPost); + this.listenTo(this.newPostView, 'newPost:createPost', this.onNewPostCreated); this.listenTo(this.newPostView, 'newPost:cancel', this.hideNewPost); this.discussion.on('add', this.addThread); @@ -214,6 +214,11 @@ this.showed = true; }, + onNewPostCreated: function() { + this.navigateToAllPosts(); + this.hideNewPost(); + }, + hideNewPost: function() { this.$('section.discussion').find('.inline-discussion-thread-container').removeClass('is-hidden'); this.$('section.discussion').find('.add_post_btn_container') 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 d7c375d48f..0ade9f0e5c 100644 --- a/common/static/common/js/discussion/views/new_post_view.js +++ b/common/static/common/js/discussion/views/new_post_view.js @@ -1,4 +1,4 @@ -/* globals DiscussionTopicMenuView, DiscussionUtil, Thread */ +/* globals _, Backbone, DiscussionTopicMenuView, DiscussionUtil, Thread */ (function() { 'use strict'; var __hasProp = {}.hasOwnProperty, @@ -81,14 +81,14 @@ }; NewPostView.prototype.getCohortOptions = function() { - var user_cohort_id; + var userCohortId; if (this.course_settings.get('is_cohorted') && DiscussionUtil.isPrivilegedUser()) { - user_cohort_id = $('#discussion-container').data('user-cohort-id'); + userCohortId = $('#discussion-container').data('user-cohort-id'); return _.map(this.course_settings.get('cohorts'), function(cohort) { return { value: cohort.id, text: cohort.name, - selected: cohort.id === user_cohort_id + selected: cohort.id === userCohortId }; }); } else { @@ -126,15 +126,15 @@ }; NewPostView.prototype.createPost = function(event) { - var anonymous, anonymous_to_peers, body, follow, group, thread_type, title, topicId, url, + var anonymous, anonymousToPeers, body, follow, group, threadType, title, topicId, url, self = this; event.preventDefault(); - thread_type = this.$('.post-type-input:checked').val(); + threadType = this.$('.post-type-input:checked').val(); title = this.$('.js-post-title').val(); body = this.$('.js-post-body').find('.wmd-input').val(); group = this.$('.js-group-select option:selected').attr('value'); anonymous = false || this.$('.js-anon').is(':checked'); - anonymous_to_peers = false || this.$('.js-anon-peers').is(':checked'); + anonymousToPeers = false || this.$('.js-anon-peers').is(':checked'); follow = false || this.$('.js-follow').is(':checked'); topicId = this.isTabMode() ? this.topicView.getCurrentTopicId() : this.topicId; url = DiscussionUtil.urlFor('create_thread', topicId); @@ -145,11 +145,11 @@ type: 'POST', dataType: 'json', data: { - thread_type: thread_type, + thread_type: threadType, title: title, body: body, anonymous: anonymous, - anonymous_to_peers: anonymous_to_peers, + anonymous_to_peers: anonymousToPeers, auto_subscribe: follow, group_id: group }, @@ -179,7 +179,7 @@ } } this.trigger('newPost:cancel'); - return this.resetForm(); + this.resetForm(); }; NewPostView.prototype.resetForm = function() { @@ -187,7 +187,7 @@ DiscussionUtil.clearFormErrors(this.$('.post-errors')); this.$('.wmd-preview p').html(''); if (this.isTabMode()) { - return this.topicView.setTopic(this.$('button.topic-title').first()); + this.topicView.setTopic(this.$('button.topic-title').first()); } }; diff --git a/common/static/common/js/spec/discussion/view/discussion_inline_view_spec.js b/common/static/common/js/spec/discussion/view/discussion_inline_view_spec.js index 5e7b906ef2..77aba3f7e8 100644 --- a/common/static/common/js/spec/discussion/view/discussion_inline_view_spec.js +++ b/common/static/common/js/spec/discussion/view/discussion_inline_view_spec.js @@ -120,13 +120,36 @@ expect(testView.$('.new-post-article')).toHaveClass('is-hidden'); }); - it('should be hidden when the "close" button is clicked', function() { + it('should be hidden when the "Close" button is clicked', function() { var testView = createTestView(this); showDiscussion(this, testView); testView.$('.new-post-btn').click(); testView.$('.forum-new-post-form .add-post-cancel').click(); expect(testView.$('.new-post-article')).toHaveClass('is-hidden'); }); + + it('should return to the thread listing after adding a post', function() { + var testView = createTestView(this); + showDiscussion(this, testView); + + // Navigate to an individual thread + testView.$('.forum-nav-thread-link').click(); + + // Click "Add a Post", fill in the form, and submit it + testView.$('.new-post-btn').click(); + testView.$('.js-post-title').text('Test title'); + testView.$('.wmd-input').text('Test body'); + setNextAjaxResult(this, { + hello: 'world' + }); + testView.$('.forum-new-post-form .submit').click(); + + // Verify that the list of threads is shown + expect(testView.$('.inline-threads')).not.toHaveClass('is-hidden'); + + // Verify that the individual thread is no longer shown + expect(testView.$('.group-visibility-label').length).toBe(0); + }); }); describe('thread listing', function() {