Commit 18543c5c authored by Nick Stenning's avatar Nick Stenning

Only uncollapse threads if there are replies

It doesn't make any sense to uncollapse threads which have no replies,
so bake this into the toggleCollapsed method of the ThreadController.
parent 2d7959e4
......@@ -24,15 +24,22 @@ describe 'h:directives.thread', ->
controller
describe '#toggleCollapsed', ->
it 'toggles whether or not the thread is collapsed', ->
controller = null
count = null
beforeEach ->
controller = createController()
count = sinon.stub().returns(0)
count.withArgs('message').returns(2)
controller.counter = {count: count}
it 'toggles whether or not the thread is collapsed', ->
before = controller.collapsed
controller.toggleCollapsed()
after = controller.collapsed
assert.equal(before, !after)
it 'can accept an argument to force a particular state', ->
controller = createController()
controller.toggleCollapsed(true)
assert.isTrue(controller.collapsed)
controller.toggleCollapsed(true)
......@@ -42,6 +49,15 @@ describe 'h:directives.thread', ->
controller.toggleCollapsed(false)
assert.isFalse(controller.collapsed)
it 'does not allow uncollapsing the thread if there are no replies', ->
count.withArgs('message').returns(1)
controller.toggleCollapsed()
assert.isTrue(controller.collapsed)
controller.toggleCollapsed()
assert.isTrue(controller.collapsed)
controller.toggleCollapsed(false)
assert.isTrue(controller.collapsed)
describe '#shouldShowAsReply', ->
controller = null
count = null
......
......@@ -27,10 +27,16 @@ ThreadController = [
# thread filter, if present.
###
this.toggleCollapsed = (value) ->
@collapsed = if value?
!!value
else
not @collapsed
newval = if value?
!!value
else
not @collapsed
# We only allow uncollapsing of the thread if there are some replies to
# display.
if newval == false and this.numReplies() <= 0
return
@collapsed = newval
###*
# @ngdoc method
......
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