@@ -223,16 +223,27 @@ describe('treeControl', function() {
223223 expect ( $rootScope . itemSelected ) . toHaveBeenCalledWith ( 'node 1' ) ;
224224 } ) ;
225225
226- it ( 'should not invoke on-selection callback when item is re-selected ' , function ( ) {
226+ it ( 'should call on-selection callback on item unselection with undefined node ' , function ( ) {
227227 $rootScope . treedata = createSubTree ( 2 , 2 ) ;
228- element = $compile ( '<treecontrol tree-model="treedata" on-selection="itemSelected(node.label )">{{node.label}}</treecontrol>' ) ( $rootScope ) ;
228+ element = $compile ( '<treecontrol tree-model="treedata" on-selection="itemSelected(node)">{{node.label}}</treecontrol>' ) ( $rootScope ) ;
229229 $rootScope . $digest ( ) ;
230230
231231 $rootScope . itemSelected = jasmine . createSpy ( 'itemSelected' ) ;
232232 element . find ( 'li:eq(0) div' ) . click ( ) ;
233233 element . find ( 'li:eq(0) div' ) . click ( ) ;
234- expect ( $rootScope . itemSelected ) . toHaveBeenCalledWith ( 'node 1' ) ;
235- expect ( $rootScope . itemSelected . calls . length ) . toBe ( 1 ) ;
234+ expect ( $rootScope . itemSelected ) . toHaveBeenCalledWith ( $rootScope . treedata [ 0 ] ) ;
235+ expect ( $rootScope . itemSelected ) . toHaveBeenCalledWith ( undefined ) ;
236+ expect ( $rootScope . itemSelected . calls . length ) . toBe ( 2 ) ;
237+ } ) ;
238+
239+ it ( 'should un-select a node after second click' , function ( ) {
240+ $rootScope . treedata = createSubTree ( 2 , 2 ) ;
241+ $rootScope . selectedItem = $rootScope . treedata [ 0 ] ;
242+ element = $compile ( '<treecontrol tree-model="treedata" selected-node="selectedItem">{{node.label}}</treecontrol>' ) ( $rootScope ) ;
243+ $rootScope . $digest ( ) ;
244+
245+ element . find ( 'li:eq(0) div' ) . click ( ) ;
246+ expect ( $rootScope . selectedItem ) . toBeUndefined ( )
236247 } ) ;
237248
238249 it ( 'should retain selection after full model refresh' , function ( ) {
0 commit comments