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 9ef0d5bd63..b7eca47b23 100644 --- a/common/static/common/js/discussion/views/new_post_view.js +++ b/common/static/common/js/discussion/views/new_post_view.js @@ -186,11 +186,13 @@ }; NewPostView.prototype.resetForm = function() { + var $general; this.$('.forum-new-post-form')[0].reset(); DiscussionUtil.clearFormErrors(this.$('.post-errors')); this.$('.wmd-preview p').html(''); if (this.isTabMode()) { - this.topicView.setTopic(this.$('button.topic-title').first()); + $general = this.$('.post-topic option:contains(General)'); + this.topicView.setTopic($general || this.$('button.topic-title').first()); } }; diff --git a/common/static/common/js/spec/discussion/view/new_post_view_spec.js b/common/static/common/js/spec/discussion/view/new_post_view_spec.js index 975352becb..ea5653cf18 100644 --- a/common/static/common/js/spec/discussion/view/new_post_view_spec.js +++ b/common/static/common/js/spec/discussion/view/new_post_view_spec.js @@ -240,6 +240,66 @@ }); }); }); + describe('default topic ', function() { + beforeEach(function() { + this.course_settings = new DiscussionCourseSettings({ + allow_anonymous_to_peers: true, + allow_anonymous: true, + category_map: { + subcategories: { + 'Week 1': { + subcategories: {}, + children: [ + ['Topic-Level Student-Visible Label', 'entry'] + ], + entries: { + 'Topic-Level Student-Visible Label': { + sort_key: null, + is_cohorted: false, + id: '2b3a858d0c884eb4b272dbbe3f2ffddd' + } + } + } + }, + children: [ + ['First topic', 'entry'], + ['Week 1', 'subcategory'] + ], + entries: { + 'First topic': { + sort_key: 'First topic', + is_cohorted: false, + id: 'i4x-waqastest-waqastest-course-waqastest' + } + } + } + }); + }); + + it('should be the first topic if General is not found', function() { + var eventSpy, view; + view = new NewPostView({ + el: $('#fixture-element'), + collection: this.discussion, + course_settings: this.course_settings, + mode: 'tab' + }); + view.render(); + eventSpy = jasmine.createSpy('eventSpy'); + view.listenTo(view, 'newPost:cancel', eventSpy); + view.$('.post-errors').html("