@@ -11,7 +11,7 @@ import {
11
11
import { By } from '@angular/platform-browser' ;
12
12
import { IgxActionStripComponent } from '../../action-strip/action-strip.component' ;
13
13
import { IgxActionStripModule } from '../../action-strip/action-strip.module' ;
14
- import { UIInteractions } from '../../test-utils/ui-interactions.spec' ;
14
+ import { UIInteractions , wait } from '../../test-utils/ui-interactions.spec' ;
15
15
16
16
describe ( 'IgxGrid - Row Adding #grid' , ( ) => {
17
17
let fixture ;
@@ -111,5 +111,69 @@ describe('IgxGrid - Row Adding #grid', () => {
111
111
expect ( grid . getRowByIndex ( 1 ) . addRow ) . toBeFalse ( ) ;
112
112
} ) ;
113
113
114
+ it ( 'should navigate to added row on snackbar button click.' , async ( ) => {
115
+ const rows = grid . rowList . toArray ( ) ;
116
+ const dataCount = grid . data . length ;
117
+ rows [ 0 ] . beginAddRow ( ) ;
118
+ fixture . detectChanges ( ) ;
119
+
120
+ grid . endEdit ( true ) ;
121
+ fixture . detectChanges ( ) ;
122
+
123
+ // check row is in data
124
+ expect ( grid . data . length ) . toBe ( dataCount + 1 ) ;
125
+
126
+ const addedRec = grid . data [ grid . data . length - 1 ] ;
127
+
128
+ grid . addRowSnackbar . triggerAction ( ) ;
129
+ fixture . detectChanges ( ) ;
130
+
131
+ await wait ( 100 ) ;
132
+ fixture . detectChanges ( ) ;
133
+
134
+ // check added row is rendered and is in view
135
+ const row = grid . getRowByKey ( addedRec [ grid . primaryKey ] ) ;
136
+ expect ( row ) . not . toBeNull ( ) ;
137
+ const gridOffsets = grid . tbody . nativeElement . getBoundingClientRect ( ) ;
138
+ const rowOffsets = row . nativeElement . getBoundingClientRect ( ) ;
139
+ expect ( rowOffsets . top >= gridOffsets . top && rowOffsets . bottom <= gridOffsets . bottom ) . toBeTruthy ( ) ;
140
+ } ) ;
141
+
142
+ it ( 'should navigate to added row on snackbar button click when row is not in current view.' , async ( ) => {
143
+ grid . paging = true ;
144
+ grid . perPage = 5 ;
145
+ fixture . detectChanges ( ) ;
146
+
147
+ const rows = grid . rowList . toArray ( ) ;
148
+ const dataCount = grid . data . length ;
149
+
150
+ rows [ 0 ] . beginAddRow ( ) ;
151
+ fixture . detectChanges ( ) ;
152
+
153
+ grid . endEdit ( true ) ;
154
+ fixture . detectChanges ( ) ;
155
+
156
+ // check row is in data
157
+ expect ( grid . data . length ) . toBe ( dataCount + 1 ) ;
158
+
159
+ const addedRec = grid . data [ grid . data . length - 1 ] ;
160
+
161
+ grid . addRowSnackbar . triggerAction ( ) ;
162
+ fixture . detectChanges ( ) ;
163
+
164
+ await wait ( 100 ) ;
165
+ fixture . detectChanges ( ) ;
166
+
167
+ // check page is correct
168
+ expect ( grid . page ) . toBe ( 5 ) ;
169
+
170
+ // check added row is rendered and is in view
171
+ const row = grid . getRowByKey ( addedRec [ grid . primaryKey ] ) ;
172
+ expect ( row ) . not . toBeNull ( ) ;
173
+ const gridOffsets = grid . tbody . nativeElement . getBoundingClientRect ( ) ;
174
+ const rowOffsets = row . nativeElement . getBoundingClientRect ( ) ;
175
+ expect ( rowOffsets . top >= gridOffsets . top && rowOffsets . bottom <= gridOffsets . bottom ) . toBeTruthy ( ) ;
176
+ } ) ;
177
+
114
178
} ) ;
115
179
} ) ;
0 commit comments