|
| 1 | +import { TestBed, fakeAsync, ComponentFixture } from '@angular/core/testing'; |
| 2 | +import { By } from '@angular/platform-browser'; |
| 3 | +import { NoopAnimationsModule } from '@angular/platform-browser/animations'; |
| 4 | +import { IgxPivotGridComponent, IgxPivotGridModule } from 'igniteui-angular'; |
| 5 | +import { configureTestSuite } from '../../test-utils/configure-suite'; |
| 6 | +import { GridFunctions } from '../../test-utils/grid-functions.spec'; |
| 7 | +import { IgxPivotGridMultipleRowComponent } from '../../test-utils/pivot-grid-samples.spec'; |
| 8 | +import { UIInteractions, wait } from '../../test-utils/ui-interactions.spec'; |
| 9 | + |
| 10 | +const DEBOUNCE_TIME = 250; |
| 11 | +const PIVOT_TBODY_CSS_CLASS = '.igx-grid__tbody'; |
| 12 | +const PIVOT_ROW_DIMENSION_CONTENT = 'igx-pivot-row-dimension-content'; |
| 13 | +const PIVOT_HEADER_ROW = 'igx-pivot-header-row'; |
| 14 | +const HEADER_CELL_CSS_CLASS = '.igx-grid-th'; |
| 15 | +const ACTIVE_CELL_CSS_CLASS = '.igx-grid-th--active'; |
| 16 | + |
| 17 | +describe('IgxPivotGrid - Keyboard navigation #pivotGrid', () => { |
| 18 | + |
| 19 | + let fixture: ComponentFixture<IgxPivotGridMultipleRowComponent>; |
| 20 | + let pivotGrid: IgxPivotGridComponent; |
| 21 | + configureTestSuite((() => { |
| 22 | + TestBed.configureTestingModule({ |
| 23 | + declarations: [ |
| 24 | + IgxPivotGridMultipleRowComponent |
| 25 | + ], |
| 26 | + imports: [ |
| 27 | + NoopAnimationsModule, IgxPivotGridModule] |
| 28 | + }); |
| 29 | + })); |
| 30 | + |
| 31 | + beforeEach(fakeAsync(() => { |
| 32 | + fixture = TestBed.createComponent(IgxPivotGridMultipleRowComponent); |
| 33 | + fixture.detectChanges(); |
| 34 | + pivotGrid = fixture.componentInstance.pivotGrid; |
| 35 | + })); |
| 36 | + |
| 37 | + it('should allow navigating between row headers', () => { |
| 38 | + const [firstCell, secondCell] = fixture.debugElement.queryAll( |
| 39 | + By.css(`${PIVOT_TBODY_CSS_CLASS} ${PIVOT_ROW_DIMENSION_CONTENT} ${HEADER_CELL_CSS_CLASS}`)); |
| 40 | + UIInteractions.simulateClickAndSelectEvent(firstCell); |
| 41 | + fixture.detectChanges(); |
| 42 | + |
| 43 | + GridFunctions.verifyHeaderIsFocused(firstCell.parent); |
| 44 | + let activeCells = fixture.debugElement.queryAll(By.css(`${ACTIVE_CELL_CSS_CLASS}`)); |
| 45 | + expect(activeCells.length).toBe(1); |
| 46 | + |
| 47 | + UIInteractions.triggerKeyDownEvtUponElem('ArrowRight', firstCell.nativeElement); |
| 48 | + fixture.detectChanges(); |
| 49 | + GridFunctions.verifyHeaderIsFocused(secondCell.parent); |
| 50 | + activeCells = fixture.debugElement.queryAll(By.css(`${ACTIVE_CELL_CSS_CLASS}`)); |
| 51 | + expect(activeCells.length).toBe(1); |
| 52 | + }); |
| 53 | + |
| 54 | + it('should not go outside of the boundaries of the row dimensions content', () => { |
| 55 | + const [firstCell, _, thirdCell] = fixture.debugElement.queryAll( |
| 56 | + By.css(`${PIVOT_TBODY_CSS_CLASS} ${PIVOT_ROW_DIMENSION_CONTENT} ${HEADER_CELL_CSS_CLASS}`)); |
| 57 | + UIInteractions.simulateClickAndSelectEvent(firstCell); |
| 58 | + fixture.detectChanges(); |
| 59 | + |
| 60 | + UIInteractions.triggerKeyDownEvtUponElem('ArrowLeft', firstCell.nativeElement); |
| 61 | + fixture.detectChanges(); |
| 62 | + |
| 63 | + GridFunctions.verifyHeaderIsFocused(firstCell.parent); |
| 64 | + let activeCells = fixture.debugElement.queryAll(By.css(`${ACTIVE_CELL_CSS_CLASS}`)); |
| 65 | + expect(activeCells.length).toBe(1); |
| 66 | + |
| 67 | + UIInteractions.simulateClickAndSelectEvent(thirdCell); |
| 68 | + fixture.detectChanges(); |
| 69 | + |
| 70 | + UIInteractions.triggerKeyDownEvtUponElem('ArrowRight', thirdCell.nativeElement); |
| 71 | + fixture.detectChanges(); |
| 72 | + |
| 73 | + GridFunctions.verifyHeaderIsFocused(thirdCell.parent); |
| 74 | + activeCells = fixture.debugElement.queryAll(By.css(`${ACTIVE_CELL_CSS_CLASS}`)); |
| 75 | + expect(activeCells.length).toBe(1); |
| 76 | + }); |
| 77 | + |
| 78 | + it('should allow navigating from first to last row headers in a row(Home/End)', () => { |
| 79 | + const [firstCell, _, thirdCell] = fixture.debugElement.queryAll( |
| 80 | + By.css(`${PIVOT_TBODY_CSS_CLASS} ${PIVOT_ROW_DIMENSION_CONTENT} ${HEADER_CELL_CSS_CLASS}`)); |
| 81 | + UIInteractions.simulateClickAndSelectEvent(firstCell); |
| 82 | + fixture.detectChanges(); |
| 83 | + |
| 84 | + UIInteractions.triggerKeyDownEvtUponElem('End', firstCell.nativeElement); |
| 85 | + fixture.detectChanges(); |
| 86 | + GridFunctions.verifyHeaderIsFocused(thirdCell.parent); |
| 87 | + let activeCells = fixture.debugElement.queryAll(By.css(`${ACTIVE_CELL_CSS_CLASS}`)); |
| 88 | + expect(activeCells.length).toBe(1); |
| 89 | + |
| 90 | + UIInteractions.triggerKeyDownEvtUponElem('Home', thirdCell.nativeElement); |
| 91 | + fixture.detectChanges(); |
| 92 | + GridFunctions.verifyHeaderIsFocused(firstCell.parent); |
| 93 | + activeCells = fixture.debugElement.queryAll(By.css(`${ACTIVE_CELL_CSS_CLASS}`)); |
| 94 | + expect(activeCells.length).toBe(1); |
| 95 | + }); |
| 96 | + |
| 97 | + it('should allow navigating from first to last row headers(Ctrl + ArrowDown)', () => { |
| 98 | + const [_firstCell, _secondCell, thirdCell] = fixture.debugElement.queryAll( |
| 99 | + By.css(`${PIVOT_TBODY_CSS_CLASS} ${PIVOT_ROW_DIMENSION_CONTENT} ${HEADER_CELL_CSS_CLASS}`)); |
| 100 | + UIInteractions.simulateClickAndSelectEvent(thirdCell); |
| 101 | + fixture.detectChanges(); |
| 102 | + |
| 103 | + UIInteractions.triggerKeyDownEvtUponElem('ArrowDown', thirdCell.nativeElement, true, false, false, true); |
| 104 | + fixture.detectChanges(); |
| 105 | + |
| 106 | + const allCells = fixture.debugElement.queryAll( |
| 107 | + By.css(`${PIVOT_TBODY_CSS_CLASS} ${PIVOT_ROW_DIMENSION_CONTENT} ${HEADER_CELL_CSS_CLASS}`)); |
| 108 | + const lastCell = allCells[allCells.length - 1]; |
| 109 | + GridFunctions.verifyHeaderIsFocused(lastCell.parent); |
| 110 | + const activeCells = fixture.debugElement.queryAll(By.css(`${ACTIVE_CELL_CSS_CLASS}`)); |
| 111 | + expect(activeCells.length).toBe(1); |
| 112 | + }); |
| 113 | + |
| 114 | + it('should allow navigating between column headers', () => { |
| 115 | + const [firstHeader, secondHeader] = fixture.debugElement.queryAll( |
| 116 | + By.css(`${PIVOT_HEADER_ROW} ${HEADER_CELL_CSS_CLASS}`)); |
| 117 | + UIInteractions.simulateClickAndSelectEvent(firstHeader); |
| 118 | + fixture.detectChanges(); |
| 119 | + |
| 120 | + GridFunctions.verifyHeaderIsFocused(firstHeader.parent); |
| 121 | + let activeCells = fixture.debugElement.queryAll(By.css(`${ACTIVE_CELL_CSS_CLASS}`)); |
| 122 | + expect(activeCells.length).toBe(1); |
| 123 | + |
| 124 | + UIInteractions.triggerKeyDownEvtUponElem('ArrowRight', firstHeader.nativeElement); |
| 125 | + fixture.detectChanges(); |
| 126 | + GridFunctions.verifyHeaderIsFocused(secondHeader.parent); |
| 127 | + activeCells = fixture.debugElement.queryAll(By.css(`${ACTIVE_CELL_CSS_CLASS}`)); |
| 128 | + expect(activeCells.length).toBe(1); |
| 129 | + }); |
| 130 | + |
| 131 | + it('should allow navigating from first to last column headers', async () => { |
| 132 | + const [firstHeader] = fixture.debugElement.queryAll( |
| 133 | + By.css(`${PIVOT_HEADER_ROW} ${HEADER_CELL_CSS_CLASS}`)); |
| 134 | + UIInteractions.simulateClickAndSelectEvent(firstHeader); |
| 135 | + fixture.detectChanges(); |
| 136 | + |
| 137 | + GridFunctions.verifyHeaderIsFocused(firstHeader.parent); |
| 138 | + let activeCells = fixture.debugElement.queryAll(By.css(`${ACTIVE_CELL_CSS_CLASS}`)); |
| 139 | + expect(activeCells.length).toBe(1); |
| 140 | + |
| 141 | + UIInteractions.triggerKeyDownEvtUponElem('End', pivotGrid.theadRow.nativeElement); |
| 142 | + await wait(DEBOUNCE_TIME); |
| 143 | + fixture.detectChanges(); |
| 144 | + |
| 145 | + const allHeaders = fixture.debugElement.queryAll( |
| 146 | + By.css(`${PIVOT_HEADER_ROW} ${HEADER_CELL_CSS_CLASS}`)); |
| 147 | + const lastHeader = allHeaders[allHeaders.length - 1]; |
| 148 | + GridFunctions.verifyHeaderIsFocused(lastHeader.parent); |
| 149 | + activeCells = fixture.debugElement.queryAll(By.css(`${ACTIVE_CELL_CSS_CLASS}`)); |
| 150 | + expect(activeCells.length).toBe(1); |
| 151 | + }); |
| 152 | + |
| 153 | + it('should allow navigating in column headers when switching focus from rows to columns', () => { |
| 154 | + const [firstCell] = fixture.debugElement.queryAll( |
| 155 | + By.css(`${PIVOT_TBODY_CSS_CLASS} ${PIVOT_ROW_DIMENSION_CONTENT} ${HEADER_CELL_CSS_CLASS}`)); |
| 156 | + UIInteractions.simulateClickAndSelectEvent(firstCell); |
| 157 | + fixture.detectChanges(); |
| 158 | + |
| 159 | + const [firstHeader, secondHeader] = fixture.debugElement.queryAll( |
| 160 | + By.css(`${PIVOT_HEADER_ROW} ${HEADER_CELL_CSS_CLASS}`)); |
| 161 | + UIInteractions.simulateClickAndSelectEvent(firstHeader); |
| 162 | + fixture.detectChanges(); |
| 163 | + |
| 164 | + GridFunctions.verifyHeaderIsFocused(firstHeader.parent); |
| 165 | + let activeCells = fixture.debugElement.queryAll(By.css(`${ACTIVE_CELL_CSS_CLASS}`)); |
| 166 | + expect(activeCells.length).toBe(1); |
| 167 | + |
| 168 | + UIInteractions.triggerKeyDownEvtUponElem('ArrowRight', firstHeader.nativeElement); |
| 169 | + fixture.detectChanges(); |
| 170 | + GridFunctions.verifyHeaderIsFocused(secondHeader.parent); |
| 171 | + activeCells = fixture.debugElement.queryAll(By.css(`${ACTIVE_CELL_CSS_CLASS}`)); |
| 172 | + expect(activeCells.length).toBe(1); |
| 173 | + }); |
| 174 | +}); |
0 commit comments