Commit 298ad30a by Waqas Khalid

Merge pull request #5142 from mlkwaqas/waqas/tnl150-stop-comment--on-closed-thread

Don't allow commenting while the thread is closed
parents aa5781c1 fcf46546
...@@ -40,6 +40,32 @@ describe "DiscussionThreadView", -> ...@@ -40,6 +40,32 @@ describe "DiscussionThreadView", ->
else else
expect(view.$el.find(".load-response-button").length).toEqual(0) expect(view.$el.find(".load-response-button").length).toEqual(0)
describe "closed and open Threads", ->
checkCommentForm = (originallyClosed, mode) ->
threadData = DiscussionViewSpecHelper.makeThreadWithProps({closed: originallyClosed})
thread = new Thread(threadData)
view = new DiscussionThreadView({ model: thread, el: $("#fixture-element"), mode: mode})
renderWithContent(view, {resp_total: 1, children: [{}]})
if mode == "inline"
view.expand()
spyOn(DiscussionUtil, "updateWithUndo").andCallFake(
(model, updates, safeAjaxParams, errorMsg) ->
model.set(updates)
)
expect(view.$('.comment-form').closest('li').is(":visible")).toBe(not originallyClosed)
expect(view.$(".discussion-reply-new").is(":visible")).toBe(not originallyClosed)
view.$(".action-close").click()
expect(view.$('.comment-form').closest('li').is(":visible")).toBe(originallyClosed)
expect(view.$(".discussion-reply-new").is(":visible")).toBe(originallyClosed)
_.each(["tab", "inline"], (mode) =>
it 'Test that in #{mode} mode when a closed thread is opened the comment form is displayed', ->
checkCommentForm(true, mode)
it 'Test that in #{mode} mode when a open thread is closed the comment form is hidden', ->
checkCommentForm(false, mode)
)
describe "tab mode", -> describe "tab mode", ->
beforeEach -> beforeEach ->
@view = new DiscussionThreadView({ model: @thread, el: $("#fixture-element"), mode: "tab"}) @view = new DiscussionThreadView({ model: @thread, el: $("#fixture-element"), mode: "tab"})
......
...@@ -3,13 +3,42 @@ describe 'ThreadResponseView', -> ...@@ -3,13 +3,42 @@ describe 'ThreadResponseView', ->
DiscussionSpecHelper.setUpGlobals() DiscussionSpecHelper.setUpGlobals()
DiscussionSpecHelper.setUnderscoreFixtures() DiscussionSpecHelper.setUnderscoreFixtures()
@thread = new Thread({"thread_type": "discussion"})
@response = new Comment { @response = new Comment {
children: [{}, {}] children: [{}, {}],
thread: @thread,
} }
@view = new ThreadResponseView({model: @response, el: $("#fixture-element")}) @view = new ThreadResponseView({model: @response, el: $("#fixture-element")})
spyOn(ThreadResponseShowView.prototype, "render") spyOn(ThreadResponseShowView.prototype, "render")
spyOn(ResponseCommentView.prototype, "render") spyOn(ResponseCommentView.prototype, "render")
describe 'closed and open Threads', ->
checkCommentForm = (closed) ->
thread = new Thread({"thread_type": "discussion", "closed": closed})
commentData = {
id: "dummy",
user_id: "567",
course_id: "TestOrg/TestCourse/TestRun",
body: "this is a comment",
created_at: "2013-04-03T20:08:39Z",
abuse_flaggers: [],
type: "comment",
children: [],
thread: thread,
}
comment = new Comment(commentData)
view = new ThreadResponseView({
model: comment, el: $("#fixture-element"),
})
view.render()
expect(view.$('.comment-form').closest('li').is(":visible")).toBe(not closed)
it 'hides comment form when thread is closed', ->
checkCommentForm(true)
it 'show comment form when thread is open', ->
checkCommentForm(false)
describe 'renderComments', -> describe 'renderComments', ->
it 'hides "show comments" link if collapseComments is not set', -> it 'hides "show comments" link if collapseComments is not set', ->
@view.render() @view.render()
...@@ -17,7 +46,7 @@ describe 'ThreadResponseView', -> ...@@ -17,7 +46,7 @@ describe 'ThreadResponseView', ->
expect(@view.$(".action-show-comments")).not.toBeVisible() expect(@view.$(".action-show-comments")).not.toBeVisible()
it 'hides "show comments" link if collapseComments is set but response has no comments', -> it 'hides "show comments" link if collapseComments is set but response has no comments', ->
@response = new Comment { children: [] } @response = new Comment { children: [], thread: @thread }
@view = new ThreadResponseView({ @view = new ThreadResponseView({
model: @response, el: $("#fixture-element"), model: @response, el: $("#fixture-element"),
collapseComments: true collapseComments: true
......
...@@ -55,6 +55,7 @@ if Backbone? ...@@ -55,6 +55,7 @@ if Backbone?
attrRenderer: $.extend({}, DiscussionContentView.prototype.attrRenderer, { attrRenderer: $.extend({}, DiscussionContentView.prototype.attrRenderer, {
closed: (closed) -> closed: (closed) ->
@$(".discussion-reply-new").toggle(not closed) @$(".discussion-reply-new").toggle(not closed)
@$('.comment-form').closest('li').toggle(not closed)
@renderAddResponseButton() @renderAddResponseButton()
}) })
......
...@@ -28,6 +28,8 @@ if Backbone? ...@@ -28,6 +28,8 @@ if Backbone?
@renderShowView() @renderShowView()
@renderAttrs() @renderAttrs()
if @model.get("thread").get("closed")
@hideCommentForm()
@renderComments() @renderComments()
@ @
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment