Skip to content

Commit 010b751

Browse files
committed
test(pivot): Add more tests for better coverage
1 parent ca6bfda commit 010b751

File tree

2 files changed

+117
-1
lines changed

2 files changed

+117
-1
lines changed

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

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ describe('IgxPivotGrid - Keyboard navigation #pivotGrid', () => {
133133

134134
UIInteractions.triggerKeyDownEvtUponElem('ArrowRight', pivotGrid.theadRow.nativeElement);
135135
fixture.detectChanges();
136-
136+
137137
const secondHeader = fixture.debugElement.queryAll(
138138
By.css(`${PIVOT_HEADER_ROW} ${HEADER_CELL_CSS_CLASS}`))[1];
139139
GridFunctions.verifyHeaderIsFocused(secondHeader.parent);
@@ -191,4 +191,32 @@ describe('IgxPivotGrid - Keyboard navigation #pivotGrid', () => {
191191
activeCells = fixture.debugElement.queryAll(By.css(`${ACTIVE_CELL_CSS_CLASS}`));
192192
expect(activeCells.length).toBe(1);
193193
});
194+
195+
it('should allow navigating within the cells of the body', () => {
196+
const cell = pivotGrid.rowList.first.cells.first;
197+
GridFunctions.focusFirstCell(fixture, pivotGrid);
198+
fixture.detectChanges();
199+
expect(pivotGrid.navigation.activeNode.row).toBeUndefined();
200+
expect(pivotGrid.navigation.activeNode.column).toBeUndefined();
201+
202+
UIInteractions.simulateClickAndSelectEvent(cell.nativeElement);
203+
fixture.detectChanges();
204+
205+
GridFunctions.focusFirstCell(fixture, pivotGrid);
206+
fixture.detectChanges();
207+
expect(pivotGrid.navigation.activeNode.row).toBeDefined();
208+
expect(pivotGrid.navigation.activeNode.column).toBeDefined();
209+
210+
let activeCells = fixture.debugElement.queryAll(By.css(`.igx-grid__td--active`));
211+
expect(activeCells.length).toBe(1);
212+
expect(cell.column.field).toEqual('Stanley-UnitsSold');
213+
214+
const gridContent = GridFunctions.getGridContent(fixture);
215+
UIInteractions.triggerEventHandlerKeyDown('arrowright', gridContent);
216+
fixture.detectChanges();
217+
218+
activeCells = fixture.debugElement.queryAll(By.css(`.igx-grid__td--active`));
219+
expect(activeCells.length).toBe(1);
220+
expect(activeCells[0].componentInstance.column.field).toEqual('Stanley-UnitPrice')
221+
});
194222
});

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

Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -759,6 +759,87 @@ describe('IgxPivotGrid #pivotGrid', () => {
759759
expect(filtersChip).not.toBeUndefined();
760760
});
761761

762+
it('should do nothing on filtering pointer down', () => {
763+
const pivotGrid = fixture.componentInstance.pivotGrid;
764+
pivotGrid.pivotConfiguration.filters = [
765+
{
766+
memberName: 'Date',
767+
enabled: true
768+
},
769+
{
770+
memberName: 'ProductCategory',
771+
enabled: true
772+
}
773+
];
774+
775+
pivotGrid.pivotConfiguration.rows = [{
776+
memberName: 'SellerName',
777+
enabled: true
778+
}];
779+
pivotGrid.pipeTrigger++;
780+
pivotGrid.setupColumns();
781+
fixture.detectChanges();
782+
783+
const headerRow = fixture.debugElement.queryAll(
784+
By.directive(IgxPivotHeaderRowComponent))[0].componentInstance;
785+
const filtersChip = headerRow.nativeElement.querySelector('igx-chip[id="Date"]');
786+
expect(filtersChip).not.toBeUndefined();
787+
const filterIcon = filtersChip.querySelectorAll('igx-icon')[1];
788+
spyOn(headerRow, "onFilteringIconPointerDown");
789+
790+
filterIcon.dispatchEvent(new Event('pointerdown'));
791+
fixture.detectChanges();
792+
793+
expect(headerRow.onFilteringIconPointerDown).toHaveBeenCalledTimes(1);
794+
});
795+
796+
it('should correctly remove chip from filters dropdown', () => {
797+
const pivotGrid = fixture.componentInstance.pivotGrid;
798+
pivotGrid.pivotConfiguration = {
799+
columns: [],
800+
rows: [
801+
{
802+
memberName: 'SellerName',
803+
enabled: true
804+
}
805+
],
806+
filters: [
807+
{
808+
memberName: 'Date',
809+
enabled: true
810+
},
811+
{
812+
memberName: 'ProductCategory',
813+
enabled: true
814+
},
815+
{
816+
memberName: 'Country',
817+
enabled: true
818+
}
819+
]
820+
};
821+
pivotGrid.pipeTrigger++;
822+
pivotGrid.setupColumns();
823+
fixture.detectChanges();
824+
825+
const headerRow = fixture.nativeElement.querySelector('igx-pivot-header-row');
826+
const dropdownIcon = headerRow.querySelector('.igx-grid__tr-pivot--filter').querySelectorAll('igx-icon')[4];
827+
expect(dropdownIcon).not.toBeUndefined();
828+
expect(headerRow.querySelector('igx-badge').innerText).toBe('2');
829+
dropdownIcon.click();
830+
fixture.detectChanges();
831+
832+
const excelMenu = GridFunctions.getExcelStyleFilteringComponents(fixture, 'igx-pivot-grid')[0];
833+
const chip = excelMenu.querySelectorAll('igx-chip')[0];
834+
const removeIcon = chip.querySelectorAll('igx-icon')[1];
835+
removeIcon.click();
836+
fixture.detectChanges();
837+
838+
const filtersChip = headerRow.querySelector('igx-chip[id="Date"]');
839+
expect(filtersChip).toBeDefined();
840+
expect(headerRow.querySelector('igx-chip[id="ProductCategory"]')).toBeNull();
841+
});
842+
762843
it('should apply sorting for dimension via row chip', () => {
763844
fixture.detectChanges();
764845
const pivotGrid = fixture.componentInstance.pivotGrid;
@@ -1119,6 +1200,13 @@ describe('IgxPivotGrid #pivotGrid', () => {
11191200
owner: colChip2
11201201
}, colChipArea, PivotDimensionType.Column);
11211202
pivotGrid.cdr.detectChanges();
1203+
1204+
headerRow.onDimDragLeave({
1205+
owner: colChip2
1206+
});
1207+
expect((colChip2.nativeElement.previousElementSibling as any).style.visibility).toBe('hidden');
1208+
expect((colChip2.nativeElement.nextElementSibling as any).style.visibility).toBe('hidden');
1209+
11221210
//check chip order is updated.
11231211
expect(colChipArea.chipsList.toArray()[0].id).toBe(colChip2.id);
11241212
expect(colChipArea.chipsList.toArray()[1].id).toBe(colChip1.id);

0 commit comments

Comments
 (0)