Skip to content

Commit

Permalink
test(treeGrid): add initial tests #3519
Browse files Browse the repository at this point in the history
  • Loading branch information
Tacho committed Jan 18, 2019
1 parent a2cc3c8 commit 91a3259
Show file tree
Hide file tree
Showing 2 changed files with 72 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import { DebugElement } from '@angular/core';
const HIGHLIGHT_CLASS = 'igx-highlight';
const ACTIVE_CLASS = 'igx-highlight__active';

describe('IgxTreeGrid - search API', () => {
fdescribe('IgxTreeGrid - search API', () => {
configureTestSuite();
let fix;
let fixNativeElement;
Expand All @@ -37,13 +37,60 @@ describe('IgxTreeGrid - search API', () => {
treeGrid.getColumnByName('JobTitle').autosize();
});

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

const spans = getHighlightSpans(fixNativeElement);
const activeSpan = getActiveSpan(fixNativeElement);
// Verify total number of occurrences in treeGrid.
verifySearchResult(fixNativeElement, actualCount, 10, 0);

// TODO
// Verify occurrences within a tree cell
const treeCell = TreeGridFunctions.getTreeCell(TreeGridFunctions.getAllRows(fix)[1]);
expect(treeCell.nativeElement.innerText.trim()).toBe('Software Developer Evangelist');

// Active highlight is in second tree cell.
let spans = getHighlightSpans(treeCell.nativeElement);
let activeSpan = getActiveSpan(treeCell.nativeElement);
expect(spans.length).toBe(2);
expect(activeSpan).toBe(spans[0]);

// Find next
actualCount = treeGrid.findNext('ev');

// Active highlight is still in second tree cell.
spans = getHighlightSpans(treeCell.nativeElement);
activeSpan = getActiveSpan(treeCell.nativeElement);
expect(spans.length).toBe(2);
expect(activeSpan).toBe(spans[1]);

// Find next
actualCount = treeGrid.findNext('ev');

// Active highlight is no longer in the second tree cell.
spans = getHighlightSpans(treeCell.nativeElement);
activeSpan = getActiveSpan(treeCell.nativeElement);
expect(spans.length).toBe(2);
expect(activeSpan).not.toBe(spans[0]);
expect(activeSpan).not.toBe(spans[1]);

const othertreeCell = TreeGridFunctions.getTreeCell(TreeGridFunctions.getAllRows(fix)[2]);
expect(othertreeCell.nativeElement.innerText.trim()).toBe('Junior Software Developer');

// Active highlight is now in the third tree cell.
spans = getHighlightSpans(othertreeCell.nativeElement);
activeSpan = getActiveSpan(othertreeCell.nativeElement);
expect(spans.length).toBe(1);
expect(activeSpan).toBe(spans[0]);
});

it('Search highlights should work for root and child rows', () => {
let actualCount = treeGrid.findNext('Software Developer');
verifySearchResult(fixNativeElement, actualCount, 6, 0);

actualCount = treeGrid.findNext('Software Developer');
verifySearchResult(fixNativeElement, actualCount, 6, 1);

actualCount = treeGrid.findPrev('Software Developer');
verifySearchResult(fixNativeElement, actualCount, 6, 0);
});

});
Expand All @@ -58,10 +105,23 @@ describe('IgxTreeGrid - search API', () => {
});
});

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

function getActiveSpan(parent: HTMLElement) {
return parent.querySelector('.' + ACTIVE_CLASS);
function getActiveSpan(nativeParent: HTMLElement) {
return nativeParent.querySelector('.' + ACTIVE_CLASS);
}

/**
* Verifies the results from a search execution by providing the actualSearchCount that is returned
* by the findNext/findPrev methods and the expected count and active index.
*/
function verifySearchResult(nativeParent, actualAPISearchCount, expectedHighlightSpansCount, expectedActiveSpanIndex) {
const spans = getHighlightSpans(nativeParent);
const activeSpan = getActiveSpan(nativeParent);

expect(actualAPISearchCount).toBe(expectedHighlightSpansCount, 'incorrect highlight elements count returned from api');
expect(spans.length).toBe(expectedHighlightSpansCount, 'incorrect highlight elements count');
expect(activeSpan).toBe(spans[expectedActiveSpanIndex], 'incorrect active element');
}
Original file line number Diff line number Diff line change
Expand Up @@ -1063,7 +1063,7 @@ export class SampleTestData {
Name: 'Michael Langdon',
HireDate: new Date(2011, 6, 3),
Age: 30,
JobTitle: 'Junior Software Developer',
JobTitle: 'Software Developer Evangelist',
Employees: null
},
{
Expand All @@ -1083,7 +1083,7 @@ export class SampleTestData {
Employees: [
{
ID: 711,
Name: 'Roland Mendel',
Name: 'Eva Mendel',
HireDate: new Date(2015, 9, 17),
JobTitle: 'Senior Software Developer',
Age: 35
Expand Down

0 comments on commit 91a3259

Please sign in to comment.