@@ -213,26 +213,26 @@ describe('treeControl', function() {
213213 expect ( element . find ( 'li:eq(1) div.tree-selected' ) . length ) . toBe ( 1 ) ;
214214 } ) ;
215215
216- it ( 'should invoke on-selection callback when item is selected' , function ( ) {
216+ it ( 'should invoke on-selection callback when item is selected and selected==true ' , function ( ) {
217217 $rootScope . treedata = createSubTree ( 2 , 2 ) ;
218- element = $compile ( '<treecontrol tree-model="treedata" on-selection="itemSelected(node.label)">{{node.label}}</treecontrol>' ) ( $rootScope ) ;
218+ element = $compile ( '<treecontrol tree-model="treedata" on-selection="itemSelected(node.label, selected )">{{node.label}}</treecontrol>' ) ( $rootScope ) ;
219219 $rootScope . $digest ( ) ;
220220
221221 $rootScope . itemSelected = jasmine . createSpy ( 'itemSelected' ) ;
222222 element . find ( 'li:eq(0) div' ) . click ( ) ;
223- expect ( $rootScope . itemSelected ) . toHaveBeenCalledWith ( 'node 1' ) ;
223+ expect ( $rootScope . itemSelected ) . toHaveBeenCalledWith ( $rootScope . treedata [ 0 ] . label , true ) ;
224224 } ) ;
225225
226- it ( 'should call on-selection callback on item unselection with undefined node' , function ( ) {
226+ it ( 'should call on-selection callback on item unselection with the node and selected==false ' , function ( ) {
227227 $rootScope . treedata = createSubTree ( 2 , 2 ) ;
228- element = $compile ( '<treecontrol tree-model="treedata" on-selection="itemSelected(node)">{{node.label}}</treecontrol>' ) ( $rootScope ) ;
228+ element = $compile ( '<treecontrol tree-model="treedata" on-selection="itemSelected(node.label, selected )">{{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 ( $rootScope . treedata [ 0 ] ) ;
235- expect ( $rootScope . itemSelected ) . toHaveBeenCalledWith ( undefined ) ;
234+ expect ( $rootScope . itemSelected ) . toHaveBeenCalledWith ( $rootScope . treedata [ 0 ] . label , true ) ;
235+ expect ( $rootScope . itemSelected ) . toHaveBeenCalledWith ( $rootScope . treedata [ 0 ] . label , false ) ;
236236 expect ( $rootScope . itemSelected . calls . length ) . toBe ( 2 ) ;
237237 } ) ;
238238
@@ -287,52 +287,57 @@ describe('treeControl', function() {
287287 expect ( element . find ( 'li:eq(1) li:eq(0) div.tree-selected' ) . length ) . toBe ( 1 ) ;
288288 } ) ;
289289
290- it ( 'should invoke on-selection callback when item is selected' , function ( ) {
290+ it ( 'should invoke on-selection callback when item is selected and selected==true ' , function ( ) {
291291 $rootScope . treeOptions = { multiSelection : true } ;
292292 $rootScope . treedata = createSubTree ( 2 , 2 ) ;
293- element = $compile ( '<treecontrol tree-model="treedata" on-selection="itemSelected(node.label)" options="treeOptions">{{node.label}}</treecontrol>' ) ( $rootScope ) ;
293+ element = $compile ( '<treecontrol tree-model="treedata" on-selection="itemSelected(node.label, selected )" options="treeOptions">{{node.label}}</treecontrol>' ) ( $rootScope ) ;
294294 $rootScope . $digest ( ) ;
295295
296296 $rootScope . itemSelected = jasmine . createSpy ( 'itemSelected' ) ;
297297 element . find ( 'li:eq(0) div' ) . click ( ) ;
298- expect ( $rootScope . itemSelected ) . toHaveBeenCalledWith ( 'node 1' ) ;
298+ expect ( $rootScope . itemSelected ) . toHaveBeenCalledWith ( $rootScope . treedata [ 0 ] . label , true ) ;
299299 } ) ;
300300
301- xit ( 'should call on-selection callback on item unselection with undefined node' , function ( ) {
301+ it ( 'should call on-selection callback on item unselection with the node and selected==false' , function ( ) {
302+ $rootScope . treeOptions = { multiSelection : true } ;
302303 $rootScope . treedata = createSubTree ( 2 , 2 ) ;
303- element = $compile ( '<treecontrol tree-model="treedata" on-selection="itemSelected(node) ">{{node.label}}</treecontrol>' ) ( $rootScope ) ;
304+ element = $compile ( '<treecontrol tree-model="treedata" on-selection="itemSelected(node.label, selected)" options="treeOptions ">{{node.label}}</treecontrol>' ) ( $rootScope ) ;
304305 $rootScope . $digest ( ) ;
305306
306307 $rootScope . itemSelected = jasmine . createSpy ( 'itemSelected' ) ;
307308 element . find ( 'li:eq(0) div' ) . click ( ) ;
308309 element . find ( 'li:eq(0) div' ) . click ( ) ;
309- expect ( $rootScope . itemSelected ) . toHaveBeenCalledWith ( $rootScope . treedata [ 0 ] ) ;
310- expect ( $rootScope . itemSelected ) . toHaveBeenCalledWith ( undefined ) ;
310+ expect ( $rootScope . itemSelected ) . toHaveBeenCalledWith ( $rootScope . treedata [ 0 ] . label , true ) ;
311+ expect ( $rootScope . itemSelected ) . toHaveBeenCalledWith ( $rootScope . treedata [ 0 ] . label , false ) ;
311312 expect ( $rootScope . itemSelected . calls . length ) . toBe ( 2 ) ;
312313 } ) ;
313314
314- xit ( 'should un-select a node after second click' , function ( ) {
315+ it ( 'should un-select a node after second click' , function ( ) {
316+ $rootScope . treeOptions = { multiSelection : true } ;
315317 $rootScope . treedata = createSubTree ( 2 , 2 ) ;
316- $rootScope . selectedItem = $rootScope . treedata [ 0 ] ;
317- element = $compile ( '<treecontrol tree-model="treedata" selected-node="selectedItem ">{{node.label}}</treecontrol>' ) ( $rootScope ) ;
318+ $rootScope . selectedItems = [ $rootScope . treedata [ 0 ] ] ;
319+ element = $compile ( '<treecontrol tree-model="treedata" selected-nodes="selectedItems" options="treeOptions ">{{node.label}}</treecontrol>' ) ( $rootScope ) ;
318320 $rootScope . $digest ( ) ;
319321
320322 element . find ( 'li:eq(0) div' ) . click ( ) ;
321- expect ( $rootScope . selectedItem ) . toBeUndefined ( )
323+ expect ( $rootScope . selectedItems . length ) . toBe ( 0 ) ;
322324 } ) ;
323325
324- xit ( 'should retain selection after full model refresh' , function ( ) {
326+ it ( 'should retain selection after full model refresh' , function ( ) {
327+ $rootScope . treeOptions = { multiSelection : true } ;
325328 var testTree = createSubTree ( 2 , 2 ) ;
326329 $rootScope . treedata = angular . copy ( testTree ) ;
327- element = $compile ( '<treecontrol tree-model="treedata">{{node.label}}</treecontrol>' ) ( $rootScope ) ;
330+ element = $compile ( '<treecontrol tree-model="treedata" options="treeOptions" >{{node.label}}</treecontrol>' ) ( $rootScope ) ;
328331 $rootScope . $digest ( ) ;
329332
330333 element . find ( 'li:eq(0) div' ) . click ( ) ;
331- expect ( element . find ( '.tree-selected' ) . length ) . toBe ( 1 ) ;
334+ element . find ( 'li:eq(1) .tree-branch-head' ) . click ( ) ;
335+ element . find ( 'li:eq(1) li:eq(0) div' ) . click ( ) ;
336+ expect ( element . find ( '.tree-selected' ) . length ) . toBe ( 2 ) ;
332337
333338 $rootScope . treedata = angular . copy ( testTree ) ;
334339 $rootScope . $digest ( ) ;
335- expect ( element . find ( '.tree-selected' ) . length ) . toBe ( 1 ) ;
340+ expect ( element . find ( '.tree-selected' ) . length ) . toBe ( 2 ) ;
336341 } ) ;
337342 } ) ;
338343
0 commit comments