Commit 24334ac8 authored by Nick Stenning's avatar Nick Stenning Committed by Randall Leeds

Allow toggleCollapsed to take a forced value

parent 7f32e044
......@@ -24,13 +24,24 @@ describe 'h:directives.thread', ->
controller
describe '#toggleCollapsed', ->
it 'sets the collapsed property', ->
it 'toggles whether or not the thread is collapsed', ->
controller = createController()
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)
assert.isTrue(controller.collapsed)
controller.toggleCollapsed(false)
assert.isFalse(controller.collapsed)
controller.toggleCollapsed(false)
assert.isFalse(controller.collapsed)
describe '#shouldShowReply', ->
count = null
controller = null
......@@ -53,12 +64,12 @@ describe 'h:directives.thread', ->
it 'shows the reply if the thread is collapsed and has children', ->
count.withArgs('message').returns(1)
controller.collapsed = true
controller.toggleCollapsed(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
controller.toggleCollapsed(true)
assert.isFalse(controller.shouldShowReply(count, false))
describe 'and when filtered with children', ->
......@@ -86,12 +97,12 @@ describe 'h:directives.thread', ->
it 'does not show the reply if the thread is collapsed and has children', ->
count.withArgs('message').returns(1)
controller.collapsed = true
controller.toggleCollapsed(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
controller.toggleCollapsed(true)
assert.isFalse(controller.shouldShowReply(count, false))
describe 'and when filtered with children', ->
......
......@@ -26,8 +26,11 @@ ThreadController = [
# @description
# Toggle the collapsed property.
###
this.toggleCollapsed = ->
@collapsed = not @collapsed
this.toggleCollapsed = (value) ->
@collapsed = if value?
!!value
else
not @collapsed
###*
# @ngdoc method
......@@ -160,7 +163,7 @@ thread = [
# Watch the thread-collapsed attribute.
if attrs.threadCollapsed
scope.$watch $parse(attrs.threadCollapsed), (collapsed) ->
ctrl.toggleCollapsed() if !!collapsed != ctrl.collapsed
ctrl.toggleCollapsed(collapsed)
controller: 'ThreadController'
controllerAs: 'vm'
......
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