Skip to content

Commit 194bbb6

Browse files
refactor(test-utils): remove duplicate functions from helper-utils
1 parent bcc5ae0 commit 194bbb6

File tree

4 files changed

+64
-438
lines changed

4 files changed

+64
-438
lines changed

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

Lines changed: 38 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ import {
1414
IgxHierarchicalGridRowSelectionNoTransactionsComponent
1515
} from '../../test-utils/hierarhical-grid-components.spec';
1616
import { IgxRowSelectorsModule } from '../igx-row-selectors.module';
17-
import { HelperUtils } from '../../test-utils/helper-utils.spec';
1817
import { GridSelectionFunctions } from '../../test-utils/grid-functions.spec';
1918
import { GridSelectionMode } from '../types';
2019

@@ -757,106 +756,106 @@ describe('IgxHierarchicalGrid selection #hGrid', () => {
757756
it('Row context `select` method selects a single row', () => {
758757
// root grid
759758
const firstRootRow = hGrid.getRowByIndex(0);
760-
HelperUtils.rowCheckboxClick(firstRootRow);
759+
GridSelectionFunctions.clickRowCheckbox(firstRootRow);
761760
fix.detectChanges();
762-
HelperUtils.verifyRowSelected(hGrid.getRowByIndex(0));
763-
HelperUtils.verifyHeaderRowCheckboxState(fix, false, true);
761+
GridSelectionFunctions.verifyRowSelected(hGrid.getRowByIndex(0));
762+
GridSelectionFunctions.verifyHeaderRowCheckboxState(fix, false, true);
764763

765764
// child grid
766-
HelperUtils.expandRowIsland(2);
765+
GridSelectionFunctions.expandRowIsland(2);
767766
fix.detectChanges();
768767

769768
const childGrid = hGrid.hgridAPI.getChildGrids(false)[0];
770769
const childRow = childGrid.getRowByIndex(0);
771-
HelperUtils.rowCheckboxClick(childRow);
770+
GridSelectionFunctions.clickRowCheckbox(childRow);
772771
fix.detectChanges();
773772

774-
HelperUtils.verifyRowSelected(childRow);
775-
HelperUtils.verifyHeaderRowCheckboxState(childGrid, false, true);
773+
GridSelectionFunctions.verifyRowSelected(childRow);
774+
GridSelectionFunctions.verifyHeaderRowCheckboxState(childGrid, false, true);
776775
});
777776

778-
it('Row context `deselect` method deselects an already selected row', () => {
777+
it('Row context `deselect` method deselects an already selected row', fakeAsync(() => {
779778
// root grid
780779
const firstRootRow = hGrid.getRowByIndex(1);
781-
HelperUtils.rowCheckboxClick(firstRootRow);
780+
GridSelectionFunctions.clickRowCheckbox(firstRootRow);
782781
fix.detectChanges();
783-
HelperUtils.verifyRowSelected(firstRootRow);
784-
HelperUtils.verifyHeaderRowCheckboxState(hGrid, false, true);
782+
GridSelectionFunctions.verifyRowSelected(firstRootRow);
783+
GridSelectionFunctions.verifyHeaderRowCheckboxState(hGrid, false, true);
785784

786-
HelperUtils.rowCheckboxClick(firstRootRow);
785+
GridSelectionFunctions.clickRowCheckbox(firstRootRow);
787786
fix.detectChanges();
788-
HelperUtils.verifyRowSelected(firstRootRow, false);
789-
HelperUtils.verifyHeaderRowCheckboxState(hGrid, false, false);
787+
GridSelectionFunctions.verifyRowSelected(firstRootRow, false);
788+
GridSelectionFunctions.verifyHeaderRowCheckboxState(hGrid, false, false);
790789

791790
// child grid
792-
HelperUtils.expandRowIsland(2);
791+
GridSelectionFunctions.expandRowIsland(2);
793792
fix.detectChanges();
794793

795794
const childGrid = hGrid.hgridAPI.getChildGrids(false)[0];
796795
const childRow = childGrid.getRowByIndex(0);
797796

798-
HelperUtils.rowCheckboxClick(childRow);
797+
GridSelectionFunctions.clickRowCheckbox(childRow);
799798
fix.detectChanges();
800-
HelperUtils.verifyRowSelected(childRow);
801-
HelperUtils.verifyHeaderRowCheckboxState(childGrid, false, true);
799+
GridSelectionFunctions.verifyRowSelected(childRow);
800+
GridSelectionFunctions.verifyHeaderRowCheckboxState(childGrid, false, true);
802801

803-
HelperUtils.rowCheckboxClick(childRow);
802+
GridSelectionFunctions.clickRowCheckbox(childRow);
804803
fix.detectChanges();
805-
HelperUtils.verifyRowSelected(childRow, false);
806-
HelperUtils.verifyHeaderRowCheckboxState(childGrid, false, false);
807-
});
804+
GridSelectionFunctions.verifyRowSelected(childRow, false);
805+
GridSelectionFunctions.verifyHeaderRowCheckboxState(childGrid, false, false);
806+
}));
808807

809808
it('Header context `selectAll` method selects all rows', () => {
810809
// root grid
811-
HelperUtils.clickHeaderRowCheckbox(hGrid);
810+
GridSelectionFunctions.clickHeaderRowCheckbox(hGrid);
812811
fix.detectChanges();
813-
HelperUtils.verifyHeaderRowCheckboxState(hGrid, true, false);
812+
GridSelectionFunctions.verifyHeaderRowCheckboxState(hGrid, true, false);
814813
expect(hGrid.selectionService.areAllRowSelected()).toBeTruthy();
815814

816815
// child grid
817-
HelperUtils.expandRowIsland(2);
816+
GridSelectionFunctions.expandRowIsland(2);
818817
fix.detectChanges();
819818

820819
const childGrid = hGrid.hgridAPI.getChildGrids(false)[0];
821-
HelperUtils.clickHeaderRowCheckbox(childGrid);
820+
GridSelectionFunctions.clickHeaderRowCheckbox(childGrid);
822821
fix.detectChanges();
823822

824823
expect(childGrid.selectionService.areAllRowSelected()).toBeTruthy();
825824
});
826825

827826
it('Header context `deselectAll` method deselects all rows', () => {
828827
// root grid
829-
HelperUtils.clickHeaderRowCheckbox(hGrid);
828+
GridSelectionFunctions.clickHeaderRowCheckbox(hGrid);
830829
fix.detectChanges();
831-
HelperUtils.verifyHeaderRowCheckboxState(hGrid, true, false);
830+
GridSelectionFunctions.verifyHeaderRowCheckboxState(hGrid, true, false);
832831
expect(hGrid.selectionService.areAllRowSelected()).toBeTruthy();
833832

834-
HelperUtils.clickHeaderRowCheckbox(hGrid);
833+
GridSelectionFunctions.clickHeaderRowCheckbox(hGrid);
835834
fix.detectChanges();
836-
HelperUtils.verifyHeaderRowCheckboxState(hGrid, false, false);
835+
GridSelectionFunctions.verifyHeaderRowCheckboxState(hGrid, false, false);
837836
expect(hGrid.selectionService.areAllRowSelected()).toBeFalsy();
838837

839838
// child grid
840-
HelperUtils.expandRowIsland(2);
839+
GridSelectionFunctions.expandRowIsland(2);
841840
fix.detectChanges();
842841

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

845-
HelperUtils.clickHeaderRowCheckbox(childGrid);
844+
GridSelectionFunctions.clickHeaderRowCheckbox(childGrid);
846845
fix.detectChanges();
847-
HelperUtils.verifyHeaderRowCheckboxState(childGrid, true, false);
846+
GridSelectionFunctions.verifyHeaderRowCheckboxState(childGrid, true, false);
848847
expect(childGrid.selectionService.areAllRowSelected()).toBeTruthy();
849848

850-
HelperUtils.clickHeaderRowCheckbox(childGrid);
849+
GridSelectionFunctions.clickHeaderRowCheckbox(childGrid);
851850
fix.detectChanges();
852-
HelperUtils.verifyHeaderRowCheckboxState(childGrid, false, false);
851+
GridSelectionFunctions.verifyHeaderRowCheckboxState(childGrid, false, false);
853852
expect(childGrid.selectionService.areAllRowSelected()).toBeFalsy();
854853
});
855854

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

859-
HelperUtils.headerCheckboxClick(hGrid);
858+
GridSelectionFunctions.headerCheckboxClick(hGrid);
860859
fix.detectChanges();
861860

862861
expect(fix.componentInstance.handleHeadSelectorClick).toHaveBeenCalledWith(new MouseEvent('click'), {
@@ -870,7 +869,7 @@ describe('IgxHierarchicalGrid selection #hGrid', () => {
870869
it('Should have the correct properties in the custom row selector template context', () => {
871870
spyOn(fix.componentInstance, 'handleRowSelectorClick').and.callThrough();
872871

873-
HelperUtils.rowCheckboxClick(hGrid.getRowByIndex(1));
872+
GridSelectionFunctions.rowCheckboxClick(hGrid.getRowByIndex(1));
874873
fix.detectChanges();
875874

876875
expect(fix.componentInstance.handleRowSelectorClick).toHaveBeenCalledWith(new MouseEvent('click'), {
@@ -889,7 +888,7 @@ describe('IgxHierarchicalGrid selection #hGrid', () => {
889888
expect(hGrid.getRowByIndex(0).nativeElement.querySelector('.rowNumber').textContent).toEqual('15');
890889

891890
// child grid
892-
HelperUtils.expandRowIsland(3);
891+
GridSelectionFunctions.expandRowIsland(3);
893892
fix.detectChanges();
894893

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

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

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,8 @@ const HEADER_ROW_CSS_CLASS = '.igx-grid__thead';
3333
const CHECKBOX_INPUT_CSS_CLASS = '.igx-checkbox__input';
3434
const SCROLL_START_CSS_CLASS = '.igx-grid__scroll-start';
3535
const CHECKBOX_ELEMENT = 'igx-checkbox';
36+
const ICON_CSS_CLASS = 'material-icons igx-icon';
37+
const CHECKBOX_LBL_CSS_CLASS = '.igx-checkbox__composite';
3638
const DEBOUNCETIME = 50;
3739

3840
export class GridFunctions {
@@ -1280,4 +1282,21 @@ export class GridSelectionFunctions {
12801282
const checkboxElement = GridSelectionFunctions.getRowCheckboxDiv(GridSelectionFunctions.getHeaderRow(parent));
12811283
checkboxElement.dispatchEvent(new Event('click', {}));
12821284
}
1285+
1286+
// select - deselect a checkbox without a handler
1287+
public static rowCheckboxClick(row) {
1288+
const checkboxElement = row.nativeElement ?
1289+
row.nativeElement.querySelector(CHECKBOX_LBL_CSS_CLASS) :
1290+
row.querySelector(CHECKBOX_LBL_CSS_CLASS);
1291+
checkboxElement.click();
1292+
}
1293+
1294+
public static headerCheckboxClick(parent) {
1295+
GridSelectionFunctions.rowCheckboxClick(GridSelectionFunctions.getHeaderRow(parent));
1296+
}
1297+
//
1298+
1299+
public static expandRowIsland(rowNumber = 1) {
1300+
(<any>document.getElementsByClassName(ICON_CSS_CLASS)[rowNumber]).click();
1301+
}
12831302
}

0 commit comments

Comments
 (0)