Commit 848d0694 authored by Aron Carroll's avatar Aron Carroll

Move logic for toggling threads into the controller

parent 243e6c65
......@@ -29,6 +29,20 @@ ThreadController = [
this.toggleCollapsed = ->
@collapsed = not @collapsed
###*
# @ngdoc method
# @name thread.ThreadController#shouldShowReply
# @description
# Determines if the reply counter should be rendered. Requires the
# `count` directive to be passed and a boolean that indicates whether
# the thread is currently filtered.
###
this.shouldShowReply = (count, isFilterActive) ->
isCollapsedReply = (@collapsed && !@isRoot)
hasChildren = count('message') > 0
hasFilterMatch = !isFilterActive || count('message') == count('match')
!isCollapsedReply && hasChildren && hasFilterMatch
this
]
......
......@@ -17,7 +17,7 @@
</article>
<!-- Reply count -->
<div class="thread-reply" ng-show="!(vm.collapsed && !vm.isRoot) && count('message') > 0 && (!threadFilter.active() || count('message') == count('match'))">
<div class="thread-reply" ng-show="vm.shouldShowReply(count, threadFilter.active())">
<a class="reply-count small"
href=""
ng-pluralize count="count('message') - 1"
......
......@@ -23,6 +23,80 @@ describe 'h.directives.thread.ThreadController', ->
after = controller.collapsed
assert.equal(before, !after)
describe '#shouldShowReply', ->
count = null
controller = null
beforeEach ->
controller = createController()
count = sinon.stub()
describe 'when root', ->
beforeEach -> controller.isRoot = true
describe 'and when not filtered', ->
it 'shows the reply if the thread is not collapsed and has children', ->
count.withArgs('message').returns(1)
assert.isTrue(controller.shouldShowReply(count, false))
it 'does not show the reply if the thread is not collapsed and has no children', ->
count.withArgs('message').returns(0)
assert.isFalse(controller.shouldShowReply(count, false))
it 'shows the reply if the thread is collapsed and has children', ->
count.withArgs('message').returns(1)
controller.collapsed = true
assert.isTrue(controller.shouldShowReply(count, false))
it 'does not show the reply if the thread is collapsed and has no children', ->
count.withArgs('message').returns(0)
controller.collapsed = true
assert.isFalse(controller.shouldShowReply(count, false))
describe 'and when filtered with children', ->
it 'shows the reply if the thread is not collapsed', ->
count.withArgs('match').returns(1)
count.withArgs('message').returns(1)
assert.isTrue(controller.shouldShowReply(count, true))
it 'does not show the reply if the thread is not collapsed and the message count does not match the match count', ->
count.withArgs('match').returns(0)
count.withArgs('message').returns(1)
assert.isFalse(controller.shouldShowReply(count, true))
describe 'when reply', ->
beforeEach -> controller.isRoot = false
describe 'and when not filtered', ->
it 'shows the reply if the thread is not collapsed and has children', ->
count.withArgs('message').returns(1)
assert.isTrue(controller.shouldShowReply(count, false))
it 'does not show the reply if the thread is not collapsed and has no children', ->
count.withArgs('message').returns(0)
assert.isFalse(controller.shouldShowReply(count, false))
it 'does not show the reply if the thread is collapsed and has children', ->
count.withArgs('message').returns(1)
controller.collapsed = true
assert.isFalse(controller.shouldShowReply(count, false))
it 'does not show the reply if the thread is collapsed and has no children', ->
count.withArgs('message').returns(0)
controller.collapsed = true
assert.isFalse(controller.shouldShowReply(count, false))
describe 'and when filtered with children', ->
it 'shows the reply if the thread is not collapsed', ->
count.withArgs('match').returns(1)
count.withArgs('message').returns(1)
assert.isTrue(controller.shouldShowReply(count, true))
it 'does not show the reply if the thread is not collapsed and the message count does not match the match count', ->
count.withArgs('match').returns(0)
count.withArgs('message').returns(1)
assert.isFalse(controller.shouldShowReply(count, true))
describe 'h.directives.thread.thread', ->
$element = null
......
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