Skip to content

Commit 882f6d7

Browse files
MKirovaMKirova
MKirova
authored and
MKirova
committed
chore(*): Adding kb up/down tests.
1 parent bbed683 commit 882f6d7

File tree

2 files changed

+143
-1
lines changed

2 files changed

+143
-1
lines changed

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

+137-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Component, ViewChild, EventEmitter } from '@angular/core';
1+
import { Component, ViewChild, EventEmitter, OnInit } from '@angular/core';
22
import { async, TestBed, ComponentFixture } from '@angular/core/testing';
33
import { configureTestSuite } from '../../test-utils/configure-suite';
44
import { NoopAnimationsModule } from '@angular/platform-browser/animations';
@@ -12,6 +12,7 @@ import { GridFunctions } from '../../test-utils/grid-functions.spec';
1212

1313
const COLLAPSED_ICON_NAME = 'chevron_right';
1414
const EXPANDED_ICON_NAME = 'expand_more';
15+
const DEBOUNCETIME = 30;
1516

1617
describe('IgxGrid Master Detail', () => {
1718
let fix: ComponentFixture<any>;
@@ -129,6 +130,106 @@ describe('IgxGrid Master Detail', () => {
129130
});
130131
});
131132
});
133+
134+
describe('Keyboard Navigation ', () => {
135+
configureTestSuite();
136+
beforeEach(async(() => {
137+
TestBed.configureTestingModule({
138+
declarations: [
139+
AllExpandedGridMasterDetailComponent
140+
],
141+
imports: [IgxGridModule, NoopAnimationsModule]
142+
}).compileComponents();
143+
}));
144+
145+
beforeEach(async(() => {
146+
fix = TestBed.createComponent(AllExpandedGridMasterDetailComponent);
147+
fix.detectChanges();
148+
grid = fix.componentInstance.grid;
149+
}));
150+
151+
it('Should navigate down through a detail view by focusing the whole row and continuing onto the next with arrow down.',
152+
async() => {
153+
const targetCellElement = grid.getCellByColumn(0, 'ContactName');
154+
UIInteractions.triggerKeyDownEvtUponElem('arrowdown', targetCellElement, true);
155+
await wait(DEBOUNCETIME);
156+
fix.detectChanges();
157+
const firstRowDetail = GridFunctions.getMasterRowDetail(grid.rowList.first);
158+
expect(document.activeElement).toBe(firstRowDetail);
159+
UIInteractions.triggerKeyDownEvtUponElem('arrowdown', firstRowDetail, true);
160+
await wait(DEBOUNCETIME);
161+
fix.detectChanges();
162+
expect(grid.getCellByColumn(2, 'ContactName').selected).toBeTruthy();
163+
});
164+
165+
it('Should navigate down through a detail view partially out of view by scrolling it so it becomes fully visible.', async() => {
166+
const row = grid.getRowByIndex(4) as IgxGridRowComponent;
167+
const targetCellElement = grid.getCellByColumn(4, 'ContactName');
168+
UIInteractions.triggerKeyDownEvtUponElem('arrowdown', targetCellElement, true);
169+
await wait(DEBOUNCETIME);
170+
fix.detectChanges();
171+
const detailRow = GridFunctions.getMasterRowDetail(row);
172+
expect(document.activeElement).toBe(detailRow);
173+
expect(GridFunctions.elementInGridView(grid, detailRow)).toBeTruthy();
174+
});
175+
it('Should navigate down through a detail view completely out of view by scrolling to it.', async() => {
176+
grid.navigateTo(6, 0);
177+
await wait(DEBOUNCETIME);
178+
fix.detectChanges();
179+
const row = grid.getRowByIndex(6) as IgxGridRowComponent;
180+
const targetCellElement = grid.getCellByColumn(6, 'ContactName');
181+
UIInteractions.triggerKeyDownEvtUponElem('arrowdown', targetCellElement, true);
182+
await wait(DEBOUNCETIME);
183+
fix.detectChanges();
184+
const detailRow = GridFunctions.getMasterRowDetail(row);
185+
expect(document.activeElement).toBe(detailRow);
186+
expect(GridFunctions.elementInGridView(grid, detailRow)).toBeTruthy();
187+
});
188+
189+
it('Should navigate up through a detail view by focusing the whole row and continuing onto the next with arrow up.', async() => {
190+
const prevRow = grid.getRowByIndex(0) as IgxGridRowComponent;
191+
const targetCellElement = grid.getCellByColumn(2, 'ContactName');
192+
UIInteractions.triggerKeyDownEvtUponElem('arrowup', targetCellElement, true);
193+
await wait(DEBOUNCETIME);
194+
fix.detectChanges();
195+
const detailRow = GridFunctions.getMasterRowDetail(prevRow);
196+
expect(document.activeElement).toBe(detailRow);
197+
UIInteractions.triggerKeyDownEvtUponElem('arrowup', detailRow, true);
198+
await wait(DEBOUNCETIME);
199+
fix.detectChanges();
200+
expect(prevRow.cells.toArray()[0].selected).toBeTruthy();
201+
});
202+
203+
it('Should navigate up through a detail view partially out of view by scrolling it so it becomes fully visible.', async() => {
204+
grid.verticalScrollContainer.addScrollTop(90);
205+
await wait(DEBOUNCETIME);
206+
fix.detectChanges();
207+
const row = grid.getRowByIndex(2);
208+
const targetCellElement = grid.getCellByColumn(2, 'ContactName');
209+
UIInteractions.triggerKeyDownEvtUponElem('arrowup', targetCellElement, true);
210+
await wait(DEBOUNCETIME);
211+
fix.detectChanges();
212+
const detailRow = row.element.nativeElement.previousElementSibling;
213+
expect(document.activeElement).toBe(detailRow);
214+
expect(GridFunctions.elementInGridView(grid, detailRow)).toBeTruthy();
215+
});
216+
217+
it('Should navigate up through a detail view completely out of view by scrolling to it.', async() => {
218+
grid.verticalScrollContainer.addScrollTop(170);
219+
await wait(DEBOUNCETIME);
220+
fix.detectChanges();
221+
const row = grid.getRowByIndex(2);
222+
const targetCellElement = grid.getCellByColumn(2, 'ContactName');
223+
UIInteractions.triggerKeyDownEvtUponElem('arrowup', targetCellElement, true);
224+
await wait(DEBOUNCETIME);
225+
fix.detectChanges();
226+
const detailRow = row.element.nativeElement.previousElementSibling;
227+
expect(document.activeElement).toBe(detailRow);
228+
expect(GridFunctions.elementInGridView(grid, detailRow)).toBeTruthy();
229+
});
230+
231+
232+
});
132233
});
133234

