@@ -48,20 +48,124 @@ describe('Pivot pipes', () => {
4848 filters : null
4949 } ;
5050
51- fit ( 'transforms flat data to pivot data' , ( ) => {
51+ it ( 'transforms flat data to pivot data' , ( ) => {
5252 const rowPipeResult = rowPipe . transform ( data , pivotConfigHierarchy . rows , pivotConfigHierarchy . values ) ;
5353 const columnPipeResult = columnPipe . transform ( rowPipeResult , pivotConfigHierarchy . columns , pivotConfigHierarchy . values ) ;
5454 expect ( columnPipeResult ) . toEqual ( [
55- { field1 : 'All' , All : 2127 , Bulgaria : 774 , USA : 829 , Uruguay : 524 , level : 0 , records : [
56- { field1 : 'Clothing' , All : 1526 , Bulgaria : 774 , USA : 296 , Uruguay : 456 , level : 1 } ,
57- { field1 : 'Bikes' , All : 68 , Uruguay : 68 , level : 1 } ,
58- { field1 : 'Accessories' , All : 293 , USA : 293 , level : 1 } ,
59- { field1 : 'Components' , All : 240 , USA : 240 , level : 1 }
60- ] } ,
61- { field1 : 'Clothing' , All : 1526 , Bulgaria : 774 , USA : 296 , Uruguay : 456 , level : 1 } ,
62- { field1 : 'Bikes' , All : 68 , Uruguay : 68 , level : 1 } ,
63- { field1 : 'Accessories' , All : 293 , USA : 293 , level : 1 } ,
64- { field1 : 'Components' , All : 240 , USA : 240 , level : 1 }
55+ {
56+ field1 : 'All' , All : 2127 , Bulgaria : 774 , USA : 829 , Uruguay : 524 , level : 0 , records : [
57+ { field1 : 'Clothing' , All : 1526 , Bulgaria : 774 , USA : 296 , Uruguay : 456 , level : 1 } ,
58+ { field1 : 'Bikes' , All : 68 , Uruguay : 68 , level : 1 } ,
59+ { field1 : 'Accessories' , All : 293 , USA : 293 , level : 1 } ,
60+ { field1 : 'Components' , All : 240 , USA : 240 , level : 1 }
61+ ]
62+ } ,
63+ { field1 : 'Clothing' , All : 1526 , Bulgaria : 774 , USA : 296 , Uruguay : 456 , level : 1 } ,
64+ { field1 : 'Bikes' , All : 68 , Uruguay : 68 , level : 1 } ,
65+ { field1 : 'Accessories' , All : 293 , USA : 293 , level : 1 } ,
66+ { field1 : 'Components' , All : 240 , USA : 240 , level : 1 }
67+ ] ) ;
68+ } ) ;
69+
70+ it ( 'transforms flat data to pivot data single row dimension and no children are defined' , ( ) => {
71+ const rowPipeResult = rowPipe . transform ( data , [ {
72+ member : 'ProductCategory' ,
73+ enabled : true ,
74+ childLevels : [ ]
75+ } ] , pivotConfigHierarchy . values ) ;
76+ expect ( rowPipeResult ) . toEqual ( [
77+ {
78+ ProductCategory : 'Clothing' , level : 0 , records : [
79+ { ProductCategory : 'Clothing' , UnitPrice : 12.81 , SellerName : 'Stanley' , Country : 'Bulgaria' , Date : '01/01/2021' , UnitsSold : 282 } ,
80+ { ProductCategory : 'Clothing' , UnitPrice : 49.57 , SellerName : 'Elisa' , Country : 'USA' , Date : '01/05/2019' , UnitsSold : 296 } ,
81+ { ProductCategory : 'Clothing' , UnitPrice : 68.33 , SellerName : 'Larry' , Country : 'Uruguay' , Date : '05/12/2020' , UnitsSold : 456 } ,
82+ { ProductCategory : 'Clothing' , UnitPrice : 16.05 , SellerName : 'Walter' , Country : 'Bulgaria' , Date : '02/19/2020' , UnitsSold : 492 } ]
83+ } ,
84+ {
85+ ProductCategory : 'Bikes' , level : 0 , records : [
86+ { ProductCategory : 'Bikes' , UnitPrice : 3.56 , SellerName : 'Lydia' , Country : 'Uruguay' , Date : '01/06/2020' , UnitsSold : 68 }
87+ ]
88+ } ,
89+ {
90+ ProductCategory : 'Accessories' , level : 0 , records : [
91+ { ProductCategory : 'Accessories' , UnitPrice : 85.58 , SellerName : 'David' , Country : 'USA' , Date : '04/07/2021' , UnitsSold : 293 }
92+ ]
93+ } ,
94+ {
95+ ProductCategory : 'Components' , level : 0 , records : [
96+ { ProductCategory : 'Components' , UnitPrice : 18.13 , SellerName : 'John' , Country : 'USA' , Date : '12/08/2021' , UnitsSold : 240 }
97+ ]
98+ }
99+ ] ) ;
100+ const columnPipeResult = columnPipe . transform ( rowPipeResult , pivotConfigHierarchy . columns , pivotConfigHierarchy . values ) ;
101+ expect ( columnPipeResult ) . toEqual ( [
102+ { ProductCategory : 'Clothing' , All : 1526 , Bulgaria : 774 , USA : 296 , Uruguay : 456 , level : 0 } ,
103+ { ProductCategory : 'Bikes' , All : 68 , Uruguay : 68 , level : 0 } ,
104+ { ProductCategory : 'Accessories' , All : 293 , USA : 293 , level : 0 } ,
105+ { ProductCategory : 'Components' , All : 240 , USA : 240 , level : 0 }
106+ ] ) ;
107+ } ) ;
108+
109+ it ( 'transforms flat data to pivot data multiple row dimensions' , ( ) => {
110+ const rowPipeResult = rowPipe . transform ( data , [ {
111+ member : 'ProductCategory' ,
112+ enabled : true ,
113+ childLevels : [ ]
114+ } ,
115+ {
116+ member : 'Date' ,
117+ enabled : true ,
118+ childLevels : [ ]
119+ } ] , pivotConfigHierarchy . values ) ;
120+
121+ expect ( rowPipeResult ) . toEqual ( [
122+ {
123+ ProductCategory : 'Clothing' , level : 0 , children : [
124+ { Date : '01/01/2021' , records : [
125+ { ProductCategory : 'Clothing' , UnitPrice : 12.81 , SellerName : 'Stanley' , Country : 'Bulgaria' , Date : '01/01/2021' , UnitsSold : 282 }
126+ ] } ,
127+ { Date : '01/05/2019' , records : [
128+ { ProductCategory : 'Clothing' , UnitPrice : 49.57 , SellerName : 'Elisa' , Country : 'USA' , Date : '01/05/2019' , UnitsSold : 296 }
129+ ] } ,
130+ { Date : '05/12/2020' , records : [
131+ { ProductCategory : 'Clothing' , UnitPrice : 68.33 , SellerName : 'Larry' , Country : 'Uruguay' , Date : '05/12/2020' , UnitsSold : 456 }
132+ ] } ,
133+ { Date : '02/19/2020' , records : [
134+ { ProductCategory : 'Clothing' , UnitPrice : 16.05 , SellerName : 'Walter' , Country : 'Bulgaria' , Date : '02/19/2020' , UnitsSold : 492 }
135+ ] } ,
136+ ] , records : [
137+ { ProductCategory : 'Clothing' , UnitPrice : 12.81 , SellerName : 'Stanley' , Country : 'Bulgaria' , Date : '01/01/2021' , UnitsSold : 282 } ,
138+ { ProductCategory : 'Clothing' , UnitPrice : 49.57 , SellerName : 'Elisa' , Country : 'USA' , Date : '01/05/2019' , UnitsSold : 296 } ,
139+ { ProductCategory : 'Clothing' , UnitPrice : 68.33 , SellerName : 'Larry' , Country : 'Uruguay' , Date : '05/12/2020' , UnitsSold : 456 } ,
140+ { ProductCategory : 'Clothing' , UnitPrice : 16.05 , SellerName : 'Walter' , Country : 'Bulgaria' , Date : '02/19/2020' , UnitsSold : 492 } ]
141+ } ,
142+ {
143+ ProductCategory : 'Bikes' , level : 0 , children : [
144+ { Date : '01/06/2020' , records : [
145+ { ProductCategory : 'Bikes' , UnitPrice : 3.56 , SellerName : 'Lydia' , Country : 'Uruguay' , Date : '01/06/2020' , UnitsSold : 68 }
146+ ] }
147+ ] , records : [
148+ { ProductCategory : 'Bikes' , UnitPrice : 3.56 , SellerName : 'Lydia' , Country : 'Uruguay' , Date : '01/06/2020' , UnitsSold : 68 }
149+ ]
150+ } ,
151+ {
152+ ProductCategory : 'Accessories' , level : 0 , children : [
153+ { Date : '04/07/2021' , records : [
154+ { ProductCategory : 'Accessories' , UnitPrice : 85.58 , SellerName : 'David' , Country : 'USA' , Date : '04/07/2021' , UnitsSold : 293 }
155+ ] }
156+ ] , records : [
157+ { ProductCategory : 'Accessories' , UnitPrice : 85.58 , SellerName : 'David' , Country : 'USA' , Date : '04/07/2021' , UnitsSold : 293 }
158+ ]
159+ } ,
160+ {
161+ ProductCategory : 'Components' , level : 0 , children : [
162+ { Date : '12/08/2021' , records : [
163+ { ProductCategory : 'Components' , UnitPrice : 18.13 , SellerName : 'John' , Country : 'USA' , Date : '12/08/2021' , UnitsSold : 240 }
164+ ] }
165+ ] , records : [
166+ { ProductCategory : 'Components' , UnitPrice : 18.13 , SellerName : 'John' , Country : 'USA' , Date : '12/08/2021' , UnitsSold : 240 }
167+ ]
168+ }
65169 ] ) ;
66170 } ) ;
67171
0 commit comments