Skip to content

Commit

Permalink
test(hGrid): update test scenarios #4998
Browse files Browse the repository at this point in the history
  • Loading branch information
jackofdiamond5 committed Aug 29, 2019
1 parent fd58b83 commit 495c9e4
Show file tree
Hide file tree
Showing 3 changed files with 74 additions and 39 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -749,83 +749,109 @@ describe('IgxHierarchicalGrid selection #hGrid', () => {
firstLevelChild = fix.componentInstance.firstLevelChild;
}));

/** Tests should check root and child grids */

it('Row context `select` method selects a single row', () => {
// root grid
const firstRootRow = hGrid.getRowByIndex(0);
firstRootRow.nativeElement.click();
HelperUtils.rowCheckboxClick(firstRootRow);
fix.detectChanges();
HelperUtils.verifyRowSelected(hGrid.getRowByIndex(0));
HelperUtils.verifyHeaderRowCheckboxState(fix, false, true);

// child grid
HelperUtils.expandRowIsland(2);
fix.detectChanges();
const firstChildRow = firstLevelChild.getRowByIndex(0);
firstChildRow.nativeElement.click();

const childGrid = hGrid.hgridAPI.getChildGrids(false)[0];
const childRow = childGrid.getRowByIndex(0);
HelperUtils.rowCheckboxClick(childRow);
fix.detectChanges();

HelperUtils.verifyRowSelected(firstLevelChild.getRowByIndex(0));
HelperUtils.verifyHeaderRowCheckboxState(fix, false, true);
HelperUtils.verifyRowSelected(childRow);
HelperUtils.verifyHeaderRowCheckboxState(childGrid, false, true);
});

it('Row context `deselect` method deselects an already selected row', () => {
// root grid
const firstRootRow = hGrid.getRowByIndex(1);
HelperUtils.rowCheckboxClick(firstRootRow);
fix.detectChanges();

HelperUtils.verifyRowSelected(hGrid.getRowByIndex(1));
HelperUtils.verifyHeaderRowCheckboxState(fix, false, true);
HelperUtils.verifyRowSelected(firstRootRow);
HelperUtils.verifyHeaderRowCheckboxState(hGrid, false, true);

HelperUtils.rowCheckboxClick(firstRootRow);
fix.detectChanges();

HelperUtils.verifyRowSelected(hGrid.getRowByIndex(1), false);
HelperUtils.verifyHeaderRowCheckboxState(fix, false, false);
HelperUtils.verifyRowSelected(firstRootRow, false);
HelperUtils.verifyHeaderRowCheckboxState(hGrid, false, false);

// child grid
HelperUtils.expandRowIsland(2);
const firstLevelChildRow = firstLevelChild.getRowByIndex(0);
HelperUtils.rowCheckboxClick(firstLevelChildRow);
fix.detectChanges();

HelperUtils.verifyRowSelected(firstLevelChildRow);
HelperUtils.verifyHeaderRowCheckboxState(fix, false, true);
const childGrid = hGrid.hgridAPI.getChildGrids(false)[0];
const childRow = childGrid.getRowByIndex(0);

HelperUtils.rowCheckboxClick(firstLevelChildRow);
HelperUtils.rowCheckboxClick(childRow);
fix.detectChanges();
HelperUtils.verifyRowSelected(childRow);
HelperUtils.verifyHeaderRowCheckboxState(childGrid, false, true);

HelperUtils.verifyRowSelected(firstLevelChildRow, false);
HelperUtils.verifyHeaderRowCheckboxState(fix, false, false);
HelperUtils.rowCheckboxClick(childRow);
fix.detectChanges();
HelperUtils.verifyRowSelected(childRow, false);
HelperUtils.verifyHeaderRowCheckboxState(childGrid, false, false);
});

it('Header context `selectAll` method selects all rows', () => {
HelperUtils.clickHeaderRowCheckbox(fix);
// root grid
HelperUtils.headerCheckboxClick(hGrid);
fix.detectChanges();

HelperUtils.verifyHeaderRowCheckboxState(fix, true, false);
HelperUtils.verifyHeaderRowCheckboxState(hGrid, true, false);
expect(hGrid.selectionService.areAllRowSelected()).toBeTruthy();

// child grid
HelperUtils.expandRowIsland(2);
fix.detectChanges();

const childGrid = hGrid.hgridAPI.getChildGrids(false)[0];
HelperUtils.headerCheckboxClick(childGrid);
fix.detectChanges();

expect(childGrid.selectionService.areAllRowSelected()).toBeTruthy();
});

