Skip to content

Commit

Permalink
test(treeGrid): add search helper methods #3519
Browse files Browse the repository at this point in the history
  • Loading branch information
Tacho committed Jan 18, 2019
1 parent 4e37998 commit a2cc3c8
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,16 @@ import { TreeGridFunctions } from '../../test-utils/tree-grid-functions.spec';
import { IgxTreeGridSearchComponent, IgxTreeGridPrimaryForeignKeyComponent } from '../../test-utils/tree-grid-components.spec';
import { NoopAnimationsModule } from '@angular/platform-browser/animations';
import { configureTestSuite } from '../../test-utils/configure-suite';
import { By } from '@angular/platform-browser';
import { DebugElement } from '@angular/core';

const HIGHLIGHT_CLASS = 'igx-highlight';
const ACTIVE_CLASS = 'igx-highlight__active';

describe('IgxTreeGrid - search API', () => {
configureTestSuite();
let fix;
let fixNativeElement;
let treeGrid: IgxTreeGridComponent;

beforeEach(async(() => {
Expand All @@ -26,7 +31,19 @@ describe('IgxTreeGrid - search API', () => {
beforeEach(() => {
fix = TestBed.createComponent(IgxTreeGridSearchComponent);
fix.detectChanges();
fixNativeElement = fix.debugElement.nativeElement;
treeGrid = fix.componentInstance.treeGrid;

treeGrid.getColumnByName('JobTitle').autosize();
});

it('Search highlights should work for tree cells', () => {
const searchCount = treeGrid.findNext('QA');

const spans = getHighlightSpans(fixNativeElement);
const activeSpan = getActiveSpan(fixNativeElement);

// TODO
});

});
Expand All @@ -40,3 +57,11 @@ describe('IgxTreeGrid - search API', () => {

});
});

function getHighlightSpans(parent: HTMLElement) {
return parent.querySelectorAll('.' + HIGHLIGHT_CLASS);
}

function getActiveSpan(parent: HTMLElement) {
return parent.querySelector('.' + ACTIVE_CLASS);
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,12 @@ export class TreeGridFunctions {
return rowDOM.query(By.css('igx-tree-grid-cell'));
}

public static getCell(fix, rowIndex, columnKey) {
const rowDOM = TreeGridFunctions.sortElementsVertically(TreeGridFunctions.getAllRows(fix))[rowIndex];
const rowCells = [TreeGridFunctions.getTreeCell(rowDOM)].concat(TreeGridFunctions.getNormalCells(rowDOM));
return rowCells.filter((DOMcell) => DOMcell.componentInstance.column.field === columnKey)[0];
}

public static getTreeCells(fix) {
return fix.debugElement.queryAll(By.css('igx-tree-grid-cell'));
}
Expand Down

0 comments on commit a2cc3c8

Please sign in to comment.