Skip to content

Commit 6332f07

Browse files
committed
test(pivot): Update base pivot tests
1 parent 5be4a1a commit 6332f07

File tree

1 file changed

+71
-64
lines changed

1 file changed

+71
-64
lines changed

projects/igniteui-angular/src/lib/grids/pivot-grid/pivot-grid.spec.ts

Lines changed: 71 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { ComponentFixture, fakeAsync, TestBed, tick, waitForAsync } from '@angular/core/testing';
22
import { By } from '@angular/platform-browser';
33
import { NoopAnimationsModule } from '@angular/platform-browser/animations';
4-
import { CellType, FilteringExpressionsTree, FilteringLogic, GridColumnDataType, IGridCellEventArgs, IgxIconComponent, IgxPivotGridComponent, IgxStringFilteringOperand } from 'igniteui-angular';
4+
import { FilteringExpressionsTree, FilteringLogic, GridColumnDataType, IGridCellEventArgs, IgxGridCell, IgxIconComponent, IgxPivotGridComponent, IgxStringFilteringOperand } from 'igniteui-angular';
55
import { IgxChipComponent } from '../../chips/chip.component';
66
import { IgxChipsAreaComponent } from '../../chips/chips-area.component';
77
import { DefaultPivotSortingStrategy } from '../../data-operations/pivot-sort-strategy';
@@ -22,7 +22,6 @@ import { Size } from '../common/enums';
2222
import { setElementSize } from '../../test-utils/helper-utils.spec';
2323
import { IgxPivotRowDimensionMrlRowComponent } from './pivot-row-dimension-mrl-row.component';
2424
import { IgxPivotRowDimensionContentComponent } from './pivot-row-dimension-content.component';
25-
import { IgxGridCellComponent } from '../cell.component';
2625

2726
const CSS_CLASS_LIST = 'igx-drop-down__list';
2827
const CSS_CLASS_ITEM = 'igx-drop-down__item';
@@ -760,7 +759,7 @@ describe('IgxPivotGrid #pivotGrid', () => {
760759
expect(pivotGrid.columns.length).toBe(3);
761760
});
762761

