|
1 | 1 | import { fakeAsync, TestBed } from '@angular/core/testing'; |
| 2 | +import { By } from '@angular/platform-browser'; |
2 | 3 | import { NoopAnimationsModule } from '@angular/platform-browser/animations'; |
3 | 4 | import { IgxPivotGridModule } from 'igniteui-angular'; |
4 | 5 | import { configureTestSuite } from '../../test-utils/configure-suite'; |
5 | | -import { IgxPivotGridTestBaseComponent } from '../../test-utils/pivot-grid-samples.spec'; |
| 6 | +import { IgxPivotGridTestBaseComponent, IgxTotalSaleAggregate } from '../../test-utils/pivot-grid-samples.spec'; |
| 7 | +import { UIInteractions } from '../../test-utils/ui-interactions.spec'; |
| 8 | +const CSS_CLASS_DROP_DOWN_BASE = 'igx-drop-down'; |
| 9 | +const CSS_CLASS_LIST = 'igx-drop-down__list'; |
| 10 | +const CSS_CLASS_ITEM = 'igx-drop-down__item'; |
6 | 11 |
|
7 | 12 | describe('Basic IgxPivotGrid #pivotGrid', () => { |
8 | 13 | let fixture; |
@@ -37,4 +42,81 @@ describe('Basic IgxPivotGrid #pivotGrid', () => { |
37 | 42 | expect(cells.first.nativeElement.classList).toContain('test'); |
38 | 43 | expect(cells.last.nativeElement.classList).not.toContain('test'); |
39 | 44 | }); |
| 45 | + |
| 46 | + describe('IgxPivotGrid Features #pivotGrid', () => { |
| 47 | + it('should allow changing default aggregation via value chip drop-down.', () => { |
| 48 | + fixture.detectChanges(); |
| 49 | + const pivotGrid = fixture.componentInstance.pivotGrid; |
| 50 | + const headerRow = fixture.nativeElement.querySelector('igx-pivot-header-row'); |
| 51 | + const valueChip = headerRow.querySelector('igx-chip[id="UnitsSold"]'); |
| 52 | + let content = valueChip.querySelector('.igx-chip__content'); |
| 53 | + expect(content.textContent.trim()).toBe('SUM(UnitsSold)'); |
| 54 | + |
| 55 | + const aggregatesIcon = valueChip.querySelectorAll('igx-icon')[1]; |
| 56 | + aggregatesIcon.click(); |
| 57 | + fixture.detectChanges(); |
| 58 | + const items = fixture.debugElement.queryAll(By.css(`.${CSS_CLASS_ITEM}`)); |
| 59 | + expect(items.length).toBe(5); |
| 60 | + // select count |
| 61 | + items[0].triggerEventHandler('click', UIInteractions.getMouseEvent('click')); |
| 62 | + fixture.detectChanges(); |
| 63 | + |
| 64 | + // check chip and row |
| 65 | + content = valueChip.querySelector('.igx-chip__content'); |
| 66 | + expect(content.textContent.trim()).toBe('COUNT(UnitsSold)'); |
| 67 | + expect(pivotGrid.gridAPI.get_cell_by_index(0, 'Bulgaria-UnitsSold').value).toBe(2); |
| 68 | + expect(pivotGrid.gridAPI.get_cell_by_index(0, 'USA-UnitsSold').value).toBe(3); |
| 69 | + expect(pivotGrid.gridAPI.get_cell_by_index(0, 'Uruguay-UnitsSold').value).toBe(2); |
| 70 | + |
| 71 | + }); |
| 72 | + it('should allow showing custom aggregations via pivot configuration.', () => { |
| 73 | + const pivotGrid = fixture.componentInstance.pivotGrid; |
| 74 | + pivotGrid.pivotConfiguration.values.push({ |
| 75 | + member: 'AmountOfSale', |
| 76 | + displayName: 'Amount of Sale', |
| 77 | + aggregate: { |
| 78 | + key: 'SUM', |
| 79 | + aggregator: IgxTotalSaleAggregate.totalSale, |
| 80 | + label: 'Sum of Sale' |
| 81 | + }, |
| 82 | + aggregateList: [{ |
| 83 | + key: 'SUM', |
| 84 | + aggregator: IgxTotalSaleAggregate.totalSale, |
| 85 | + label: 'Sum of Sale' |
| 86 | + },{ |
| 87 | + key: 'MIN', |
| 88 | + aggregator: IgxTotalSaleAggregate.totalMin, |
| 89 | + label: 'Minimum of Sale' |
| 90 | + },{ |
| 91 | + key: 'MAX', |
| 92 | + aggregator: IgxTotalSaleAggregate.totalMax, |
| 93 | + label: 'Maximum of Sale' |
| 94 | + }], |
| 95 | + enabled: true |
| 96 | + }); |
| 97 | + pivotGrid.pipeTrigger++; |
| 98 | + pivotGrid.setupColumns(); |
| 99 | + fixture.detectChanges(); |
| 100 | + const headerRow = fixture.nativeElement.querySelector('igx-pivot-header-row'); |
| 101 | + const valueChip = headerRow.querySelector('igx-chip[id="AmountOfSale"]'); |
| 102 | + let content = valueChip.querySelector('.igx-chip__content'); |
| 103 | + expect(content.textContent.trim()).toBe('SUM(Amount of Sale)'); |
| 104 | + |
| 105 | + const aggregatesIcon = valueChip.querySelectorAll('igx-icon')[1]; |
| 106 | + aggregatesIcon.click(); |
| 107 | + fixture.detectChanges(); |
| 108 | + |
| 109 | + const items = fixture.debugElement.queryAll(By.css(`.${CSS_CLASS_ITEM}`)); |
| 110 | + expect(items.length).toBe(3); |
| 111 | + // select min |
| 112 | + items[1].triggerEventHandler('click', UIInteractions.getMouseEvent('click')); |
| 113 | + fixture.detectChanges(); |
| 114 | + // check chip and row values |
| 115 | + content = valueChip.querySelector('.igx-chip__content'); |
| 116 | + expect(content.textContent.trim()).toBe('MIN(Amount of Sale)'); |
| 117 | + expect(pivotGrid.gridAPI.get_cell_by_index(0, 'Bulgaria-AmountOfSale').value).toBe(3612.42); |
| 118 | + expect(pivotGrid.gridAPI.get_cell_by_index(0, 'USA-AmountOfSale').value).toBe(0); |
| 119 | + expect(pivotGrid.gridAPI.get_cell_by_index(0, 'Uruguay-AmountOfSale').value).toBe(242.08); |
| 120 | + }); |
| 121 | + }); |
40 | 122 | }); |
0 commit comments