11import { NoopPivotDimensionsStrategy } from '../../data-operations/pivot-strategy' ;
2+ import { configureTestSuite } from '../../test-utils/configure-suite' ;
23import { IgxNumberSummaryOperand } from '../summaries/grid-summary' ;
34import { IPivotConfiguration } from './pivot-grid.interface' ;
45import { IgxPivotColumnPipe , IgxPivotRowExpansionPipe , IgxPivotRowPipe } from './pivot-grid.pipes' ;
56
67describe ( '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- childLevels : [ {
28- memberName : 'Country' ,
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' ,
2929 enabled : true ,
30- childLevels : [ ]
31- } ]
32- } ] ,
33- rows : [ {
34- memberName : 'All' ,
35- memberFunction : ( ) => 'All' ,
36- enabled : true ,
37- childLevels : [
38- {
39- memberName : 'ProductCategory' ,
40- memberFunction : ( d ) => d . ProductCategory ,
30+ childLevels : [ {
31+ memberName : 'Country' ,
4132 enabled : true ,
4233 childLevels : [ ]
34+ } ]
35+ } ] ,
36+ rows : [ {
37+ memberName : 'All' ,
38+ memberFunction : ( ) => 'All' ,
39+ enabled : true ,
40+ childLevels : [
41+ {
42+ memberName : 'ProductCategory' ,
43+ memberFunction : ( d ) => d . ProductCategory ,
44+ enabled : true ,
45+ childLevels : [ ]
46+ }
47+ ]
48+ } ] ,
49+ values : [
50+ {
51+ member : 'UnitsSold' ,
52+ aggregate : IgxNumberSummaryOperand . sum ,
53+ enabled : true
4354 }
44- ]
45- } ] ,
46- values : [
47- {
48- member : 'UnitsSold' ,
49- aggregate : IgxNumberSummaryOperand . sum ,
50- enabled : true
51- }
52- ] ,
53- filters : null
54- } ;
55+ ] ,
56+ filters : null
57+ } ;
58+ expansionStates = new Map < any , boolean > ( ) ;
59+ rowPipe = new IgxPivotRowPipe ( ) ;
60+ rowStatePipe = new IgxPivotRowExpansionPipe ( ) ;
61+ columnPipe = new IgxPivotColumnPipe ( ) ;
62+ } ) ;
5563
5664 it ( 'transforms flat data to pivot data' , ( ) => {
57- const rowPipeResult = rowPipe . transform ( data , pivotConfigHierarchy , expansionStates ) ;
58- const rowStatePipeResult = rowStatePipe . transform ( rowPipeResult , pivotConfigHierarchy , expansionStates ) ;
59- const columnPipeResult = columnPipe . transform ( rowStatePipeResult , pivotConfigHierarchy , expansionStates ) ;
65+ const rowPipeResult = rowPipe . transform ( data , pivotConfig , expansionStates ) ;
66+ const rowStatePipeResult = rowStatePipe . transform ( rowPipeResult , pivotConfig , expansionStates ) ;
67+ const columnPipeResult = columnPipe . transform ( rowStatePipeResult , pivotConfig , expansionStates ) ;
6068 expect ( columnPipeResult ) . toEqual ( [
6169 { All : 2127 , 'All-Bulgaria' : 774 , 'All-USA' : 829 , 'All-Uruguay' : 524 , All_level : 0 } ,
6270 { ProductCategory : 'Clothing' , All : 1526 , 'All-Bulgaria' : 774 , 'All-USA' : 296 , 'All-Uruguay' : 456 , ProductCategory_level : 1 } ,
@@ -67,13 +75,12 @@ describe('Pivot pipes', () => {
6775 } ) ;
6876
6977 it ( 'transforms flat data to pivot data single row dimension and no children are defined' , ( ) => {
70- const config = Object . assign ( { } , pivotConfigHierarchy ) ;
71- config . rows = [ {
78+ pivotConfig . rows = [ {
7279 memberName : 'ProductCategory' ,
7380 enabled : true ,
7481 childLevels : [ ]
7582 } ] ;
76- const rowPipeResult = rowPipe . transform ( data , config , expansionStates ) ;
83+ const rowPipeResult = rowPipe . transform ( data , pivotConfig , expansionStates ) ;
7784 expect ( rowPipeResult ) . toEqual ( [
7885 {
7986 ProductCategory : 'Clothing' , records : [
@@ -151,7 +158,7 @@ describe('Pivot pipes', () => {
151158 }
152159 ] , level : 0
153160 } ] ) ;
154- const columnPipeResult = columnPipe . transform ( rowPipeResult , config , expansionStates ) ;
161+ const columnPipeResult = columnPipe . transform ( rowPipeResult , pivotConfig , expansionStates ) ;
155162 expect ( columnPipeResult ) . toEqual ( [
156163 {
157164 ProductCategory : 'Clothing' , All : 1526 , 'All-Bulgaria' : 774 , 'All-USA' : 296 ,
@@ -166,8 +173,8 @@ describe('Pivot pipes', () => {
166173 it ( 'allows setting expand/collapse state.' , ( ) => {
167174 const expanded = new Map < any , boolean > ( ) ;
168175 expanded . set ( 'All' , false ) ;
169- const rowPipeResult = rowPipe . transform ( data , pivotConfigHierarchy , expanded ) ;
170- const rowPipeCollapseResult = rowStatePipe . transform ( rowPipeResult , pivotConfigHierarchy , expanded ) ;
176+ const rowPipeResult = rowPipe . transform ( data , pivotConfig , expanded ) ;
177+ const rowPipeCollapseResult = rowStatePipe . transform ( rowPipeResult , pivotConfig , expanded ) ;
171178 expect ( rowPipeCollapseResult ) . toEqual ( [
172179 {
173180 All : 'All' , All_records : [
@@ -280,7 +287,7 @@ describe('Pivot pipes', () => {
280287 } ] ) ;
281288
282289 expanded . set ( 'All' , true ) ;
283- const rowPipeExpandResult = rowStatePipe . transform ( rowPipeResult , pivotConfigHierarchy , expanded ) ;
290+ const rowPipeExpandResult = rowStatePipe . transform ( rowPipeResult , pivotConfig , expanded ) ;
284291 expect ( rowPipeExpandResult ) . toEqual ( [
285292 {
286293 All : 'All' , All_records : [
@@ -467,8 +474,7 @@ describe('Pivot pipes', () => {
467474 } ) ;
468475
469476 it ( 'transforms flat data to pivot data multiple row dimensions' , ( ) => {
470- const config = Object . assign ( { } , pivotConfigHierarchy ) ;
471- config . rows = [ {
477+ pivotConfig . rows = [ {
472478 memberName : 'ProductCategory' ,
473479 enabled : true ,
474480 childLevels : [ ]
@@ -478,8 +484,8 @@ describe('Pivot pipes', () => {
478484 enabled : true ,
479485 childLevels : [ ]
480486 } ] ;
481- const rowPipeResult = rowPipe . transform ( data , config , expansionStates ) ;
482- const rowStatePipeResult = rowStatePipe . transform ( rowPipeResult , config , expansionStates ) ;
487+ const rowPipeResult = rowPipe . transform ( data , pivotConfig , expansionStates ) ;
488+ const rowStatePipeResult = rowStatePipe . transform ( rowPipeResult , pivotConfig , expansionStates ) ;
483489
484490 expect ( rowStatePipeResult ) . toEqual ( [
485491 {
@@ -656,8 +662,7 @@ describe('Pivot pipes', () => {
656662 } ) ;
657663
658664 it ( 'transforms flat data to pivot data with multiple nested row dimensions' , ( ) => {
659- const config = Object . assign ( { } , pivotConfigHierarchy ) ;
660- config . rows = [ {
665+ pivotConfig . rows = [ {
661666 memberName : 'AllProd' ,
662667 memberFunction : ( ) => 'AllProd' ,
663668 enabled : true ,
@@ -677,9 +682,9 @@ describe('Pivot pipes', () => {
677682 childLevels : [ ]
678683 } ]
679684 } ] ;
680- const rowPipeResult = rowPipe . transform ( data , config , expansionStates ) ;
681- const rowStatePipeResult = rowStatePipe . transform ( rowPipeResult , config , expansionStates ) ;
682- const columnPipeResult = columnPipe . transform ( rowStatePipeResult , config , expansionStates ) ;
685+ const rowPipeResult = rowPipe . transform ( data , pivotConfig , expansionStates ) ;
686+ const rowStatePipeResult = rowStatePipe . transform ( rowPipeResult , pivotConfig , expansionStates ) ;
687+ const columnPipeResult = columnPipe . transform ( rowStatePipeResult , pivotConfig , expansionStates ) ;
683688 expect ( columnPipeResult ) . toEqual ( [
684689 {
685690 All : 2127 , 'All-Bulgaria' : 774 , 'All-Uruguay' : 524 , 'All-USA' : 829 , AllDate : 'AllDate' ,
@@ -710,8 +715,7 @@ describe('Pivot pipes', () => {
710715 } ) ;
711716
712717 it ( 'transforms flat data to pivot data 2 column dimensions' , ( ) => {
713- const config = Object . assign ( { } , pivotConfigHierarchy ) ;
714- config . columns = [ {
718+ pivotConfig . columns = [ {
715719 memberName : 'Country' ,
716720 enabled : true ,
717721 childLevels : [ ]
@@ -721,9 +725,9 @@ describe('Pivot pipes', () => {
721725 enabled : true ,
722726 childLevels : [ ]
723727 } ] ;
724- const rowPipeResult = rowPipe . transform ( data , config , new Map < any , boolean > ( ) ) ;
725- const rowStatePipeResult = rowStatePipe . transform ( rowPipeResult , pivotConfigHierarchy , new Map < any , boolean > ( ) ) ;
726- const columnPipeResult = columnPipe . transform ( rowStatePipeResult , config , new Map < any , boolean > ( ) ) ;
728+ const rowPipeResult = rowPipe . transform ( data , pivotConfig , new Map < any , boolean > ( ) ) ;
729+ const rowStatePipeResult = rowStatePipe . transform ( rowPipeResult , pivotConfig , new Map < any , boolean > ( ) ) ;
730+ const columnPipeResult = columnPipe . transform ( rowStatePipeResult , pivotConfig , new Map < any , boolean > ( ) ) ;
727731 /* eslint-disable quote-props */
728732 expect ( columnPipeResult ) . toEqual ( [
729733 {
@@ -742,8 +746,7 @@ describe('Pivot pipes', () => {
742746 } ) ;
743747
744748 it ( 'transforms flat data to pivot data 3 column dimensions' , ( ) => {
745- const config = Object . assign ( { } , pivotConfigHierarchy ) ;
746- config . columns = [ {
749+ pivotConfig . columns = [ {
747750 memberName : 'Country' ,
748751 enabled : true ,
749752 childLevels : [ ]
@@ -758,9 +761,9 @@ describe('Pivot pipes', () => {
758761 enabled : true ,
759762 childLevels : [ ]
760763 } ] ;
761- const rowPipeResult = rowPipe . transform ( data , config , new Map < any , boolean > ( ) ) ;
762- const rowStateResult = rowStatePipe . transform ( rowPipeResult , config , new Map < any , boolean > ( ) ) ;
763- const columnPipeResult = columnPipe . transform ( rowStateResult , config , new Map < any , boolean > ( ) ) ;
764+ const rowPipeResult = rowPipe . transform ( data , pivotConfig , new Map < any , boolean > ( ) ) ;
765+ const rowStateResult = rowStatePipe . transform ( rowPipeResult , pivotConfig , new Map < any , boolean > ( ) ) ;
766+ const columnPipeResult = columnPipe . transform ( rowStateResult , pivotConfig , new Map < any , boolean > ( ) ) ;
764767 /* eslint-disable quote-props */
765768 expect ( columnPipeResult ) . toEqual ( [
766769 {
@@ -781,8 +784,7 @@ describe('Pivot pipes', () => {
781784 } ) ;
782785
783786 it ( 'transforms flat data to pivot data 2 value dimensions' , ( ) => {
784- const config = Object . assign ( { } , pivotConfigHierarchy ) ;
785- config . values = [
787+ pivotConfig . values = [
786788 {
787789 member : 'UnitsSold' ,
788790 aggregate : IgxNumberSummaryOperand . sum ,
@@ -794,9 +796,9 @@ describe('Pivot pipes', () => {
794796 enabled : true
795797 }
796798 ] ;
797- const rowPipeResult = rowPipe . transform ( data , config , expansionStates ) ;
798- const rowStatePipeResult = rowStatePipe . transform ( rowPipeResult , pivotConfigHierarchy , new Map < any , boolean > ( ) ) ;
799- const columnPipeResult = columnPipe . transform ( rowStatePipeResult , config , expansionStates ) ;
799+ const rowPipeResult = rowPipe . transform ( data , pivotConfig , expansionStates ) ;
800+ const rowStatePipeResult = rowStatePipe . transform ( rowPipeResult , pivotConfig , new Map < any , boolean > ( ) ) ;
801+ const columnPipeResult = columnPipe . transform ( rowStatePipeResult , pivotConfig , expansionStates ) ;
800802 expect ( columnPipeResult ) . toEqual ( [
801803 {
802804 'All' : 'All' , 'All_level' : 0 , 'All-UnitsSold' : 2127 , 'All-Bulgaria-UnitsSold' : 774 , 'All-Bulgaria-UnitPrice' : 28.86 ,
@@ -822,7 +824,6 @@ describe('Pivot pipes', () => {
822824 } ) ;
823825
824826 it ( 'allow setting NoopPivotDimensionsStrategy for rows/columns' , ( ) => {
825- const config = Object . assign ( { } , pivotConfigHierarchy ) ;
826827 const preprocessedData = [
827828 {
828829 All : 2127 , All_records : [
@@ -832,14 +833,14 @@ describe('Pivot pipes', () => {
832833 { ProductCategory : 'Components' , level : 1 , All : 240 , 'All-USA' : 240 } ]
833834 , level : 0 , 'All-Bulgaria' : 774 , 'All-USA' : 829 , 'All-Uruguay' : 524
834835 } ] ;
835- config . columnStrategy = NoopPivotDimensionsStrategy . instance ( ) ;
836- config . columns [ 0 ] . memberName = 'All' ;
837- config . rowStrategy = NoopPivotDimensionsStrategy . instance ( ) ;
838- config . rows [ 0 ] . memberName = 'All' ;
836+ pivotConfig . columnStrategy = NoopPivotDimensionsStrategy . instance ( ) ;
837+ pivotConfig . columns [ 0 ] . memberName = 'All' ;
838+ pivotConfig . rowStrategy = NoopPivotDimensionsStrategy . instance ( ) ;
839+ pivotConfig . rows [ 0 ] . memberName = 'All' ;
839840
840- const rowPipeResult = rowPipe . transform ( preprocessedData , config , new Map < any , boolean > ( ) ) ;
841- const rowStateResult = rowStatePipe . transform ( rowPipeResult , config , new Map < any , boolean > ( ) ) ;
842- const columnPipeResult = columnPipe . transform ( rowStateResult , config , new Map < any , boolean > ( ) ) ;
841+ const rowPipeResult = rowPipe . transform ( preprocessedData , pivotConfig , new Map < any , boolean > ( ) ) ;
842+ const rowStateResult = rowStatePipe . transform ( rowPipeResult , pivotConfig , new Map < any , boolean > ( ) ) ;
843+ const columnPipeResult = columnPipe . transform ( rowStateResult , pivotConfig , new Map < any , boolean > ( ) ) ;
843844
844845 // same data but expanded
845846 expect ( columnPipeResult ) . toEqual ( [
0 commit comments