@@ -175,6 +175,9 @@ describe('ui.grid.expandable', function() {
175175 grid . api . registerMethodsFromObject . and . callFake ( function ( publicMethods ) {
176176 methods = publicMethods . expandable ;
177177 } ) ;
178+ grid . api . registerEventsFromObject . and . callFake ( function ( events ) {
179+ grid . api . expandable = { raise : events . expandable } ;
180+ } ) ;
178181 grid . rows = [
179182 { entity : { id : 1 , name : 'John Doe' } , isExpanded : true } ,
180183 { entity : { id : 2 , name : 'Joe Doe' } , isExpanded : false } ,
@@ -233,20 +236,64 @@ describe('ui.grid.expandable', function() {
233236 } ) ;
234237 describe ( 'expandRow' , function ( ) {
235238 beforeEach ( function ( ) {
236- grid . getRow . and . returnValue ( null ) ;
237- methods . expandRow ( grid . rows [ 1 ] . entity ) ;
239+ grid . getRow . and . callFake ( function ( rowEntity ) {
240+ return rowEntity ;
241+ } ) ;
242+
243+ grid . rows = [
244+ { isExpanded : false , grid : grid } ,
245+ { isExpanded : true , grid : grid } ,
246+ { isExpanded : true , grid : grid } ,
247+ { isExpanded : true , grid : grid } ,
248+ { isExpanded : true , grid : grid } ,
249+ { isExpanded : true , grid : grid }
250+ ] ;
238251 } ) ;
239- it ( 'should call getRow on the grid with the row entity passed in' , function ( ) {
240- expect ( grid . getRow ) . toHaveBeenCalledWith ( grid . rows [ 1 ] . entity ) ;
252+ it ( 'should do nothing when the current row is expanded' , function ( ) {
253+ methods . expandRow ( grid . rows [ 1 ] ) ;
254+
255+ expect ( grid . rows [ 1 ] . isExpanded ) . toEqual ( true ) ;
256+ } ) ;
257+ it ( 'should expand the current row if it is collapsed' , function ( ) {
258+ methods . expandRow ( grid . rows [ 0 ] ) ;
259+
260+ expect ( grid . rows [ 0 ] . isExpanded ) . toEqual ( true ) ;
261+ } ) ;
262+ it ( 'should update the value of expandAll if all rows are expanded' , function ( ) {
263+ methods . expandRow ( grid . rows [ 0 ] ) ;
264+
265+ expect ( grid . expandable . expandedAll ) . toEqual ( true ) ;
241266 } ) ;
242267 } ) ;
243268 describe ( 'collapseRow' , function ( ) {
244269 beforeEach ( function ( ) {
245- grid . getRow . and . returnValue ( null ) ;
246- methods . collapseRow ( grid . rows [ 0 ] . entity ) ;
270+ grid . getRow . and . callFake ( function ( rowEntity ) {
271+ return rowEntity ;
272+ } ) ;
273+
274+ grid . rows = [
275+ { isExpanded : false , grid : grid } ,
276+ { isExpanded : true , grid : grid } ,
277+ { isExpanded : true , grid : grid } ,
278+ { isExpanded : true , grid : grid } ,
279+ { isExpanded : true , grid : grid } ,
280+ { isExpanded : true , grid : grid }
281+ ] ;
247282 } ) ;
248- it ( 'should call getRow on the grid with the row entity passed in' , function ( ) {
249- expect ( grid . getRow ) . toHaveBeenCalledWith ( grid . rows [ 0 ] . entity ) ;
283+ it ( 'should do nothing when the current row is collapsed' , function ( ) {
284+ methods . collapseRow ( grid . rows [ 0 ] ) ;
285+
286+ expect ( grid . rows [ 0 ] . isExpanded ) . toEqual ( false ) ;
287+ } ) ;
288+ it ( 'should collapse the current row if it is expanded' , function ( ) {
289+ methods . collapseRow ( grid . rows [ 1 ] ) ;
290+
291+ expect ( grid . rows [ 1 ] . isExpanded ) . toEqual ( false ) ;
292+ } ) ;
293+ it ( 'should update the value of expandAll if one row is collapsed' , function ( ) {
294+ methods . collapseRow ( grid . rows [ 0 ] ) ;
295+
296+ expect ( grid . expandable . expandedAll ) . toEqual ( false ) ;
250297 } ) ;
251298 } ) ;
252299 describe ( 'getExpandedRows' , function ( ) {
@@ -293,7 +340,18 @@ describe('ui.grid.expandable', function() {
293340 } ) ;
294341
295342 describe ( 'getExpandedRows' , function ( ) {
343+ it ( 'should return only the rows that are expanded' , function ( ) {
344+ grid . rows = [
345+ { isExpanded : false } ,
346+ { isExpanded : true } ,
347+ { isExpanded : false } ,
348+ { isExpanded : true } ,
349+ { isExpanded : true } ,
350+ { isExpanded : true }
351+ ] ;
296352
353+ expect ( uiGridExpandableService . getExpandedRows ( grid ) . length ) . toEqual ( 4 ) ;
354+ } ) ;
297355 } ) ;
298356 } ) ;
299357} ) ;
0 commit comments