@@ -57,6 +57,77 @@ describe('IgxGrid Master Detail', () => {
57
57
expect ( firstRowIcon . innerText ) . toEqual ( EXPANDED_ICON_NAME ) ;
58
58
expect ( firstRowDetail . querySelector ( '.addressArea' ) . innerText ) . toEqual ( 'Obere Str. 57' ) ;
59
59
} ) ) ;
60
+
61
+ it ( 'Should expand and collapse a row in view by using the expand(rowID) and collapse(rowID) methods.' , ( ) => {
62
+ grid . expand ( fix . componentInstance . data [ 0 ] . ID ) ;
63
+ fix . detectChanges ( ) ;
64
+ let firstRowIcon = grid . rowList . first . element . nativeElement . querySelector ( 'igx-icon' ) ;
65
+ expect ( grid . expansionStates . size ) . toEqual ( 1 ) ;
66
+ expect ( grid . expansionStates . has ( grid . rowList . first . rowID ) ) . toBeTruthy ( ) ;
67
+ expect ( grid . rowList . toArray ( ) [ 0 ] . expanded ) . toBeTruthy ( ) ;
68
+ expect ( firstRowIcon . innerText ) . toEqual ( EXPANDED_ICON_NAME ) ;
69
+ grid . collapse ( fix . componentInstance . data [ 0 ] . ID ) ;
70
+ fix . detectChanges ( ) ;
71
+ firstRowIcon = grid . rowList . first . element . nativeElement . querySelector ( 'igx-icon' ) ;
72
+ expect ( grid . expansionStates . get ( fix . componentInstance . data [ 0 ] . ID ) ) . toBeFalsy ( ) ;
73
+ expect ( grid . rowList . toArray ( ) [ 0 ] . expanded ) . toBeFalsy ( ) ;
74
+ expect ( firstRowIcon . innerText ) . toEqual ( COLLAPSED_ICON_NAME ) ;
75
+ } ) ;
76
+
77
+ it ( 'Should expand a row out of view by using the collapse() method and update expansionStates.' , ( ) => {
78
+ const lastIndex = fix . componentInstance . data . length - 1 ;
79
+ const lastDataRecID = fix . componentInstance . data [ lastIndex ] . ID ;
80
+ grid . expand ( lastDataRecID ) ;
81
+ fix . detectChanges ( ) ;
82
+ expect ( grid . expansionStates . size ) . toEqual ( 1 ) ;
83
+ expect ( grid . expansionStates . get ( lastDataRecID ) ) . toBeTruthy ( ) ;
84
+ } ) ;
85
+
86
+ it ( 'Should collapse a row out of view by using the collapse() method and update expansionStates.' , ( ) => {
87
+ GridFunctions . setAllExpanded ( grid , fix . componentInstance . data ) ;
88
+ fix . detectChanges ( ) ;
89
+ const lastIndex = fix . componentInstance . data . length - 1 ;
90
+ const lastDataRecID = fix . componentInstance . data [ lastIndex ] . ID ;
91
+ grid . collapse ( lastDataRecID ) ;
92
+ fix . detectChanges ( ) ;
93
+ expect ( grid . expansionStates . size ) . toEqual ( fix . componentInstance . data . length ) ;
94
+ expect ( grid . expansionStates . get ( lastDataRecID ) ) . toBeFalsy ( ) ;
95
+ } ) ;
96
+
97
+ it ( 'Should toggle a row expand state by using the toggleRow(rowID) method.' , ( ) => {
98
+ grid . toggleRow ( fix . componentInstance . data [ 0 ] . ID ) ;
99
+ fix . detectChanges ( ) ;
100
+ expect ( grid . expansionStates . size ) . toEqual ( 1 ) ;
101
+ expect ( grid . expansionStates . has ( grid . rowList . first . rowID ) ) . toBeTruthy ( ) ;
102
+ expect ( grid . rowList . toArray ( ) [ 0 ] . expanded ) . toBeTruthy ( ) ;
103
+ grid . toggleRow ( fix . componentInstance . data [ 0 ] . ID ) ;
104
+ fix . detectChanges ( ) ;
105
+ expect ( grid . expansionStates . get ( fix . componentInstance . data [ 0 ] . ID ) ) . toBeFalsy ( ) ;
106
+ expect ( grid . rowList . toArray ( ) [ 0 ] . expanded ) . toBeFalsy ( ) ;
107
+ } ) ;
108
+
109
+ it ( 'Should expand all rows using the expandAll() method and the expansion state should be updated.' , ( ) => {
110
+ grid . expandAll ( ) ;
111
+ fix . detectChanges ( ) ;
112
+ expect ( grid . expansionStates . size ) . toEqual ( fix . componentInstance . data . length ) ;
113
+ grid . rowList . toArray ( ) . forEach ( row => {
114
+ expect ( row . expanded ) . toBeTruthy ( ) ;
115
+ } ) ;
116
+ } ) ;
117
+
118
+ it ( 'Should collapse all rows using the collapseAll() method and the expansion state should be updated.' , ( ) => {
119
+ GridFunctions . setAllExpanded ( grid , fix . componentInstance . data ) ;
120
+ fix . detectChanges ( ) ;
121
+ grid . rowList . toArray ( ) . forEach ( row => {
122
+ expect ( row . expanded ) . toBeTruthy ( ) ;
123
+ } ) ;
124
+ grid . collapseAll ( ) ;
125
+ fix . detectChanges ( ) ;
126
+ expect ( grid . expansionStates . size ) . toEqual ( 0 ) ;
127
+ grid . rowList . toArray ( ) . forEach ( row => {
128
+ expect ( row . expanded ) . toBeFalsy ( ) ;
129
+ } ) ;
130
+ } ) ;
60
131
} ) ;
61
132
} ) ;
62
133
0 commit comments