134235
@Component({
@@ -173,3 +274,38 @@ export class DefaultGridMasterDetailComponent {
173274
this.checkboxChanged.emit({ event: event, context: context });
174275
}
175276
}
277+
278+
@Component({
279+
template: `
280+
<igx-grid [data]="data" [expansionStates]='expStates'
281+
[width]="width" [height]="height" [primaryKey]="'ID'" [paging]="paging" [rowSelectable]="rowSelectable">
282+
<igx-column *ngFor="let c of columns" [field]="c.field" [header]="c.field" [width]="c.width" [dataType]='c.dataType'
283+
[hidden]='c.hidden' [sortable]="c.sortable" [movable]='c.movable' [groupable]='c.groupable' [editable]="c.editable"
284+
[hasSummary]="c.hasSummary" [pinned]='c.pinned'>
285+
</igx-column>
286+
287+
<ng-template igxGridDetail let-dataItem>
288+
<div>
289+
<div class="checkboxArea">
290+
<igx-checkbox (change)="onCheckboxClicked($event, dataItem)" [disableRipple]="true"></igx-checkbox>
291+
<span style="font-weight: 600">Available</span>
292+
</div>
293+
<div class="addressArea">{{dataItem.Address}}</div>
294+
<div class="inputArea"><input type="text" name="Comment"></div>
295+
</div>
296+
</ng-template>
297+
</igx-grid>
298+
`
299+
})
300+
export class AllExpandedGridMasterDetailComponent extends DefaultGridMasterDetailComponent implements OnInit {
301+
public expStates = new Map<any, boolean>();
302+
ngOnInit(): void {
303+
const allExpanded = new Map<any, boolean>();
304+
this.data.forEach(item => {
305+
allExpanded.set(item['ID'], true);
306+
});
307+
this.expStates = allExpanded;
308+
}
309+
310+
311+
}

projects/igniteui-angular/src/lib/test-utils/grid-functions.spec.ts

+6
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,12 @@ export class GridFunctions {
171171
grid.expansionStates = allExpanded;
172172
}
173173

174+
public static elementInGridView(grid, element) : boolean {
175+
const gridBottom = grid.tbody.nativeElement.getBoundingClientRect().bottom;
176+
const gridTop = grid.tbody.nativeElement.getBoundingClientRect().top;
177+
return element.getBoundingClientRect().top >= gridTop && element.getBoundingClientRect().bottom <= gridBottom;
178+
}
179+
174180
public static expandMasterRowByClick = (fix, row: IgxGridRowComponent) => new Promise(async (resolve, reject) => {
175181
const icon = row.element.nativeElement.querySelector('igx-icon');
176182
UIInteractions.clickElement(icon.parentElement);

0 commit comments

Comments
 (0)