Skip to content

Commit

Permalink
Merge pull request #11241 from IgniteUI/mkirova/pivot-test-coverage
Browse files Browse the repository at this point in the history
chore(*): Add coverage for different pivot aggregates.
  • Loading branch information
dkamburov authored Mar 23, 2022
2 parents f530543 + 704f95a commit 703c14f
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand All @@ -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);
}
}
Expand Down Expand Up @@ -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);
}

Expand All @@ -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);
}
}
Original file line number Diff line number Diff line change
@@ -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';
Expand Down Expand Up @@ -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 = [
{
Expand Down

0 comments on commit 703c14f

Please sign in to comment.