it('Header context `deselectAll` method deselects all rows', () => {
HelperUtils.clickHeaderRowCheckbox(fix);
// root grid
HelperUtils.headerCheckboxClick(hGrid);
fix.detectChanges();

HelperUtils.verifyHeaderRowCheckboxState(fix, true, false);
HelperUtils.verifyHeaderRowCheckboxState(hGrid, true, false);
expect(hGrid.selectionService.areAllRowSelected()).toBeTruthy();

HelperUtils.clickHeaderRowCheckbox(fix);
HelperUtils.clickHeaderRowCheckbox(hGrid);
fix.detectChanges();

HelperUtils.verifyHeaderRowCheckboxState(fix, false, false);
HelperUtils.verifyHeaderRowCheckboxState(hGrid, false, false);
expect(hGrid.selectionService.areAllRowSelected()).toBeFalsy();

// root grid
HelperUtils.expandRowIsland(2);
fix.detectChanges();

const childGrid = hGrid.hgridAPI.getChildGrids(false)[0];

HelperUtils.headerCheckboxClick(childGrid);
fix.detectChanges();
HelperUtils.verifyHeaderRowCheckboxState(childGrid, true, false);
expect(childGrid.selectionService.areAllRowSelected()).toBeTruthy();

HelperUtils.clickHeaderRowCheckbox(childGrid);
fix.detectChanges();
HelperUtils.verifyHeaderRowCheckboxState(childGrid, false, false);
expect(childGrid.selectionService.areAllRowSelected()).toBeFalsy();
});

it('Should have the correct properties in the custom row selector header template', () => {
it('Should have the correct properties in the custom row selector header template context', () => {
spyOn(fix.componentInstance, 'handleHeadSelectorClick').and.callThrough();
HelperUtils.headerCheckboxClick(fix);

HelperUtils.headerCheckboxClick(hGrid);
fix.detectChanges();

expect(fix.componentInstance.handleHeadSelectorClick).toHaveBeenCalledWith(new MouseEvent('click'), {
Expand All @@ -836,11 +862,10 @@ describe('IgxHierarchicalGrid selection #hGrid', () => {
});
});

it('Should have the correct properties in the custom row selector template', () => {
it('Should have the correct properties in the custom row selector template context', () => {
spyOn(fix.componentInstance, 'handleRowSelectorClick').and.callThrough();

const firstRootRow = hGrid.getRowByIndex(1);
HelperUtils.rowCheckboxClick(firstRootRow);
HelperUtils.rowCheckboxClick(hGrid.getRowByIndex(1));
fix.detectChanges();

expect(fix.componentInstance.handleRowSelectorClick).toHaveBeenCalledWith(new MouseEvent('click'), {
Expand All @@ -853,11 +878,20 @@ describe('IgxHierarchicalGrid selection #hGrid', () => {
});

it('Should have correct indices on all pages', () => {
// root grid
hGrid.nextPage();
fix.detectChanges();
expect(hGrid.getRowByIndex(0).nativeElement.querySelector('.rowNumber').textContent).toEqual('15');

const firstRootRow = hGrid.getRowByIndex(0);
expect(firstRootRow.nativeElement.querySelector('.rowNumber').textContent).toEqual('15');
// child grid
HelperUtils.expandRowIsland(3);
fix.detectChanges();

const childGrid = hGrid.hgridAPI.getChildGrids(false)[0];

childGrid.nextPage();
fix.detectChanges();
expect(childGrid.getRowByIndex(2).nativeElement.querySelector('.rowNumberChild').textContent).toEqual('17');
});
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -518,8 +518,8 @@ export class HelperUtils {
checkboxElement.click();
}

public static headerCheckboxClick(fix) {
HelperUtils.rowCheckboxClick(HelperUtils.getHeaderRow(fix));
public static headerCheckboxClick(parent) {
HelperUtils.rowCheckboxClick(HelperUtils.getHeaderRow(parent));
}
//

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ export class IgxHierarchicalGridRowSelectionNoTransactionsComponent {
[rowSelection]="'multiple'">
<igx-column field="ChildLevels"></igx-column>
<igx-column field="ProductName"></igx-column>
<igx-row-island [key]="'childData'" #rowIsland1 [primaryKey]="'ID'" [rowSelection]="'single'">
<igx-row-island [key]="'childData'" #rowIsland1 [paging]="true" [primaryKey]="'ID'" [rowSelection]="'single'">
<igx-column field="ChildLevels"></igx-column>
<igx-column field="ProductName"></igx-column>
<ng-template igxHeadSelector let-headContext>
Expand All @@ -133,6 +133,7 @@ export class IgxHierarchicalGridRowSelectionNoTransactionsComponent {
</igx-checkbox>
</ng-template>
<ng-template igxRowSelector let-rowContext>
<span class="rowNumberChild">{{ rowContext.index }}</span>
<igx-checkbox (click)="handleRowSelectorClick($event, rowContext)" [checked]="rowContext.selected">
</igx-checkbox>
</ng-template>
Expand Down

0 comments on commit 495c9e4

Please sign in to comment.