From f6150f6398a351c1eab487b959f7644197df90f6 Mon Sep 17 00:00:00 2001 From: MKirova Date: Wed, 16 Mar 2022 12:12:46 +0200 Subject: [PATCH] chore(*): Add coverage for different pivot aggregates. --- .../grids/pivot-grid/pivot-grid-aggregate.ts | 8 ++--- .../grids/pivot-grid/pivot-grid.pipes.spec.ts | 33 ++++++++++++++++++- 2 files changed, 36 insertions(+), 5 deletions(-) diff --git a/projects/igniteui-angular/src/lib/grids/pivot-grid/pivot-grid-aggregate.ts b/projects/igniteui-angular/src/lib/grids/pivot-grid/pivot-grid-aggregate.ts index 53f6e4af14d..892ddf26882 100644 --- a/projects/igniteui-angular/src/lib/grids/pivot-grid/pivot-grid-aggregate.ts +++ b/projects/igniteui-angular/src/lib/grids/pivot-grid/pivot-grid-aggregate.ts @@ -173,7 +173,7 @@ export class IgxPivotDateAggregate extends IgxPivotAggregate { * * @memberof IgxPivotDateAggregate */ - public static latest(members: number[]) { + public static latest(members: any[]) { return IgxDateSummaryOperand.latest(members); } @@ -186,7 +186,7 @@ export class IgxPivotDateAggregate extends IgxPivotAggregate { * * @memberof IgxPivotDateAggregate */ - public static earliest(members: number[]) { + public static earliest(members: any[]) { return IgxDateSummaryOperand.earliest(members); } } @@ -225,7 +225,7 @@ export class IgxPivotTimeAggregate extends IgxPivotAggregate { * * @memberof IgxPivotTimeAggregate */ - public static latestTime(members: number[]) { + public static latestTime(members: any[]) { return IgxTimeSummaryOperand.latestTime(members); } @@ -238,7 +238,7 @@ export class IgxPivotTimeAggregate extends IgxPivotAggregate { * * @memberof IgxPivotTimeAggregate */ - public static earliestTime(members: number[]) { + public static earliestTime(members: any[]) { return IgxTimeSummaryOperand.earliestTime(members); } } diff --git a/projects/igniteui-angular/src/lib/grids/pivot-grid/pivot-grid.pipes.spec.ts b/projects/igniteui-angular/src/lib/grids/pivot-grid/pivot-grid.pipes.spec.ts index 4bf4d510960..f040db86f63 100644 --- a/projects/igniteui-angular/src/lib/grids/pivot-grid/pivot-grid.pipes.spec.ts +++ b/projects/igniteui-angular/src/lib/grids/pivot-grid/pivot-grid.pipes.spec.ts @@ -1,7 +1,7 @@ import { NoopPivotDimensionsStrategy } from '../../data-operations/pivot-strategy'; import { configureTestSuite } from '../../test-utils/configure-suite'; import { IgxPivotDateDimension } from './pivot-grid-dimensions'; -import { IgxPivotNumericAggregate } from './pivot-grid-aggregate'; +import { IgxPivotAggregate, IgxPivotDateAggregate, IgxPivotNumericAggregate, IgxPivotTimeAggregate } from './pivot-grid-aggregate'; import { IPivotConfiguration } from './pivot-grid.interface'; import { IgxPivotAutoTransform, IgxPivotColumnPipe, IgxPivotRowExpansionPipe, IgxPivotRowPipe } from './pivot-grid.pipes'; import { PivotGridFunctions } from '../../test-utils/pivot-grid-functions.spec'; @@ -293,6 +293,37 @@ describe('Pivot pipes #pivotGrid', () => { { 'All-USA-UnitsSold': 240, 'All-USA-UnitPrice': 18.13, 'All-UnitsSold': 240, 'All-UnitPrice': 18.13 }]); }); + it('should return correct values for each pivot aggregation type', () => { + // check each aggregator has correct aggregations + expect(IgxPivotAggregate.aggregators().map(x => x.key)).toEqual(['COUNT']); + expect(IgxPivotNumericAggregate.aggregators().map(x => x.key)).toEqual(['COUNT', 'MIN', 'MAX', 'SUM', 'AVG']); + expect(IgxPivotDateAggregate.aggregators().map(x => x.key)).toEqual(['COUNT', 'LATEST', 'EARLIEST']); + expect(IgxPivotTimeAggregate.aggregators().map(x => x.key)).toEqual(['COUNT', 'LATEST', 'EARLIEST']); + + // check aggregations are applied correctly + expect(IgxPivotAggregate.count([1, 2, 3])).toEqual(3); + + expect(IgxPivotNumericAggregate.count([1, 2, 3])).toEqual(3); + expect(IgxPivotNumericAggregate.min([1, 2, 3])).toEqual(1); + expect(IgxPivotNumericAggregate.max([1, 2, 3])).toEqual(3); + expect(IgxPivotNumericAggregate.sum([1, 2, 3])).toEqual(6); + expect(IgxPivotNumericAggregate.average([1, 2, 3])).toEqual(2); + + expect(IgxPivotDateAggregate.latest(['01/01/2021', '01/01/2022', '02/01/2021'])).toEqual('01/01/2022'); + expect(IgxPivotDateAggregate.earliest(['01/01/2021', '01/01/2022', '02/01/2021'])).toEqual('01/01/2021'); + + + expect(IgxPivotTimeAggregate.latestTime(['01/01/2021 8:00', '01/01/2021 1:00', '01/01/2021 22:00'])).toEqual(new Date('01/01/2021 22:00')); + expect(IgxPivotTimeAggregate.earliestTime(['01/01/2021 8:00', '01/01/2021 1:00', '01/01/2021 22:00'])).toEqual(new Date('01/01/2021 1:00')); + + // check localization can be changed + IgxPivotTimeAggregate.resourceStrings = { + igx_grid_pivot_aggregate_time_earliest: 'Earliest Custom Time' + }; + + expect(IgxPivotTimeAggregate.aggregators().find(x => x.key === 'EARLIEST').label).toEqual('Earliest Custom Time'); + }); + it('allow setting NoopPivotDimensionsStrategy for rows/columns', () => { const preprocessedData = [ {