|
| 1 | +import { Component, ViewChild } from '@angular/core'; |
| 2 | +import { fakeAsync, TestBed } from '@angular/core/testing'; |
| 3 | +import { NoopAnimationsModule } from '@angular/platform-browser/animations'; |
| 4 | +import { IgxNumberSummaryOperand, IgxPivotGridComponent, IgxPivotGridModule, IPivotConfiguration } from 'igniteui-angular'; |
| 5 | +import { configureTestSuite } from '../../test-utils/configure-suite'; |
| 6 | + |
| 7 | +describe('Basic IgxPivotGrid #pivotGrid', () => { |
| 8 | + let fixture; |
| 9 | + configureTestSuite((() => { |
| 10 | + TestBed.configureTestingModule({ |
| 11 | + declarations: [ |
| 12 | + IgxPivotGridTestBaseComponent |
| 13 | + ], |
| 14 | + imports: [ |
| 15 | + NoopAnimationsModule, IgxPivotGridModule] |
| 16 | + }); |
| 17 | + })); |
| 18 | + |
| 19 | + beforeEach(fakeAsync(() => { |
| 20 | + fixture = TestBed.createComponent(IgxPivotGridTestBaseComponent); |
| 21 | + fixture.detectChanges(); |
| 22 | + })); |
| 23 | + |
| 24 | + it('should apply formatter and dataType from measures', () => { |
| 25 | + const pivotGrid = fixture.componentInstance.pivotGrid; |
| 26 | + const actualFormatterValue = pivotGrid.rowList.first.cells.first.title; |
| 27 | + expect(actualFormatterValue).toEqual('774$'); |
| 28 | + const actualDataTypeValue = pivotGrid.rowList.first.cells.last.title; |
| 29 | + expect(actualDataTypeValue).toEqual('$28.86'); |
| 30 | + }); |
| 31 | + |
| 32 | + it('should apply css class to cells from measures', () => { |
| 33 | + const pivotGrid = fixture.componentInstance.pivotGrid; |
| 34 | + const cells = pivotGrid.rowList.first.cells; |
| 35 | + expect(cells.first.nativeElement.classList).toContain('test'); |
| 36 | + expect(cells.last.nativeElement.classList).not.toContain('test'); |
| 37 | + }); |
| 38 | +}); |
| 39 | + |
| 40 | + |
| 41 | +@Component({ |
| 42 | + template: ` |
| 43 | + <igx-pivot-grid #grid [data]="data" [pivotConfiguration]="pivotConfigHierarchy"> |
| 44 | + </igx-pivot-grid>` |
| 45 | +}) |
| 46 | +export class IgxPivotGridTestBaseComponent { |
| 47 | + public data; |
| 48 | + |
| 49 | + public callback = (rowData: any, columnKey: any) => rowData[columnKey] >= 5; |
| 50 | + public callback1 = (rowData: any, columnKey: any) => rowData[columnKey] < 5; |
| 51 | + |
| 52 | + public cellClasses = { |
| 53 | + test: this.callback, |
| 54 | + test2: this.callback1 |
| 55 | + }; |
| 56 | + |
| 57 | + @ViewChild('grid', { read: IgxPivotGridComponent, static: true }) public pivotGrid: IgxPivotGridComponent; |
| 58 | + |
| 59 | + public pivotConfigHierarchy: IPivotConfiguration = { |
| 60 | + columns: [{ |
| 61 | + member: 'Country', |
| 62 | + enabled: true, |
| 63 | + childLevels: [] |
| 64 | + }, |
| 65 | + ], |
| 66 | + rows: [{ |
| 67 | + member: () => 'All', |
| 68 | + enabled: true, |
| 69 | + childLevels: [ |
| 70 | + { |
| 71 | + fieldName: 'ProductCategory', |
| 72 | + member: (data) => data.ProductCategory, |
| 73 | + enabled: true, |
| 74 | + childLevels: [] |
| 75 | + } |
| 76 | + ] |
| 77 | + }], |
| 78 | + values: [ |
| 79 | + { |
| 80 | + member: 'UnitsSold', |
| 81 | + aggregate: IgxNumberSummaryOperand.sum, |
| 82 | + enabled: true, |
| 83 | + // dataType: 'currency', |
| 84 | + formatter: (value) => value ? value + '$' : undefined, |
| 85 | + styles: this.cellClasses |
| 86 | + }, |
| 87 | + { |
| 88 | + member: 'UnitPrice', |
| 89 | + aggregate: IgxNumberSummaryOperand.sum, |
| 90 | + enabled: true, |
| 91 | + dataType: 'currency' |
| 92 | + } |
| 93 | + ], |
| 94 | + filters: null |
| 95 | + }; |
| 96 | + |
| 97 | + constructor() { |
| 98 | + this.data = [{ ProductCategory: 'Clothing', UnitPrice: 12.81, SellerName: 'Stanley', Country: 'Bulgaria', Date: '01/01/2021', UnitsSold: 282 }, |
| 99 | + { ProductCategory: 'Clothing', UnitPrice: 49.57, SellerName: 'Elisa', Country: 'USA', Date: '01/05/2019', UnitsSold: 296 }, |
| 100 | + { ProductCategory: 'Bikes', UnitPrice: 3.56, SellerName: 'Lydia', Country: 'Uruguay', Date: '01/06/2020', UnitsSold: 68 }, |
| 101 | + { ProductCategory: 'Accessories', UnitPrice: 85.58, SellerName: 'David', Country: 'USA', Date: '04/07/2021', UnitsSold: 293 }, |
| 102 | + { ProductCategory: 'Components', UnitPrice: 18.13, SellerName: 'John', Country: 'USA', Date: '12/08/2021', UnitsSold: 240 }, |
| 103 | + { ProductCategory: 'Clothing', UnitPrice: 68.33, SellerName: 'Larry', Country: 'Uruguay', Date: '05/12/2020', UnitsSold: 456 }, |
| 104 | + { ProductCategory: 'Clothing', UnitPrice: 16.05, SellerName: 'Walter', Country: 'Bulgaria', Date: '02/19/2020', UnitsSold: 492 }]; |
| 105 | + |
| 106 | + |
| 107 | + } |
| 108 | +} |
0 commit comments