Skip to content

Commit 879f277

Browse files
author
Radko Kolev
committed
test(tree-grid): adding more tree-grid tests #2530
1 parent 88071bb commit 879f277

File tree

1 file changed

+237
-3
lines changed

1 file changed

+237
-3
lines changed

Diff for: projects/igniteui-angular/src/lib/grids/tree-grid/tree-grid-expanding.spec.ts

+237-3
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import { TreeGridFunctions } from '../../test-utils/tree-grid-functions.spec';
66
import { configureTestSuite } from '../../test-utils/configure-suite';
77
import { first } from 'rxjs/operators';
88

9-
describe('IgxTreeGrid - Expanding / Collapsing', () => {
9+
fdescribe('IgxTreeGrid - Expanding / Collapsing', () => {
1010
configureTestSuite();
1111
let fix;
1212
let treeGrid;
@@ -214,6 +214,21 @@ describe('IgxTreeGrid - Expanding / Collapsing', () => {
214214
expect(rows.length).toBe(4, 'root level row collapsing problem');
215215
});
216216

217+
it('should expand/collapse when using \'expandAll\' and \'collapseAll\' methods', () => {
218+
treeGrid.perPage = 50;
219+
220+
let rows = TreeGridFunctions.getAllRows(fix);
221+
expect(rows.length).toBe(4);
222+
223+
treeGrid.expandAll();
224+
rows = TreeGridFunctions.getAllRows(fix);
225+
expect(rows.length).toBe(12);
226+
227+
treeGrid.collapseAll();
228+
rows = TreeGridFunctions.getAllRows(fix);
229+
expect(rows.length).toBe(4);
230+
});
231+
217232
it('should emits an event when expanding rows (API)', (done) => {
218233
const aRow = treeGrid.getRowByIndex(0);
219234
treeGrid.onRowToggle.pipe(first()).subscribe((args) => {
@@ -305,7 +320,7 @@ describe('IgxTreeGrid - Expanding / Collapsing', () => {
305320
fix.detectChanges();
306321
});
307322

308-
it('check row expanding and collapsing are changing rows count using flat data source (UI)', () => {
323+
it('check row expanding and collapsing are changing rows count (UI)', () => {
309324
let rows = TreeGridFunctions.getAllRows(fix);
310325
expect(rows.length).toBe(3);
311326

@@ -321,7 +336,7 @@ describe('IgxTreeGrid - Expanding / Collapsing', () => {
321336
expect(rows.length).toBe(3);
322337
});
323338

324-
it('check row expanding and collapsing are changing rows count using flat data source (API)', () => {
339+
it('check row expanding and collapsing are changing rows count (API)', () => {
325340
let rows = TreeGridFunctions.getAllRows(fix);
326341
expect(rows.length).toBe(3);
327342

@@ -334,6 +349,225 @@ describe('IgxTreeGrid - Expanding / Collapsing', () => {
334349
expect(rows.length).toBe(3);
335350
});
336351

352+
it('check expand/collapse indicator changes (UI)', () => {
353+
const rows = TreeGridFunctions.getAllRows(fix);
354+
rows.forEach(row => {
355+
TreeGridFunctions.verifyTreeRowHasCollapsedIcon(row);
356+
});
357+
358+
for (let rowToToggle = 0; rowToToggle < rows.length; rowToToggle++) {
359+
const indicatorDiv = TreeGridFunctions.getExpansionIndicatorDiv(rows[rowToToggle]);
360+
indicatorDiv.triggerEventHandler('click', new Event('click'));
361+
362+
for (let rowToCheck = 0; rowToCheck < rows.length; rowToCheck++) {
363+
if (rowToCheck === rowToToggle) {
364+
TreeGridFunctions.verifyTreeRowHasExpandedIcon(rows[rowToCheck]);
365+
} else {
366+
TreeGridFunctions.verifyTreeRowHasCollapsedIcon(rows[rowToCheck]);
367+
}
368+
}
369+
370+
indicatorDiv.triggerEventHandler('click', new Event('click'));
371+
}
372+
373+
rows.forEach(row => {
374+
TreeGridFunctions.verifyTreeRowHasCollapsedIcon(row);
375+
});
376+
});
377+
378+
it('check expand/collapse indicator changes (API)', () => {
379+
const rows = TreeGridFunctions.getAllRows(fix);
380+
rows.forEach(row => {
381+
TreeGridFunctions.verifyTreeRowHasCollapsedIcon(row);
382+
});
383+
384+
for (let rowToToggle = 0; rowToToggle < rows.length; rowToToggle++) {
385+
treeGrid.toggleRow(treeGrid.getRowByIndex(rowToToggle).rowID);
386+
for (let rowToCheck = 0; rowToCheck < rows.length; rowToCheck++) {
387+
if (rowToCheck === rowToToggle) {
388+
TreeGridFunctions.verifyTreeRowHasExpandedIcon(rows[rowToCheck]);
389+
} else {
390+
TreeGridFunctions.verifyTreeRowHasCollapsedIcon(rows[rowToCheck]);
391+
}
392+
}
393+
treeGrid.toggleRow(treeGrid.getRowByIndex(rowToToggle).rowID);
394+
}
395+
396+
rows.forEach(row => {
397+
TreeGridFunctions.verifyTreeRowHasCollapsedIcon(row);
398+
});
399+
});
400+
401+
it('check second level records are having the correct indentation (UI)', () => {
402+
const rows = TreeGridFunctions.getAllRows(fix);
403+
const indicatorDiv = TreeGridFunctions.getExpansionIndicatorDiv(rows[0]);
404+
indicatorDiv.triggerEventHandler('click', new Event('click'));
405+
406+
TreeGridFunctions.verifyRowIndentationLevelByIndex(fix, 1, 1); // fix, rowIndex, expectedLevel
407+
TreeGridFunctions.verifyRowIndentationLevelByIndex(fix, 2, 1);
408+
TreeGridFunctions.verifyRowIndentationLevelByIndex(fix, 3, 0);
409+
});
410+
411+
it('check second level records are having the correct indentation (API)', () => {
412+
treeGrid.toggleRow(treeGrid.getRowByIndex(0).rowID);
413+
414+
TreeGridFunctions.verifyRowIndentationLevelByIndex(fix, 1, 1); // fix, rowIndex, expectedLevel
415+
TreeGridFunctions.verifyRowIndentationLevelByIndex(fix, 2, 1);
416+
TreeGridFunctions.verifyRowIndentationLevelByIndex(fix, 3, 0);
417+
});
418+
419+
it('check third level records are having the correct indentation (UI)', () => {
420+
// expand second level records
421+
let rows = TreeGridFunctions.getAllRows(fix);
422+
let indicatorDiv = TreeGridFunctions.getExpansionIndicatorDiv(rows[0]);
423+
indicatorDiv.triggerEventHandler('click', new Event('click'));
424+
425+
// expand third level record
426+
rows = TreeGridFunctions.getAllRows(fix);
427+
indicatorDiv = TreeGridFunctions.getExpansionIndicatorDiv(rows[1]);
428+
indicatorDiv.triggerEventHandler('click', new Event('click'));
429+
430+
// check third level records indentation
431+
TreeGridFunctions.verifyRowIndentationLevelByIndex(fix, 2, 2); // fix, rowIndex, expectedLevel
432+
TreeGridFunctions.verifyRowIndentationLevelByIndex(fix, 3, 2);
433+
});
434+
435+
it('check third level records are having the correct indentation (API)', () => {
436+
// expand second level records
437+
treeGrid.toggleRow(treeGrid.getRowByIndex(0).rowID);
438+
439+
// expand third level record
440+
treeGrid.toggleRow(treeGrid.getRowByIndex(1).rowID);
441+
442+
// check third level records indentation
443+
TreeGridFunctions.verifyRowIndentationLevelByIndex(fix, 2, 2); // fix, rowIndex, expectedLevel
444+
TreeGridFunctions.verifyRowIndentationLevelByIndex(fix, 3, 2);
445+
});
446+
447+
it('check grand children are not visible when collapsing their grand parent', () => {
448+
let rows = TreeGridFunctions.getAllRows(fix);
449+
expect(rows.length).toBe(3);
450+
451+
// expand second level records
452+
treeGrid.toggleRow(treeGrid.getRowByIndex(0).rowID);
453+
454+
// expand third level record
455+
treeGrid.toggleRow(treeGrid.getRowByIndex(1).rowID);
456+
457+
rows = TreeGridFunctions.getAllRows(fix);
458+
expect(rows.length).toBe(7);
459+
460+
// collapse first row with all its children and grand children
461+
treeGrid.toggleRow(treeGrid.getRowByIndex(0).rowID);
462+
463+
rows = TreeGridFunctions.getAllRows(fix);
464+
expect(rows.length).toBe(3);
465+
});
466+
467+
it('should expand/collapse rows when changing the \'expanded\' property', () => {
468+
let rows = TreeGridFunctions.getAllRows(fix);
469+
expect(rows.length).toBe(3);
470+
471+
// expand a root level row
472+
let aRow = treeGrid.getRowByIndex(0);
473+
expect(aRow.cells.first.value).toBe(1, 'wrong root level row');
474+
expect(aRow.expanded).toBe(false);
475+
aRow.expanded = true;
476+
rows = TreeGridFunctions.getAllRows(fix);
477+
expect(rows.length).toBe(5, 'root level row expanding problem');
478+
479+
// expand a second level row
480+
aRow = treeGrid.getRowByIndex(1);
481+
expect(aRow.cells.first.value).toBe(2, 'wrong second level row');
482+
expect(aRow.expanded).toBe(false);
483+
aRow.expanded = true;
484+
rows = TreeGridFunctions.getAllRows(fix);
485+
expect(rows.length).toBe(7, 'second level row expanding problem');
486+
487+
// check third level rows are having the correct values
488+
aRow = treeGrid.getRowByIndex(2);
489+
expect(aRow.cells.first.value).toBe(3, 'wrong third level row');
490+
aRow = treeGrid.getRowByIndex(3);
491+
expect(aRow.cells.first.value).toBe(7, 'wrong third level row');
492+
493+
// collapse a second level row
494+
aRow = treeGrid.getRowByIndex(1);
495+
aRow.expanded = false;
496+
rows = TreeGridFunctions.getAllRows(fix);
497+
expect(rows.length).toBe(5, 'second level row collapsing problem');
498+
499+
// collapse a root level row
500+
aRow = treeGrid.getRowByIndex(0);
501+
aRow.expanded = false;
502+
rows = TreeGridFunctions.getAllRows(fix);
503+
expect(rows.length).toBe(3, 'root level row collapsing problem');
504+
});
505+
506+
it('should expand/collapse when using \'expandAll\' and \'collapseAll\' methods', () => {
507+
let rows = TreeGridFunctions.getAllRows(fix);
508+
expect(rows.length).toBe(3);
509+
510+
treeGrid.expandAll();
511+
rows = TreeGridFunctions.getAllRows(fix);
512+
expect(rows.length).toBe(8);
513+
514+
treeGrid.collapseAll();
515+
rows = TreeGridFunctions.getAllRows(fix);
516+
expect(rows.length).toBe(3);
517+
});
518+
519+
it('should emits an event when expanding rows (API)', (done) => {
520+
const aRow = treeGrid.getRowByIndex(0);
521+
treeGrid.onRowToggle.pipe(first()).subscribe((args) => {
522+
expect(args.cancel).toBe(false);
523+
expect(args.event).toBeUndefined();
524+
expect(args.expanded).toBe(true);
525+
expect(args.rowID).toBe(1);
526+
done();
527+
});
528+
aRow.expanded = true;
529+
});
530+
531+
it('should emits an event when collapsing rows (API)', (done) => {
532+
const aRow = treeGrid.getRowByIndex(0);
533+
aRow.expanded = true;
534+
treeGrid.onRowToggle.pipe(first()).subscribe((args) => {
535+
expect(args.cancel).toBe(false);
536+
expect(args.event).toBeUndefined();
537+
expect(args.expanded).toBe(false);
538+
expect(args.rowID).toBe(1);
539+
done();
540+
});
541+
aRow.expanded = false;
542+
});
543+
544+
it('should emits an event when expanding rows (UI)', (done) => {
545+
treeGrid.onRowToggle.pipe(first()).subscribe((args) => {
546+
expect(args.cancel).toBe(false);
547+
expect(args.event).toBeDefined();
548+
expect(args.expanded).toBe(true);
549+
expect(args.rowID).toBe(1);
550+
done();
551+
});
552+
const rowsDOM = TreeGridFunctions.getAllRows(fix);
553+
const indicatorDivDOM = TreeGridFunctions.getExpansionIndicatorDiv(rowsDOM[0]);
554+
indicatorDivDOM.triggerEventHandler('click', new Event('click'));
555+
});
556+
557+
it('should emits an event when collapsing rows (UI)', (done) => {
558+
const rowsDOM = TreeGridFunctions.getAllRows(fix);
559+
const indicatorDivDOM = TreeGridFunctions.getExpansionIndicatorDiv(rowsDOM[0]);
560+
indicatorDivDOM.triggerEventHandler('click', new Event('click'));
561+
treeGrid.onRowToggle.pipe(first()).subscribe((args) => {
562+
expect(args.cancel).toBe(false);
563+
expect(args.event).toBeDefined();
564+
expect(args.expanded).toBe(false);
565+
expect(args.rowID).toBe(1);
566+
done();
567+
});
568+
indicatorDivDOM.triggerEventHandler('click', new Event('click'));
569+
});
570+
337571
it('should update current page when \'collapseAll\' ', () => {
338572
pending('Tree Grid issue: curent page is not updated when collapseAll');
339573
// Test prerequisites

0 commit comments

Comments
 (0)