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', -> ...@@ -24,15 +24,22 @@ describe 'h:directives.thread', ->
controller controller
describe '#toggleCollapsed', -> describe '#toggleCollapsed', ->
it 'toggles whether or not the thread is collapsed', -> controller = null
count = null
beforeEach ->
controller = createController() 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 before = controller.collapsed
controller.toggleCollapsed() controller.toggleCollapsed()
after = controller.collapsed after = controller.collapsed
assert.equal(before, !after) assert.equal(before, !after)
it 'can accept an argument to force a particular state', -> it 'can accept an argument to force a particular state', ->
controller = createController()
controller.toggleCollapsed(true) controller.toggleCollapsed(true)
assert.isTrue(controller.collapsed) assert.isTrue(controller.collapsed)
controller.toggleCollapsed(true) controller.toggleCollapsed(true)
...@@ -42,6 +49,15 @@ describe 'h:directives.thread', -> ...@@ -42,6 +49,15 @@ describe 'h:directives.thread', ->
controller.toggleCollapsed(false) controller.toggleCollapsed(false)
assert.isFalse(controller.collapsed) 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', -> describe '#shouldShowAsReply', ->
controller = null controller = null
count = null count = null
......
...@@ -27,10 +27,16 @@ ThreadController = [ ...@@ -27,10 +27,16 @@ ThreadController = [
# thread filter, if present. # thread filter, if present.
### ###
this.toggleCollapsed = (value) -> this.toggleCollapsed = (value) ->
@collapsed = if value? newval = if value?
!!value !!value
else else
not @collapsed 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 # @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