@@ -13,7 +13,7 @@ import { IgxChipComponent } from '../../chips/chip.component';
13
13
import { wait , UIInteractions } from '../../test-utils/ui-interactions.spec' ;
14
14
import { DefaultSortingStrategy , ISortingExpression , SortingDirection } from '../../data-operations/sorting-strategy' ;
15
15
import { configureTestSuite } from '../../test-utils/configure-suite' ;
16
- import { DataParent } from '../../test-utils/sample-test-data.spec' ;
16
+ import { DataParent , SampleTestData } from '../../test-utils/sample-test-data.spec' ;
17
17
import { MultiColumnHeadersWithGroupingComponent } from '../../test-utils/grid-samples.spec' ;
18
18
import { GridSelectionFunctions , GridFunctions , GRID_SCROLL_CLASS } from '../../test-utils/grid-functions.spec' ;
19
19
import { GridSelectionMode } from '../common/enums' ;
@@ -39,7 +39,8 @@ describe('IgxGrid - GroupBy #grid', () => {
39
39
GroupByEmptyColumnFieldComponent ,
40
40
MultiColumnHeadersWithGroupingComponent ,
41
41
GridGroupByRowCustomSelectorsComponent ,
42
- GridGroupByCaseSensitiveComponent
42
+ GridGroupByCaseSensitiveComponent ,
43
+ GridGroupByTestDateTimeDataComponent
43
44
] ,
44
45
imports : [ NoopAnimationsModule , IgxGridModule ]
45
46
} ) ;
@@ -180,6 +181,145 @@ describe('IgxGrid - GroupBy #grid', () => {
180
181
[ null , fix . componentInstance . prevDay , fix . componentInstance . today , fix . componentInstance . nextDay ] ) ;
181
182
} ) ) ;
182
183
184
+ it ( 'should only account for year, month and day when grouping by \'date\' dataType column' , fakeAsync ( ( ) => {
185
+ const fix = TestBed . createComponent ( GridGroupByTestDateTimeDataComponent ) ;
186
+ fix . detectChanges ( ) ;
187
+
188
+ const grid = fix . componentInstance . grid ;
189
+ fix . detectChanges ( ) ;
190
+
191
+ grid . groupBy ( {
192
+ fieldName : 'DateField' , dir : SortingDirection . Asc , ignoreCase : false
193
+ } ) ;
194
+ fix . detectChanges ( ) ;
195
+
196
+ const groupRows = grid . groupsRowList . toArray ( ) ;
197
+ expect ( groupRows . length ) . toEqual ( 3 ) ;
198
+
199
+ const targetTestVal = new Date ( 2012 , 1 , 12 ) ;
200
+ const index = groupRows . findIndex ( gr => new Date ( gr . groupRow . value ) . getTime ( ) === targetTestVal . getTime ( ) ) ;
201
+ expect ( groupRows [ index ] . groupRow . records . length ) . toEqual ( 2 ) ;
202
+
203
+ // compare the date values in the target group which are two identical dates with different time values
204
+ const field = groupRows [ index ] . groupRow . expression . fieldName ;
205
+ const record1 = groupRows [ index ] . groupRow . records [ 0 ] ;
206
+ const record2 = groupRows [ index ] . groupRow . records [ 1 ] ;
207
+ const rec1Date = new Date ( record1 [ field ] ) ;
208
+ const rec2Date = new Date ( record2 [ field ] ) ;
209
+
210
+ // the time portions of the two records differ, so the Dates are not equal even though they are in the same group
211
+ expect ( rec1Date . getTime ( ) ) . not . toEqual ( rec2Date . getTime ( ) ) ;
212
+ // the date portions are the same, so they are in the same group, as the column type is `date`
213
+ expect ( rec1Date . getDate ( ) ) . toEqual ( rec2Date . getDate ( ) ) ;
214
+ expect ( rec1Date . getMonth ( ) ) . toEqual ( rec2Date . getMonth ( ) ) ;
215
+ expect ( rec1Date . getFullYear ( ) ) . toEqual ( rec2Date . getFullYear ( ) ) ;
216
+ } ) ) ;
217
+
218
+ it ( 'should only account for hours, minutes, seconds and ms when grouping by \'time\' dataType column' , fakeAsync ( ( ) => {
219
+ const fix = TestBed . createComponent ( GridGroupByTestDateTimeDataComponent ) ;
220
+ fix . detectChanges ( ) ;
221
+
222
+ const grid = fix . componentInstance . grid ;
223
+
224
+ grid . groupBy ( {
225
+ fieldName : 'TimeField' , dir : SortingDirection . Asc , ignoreCase : false
226
+ } ) ;
227
+ fix . detectChanges ( ) ;
228
+
229
+ const groupRows = grid . groupsRowList . toArray ( ) ;
230
+ expect ( groupRows . length ) . toEqual ( 3 ) ;
231
+
232
+ const targetTestVal = new Date ( new Date ( ) . setHours ( 3 , 20 , 0 , 1 ) ) ;
233
+ const index = groupRows . findIndex ( gr => new Date ( gr . groupRow . value ) . getHours ( ) === targetTestVal . getHours ( )
234
+ && new Date ( gr . groupRow . value ) . getMinutes ( ) === targetTestVal . getMinutes ( )
235
+ && new Date ( gr . groupRow . value ) . getSeconds ( ) === targetTestVal . getSeconds ( )
236
+ && new Date ( gr . groupRow . value ) . getMilliseconds ( ) === targetTestVal . getMilliseconds ( ) ) ;
237
+
238
+ expect ( groupRows [ index ] . groupRow . records . length ) . toEqual ( 3 ) ;
239
+
240
+ // compare the date values in the target group which are three different dates with same time values
241
+ const field = groupRows [ index ] . groupRow . expression . fieldName ;
242
+ const record1 = groupRows [ index ] . groupRow . records [ 0 ] ;
243
+ const record2 = groupRows [ index ] . groupRow . records [ 1 ] ;
244
+ const record3 = groupRows [ index ] . groupRow . records [ 2 ] ;
245
+ const rec1Date = new Date ( record1 [ field ] ) ;
246
+ const rec2Date = new Date ( record2 [ field ] ) ;
247
+ const rec3Date = new Date ( record3 [ field ] ) ;
248
+
249
+ // the date portions of the following records differ, so the Dates are not equal even though they are in the same group
250
+ expect ( rec1Date . getTime ( ) ) . not . toEqual ( rec2Date . getTime ( ) ) ;
251
+ // the below are equal by date as well
252
+ expect ( rec2Date . getTime ( ) ) . toEqual ( rec3Date . getTime ( ) ) ;
253
+ // the time portions of the not equal dates are the same, so they are in the same group, as the column type is `time`
254
+ expect ( rec1Date . getHours ( ) ) . toEqual ( rec2Date . getHours ( ) ) ;
255
+ expect ( rec1Date . getMinutes ( ) ) . toEqual ( rec2Date . getMinutes ( ) ) ;
256
+ expect ( rec1Date . getSeconds ( ) ) . toEqual ( rec2Date . getSeconds ( ) ) ;
257
+ expect ( rec1Date . getMilliseconds ( ) ) . toEqual ( rec2Date . getMilliseconds ( ) ) ;
258
+ } ) ) ;
259
+
260
+ it ( 'should account for all date values when grouping by \'dateTime\' dataType column' , fakeAsync ( ( ) => {
261
+ const fix = TestBed . createComponent ( GridGroupByTestDateTimeDataComponent ) ;
262
+ fix . detectChanges ( ) ;
263
+
264
+ const grid = fix . componentInstance . grid ;
265
+
266
+ grid . groupBy ( {
267
+ fieldName : 'DateTimeField' , dir : SortingDirection . Asc , ignoreCase : false
268
+ } ) ;
269
+ fix . detectChanges ( ) ;
270
+
271
+ // there are two identical DateTime values, so 4 groups out of 5 data records
272
+ const groupRows = grid . groupsRowList . toArray ( ) ;
273
+ expect ( groupRows . length ) . toEqual ( 4 ) ;
274
+
275
+ const targetTestVal = new Date ( new Date ( '2003-03-17' ) . setHours ( 3 , 20 , 0 , 1 ) ) ;
276
+ const index = groupRows . findIndex ( gr => new Date ( gr . groupRow . value ) . getTime ( ) === targetTestVal . getTime ( ) ) ;
277
+ expect ( groupRows [ index ] . groupRow . records . length ) . toEqual ( 2 ) ;
278
+
279
+ // compare the date values in the target group which are two identical dates - date and time portions
280
+ const field = groupRows [ index ] . groupRow . expression . fieldName ;
281
+ const record1 = groupRows [ index ] . groupRow . records [ 0 ] ;
282
+ const record2 = groupRows [ index ] . groupRow . records [ 1 ] ;
283
+ const rec1Date = new Date ( record1 [ field ] ) ;
284
+ const rec2Date = new Date ( record2 [ field ] ) ;
285
+
286
+ expect ( rec1Date . getTime ( ) ) . toEqual ( rec2Date . getTime ( ) ) ;
287
+ } ) ) ;
288
+
289
+ it ( 'should display time value in the group by row when grouped by a \'time\' column' , fakeAsync ( ( ) => {
290
+ const fix = TestBed . createComponent ( GridGroupByTestDateTimeDataComponent ) ;
291
+ fix . detectChanges ( ) ;
292
+
293
+ const grid = fix . componentInstance . grid ;
294
+
295
+ grid . groupBy ( {
296
+ fieldName : 'TimeField' , dir : SortingDirection . Asc , ignoreCase : false
297
+ } ) ;
298
+ fix . detectChanges ( ) ;
299
+
300
+ const groupRows = grid . groupsRowList . toArray ( ) ;
301
+ const expectedValue1 = groupRows [ 0 ] . nativeElement . nextElementSibling . querySelectorAll ( 'igx-grid-cell' ) [ 3 ] . textContent ;
302
+ const actualValue1 = groupRows [ 0 ] . element . nativeElement . querySelector ( '.igx-group-label__text' ) . textContent ;
303
+ expect ( expectedValue1 ) . toEqual ( actualValue1 ) ;
304
+ } ) ) ;
305
+
306
+ it ( 'should display time value in the group by row when grouped by a \'dateTime\' column' , fakeAsync ( ( ) => {
307
+ const fix = TestBed . createComponent ( GridGroupByTestDateTimeDataComponent ) ;
308
+ fix . detectChanges ( ) ;
309
+
310
+ const grid = fix . componentInstance . grid ;
311
+
312
+ grid . groupBy ( {
313
+ fieldName : 'DateTimeField' , dir : SortingDirection . Asc , ignoreCase : false
314
+ } ) ;
315
+ fix . detectChanges ( ) ;
316
+
317
+ const groupRows = grid . groupsRowList . toArray ( ) ;
318
+ const expectedValue1 = groupRows [ 0 ] . nativeElement . nextElementSibling . querySelectorAll ( 'igx-grid-cell' ) [ 4 ] . textContent ;
319
+ const actualValue1 = groupRows [ 0 ] . element . nativeElement . querySelector ( '.igx-group-label__text' ) . textContent ;
320
+ expect ( expectedValue1 ) . toEqual ( actualValue1 ) ;
321
+ } ) ) ;
322
+
183
323
it ( 'should allow grouping by multiple columns.' , fakeAsync ( ( ) => {
184
324
const fix = TestBed . createComponent ( DefaultGridComponent ) ;
185
325
fix . detectChanges ( ) ;
@@ -3816,3 +3956,27 @@ export class GridGroupByCaseSensitiveComponent {
3816
3956
}
3817
3957
] ;
3818
3958
}
3959
+
3960
+ @Component ( {
3961
+ template : `
3962
+ <igx-grid
3963
+ #grid
3964
+ [width]='width'
3965
+ [height]='height'
3966
+ [data]="datesData">
3967
+ <igx-column [field]="'ProductID'" [width]="200" [groupable]="true" dataType="number"></igx-column>
3968
+ <igx-column [field]="'ProductName'" [width]="200" [groupable]="true" dataType="string"></igx-column>
3969
+ <igx-column [field]="'DateField'" [width]="200" [groupable]="true" dataType="date"></igx-column>
3970
+ <igx-column [field]="'TimeField'" [width]="200" [groupable]="true" dataType="time"></igx-column>
3971
+ <igx-column [field]="'DateTimeField'" [width]="200" [groupable]="true" dataType="dateTime"></igx-column>
3972
+ </igx-grid>
3973
+ `
3974
+ } )
3975
+ export class GridGroupByTestDateTimeDataComponent {
3976
+ @ViewChild ( "grid" , { read : IgxGridComponent , static : true } )
3977
+ public grid : IgxGridComponent ;
3978
+
3979
+ public width = '800px' ;
3980
+ public height = null ;
3981
+ public datesData = SampleTestData . generateTestDateTimeData ( ) ;
3982
+ }
0 commit comments