Skip to content

Commit f862469

Browse files
MKirovaMKirova
authored andcommitted
chore(*): Add more integration tests.
1 parent 46ea7ae commit f862469

File tree

1 file changed

+143
-3
lines changed

1 file changed

+143
-3
lines changed

projects/igniteui-angular/src/lib/grids/grid/cell-merge.spec.ts

Lines changed: 143 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,26 @@
11
import { Component, TemplateRef, ViewChild } from '@angular/core';
22
import { fakeAsync, TestBed, tick, waitForAsync } from '@angular/core/testing';
33
import { NoopAnimationsModule } from '@angular/platform-browser/animations';
4-
import { DefaultMergeStrategy, DefaultSortingStrategy, GridCellMergeMode, GridColumnDataType, GridType, IgxColumnComponent, IgxGridComponent, IgxPaginatorComponent, SortingDirection } from 'igniteui-angular';
4+
import { DefaultMergeStrategy, DefaultSortingStrategy, GridCellMergeMode, GridColumnDataType, GridType, IgxColumnComponent, IgxGridComponent, IgxPaginatorComponent, IgxStringFilteringOperand, SortingDirection } from 'igniteui-angular';
55
import { DataParent } from '../../test-utils/sample-test-data.spec';
66
import { GridFunctions, GridSelectionFunctions } from '../../test-utils/grid-functions.spec';
77
import { By } from '@angular/platform-browser';
88
import { UIInteractions, wait } from '../../test-utils/ui-interactions.spec';
99
import { hasClass } from '../../test-utils/helper-utils.spec';
10+
import { ColumnLayoutTestComponent } from './grid.multi-row-layout.spec';
1011

