Skip to content

Commit 9c0374a

Browse files
committed
test(pivot): Add some more tests to get better coverage
1 parent f6a6351 commit 9c0374a

File tree

1 file changed

+70
-1
lines changed

1 file changed

+70
-1
lines changed

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

Lines changed: 70 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { fakeAsync, TestBed } from '@angular/core/testing';
22
import { By } from '@angular/platform-browser';
33
import { NoopAnimationsModule } from '@angular/platform-browser/animations';
4-
import { IgxPivotGridModule } from 'igniteui-angular';
4+
import { IgxPivotDateDimension, IgxPivotGridModule } from 'igniteui-angular';
55
import { configureTestSuite } from '../../test-utils/configure-suite';
66
import { GridFunctions, GridSelectionFunctions } from '../../test-utils/grid-functions.spec';
77
import { IgxPivotGridTestBaseComponent, IgxPivotGridTestComplexHierarchyComponent, IgxTotalSaleAggregate } from '../../test-utils/pivot-grid-samples.spec';
@@ -106,6 +106,75 @@ describe('Basic IgxPivotGrid #pivotGrid', () => {
106106
expect(pivotGrid.columns.length).not.toBe(9);
107107
});
108108

109+
it('should collapse column with 1 value dimension', () => {
110+
const pivotGrid = fixture.componentInstance.pivotGrid;
111+
pivotGrid.pivotConfiguration.values.pop();
112+
pivotGrid.pivotConfiguration.columns = [{
113+
memberName: 'AllCountries',
114+
memberFunction: () => 'All Countries',
115+
enabled: true,
116+
childLevel: {
117+
memberName: 'Country',
118+
enabled: true
119+
}
120+
}];
121+
pivotGrid.pivotConfiguration.rows[0] = new IgxPivotDateDimension(
122+
{
123+
memberName: 'Date',
124+
enabled: true
125+
}, {
126+
total: false
127+
}
128+
);
129+
pivotGrid.notifyDimensionChange(true);
130+
expect(pivotGrid.columns.length).toBe(5);
131+
expect(pivotGrid.columnGroupStates.size).toBe(0);
132+
const headerRow = fixture.nativeElement.querySelector('igx-pivot-header-row');
133+
const header = headerRow.querySelector('igx-grid-header-group');
134+
const expander = header.querySelectorAll('igx-icon')[0];
135+
expander.click();
136+
fixture.detectChanges();
137+
expect(pivotGrid.columnGroupStates.size).toBe(1);
138+
const value = pivotGrid.columnGroupStates.entries().next().value;
139+
expect(value[0]).toEqual('All Countries');
140+
expect(value[1]).toBeTrue();
141+
});
142+
143+
it('should collapse column with 2 value dimension', () => {
144+
const pivotGrid = fixture.componentInstance.pivotGrid;
145+
pivotGrid.pivotConfiguration.columns = [{
146+
memberName: 'AllCountries',
147+
memberFunction: () => 'All Countries',
148+
enabled: true,
149+
childLevel: {
150+
memberName: 'Country',
151+
enabled: true
152+
}
153+
},
154+
{
155+
memberName: 'SellerName',
156+
enabled: true
157+
}];
158+
pivotGrid.notifyDimensionChange(true);
159+
fixture.detectChanges();
160+
expect(pivotGrid.columnGroupStates.size).toBe(0);
161+
const headerRow = fixture.nativeElement.querySelector('igx-pivot-header-row');
162+
const header = headerRow.querySelector('igx-grid-header-group');
163+
const expander = header.querySelectorAll('igx-icon')[0];
164+
expander.click();
165+
fixture.detectChanges();
166+
expect(pivotGrid.columnGroupStates.size).toBe(1);
167+
let value = pivotGrid.columnGroupStates.entries().next().value;
168+
expect(value[0]).toEqual('All Countries');
169+
expect(value[1]).toBeTrue();
170+
171+
expander.click();
172+
fixture.detectChanges();
173+
value = pivotGrid.columnGroupStates.entries().next().value;
174+
expect(value[0]).toEqual('All Countries');
175+
expect(value[1]).toBeFalse();
176+
});
177+
109178
describe('IgxPivotGrid Features #pivotGrid', () => {
110179
it('should show excel style filtering via dimension chip.', () => {
111180
const excelMenu = GridFunctions.getExcelStyleFilteringComponent(fixture, 'igx-pivot-grid');

0 commit comments

Comments
 (0)