763-
it('should calculate row headers according to grid size', async() => {
762+
it('should calculate row headers according to grid size', async () => {
764763
const pivotGrid = fixture.componentInstance.pivotGrid;
765764
const rowHeightSmall = 32;
766765
const rowHeightMedium = 40;
@@ -797,7 +796,7 @@ describe('IgxPivotGrid #pivotGrid', () => {
797796
expect(rowHeader[0].nativeElement.offsetHeight).toBe(rowHeightMedium);
798797
});
799798

800-
it('should render with correct width when set to 100% inside of flex container', async() => {
799+
it('should render with correct width when set to 100% inside of flex container', async () => {
801800
fixture = TestBed.createComponent(IgxPivotGridFlexContainerComponent);
802801
fixture.detectChanges();
803802
await wait(100);
@@ -1415,7 +1414,7 @@ describe('IgxPivotGrid #pivotGrid', () => {
14151414
GridFunctions.clickHeaderSortIcon(headerCell);
14161415
fixture.detectChanges();
14171416
expect(pivotGrid.sortingExpressions.length).toBe(0);
1418-
expectedOrder = [829, 293, undefined, 296, 240];
1417+
expectedOrder = [829, 296, undefined, 293, 240];
14191418
columnValues = pivotGrid.dataView.map(x => (x as IPivotGridRecord).aggregationValues.get('USA-UnitsSold'));
14201419
expect(columnValues).toEqual(expectedOrder);
14211420
});
@@ -2113,15 +2112,16 @@ describe('IgxPivotGrid #pivotGrid', () => {
21132112
spyOn(pivotGrid.cellClick, 'emit').and.callThrough();
21142113
fixture.detectChanges();
21152114

2116-
const cell = pivotGrid.gridAPI.get_cell_by_index(0, 'Bulgaria-UnitsSold') as CellType;
2115+
const cell = pivotGrid.gridAPI.get_cell_by_index(0, 'Bulgaria-UnitsSold');
21172116

2118-
pivotGrid.cellClick.emit({ cell, event: null });
2119-
cell.nativeElement.click();
2120-
const cellClickargs: IGridCellEventArgs = { cell, event: new MouseEvent('click') };
2117+
const event = new Event('click');
2118+
cell.nativeElement.dispatchEvent(event);
2119+
fixture.detectChanges();
2120+
2121+
const expectedCell = new IgxGridCell(pivotGrid, 0, cell.column);
21212122

2122-
const gridCell = cellClickargs.cell as IgxGridCellComponent;
2123-
const firstEntry = gridCell.rowData.aggregationValues.entries().next().value;
2124-
expect(firstEntry).toEqual(['USA-UnitsSold', 829]);
2123+
const cellClickArgs: IGridCellEventArgs = { cell: expectedCell, event };
2124+
expect(pivotGrid.cellClick.emit).toHaveBeenCalledOnceWith(cellClickArgs);
21252125
});
21262126
});
21272127
});
@@ -2139,7 +2139,7 @@ describe('IgxPivotGrid #pivotGrid', () => {
21392139
const pivotGrid = fixture.componentInstance.pivotGrid;
21402140
expect(pivotGrid.selectedRows).toEqual([]);
21412141
const pivotRows = GridFunctions.getPivotRows(fixture);
2142-
const row = pivotRows[2].componentInstance;
2142+
const row = pivotRows[1].componentInstance;
21432143
const rowHeaders = fixture.debugElement.queryAll(
21442144
By.directive(IgxPivotRowDimensionHeaderComponent));
21452145
const secondDimCell = rowHeaders.find(x => x.componentInstance.column.header === 'Clothing');
@@ -2177,13 +2177,17 @@ describe('IgxPivotGrid #pivotGrid', () => {
21772177
[
21782178
{
21792179
AllProducts: 'AllProducts', 'All cities': 'All Cities'
2180-
}, {
2181-
ProductCategory: 'Bikes', 'All cities': 'All Cities'
2182-
}, {
2180+
},
2181+
{
21832182
ProductCategory: 'Clothing', 'All cities': 'All Cities'
2184-
}, {
2183+
},
2184+
{
2185+
ProductCategory: 'Bikes', 'All cities': 'All Cities'
2186+
},
2187+
{
21852188
ProductCategory: 'Accessories', 'All cities': 'All Cities'
2186-
}, {
2189+
},
2190+
{
21872191
ProductCategory: 'Components', 'All cities': 'All Cities'
21882192
}
21892193
];
@@ -2233,38 +2237,38 @@ describe('IgxPivotGrid #pivotGrid', () => {
22332237
columns: fixture.componentInstance.pivotConfigHierarchy.columns,
22342238
rows: fixture.componentInstance.pivotConfigHierarchy.rows,
22352239
values: [
2236-
{
2237-
member: 'UnitsSold',
2238-
aggregate: {
2239-
aggregator: IgxPivotNumericAggregate.sum,
2240-
key: 'SUM',
2241-
label: 'Sum'
2242-
},
2243-
enabled: true,
2244-
formatter: (value, row, column) => {
2245-
if (!column || !column.value || column.value.member !== 'UnitsSold') {
2246-
correctFirstColumnData = false;
2240+
{
2241+
member: 'UnitsSold',
2242+
aggregate: {
2243+
aggregator: IgxPivotNumericAggregate.sum,
2244+
key: 'SUM',
2245+
label: 'Sum'
2246+
},
2247+
enabled: true,
2248+
formatter: (value, row, column) => {
2249+
if (!column || !column.value || column.value.member !== 'UnitsSold') {
2250+
correctFirstColumnData = false;
2251+
}
2252+
return value;
22472253
}
2248-
return value;
2249-
}
2250-
},
2251-
{
2252-
member: 'AmountOfSale',
2253-
displayName: 'Amount of Sale',
2254-
aggregate: {
2255-
aggregator: IgxTotalSaleAggregate.totalSale,
2256-
key: 'TOTAL',
2257-
label: 'Total'
22582254
},
2259-
enabled: true,
2260-
formatter: (value, row, column) => {
2261-
if (!column || !column.value || column.value.member !== 'AmountOfSale') {
2262-
correctSecondColumnData = false;
2255+
{
2256+
member: 'AmountOfSale',
2257+
displayName: 'Amount of Sale',
2258+
aggregate: {
2259+
aggregator: IgxTotalSaleAggregate.totalSale,
2260+
key: 'TOTAL',
2261+
label: 'Total'
2262+
},
2263+
enabled: true,
2264+
formatter: (value, row, column) => {
2265+
if (!column || !column.value || column.value.member !== 'AmountOfSale') {
2266+
correctSecondColumnData = false;
2267+
}
2268+
return value;
22632269
}
2264-
return value;
22652270
}
2266-
}
2267-
]
2271+
]
22682272
};
22692273

22702274
pivotGrid.width = '1500px';
@@ -2528,7 +2532,7 @@ describe('IgxPivotGrid #pivotGrid', () => {
25282532
const dimensionContents = fixture.debugElement.queryAll(By.css('.igx-grid__tbody-pivot-dimension'));
25292533
const rowHeaders = dimensionContents[1].queryAll(By.directive(IgxPivotRowDimensionHeaderGroupComponent));
25302534
const first = rowHeaders.map(x => x.componentInstance.column.header)[0];
2531-
expect(first).toBe('Larry Lieb');
2535+
expect(first).toBe('Stanley Brooker');
25322536

25332537
// insert in columns
25342538
pivotGrid.insertDimensionAt({ memberName: 'SellerNameColumn', memberFunction: (rec) => rec.SellerName, enabled: true }, PivotDimensionType.Column, 0);
@@ -2822,7 +2826,7 @@ describe('IgxPivotGrid #pivotGrid', () => {
28222826
//check rows
28232827
const rows = pivotGrid.rowList.toArray();
28242828
expect(rows.length).toBe(4);
2825-
const expectedHeaders = ['Accessories', 'Bikes', 'Clothing', 'Components'];
2829+
const expectedHeaders = ['Clothing', 'Bikes', 'Accessories', 'Components'];
28262830
const rowHeaders = fixture.debugElement.queryAll(
28272831
By.directive(IgxPivotRowDimensionHeaderComponent));
28282832
const rowDimensionHeaders = rowHeaders.map(x => x.componentInstance.column.header);
@@ -2835,7 +2839,7 @@ describe('IgxPivotGrid #pivotGrid', () => {
28352839

28362840
// check data
28372841
const pivotRecord = (pivotGrid.rowList.first as IgxPivotRowComponent).data;
2838-
expect(pivotRecord.aggregationValues.get('London')).toBe(293);
2842+
expect(pivotRecord.aggregationValues.get('New York')).toBe(296);
28392843

28402844
});
28412845

@@ -2868,8 +2872,8 @@ describe('IgxPivotGrid #pivotGrid', () => {
28682872
]
28692873
};
28702874
fixture.detectChanges();
2871-
expect(pivotGrid.gridAPI.get_cell_by_index(0, 0).nativeElement.innerText).toBe('Accessories/Plovdiv:undefined');
2872-
expect(pivotGrid.gridAPI.get_cell_by_index(0, 3).nativeElement.innerText).toBe('Accessories/London:293');
2875+
expect(pivotGrid.gridAPI.get_cell_by_index(0, 0).nativeElement.innerText).toBe('Clothing/Plovdiv:282');
2876+
expect(pivotGrid.gridAPI.get_cell_by_index(0, 3).nativeElement.innerText).toBe('Clothing/London:undefined');
28732877
});
28742878

28752879
it('should allow filtering a dimension runtime.', () => {
@@ -3029,7 +3033,7 @@ describe('IgxPivotGrid #pivotGrid', () => {
30293033
const rowDimensionHeadersCol2 = rowDimensionCol2.map(x => x.componentInstance.rowDimensionColumn.header);
30303034
dimensions = rowDimensionCol2.map(x => x.componentInstance.dimension);
30313035
expect(dimensions.every(x => x.memberName === "City")).toBeTruthy();
3032-
expect(rowDimensionHeadersCol2).toEqual(["Ciudad de la Costa", "London", "New York", "Plovdiv", "Sofia", "Yokohama"]);
3036+
expect(rowDimensionHeadersCol2).toEqual(['Plovdiv', 'New York', 'Ciudad de la Costa', 'London', 'Yokohama', 'Sofia']);
30333037

30343038
const rowDimensionCol3 = contentRowHeaders.filter(y => y.componentInstance.layout.colStart === 3);
30353039
const rowDimensionHeadersCol3 = rowDimensionCol3.map(x => x.componentInstance.rowDimensionColumn.header);
@@ -3042,8 +3046,8 @@ describe('IgxPivotGrid #pivotGrid', () => {
30423046
.map(x => x.componentInstance.rowDimensionColumn.header);
30433047
dimensions = rowDimensionCol4.map(x => x.componentInstance.dimension);
30443048
expect(dimensions.every(x => x.memberName === "ProductCategory")).toBeTruthy();
3045-
expect(rowDimensionHeadersCol4).toEqual(["Bikes", "Clothing", "Accessories",
3046-
"Clothing", "Clothing", "Components", "Components"]);
3049+
expect(rowDimensionHeadersCol4).toEqual(["Clothing", "Clothing", "Bikes",
3050+
"Clothing", "Accessories", "Components", "Components"]);
30473051
});
30483052

30493053
it("should horizontally expand/collapse on a single dimension hierarchy.", () => {
@@ -3262,11 +3266,14 @@ describe('IgxPivotGrid #pivotGrid', () => {
32623266
const allGroups = layoutContainer.queryAll(
32633267
By.directive(IgxPivotRowDimensionHeaderComponent));
32643268
const row0Col0 = allGroups[0];
3265-
const row0Col1 = allGroups.filter(x => x.componentInstance.column.header === "Ciudad de la Costa")[0];
3269+
const row0Col1 = allGroups.filter(x => x.componentInstance.column.header === "Plovdiv")[0];
3270+
const row1Col1 = allGroups.filter(x => x.componentInstance.column.header === "New York")[0];
3271+
32663272
const row0Col2 = allGroups.filter(x => x.componentInstance.column.header === "AllProducts")[0];
3267-
const row0Col3 = allGroups.filter(x => x.componentInstance.column.header === "Bikes")[0];
3268-
const row1Col3 = allGroups.filter(x => x.componentInstance.column.header === "Clothing")[0];
3269-
const row2Col3 = allGroups.filter(x => x.componentInstance.column.header === "Accessories")[0];
3273+
const row1Col2 = allGroups.filter(x => x.componentInstance.column.header === "AllProducts")[1];
3274+
const row0Col3 = allGroups.filter(x => x.componentInstance.column.header === "Clothing")[0];
3275+
const row1Col3 = allGroups.filter(x => x.componentInstance.column.header === "Clothing")[1];
3276+
const row2Col3 = allGroups.filter(x => x.componentInstance.column.header === "Bikes")[0];
32703277
UIInteractions.simulateClickAndSelectEvent(row0Col0);
32713278
fixture.detectChanges();
32723279

@@ -3320,18 +3327,18 @@ describe('IgxPivotGrid #pivotGrid', () => {
33203327
UIInteractions.triggerKeyDownEvtUponElem('ArrowLeft', row1Col3.nativeElement);
33213328
tick();
33223329
fixture.detectChanges();
3323-
GridFunctions.verifyHeaderIsFocused(row0Col2.parent);
3330+
GridFunctions.verifyHeaderIsFocused(row1Col2.parent);
33243331
activeCells = fixture.debugElement.queryAll(By.css(`${ACTIVE_CELL_CSS_CLASS}`));
33253332
expect(activeCells.length).toBe(1);
33263333

3327-
UIInteractions.triggerKeyDownEvtUponElem('ArrowLeft', row0Col2.nativeElement);
3334+
UIInteractions.triggerKeyDownEvtUponElem('ArrowLeft', row1Col2.nativeElement);
33283335
tick();
33293336
fixture.detectChanges();
3330-
GridFunctions.verifyHeaderIsFocused(row0Col1.parent);
3337+
GridFunctions.verifyHeaderIsFocused(row1Col1.parent);
33313338
activeCells = fixture.debugElement.queryAll(By.css(`${ACTIVE_CELL_CSS_CLASS}`));
33323339
expect(activeCells.length).toBe(1);
33333340

3334-
UIInteractions.triggerKeyDownEvtUponElem('ArrowLeft', row0Col1.nativeElement);
3341+
UIInteractions.triggerKeyDownEvtUponElem('ArrowLeft', row1Col1.nativeElement);
33353342
tick();
33363343
fixture.detectChanges();
33373344
GridFunctions.verifyHeaderIsFocused(row0Col0.parent);
@@ -3385,7 +3392,7 @@ describe('IgxPivotGrid #pivotGrid', () => {
33853392
const productRowContents = rowHeaders.filter(x => x.componentInstance.column.field === "ProductCategory");
33863393
const productRowContentsHeaders = productRowContents.map(x => x.componentInstance.column.header);
33873394

3388-
expect(productRowContentsHeaders).toEqual(['ProductCategory', 'Accessories', 'Bikes', 'Clothing', 'Components']);
3395+
expect(productRowContentsHeaders).toEqual(['ProductCategory', 'Clothing', 'Bikes', 'Accessories', 'Components']);
33893396

33903397
const sortIcon = productsHeaderColumn.querySelectorAll('igx-icon')[0];
33913398
sortIcon.click();
@@ -3408,7 +3415,7 @@ describe('IgxPivotGrid #pivotGrid', () => {
34083415
By.directive(IgxPivotRowDimensionHeaderComponent));
34093416
expect(pivotGrid.selectedRows).toEqual([]);
34103417
const pivotRows = GridFunctions.getPivotRows(fixture);
3411-
const row = pivotRows[2].componentInstance;
3418+
const row = pivotRows[4].componentInstance;
34123419
const secondDimCell = rowHeaders.find(x => x.componentInstance.column.header === 'Accessories');
34133420
secondDimCell.nativeElement.click();
34143421
fixture.detectChanges();

0 commit comments

Comments
 (0)