Commit c88a017d by Waqas Khalid

Merge pull request #5244 from mlkwaqas/waqas/tnl152-stop-voting-on-closed-thread

Don't allow voting while the thread is closed
parents 6821fd40 1efa1b31
......@@ -470,12 +470,15 @@ browser and pasting the output. When that file changes, this one should be rege
<script type="text/template" id="forum-action-vote">
<li class="actions-item">
<span aria-hidden="true" class="display-vote" style="display: none;">
<span class="vote-count"></span>
</span>
<a href="#" class="action-button action-vote" role="checkbox" aria-checked="false">
<span class="sr">Vote</span>
<span class="sr js-sr-vote-count"></span>
<span class="action-label" aria-hidden="true">
<span class="js-visual-vote-count"></span>
<span class="vote-count"></span>
</span>
<span class="action-icon" aria-hidden="true">
......
......@@ -43,7 +43,8 @@ describe "DiscussionThreadView", ->
expect(view.$el.find(".load-response-button").length).toEqual(0)
describe "closed and open Threads", ->
checkCommentForm = (originallyClosed, mode) ->
createDiscussionThreadView = (originallyClosed, mode) ->
threadData = DiscussionViewSpecHelper.makeThreadWithProps({closed: originallyClosed})
thread = new Thread(threadData)
discussion = new Discussion(thread)
......@@ -60,18 +61,36 @@ describe "DiscussionThreadView", ->
(model, updates, safeAjaxParams, errorMsg) ->
model.set(updates)
)
view
checkCommentForm = (originallyClosed, mode) ->
view = createDiscussionThreadView(originallyClosed, mode)
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)
checkVoteDisplay = (originallyClosed, mode) ->
view = createDiscussionThreadView(originallyClosed, mode)
expect(view.$('.action-vote').is(":visible")).toBe(not originallyClosed)
expect(view.$('.display-vote').is(":visible")).toBe(originallyClosed)
view.$(".action-close").click()
expect(view.$('.action-vote').is(":visible")).toBe(originallyClosed)
expect(view.$('.display-vote').is(":visible")).toBe(not 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)
it 'Test that in #{mode} mode when a closed thread is opened the vote button is displayed and vote count is hidden', ->
checkVoteDisplay(true, mode)
it 'Test that in #{mode} mode when a open thread is closed the vote button is hidden and vote count is displayed', ->
checkVoteDisplay(false, mode)
)
describe "tab mode", ->
......
......@@ -21,7 +21,7 @@ class @DiscussionViewSpecHelper
button = view.$el.find(".action-vote")
expect(button.hasClass("is-checked")).toBe(user.voted(model))
expect(button.attr("aria-checked")).toEqual(user.voted(model).toString())
expect(button.find(".js-visual-vote-count").text()).toMatch("^#{model.get('votes').up_count} Votes?$")
expect(button.find(".vote-count").text()).toMatch("^#{model.get('votes').up_count} Votes?$")
expect(button.find(".sr.js-sr-vote-count").text()).toMatch("^currently #{model.get('votes').up_count} votes?$")
@checkRenderVote = (view, model) ->
......
......@@ -118,13 +118,13 @@ if Backbone?
true
)
)
button.find(".js-visual-vote-count").html(
interpolate(
ngettext("%(numVotes)s Vote", "%(numVotes)s Votes", numVotes),
{numVotes: numVotes},
true
)
)
votesHtml = interpolate(
ngettext("%(numVotes)s Vote", "%(numVotes)s Votes", numVotes),
{numVotes: numVotes},
true
)
button.find(".vote-count").html(votesHtml)
@$el.find('.display-vote .vote-count').html(votesHtml)
pinned: (pinned) ->
@updateButtonState(".action-pin", pinned)
......
......@@ -77,6 +77,9 @@ if Backbone?
closed: (closed) ->
@$(".discussion-reply-new").toggle(not closed)
@$('.comment-form').closest('li').toggle(not closed)
@$(".action-vote").toggle(not closed)
@$(".display-vote").toggle(closed)
# @$(".display-vote").toggle(closed)
@renderAddResponseButton()
})
......@@ -309,6 +312,7 @@ if Backbone?
closeEditView: (event) =>
@createShowView()
@renderShowView()
@renderAttrs()
# next call is necessary to re-render the post action controls after
# submitting or cancelling a thread edit in inline mode.
@$el.find(".post-extended-content").show()
......
......@@ -518,13 +518,16 @@ ${primaryAction("follow", "star", _("Follow"), _("Follow"), _("Unfollow"))}
<script type="text/template" id="forum-action-vote">
<li class="actions-item">
<span aria-hidden="true" class="display-vote" >
<span class="vote-count"></span>
</span>
<a href="#" class="action-button action-vote" role="checkbox" aria-checked="false">
## Vote counts are populated by JS
<span class="sr">${_("Vote")}</span>
<span class="sr js-sr-vote-count"></span>
<span class="action-label" aria-hidden="true">
<span class="js-visual-vote-count"></span>
<span class="vote-count"></span>
</span>
<span class="action-icon" aria-hidden="true">
......
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