|
| 1 | +import { IgxNumberSummaryOperand } from '../summaries/grid-summary'; |
| 2 | +import { IPivotConfiguration } from './pivot-grid.interface'; |
| 3 | +import { IgxPivotColumnPipe, IgxPivotRowPipe } from './pivot-grid.pipes'; |
| 4 | + |
| 5 | +describe('Pivot pipes', () => { |
| 6 | + // This pipe is a pure, stateless function so no need for BeforeEach |
| 7 | + const rowPipe = new IgxPivotRowPipe(); |
| 8 | + const columnPipe = new IgxPivotColumnPipe(); |
| 9 | + |
| 10 | + const data = [ |
| 11 | + { ProductCategory: 'Clothing', UnitPrice: 12.81, SellerName: 'Stanley', Country: 'Bulgaria', Date: '01/01/2021', UnitsSold: 282 }, |
| 12 | + { ProductCategory: 'Clothing', UnitPrice: 49.57, SellerName: 'Elisa', Country: 'USA', Date: '01/05/2019', UnitsSold: 296 }, |
| 13 | + { ProductCategory: 'Bikes', UnitPrice: 3.56, SellerName: 'Lydia', Country: 'Uruguay', Date: '01/06/2020', UnitsSold: 68 }, |
| 14 | + { ProductCategory: 'Accessories', UnitPrice: 85.58, SellerName: 'David', Country: 'USA', Date: '04/07/2021', UnitsSold: 293 }, |
| 15 | + { ProductCategory: 'Components', UnitPrice: 18.13, SellerName: 'John', Country: 'USA', Date: '12/08/2021', UnitsSold: 240 }, |
| 16 | + { ProductCategory: 'Clothing', UnitPrice: 68.33, SellerName: 'Larry', Country: 'Uruguay', Date: '05/12/2020', UnitsSold: 456 }, |
| 17 | + { ProductCategory: 'Clothing', UnitPrice: 16.05, SellerName: 'Walter', Country: 'Bulgaria', Date: '02/19/2020', UnitsSold: 492 } |
| 18 | + ]; |
| 19 | + |
| 20 | + const pivotConfigHierarchy: IPivotConfiguration = { |
| 21 | + columns: [{ |
| 22 | + member: () => 'All', |
| 23 | + enabled: true, |
| 24 | + childLevels: [{ |
| 25 | + member: 'Country', |
| 26 | + enabled: true, |
| 27 | + childLevels: [] |
| 28 | + }] |
| 29 | + }], |
| 30 | + rows: [{ |
| 31 | + member: () => 'All', |
| 32 | + enabled: true, |
| 33 | + childLevels: [ |
| 34 | + { |
| 35 | + member: (d) => d.ProductCategory, |
| 36 | + enabled: true, |
| 37 | + childLevels: [] |
| 38 | + } |
| 39 | + ] |
| 40 | + }], |
| 41 | + values: [ |
| 42 | + { |
| 43 | + member: 'UnitsSold', |
| 44 | + aggregate: IgxNumberSummaryOperand.sum, |
| 45 | + enabled: true |
| 46 | + } |
| 47 | + ], |
| 48 | + filters: null |
| 49 | + }; |
| 50 | + |
| 51 | + it('transforms flat data to pivot data', () => { |
| 52 | + const rowPipeResult = rowPipe.transform(data, pivotConfigHierarchy.rows, pivotConfigHierarchy.values); |
| 53 | + const columnPipeResult = columnPipe.transform(rowPipeResult, pivotConfigHierarchy.columns, pivotConfigHierarchy.values); |
| 54 | + expect(columnPipeResult).toEqual([ |
| 55 | + { field1: 'All', All: 1000, Bulgaria: 774, USA: 829, Uruguay: 524, level: 0, records: [ |
| 56 | + { field1: 'Clothing', Bulgaria: 774, USA: 296, Uruguay: 456, level: 1 }, |
| 57 | + { field1: 'Bikes', Uruguay: 68, level: 1 }, |
| 58 | + { field1: 'Accessories', USA: 293, level: 1 }, |
| 59 | + { field1: 'Components', USA: 240, level: 1 } |
| 60 | + ] }, |
| 61 | + { field1: 'Clothing', All: 1000, Bulgaria: 774, USA: 296, Uruguay: 456, level: 1 }, |
| 62 | + { field1: 'Bikes', All: 1000, Uruguay: 68, level: 1 }, |
| 63 | + { field1: 'Accessories', All: 1000, USA: 293, level: 1 }, |
| 64 | + { field1: 'Components', All: 1000, USA: 240, level: 1 } |
| 65 | + ]); |
| 66 | + }); |
| 67 | + |
| 68 | +}); |
0 commit comments