@@ -8,17 +8,21 @@ import { configureTestSuite } from '../../test-utils/configure-suite';
8
8
import { ColumnPinningPosition , RowPinningPosition } from '../common/enums' ;
9
9
import { IPinningConfig } from '../common/grid.interface' ;
10
10
import { SampleTestData } from '../../test-utils/sample-test-data.spec' ;
11
+ import { IgxGridTransaction } from '../tree-grid' ;
12
+ import { IgxTransactionService } from '../../services' ;
11
13
12
14
describe ( 'Row Pinning #grid' , ( ) => {
13
15
const FIXED_ROW_CONTAINER = '.igx-grid__tr--pinned ' ;
16
+ const CELL_CSS_CLASS = '.igx-grid__td' ;
14
17
configureTestSuite ( ) ;
15
18
let fix ;
16
19
let grid : IgxGridComponent ;
17
20
18
21
beforeAll ( async ( ( ) => {
19
22
TestBed . configureTestingModule ( {
20
23
declarations : [
21
- GridRowPinningComponent
24
+ GridRowPinningComponent ,
25
+ GridRowPinningWithTransactionsComponent
22
26
] ,
23
27
imports : [
24
28
NoopAnimationsModule ,
@@ -42,7 +46,7 @@ describe('Row Pinning #grid', () => {
42
46
grid . pinRow ( fix . componentInstance . data [ 1 ] ) ;
43
47
fix . detectChanges ( ) ;
44
48
45
- expect ( grid . pinnedRecords . length ) . toBe ( 1 ) ;
49
+ expect ( grid . pinnedRows . length ) . toBe ( 1 ) ;
46
50
let pinRowContainer = fix . debugElement . queryAll ( By . css ( FIXED_ROW_CONTAINER ) ) ;
47
51
expect ( pinRowContainer . length ) . toBe ( 1 ) ;
48
52
expect ( pinRowContainer [ 0 ] . children . length ) . toBe ( 1 ) ;
@@ -78,7 +82,7 @@ describe('Row Pinning #grid', () => {
78
82
grid . pinRow ( fix . componentInstance . data [ 1 ] ) ;
79
83
fix . detectChanges ( ) ;
80
84
81
- expect ( grid . pinnedRecords . length ) . toBe ( 1 ) ;
85
+ expect ( grid . pinnedRows . length ) . toBe ( 1 ) ;
82
86
let pinRowContainer = fix . debugElement . queryAll ( By . css ( FIXED_ROW_CONTAINER ) ) ;
83
87
expect ( pinRowContainer . length ) . toBe ( 1 ) ;
84
88
expect ( pinRowContainer [ 0 ] . children . length ) . toBe ( 1 ) ;
@@ -138,7 +142,7 @@ describe('Row Pinning #grid', () => {
138
142
grid . pinRow ( fix . componentInstance . data [ 1 ] ) ;
139
143
fix . detectChanges ( ) ;
140
144
141
- expect ( grid . pinnedRecords . length ) . toBe ( 1 ) ;
145
+ expect ( grid . pinnedRows . length ) . toBe ( 1 ) ;
142
146
let pinRowContainer = fix . debugElement . queryAll ( By . css ( FIXED_ROW_CONTAINER ) ) ;
143
147
expect ( pinRowContainer . length ) . toBe ( 1 ) ;
144
148
expect ( pinRowContainer [ 0 ] . children . length ) . toBe ( 1 ) ;
@@ -153,7 +157,7 @@ describe('Row Pinning #grid', () => {
153
157
grid . unpinRow ( fix . componentInstance . data [ 1 ] ) ;
154
158
fix . detectChanges ( ) ;
155
159
156
- expect ( grid . pinnedRecords . length ) . toBe ( 0 ) ;
160
+ expect ( grid . pinnedRows . length ) . toBe ( 0 ) ;
157
161
pinRowContainer = fix . debugElement . queryAll ( By . css ( FIXED_ROW_CONTAINER ) ) ;
158
162
expect ( pinRowContainer . length ) . toBe ( 0 ) ;
159
163
@@ -167,7 +171,7 @@ describe('Row Pinning #grid', () => {
167
171
row . pin ( ) ;
168
172
fix . detectChanges ( ) ;
169
173
170
- expect ( grid . pinnedRecords . length ) . toBe ( 1 ) ;
174
+ expect ( grid . pinnedRows . length ) . toBe ( 1 ) ;
171
175
let pinRowContainer = fix . debugElement . queryAll ( By . css ( FIXED_ROW_CONTAINER ) ) ;
172
176
expect ( pinRowContainer . length ) . toBe ( 1 ) ;
173
177
expect ( pinRowContainer [ 0 ] . children . length ) . toBe ( 1 ) ;
@@ -181,7 +185,7 @@ describe('Row Pinning #grid', () => {
181
185
row . unpin ( ) ;
182
186
fix . detectChanges ( ) ;
183
187
184
- expect ( grid . pinnedRecords . length ) . toBe ( 0 ) ;
188
+ expect ( grid . pinnedRows . length ) . toBe ( 0 ) ;
185
189
pinRowContainer = fix . debugElement . queryAll ( By . css ( FIXED_ROW_CONTAINER ) ) ;
186
190
expect ( pinRowContainer . length ) . toBe ( 0 ) ;
187
191
@@ -195,7 +199,7 @@ describe('Row Pinning #grid', () => {
195
199
row . pinned = true ;
196
200
fix . detectChanges ( ) ;
197
201
198
- expect ( grid . pinnedRecords . length ) . toBe ( 1 ) ;
202
+ expect ( grid . pinnedRows . length ) . toBe ( 1 ) ;
199
203
let pinRowContainer = fix . debugElement . queryAll ( By . css ( FIXED_ROW_CONTAINER ) ) ;
200
204
expect ( pinRowContainer . length ) . toBe ( 1 ) ;
201
205
expect ( pinRowContainer [ 0 ] . children . length ) . toBe ( 1 ) ;
@@ -209,14 +213,93 @@ describe('Row Pinning #grid', () => {
209
213
row . pinned = false ;
210
214
fix . detectChanges ( ) ;
211
215
212
- expect ( grid . pinnedRecords . length ) . toBe ( 0 ) ;
216
+ expect ( grid . pinnedRows . length ) . toBe ( 0 ) ;
213
217
pinRowContainer = fix . debugElement . queryAll ( By . css ( FIXED_ROW_CONTAINER ) ) ;
214
218
expect ( pinRowContainer . length ) . toBe ( 0 ) ;
215
219
216
220
expect ( grid . getRowByIndex ( 0 ) . rowID ) . toBe ( fix . componentInstance . data [ 0 ] ) ;
217
221
expect ( grid . getRowByIndex ( 1 ) . rowID ) . toBe ( fix . componentInstance . data [ 1 ] ) ;
218
222
} ) ;
219
223
} ) ;
224
+
225
+ describe ( ' Editing ' , ( ) => {
226
+ beforeEach ( fakeAsync ( ( ) => {
227
+ fix = TestBed . createComponent ( GridRowPinningWithTransactionsComponent ) ;
228
+ fix . detectChanges ( ) ;
229
+ grid = fix . componentInstance . instance ;
230
+ tick ( ) ;
231
+ fix . detectChanges ( ) ;
232
+ } ) ) ;
233
+
234
+ it ( 'should allow pinning edited row.' , ( ) => {
235
+ grid . updateCell ( 'New value' , 'ANTON' , 'CompanyName' ) ;
236
+ fix . detectChanges ( ) ;
237
+ grid . pinRow ( 'ANTON' ) ;
238
+ fix . detectChanges ( ) ;
239
+
240
+ expect ( grid . pinnedRows . length ) . toBe ( 1 ) ;
241
+ const pinRowContainer = fix . debugElement . queryAll ( By . css ( FIXED_ROW_CONTAINER ) ) ;
242
+ expect ( pinRowContainer . length ) . toBe ( 1 ) ;
243
+ expect ( pinRowContainer [ 0 ] . children . length ) . toBe ( 1 ) ;
244
+ expect ( pinRowContainer [ 0 ] . children [ 0 ] . context . rowID ) . toBe ( 'ANTON' ) ;
245
+ expect ( pinRowContainer [ 0 ] . children [ 0 ] . context . rowData . CompanyName ) . toBe ( 'New value' ) ;
246
+ } ) ;
247
+
248
+ it ( 'should allow pinning deleted row.' , ( ) => {
249
+ grid . deleteRow ( 'ALFKI' ) ;
250
+ fix . detectChanges ( ) ;
251
+ grid . pinRow ( 'ALFKI' ) ;
252
+ fix . detectChanges ( ) ;
253
+
254
+ expect ( grid . pinnedRows . length ) . toBe ( 1 ) ;
255
+ const pinRowContainer = fix . debugElement . queryAll ( By . css ( FIXED_ROW_CONTAINER ) ) ;
256
+ expect ( pinRowContainer . length ) . toBe ( 1 ) ;
257
+ expect ( pinRowContainer [ 0 ] . children . length ) . toBe ( 1 ) ;
258
+ expect ( pinRowContainer [ 0 ] . children [ 0 ] . context . rowID ) . toBe ( 'ALFKI' ) ;
259
+ } ) ;
260
+
261
+ it ( 'should allow pinning added row.' , ( ) => {
262
+
263
+ grid . addRow ( { 'ID' : 'Test' , 'CompanyName' : 'Test' } ) ;
264
+ fix . detectChanges ( ) ;
265
+
266
+ grid . pinRow ( 'Test' ) ;
267
+ fix . detectChanges ( ) ;
268
+ expect ( grid . pinnedRows . length ) . toBe ( 1 ) ;
269
+ const pinRowContainer = fix . debugElement . queryAll ( By . css ( FIXED_ROW_CONTAINER ) ) ;
270
+ expect ( pinRowContainer . length ) . toBe ( 1 ) ;
271
+ expect ( pinRowContainer [ 0 ] . children . length ) . toBe ( 1 ) ;
272
+ expect ( pinRowContainer [ 0 ] . children [ 0 ] . context . rowID ) . toBe ( 'Test' ) ;
273
+ } ) ;
274
+
275
+ it ( 'should stop editing when edited row is pinned/unpinned.' , ( ) => {
276
+ grid . getColumnByName ( 'CompanyName' ) . editable = true ;
277
+ fix . detectChanges ( ) ;
278
+ let cell = grid . getCellByColumn ( 0 , 'CompanyName' ) ;
279
+ let cellDomNumber = fix . debugElement . queryAll ( By . css ( CELL_CSS_CLASS ) ) [ 1 ] ;
280
+ cellDomNumber . triggerEventHandler ( 'dblclick' , { } ) ;
281
+ fix . detectChanges ( ) ;
282
+
283
+ expect ( cell . editMode ) . toBeTruthy ( ) ;
284
+
285
+ grid . pinRow ( cell . row . rowID ) ;
286
+ fix . detectChanges ( ) ;
287
+
288
+ cell = grid . getCellByColumn ( 0 , 'CompanyName' ) ;
289
+ expect ( cell . editMode ) . toBeFalsy ( ) ;
290
+
291
+ cellDomNumber = fix . debugElement . queryAll ( By . css ( CELL_CSS_CLASS ) ) [ 1 ] ;
292
+ cellDomNumber . triggerEventHandler ( 'dblclick' , { } ) ;
293
+ fix . detectChanges ( ) ;
294
+
295
+ expect ( cell . editMode ) . toBeTruthy ( ) ;
296
+ grid . unpinRow ( cell . row . rowID ) ;
297
+ fix . detectChanges ( ) ;
298
+ cell = grid . getCellByColumn ( 0 , 'CompanyName' ) ;
299
+ expect ( cell . editMode ) . toBeFalsy ( ) ;
300
+ } ) ;
301
+
302
+ } ) ;
220
303
} ) ;
221
304
222
305
@Component ( {
@@ -237,3 +320,21 @@ export class GridRowPinningComponent {
237
320
@ViewChild ( IgxGridComponent , { read : IgxGridComponent , static : true } )
238
321
public instance : IgxGridComponent ;
239
322
}
323
+
324
+
325
+ @Component ( {
326
+ template : `
327
+ <igx-grid
328
+ [pinning]='pinningConfig'
329
+ primaryKey='ID'
330
+ [width]='"800px"'
331
+ [height]='"500px"'
332
+ [data]="data"
333
+ [autoGenerate]="true">
334
+ </igx-grid>
335
+ ` ,
336
+ providers : [ { provide : IgxGridTransaction , useClass : IgxTransactionService } ]
337
+ } )
338
+ export class GridRowPinningWithTransactionsComponent extends GridRowPinningComponent {
339
+ public data = SampleTestData . contactInfoDataFull ( ) ;
340
+ }
0 commit comments