1112
describe('IgxGrid - Cell merging #grid', () => {
1213
let fix;
1314
let grid: IgxGridComponent;
1415
const MERGE_CELL_CSS_CLASS = '.igx-grid__td--merged';
1516
const CELL_CSS_CLASS = '.igx-grid__td';
1617
const CSS_CLASS_GRID_ROW = '.igx-grid__tr';
18+
const HIGHLIGHT_ACTIVE_CSS_CLASS = '.igx-highlight__active';
19+
1720
beforeEach(waitForAsync(() => {
1821
TestBed.configureTestingModule({
1922
imports: [
20-
NoopAnimationsModule, DefaultCellMergeGridComponent
23+
NoopAnimationsModule, DefaultCellMergeGridComponent, ColumnLayoutTestComponent
2124
]
2225
}).compileComponents();
2326
}));
@@ -517,6 +520,7 @@ describe('IgxGrid - Cell merging #grid', () => {
517520
]);
518521
});
519522
});
523+
520524
describe('Row Selection', () => {
521525

522526
it('should mark all merged cells that intersect with a selected row as selected.', () => {
@@ -528,7 +532,6 @@ describe('IgxGrid - Cell merging #grid', () => {
528532
fix.detectChanges();
529533

530534
expect(secondRow.selected).toBe(true);
531-
grid.markForCheck();
532535

533536
const mergedIntersectedCell = grid.gridAPI.get_cell_by_index(0, 'ProductName');
534537
// check cell has selected style
@@ -537,6 +540,143 @@ describe('IgxGrid - Cell merging #grid', () => {
537540

538541
});
539542

543+
describe('Cell Selection', () => {
544+
it('should interrupt merge sequence so that selected cell has no merging.', () => {
545+
const col = grid.getColumnByName('ProductName');
546+
grid.cellSelection = 'multiple';
547+
fix.detectChanges();
548+
549+
GridFunctions.verifyColumnMergedState(grid, col, [
550+
{ value: 'Ignite UI for JavaScript', span: 2 },
551+
{ value: 'Ignite UI for Angular', span: 1 },
552+
{ value: 'Ignite UI for JavaScript', span: 1 },
553+
{ value: 'Ignite UI for Angular', span: 2 },
554+
{ value: null, span: 1 },
555+
{ value: 'NetAdvantage', span: 2 }
556+
]);
557+
558+
const startCell = grid.gridAPI.get_cell_by_index(4, 'ProductName');
559+
const endCell = grid.gridAPI.get_cell_by_index(0, 'ID');
560+
561+
GridSelectionFunctions.selectCellsRangeNoWait(fix, startCell, endCell);
562+
fix.detectChanges();
563+
564+
GridFunctions.verifyColumnMergedState(grid, col, [
565+
{ value: 'Ignite UI for JavaScript', span: 1 },
566+
{ value: 'Ignite UI for JavaScript', span: 1 },
567+
{ value: 'Ignite UI for Angular', span: 1 },
568+
{ value: 'Ignite UI for JavaScript', span: 1 },
569+
{ value: 'Ignite UI for Angular', span: 1 },
570+
{ value: 'Ignite UI for Angular', span: 1 },
571+
{ value: null, span: 1 },
572+
{ value: 'NetAdvantage', span: 2 }
573+
]);
574+
575+
// check api
576+
expect(grid.getSelectedData().length).toBe(5);
577+
expect(grid.getSelectedData()).toEqual(grid.data.slice(0, 5).map(x => { return { 'ID': x.ID, 'ProductName': x. ProductName}}));
578+
});
579+
});
580+
581+
describe('Column selection', () => {
582+
it('should mark merged cells in selected column as selected.', () => {
583+
grid.columnSelection = 'multiple';
584+
fix.detectChanges();
585+
const col = grid.getColumnByName('ProductName');
586+
col.selected = true;
587+
fix.detectChanges();
588+
589+
const mergedCells = fix.debugElement.queryAll(By.css(MERGE_CELL_CSS_CLASS));
590+
mergedCells.forEach(element => {
591+
hasClass(element.nativeNode, 'igx-grid__td--column-selected', true);
592+
});
593+
});
594+
595+
it('selected data API should return all associated data fields as selected.', () => {
596+
grid.columnSelection = 'multiple';
597+
fix.detectChanges();
598+
const col = grid.getColumnByName('ProductName');
599+
col.selected = true;
600+
fix.detectChanges();
601+
602+
expect(grid.getSelectedColumnsData()).toEqual(grid.data.map(x => { return {'ProductName': x. ProductName}}));
603+
});
604+
});
605+
606+
describe('Filtering', () => {
607+
608+
it('should merge cells in filtered data.', () => {
609+
grid.filter('ProductName', 'Net', IgxStringFilteringOperand.instance().condition('startsWith'), true);
610+
fix.detectChanges();
611+
const col = grid.getColumnByName('ProductName');
612+
GridFunctions.verifyColumnMergedState(grid, col, [
613+
{ value: 'NetAdvantage', span: 2 }
614+
]);
615+
});
616+
617+
});
618+
619+
describe('Searching', () => {
620+
621+
it('findNext \ findPrev should count merged cells as 1 result and navigate once through them.', () => {
622+
const cell0 = grid.gridAPI.get_cell_by_index(0, 'ProductName').nativeElement;
623+
const cell3 = grid.gridAPI.get_cell_by_index(3, 'ProductName').nativeElement;
624+
const fixNativeElem = fix.debugElement.nativeElement;
625+
626+
let matches = grid.findNext('JavaScript');
627+
fix.detectChanges();
628+
629+
expect(matches).toBe(2);
630+
631+
let activeHighlight = fixNativeElem.querySelectorAll(HIGHLIGHT_ACTIVE_CSS_CLASS);
632+
expect(activeHighlight[0].closest("igx-grid-cell")).toBe(cell0);
633+
634+
matches = grid.findNext('JavaScript');
635+
fix.detectChanges();
636+
637+
activeHighlight = fixNativeElem.querySelectorAll(HIGHLIGHT_ACTIVE_CSS_CLASS);
638+
expect(activeHighlight[0].closest("igx-grid-cell")).toBe(cell3);
639+
640+
matches = grid.findPrev('JavaScript');
641+
fix.detectChanges();
642+
643+
activeHighlight = fixNativeElem.querySelectorAll(HIGHLIGHT_ACTIVE_CSS_CLASS);
644+
expect(activeHighlight[0].closest("igx-grid-cell")).toBe(cell0);
645+
});
646+
647+
it('should update matches if a cell becomes unmerged.', () => {
648+
let matches = grid.findNext('JavaScript');
649+
fix.detectChanges();
650+
651+
expect(matches).toBe(2);
652+
653+
UIInteractions.simulateClickAndSelectEvent(grid.gridAPI.get_cell_by_index(0, 'ProductName').nativeElement);
654+
fix.detectChanges();
655+
656+
matches = grid.findNext('JavaScript');
657+
fix.detectChanges();
658+
expect(matches).toBe(3);
659+
});
660+
661+
});
662+
663+
describe('Multi-row layout', () => {
664+
it('should throw warning and disallow merging with mrl.', () => {
665+
jasmine.getEnv().allowRespy(true);
666+
fix = TestBed.createComponent(ColumnLayoutTestComponent);
667+
fix.detectChanges();
668+
grid = fix.componentInstance.grid;
669+
spyOn(console, 'warn');
670+
grid.columns[1].merge = true;
671+
fix.detectChanges();
672+
673+
expect(console.warn).toHaveBeenCalledWith('Merging is not supported with multi-row layouts.');
674+
expect(console.warn).toHaveBeenCalledTimes(1);
675+
jasmine.getEnv().allowRespy(false);
676+
});
677+
678+
});
679+
540680
});
541681
});
542682

0 commit comments

Comments
 (0)