From 4197ebf7f40853d6793bf9b82ff94e982a8e343b Mon Sep 17 00:00:00 2001 From: alisan617 Date: Thu, 23 Feb 2017 09:59:30 -0500 Subject: [PATCH] check if general topic exists --- .../js/discussion/views/new_post_view.js | 4 +- .../discussion/view/new_post_view_spec.js | 60 +++++++++++++++++++ 2 files changed, 63 insertions(+), 1 deletion(-) 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("
  • Title can't be empty
  • "); + view.$("label[for$='post-type-question']").click(); + view.$('.js-post-title').val('Test Title'); + view.$('.js-post-body textarea').val('Test body'); + view.$('.wmd-preview p').html('Test body'); + view.$('input[name=follow]').prop('checked', false); + view.$('input[name=anonymous]').prop('checked', true); + view.$('input[name=anonymous_to_peers]').prop('checked', true); + view.$("a[data-discussion-id='2b3a858d0c884eb4b272dbbe3f2ffddd']").click(); + view.$('.cancel').click(); + expect(view.$('.post-topic option:selected').text()).toEqual('First topic'); + }); + }); it('posts to the correct URL', function() { var topicId, view; topicId = 'test_topic';