Skip to content

Commit a97df61

Browse files
authored
Merge pull request #10409 from IgniteUI/dkamburov/refactor-tests
test(pivot): clean the state of the pivot tests
2 parents 7b1c11e + 1afe62d commit a97df61

File tree

3 files changed

+177
-177
lines changed

3 files changed

+177
-177
lines changed

projects/igniteui-angular/src/lib/grids/pivot-grid/pivot-grid.pipes.spec.ts

Lines changed: 83 additions & 82 deletions
Original file line numberDiff line numberDiff line change
@@ -1,58 +1,66 @@
11
import { NoopPivotDimensionsStrategy } from '../../data-operations/pivot-strategy';
2+
import { configureTestSuite } from '../../test-utils/configure-suite';
23
import { IgxNumberSummaryOperand } from '../summaries/grid-summary';
34
import { IPivotConfiguration } from './pivot-grid.interface';
45
import { IgxPivotColumnPipe, IgxPivotRowExpansionPipe, IgxPivotRowPipe } from './pivot-grid.pipes';
56

67
describe('Pivot pipes', () => {
7-
// This pipe is a pure, stateless function so no need for BeforeEach
8-
const rowPipe = new IgxPivotRowPipe();
9-
const rowStatePipe = new IgxPivotRowExpansionPipe();
10-
const columnPipe = new IgxPivotColumnPipe();
11-
const expansionStates = new Map<any, boolean>();
12-
const data = [
8+
let rowPipe: IgxPivotRowPipe;
9+
let rowStatePipe: IgxPivotRowExpansionPipe;
10+
let columnPipe: IgxPivotColumnPipe;
11+
let expansionStates: Map<any, boolean>;
12+
let data: any[];
13+
let pivotConfig: IPivotConfiguration;
14+
15+
configureTestSuite();
16+
beforeEach(() => {
17+
data = [
1318
{ ProductCategory: 'Clothing', UnitPrice: 12.81, SellerName: 'Stanley', Country: 'Bulgaria', Date: '01/01/2021', UnitsSold: 282 },
1419
{ ProductCategory: 'Clothing', UnitPrice: 49.57, SellerName: 'Elisa', Country: 'USA', Date: '01/05/2019', UnitsSold: 296 },
1520
{ ProductCategory: 'Bikes', UnitPrice: 3.56, SellerName: 'Lydia', Country: 'Uruguay', Date: '01/06/2020', UnitsSold: 68 },
1621
{ ProductCategory: 'Accessories', UnitPrice: 85.58, SellerName: 'David', Country: 'USA', Date: '04/07/2021', UnitsSold: 293 },
1722
{ ProductCategory: 'Components', UnitPrice: 18.13, SellerName: 'John', Country: 'USA', Date: '12/08/2021', UnitsSold: 240 },
1823
{ ProductCategory: 'Clothing', UnitPrice: 68.33, SellerName: 'Larry', Country: 'Uruguay', Date: '05/12/2020', UnitsSold: 456 },
19-
{ ProductCategory: 'Clothing', UnitPrice: 16.05, SellerName: 'Walter', Country: 'Bulgaria', Date: '02/19/2020', UnitsSold: 492 }
20-
];
21-
22-
const pivotConfigHierarchy: IPivotConfiguration = {
23-
columns: [{
24-
memberName: 'All',
25-
memberFunction: () => 'All',
26-
enabled: true,
27-
childLevel: {
28-
memberName: 'Country',
29-
enabled: true
30-
}
31-
}],
32-
rows: [{
33-
memberName: 'All',
34-
memberFunction: () => 'All',
35-
enabled: true,
36-
childLevel: {
37-
memberName: 'ProductCategory',
38-
memberFunction: (d) => d.ProductCategory,
39-
enabled: true
40-
}
41-
}],
42-
values: [
43-
{
44-
member: 'UnitsSold',
45-
aggregate: IgxNumberSummaryOperand.sum,
46-
enabled: true
47-
}
48-
],
49-
filters: null
50-
};
24+
{ ProductCategory: 'Clothing', UnitPrice: 16.05, SellerName: 'Walter', Country: 'Bulgaria', Date: '02/19/2020', UnitsSold: 492 }];
25+
pivotConfig = {
26+
columns: [{
27+
memberName: 'All',
28+
memberFunction: () => 'All',
29+
enabled: true,
30+
childLevel: {
31+
memberName: 'Country',
32+
enabled: true
33+
}
34+
}],
35+
rows: [{
36+
memberName: 'All',
37+
memberFunction: () => 'All',
38+
enabled: true,
39+
childLevel: {
40+
memberName: 'ProductCategory',
41+
memberFunction: (d) => d.ProductCategory,
42+
enabled: true
43+
}
44+
}],
45+
values: [
46+
{
47+
member: 'UnitsSold',
48+
aggregate: IgxNumberSummaryOperand.sum,
49+
enabled: true
50+
}
51+
],
52+
filters: null
53+
};
54+
expansionStates = new Map<any, boolean>();
55+
rowPipe = new IgxPivotRowPipe();
56+
rowStatePipe = new IgxPivotRowExpansionPipe();
57+
columnPipe = new IgxPivotColumnPipe();
58+
});
5159

5260
it('transforms flat data to pivot data', () => {
53-
const rowPipeResult = rowPipe.transform(data, pivotConfigHierarchy, expansionStates);
54-
const rowStatePipeResult = rowStatePipe.transform(rowPipeResult, pivotConfigHierarchy, expansionStates);
55-
const columnPipeResult = columnPipe.transform(rowStatePipeResult, pivotConfigHierarchy, expansionStates);
61+
const rowPipeResult = rowPipe.transform(data, pivotConfig, expansionStates);
62+
const rowStatePipeResult = rowStatePipe.transform(rowPipeResult, pivotConfig, expansionStates);
63+
const columnPipeResult = columnPipe.transform(rowStatePipeResult, pivotConfig, expansionStates);
5664
expect(columnPipeResult).toEqual([
5765
{ All: 2127, 'All-Bulgaria': 774, 'All-USA': 829, 'All-Uruguay': 524, All_level: 0 },
5866
{ ProductCategory: 'Clothing', All: 1526, 'All-Bulgaria': 774, 'All-USA': 296, 'All-Uruguay': 456, ProductCategory_level: 1 },
@@ -63,12 +71,11 @@ describe('Pivot pipes', () => {
6371
});
6472

6573
it('transforms flat data to pivot data single row dimension and no children are defined', () => {
66-
const config = Object.assign({}, pivotConfigHierarchy);
67-
config.rows = [{
74+
pivotConfig.rows = [{
6875
memberName: 'ProductCategory',
6976
enabled: true
7077
}];
71-
const rowPipeResult = rowPipe.transform(data, config, expansionStates);
78+
const rowPipeResult = rowPipe.transform(data, pivotConfig, expansionStates);
7279
expect(rowPipeResult).toEqual([
7380
{
7481
ProductCategory: 'Clothing', records: [
@@ -146,7 +153,7 @@ describe('Pivot pipes', () => {
146153
}
147154
], level: 0
148155
}]);
149-
const columnPipeResult = columnPipe.transform(rowPipeResult, config, expansionStates);
156+
const columnPipeResult = columnPipe.transform(rowPipeResult, pivotConfig, expansionStates);
150157
expect(columnPipeResult).toEqual([
151158
{
152159
ProductCategory: 'Clothing', All: 1526, 'All-Bulgaria': 774, 'All-USA': 296,
@@ -161,8 +168,8 @@ describe('Pivot pipes', () => {
161168
it('allows setting expand/collapse state.', () => {
162169
const expanded = new Map<any, boolean>();
163170
expanded.set('All', false);
164-
const rowPipeResult = rowPipe.transform(data, pivotConfigHierarchy, expanded);
165-
const rowPipeCollapseResult = rowStatePipe.transform(rowPipeResult, pivotConfigHierarchy, expanded);
171+
const rowPipeResult = rowPipe.transform(data, pivotConfig, expanded);
172+
const rowPipeCollapseResult = rowStatePipe.transform(rowPipeResult, pivotConfig, expanded);
166173
expect(rowPipeCollapseResult).toEqual([
167174
{
168175
All: 'All', All_records: [
@@ -275,7 +282,7 @@ describe('Pivot pipes', () => {
275282
}]);
276283

277284
expanded.set('All', true);
278-
const rowPipeExpandResult = rowStatePipe.transform(rowPipeResult, pivotConfigHierarchy, expanded);
285+
const rowPipeExpandResult = rowStatePipe.transform(rowPipeResult, pivotConfig, expanded);
279286
expect(rowPipeExpandResult).toEqual([
280287
{
281288
All: 'All', All_records: [
@@ -462,17 +469,16 @@ describe('Pivot pipes', () => {
462469
});
463470

464471
it('transforms flat data to pivot data multiple row dimensions', () => {
465-
const config = Object.assign({}, pivotConfigHierarchy);
466-
config.rows = [{
472+
pivotConfig.rows = [{
467473
memberName: 'ProductCategory',
468474
enabled: true
469475
},
470476
{
471477
memberName: 'Date',
472478
enabled: true
473479
}];
474-
const rowPipeResult = rowPipe.transform(data, config, expansionStates);
475-
const rowStatePipeResult = rowStatePipe.transform(rowPipeResult, config, expansionStates);
480+
const rowPipeResult = rowPipe.transform(data, pivotConfig, expansionStates);
481+
const rowStatePipeResult = rowStatePipe.transform(rowPipeResult, pivotConfig, expansionStates);
476482

477483
expect(rowStatePipeResult).toEqual([
478484
{
@@ -649,8 +655,7 @@ describe('Pivot pipes', () => {
649655
});
650656

651657
it('transforms flat data to pivot data with multiple nested row dimensions', () => {
652-
const config = Object.assign({}, pivotConfigHierarchy);
653-
config.rows = [{
658+
pivotConfig.rows = [{
654659
memberName: 'AllProd',
655660
memberFunction: () => 'AllProd',
656661
enabled: true,
@@ -668,9 +673,9 @@ describe('Pivot pipes', () => {
668673
enabled: true
669674
}
670675
}];
671-
const rowPipeResult = rowPipe.transform(data, config, expansionStates);
672-
const rowStatePipeResult = rowStatePipe.transform(rowPipeResult, config, expansionStates);
673-
const columnPipeResult = columnPipe.transform(rowStatePipeResult, config, expansionStates);
676+
const rowPipeResult = rowPipe.transform(data, pivotConfig, expansionStates);
677+
const rowStatePipeResult = rowStatePipe.transform(rowPipeResult, pivotConfig, expansionStates);
678+
const columnPipeResult = columnPipe.transform(rowStatePipeResult, pivotConfig, expansionStates);
674679
expect(columnPipeResult).toEqual([
675680
{
676681
All: 2127, 'All-Bulgaria': 774, 'All-Uruguay': 524, 'All-USA': 829, AllDate: 'AllDate',
@@ -701,18 +706,17 @@ describe('Pivot pipes', () => {
701706
});
702707

703708
it('transforms flat data to pivot data 2 column dimensions', () => {
704-
const config = Object.assign({}, pivotConfigHierarchy);
705-
config.columns = [{
709+
pivotConfig.columns = [{
706710
memberName: 'Country',
707711
enabled: true
708712
},
709713
{
710714
memberName: 'Date',
711715
enabled: true
712-
}];
713-
const rowPipeResult = rowPipe.transform(data, config, new Map<any, boolean>());
714-
const rowStatePipeResult = rowStatePipe.transform(rowPipeResult, pivotConfigHierarchy, new Map<any, boolean>());
715-
const columnPipeResult = columnPipe.transform(rowStatePipeResult, config, new Map<any, boolean>());
716+
}];
717+
const rowPipeResult = rowPipe.transform(data, pivotConfig, new Map<any, boolean>());
718+
const rowStatePipeResult = rowStatePipe.transform(rowPipeResult, pivotConfig, new Map<any, boolean>());
719+
const columnPipeResult = columnPipe.transform(rowStatePipeResult, pivotConfig, new Map<any, boolean>());
716720
/* eslint-disable quote-props */
717721
expect(columnPipeResult).toEqual([
718722
{
@@ -731,8 +735,7 @@ describe('Pivot pipes', () => {
731735
});
732736

733737
it('transforms flat data to pivot data 3 column dimensions', () => {
734-
const config = Object.assign({}, pivotConfigHierarchy);
735-
config.columns = [{
738+
pivotConfig.columns = [{
736739
memberName: 'Country',
737740
enabled: true
738741
},
@@ -743,10 +746,10 @@ describe('Pivot pipes', () => {
743746
{
744747
memberName: 'Date',
745748
enabled: true
746-
}];
747-
const rowPipeResult = rowPipe.transform(data, config, new Map<any, boolean>());
748-
const rowStateResult = rowStatePipe.transform(rowPipeResult, config, new Map<any, boolean>());
749-
const columnPipeResult = columnPipe.transform(rowStateResult, config, new Map<any, boolean>());
749+
}];
750+
const rowPipeResult = rowPipe.transform(data, pivotConfig, new Map<any, boolean>());
751+
const rowStateResult = rowStatePipe.transform(rowPipeResult, pivotConfig, new Map<any, boolean>());
752+
const columnPipeResult = columnPipe.transform(rowStateResult, pivotConfig, new Map<any, boolean>());
750753
/* eslint-disable quote-props */
751754
expect(columnPipeResult).toEqual([
752755
{
@@ -767,8 +770,7 @@ describe('Pivot pipes', () => {
767770
});
768771

769772
it('transforms flat data to pivot data 2 value dimensions', () => {
770-
const config = Object.assign({}, pivotConfigHierarchy);
771-
config.values = [
773+
pivotConfig.values = [
772774
{
773775
member: 'UnitsSold',
774776
aggregate: IgxNumberSummaryOperand.sum,
@@ -780,9 +782,9 @@ describe('Pivot pipes', () => {
780782
enabled: true
781783
}
782784
];
783-
const rowPipeResult = rowPipe.transform(data, config, expansionStates);
784-
const rowStatePipeResult = rowStatePipe.transform(rowPipeResult, pivotConfigHierarchy, new Map<any, boolean>());
785-
const columnPipeResult = columnPipe.transform(rowStatePipeResult, config, expansionStates);
785+
const rowPipeResult = rowPipe.transform(data, pivotConfig, expansionStates);
786+
const rowStatePipeResult = rowStatePipe.transform(rowPipeResult, pivotConfig, new Map<any, boolean>());
787+
const columnPipeResult = columnPipe.transform(rowStatePipeResult, pivotConfig, expansionStates);
786788
expect(columnPipeResult).toEqual([
787789
{
788790
'All': 'All', 'All_level': 0, 'All-UnitsSold': 2127, 'All-Bulgaria-UnitsSold': 774, 'All-Bulgaria-UnitPrice': 28.86,
@@ -808,7 +810,6 @@ describe('Pivot pipes', () => {
808810
});
809811

810812
it('allow setting NoopPivotDimensionsStrategy for rows/columns', () => {
811-
const config = Object.assign({}, pivotConfigHierarchy);
812813
const preprocessedData = [
813814
{
814815
All: 2127, All_records: [
@@ -818,14 +819,14 @@ describe('Pivot pipes', () => {
818819
{ ProductCategory: 'Components', level: 1, All: 240, 'All-USA': 240 }]
819820
, level: 0, 'All-Bulgaria': 774, 'All-USA': 829, 'All-Uruguay': 524
820821
}];
821-
config.columnStrategy = NoopPivotDimensionsStrategy.instance();
822-
config.columns[0].memberName = 'All';
823-
config.rowStrategy = NoopPivotDimensionsStrategy.instance();
824-
config.rows[0].memberName = 'All';
822+
pivotConfig.columnStrategy = NoopPivotDimensionsStrategy.instance();
823+
pivotConfig.columns[0].memberName = 'All';
824+
pivotConfig.rowStrategy = NoopPivotDimensionsStrategy.instance();
825+
pivotConfig.rows[0].memberName = 'All';
825826

826-
const rowPipeResult = rowPipe.transform(preprocessedData, config, new Map<any, boolean>());
827-
const rowStateResult = rowStatePipe.transform(rowPipeResult, config, new Map<any, boolean>());
828-
const columnPipeResult = columnPipe.transform(rowStateResult, config, new Map<any, boolean>());
827+
const rowPipeResult = rowPipe.transform(preprocessedData, pivotConfig, new Map<any, boolean>());
828+
const rowStateResult = rowStatePipe.transform(rowPipeResult, pivotConfig, new Map<any, boolean>());
829+
const columnPipeResult = columnPipe.transform(rowStateResult, pivotConfig, new Map<any, boolean>());
829830

830831
// same data but expanded
831832
expect(columnPipeResult).toEqual([

0 commit comments

Comments
 (0)