Skip to content

Commit 91c457b

Browse files
MKirovaMKirova
authored andcommitted
chore(*): Add some UI tests for merging.
1 parent 86bc021 commit 91c457b

File tree

1 file changed

+47
-2
lines changed

1 file changed

+47
-2
lines changed

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

Lines changed: 47 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,19 @@
1-
import { Component, ViewChild } from '@angular/core';
2-
import { TestBed, waitForAsync } from '@angular/core/testing';
1+
import { Component, TemplateRef, ViewChild } from '@angular/core';
2+
import { fakeAsync, TestBed, tick, waitForAsync } from '@angular/core/testing';
33
import { NoopAnimationsModule } from '@angular/platform-browser/animations';
44
import { DefaultMergeStrategy, GridCellMergeMode, GridColumnDataType, GridType, IgxColumnComponent, IgxGridComponent, SortingDirection } from 'igniteui-angular';
55
import { DataParent } from '../../test-utils/sample-test-data.spec';
66
import { GridFunctions } from '../../test-utils/grid-functions.spec';
7+
import { By } from '@angular/platform-browser';
8+
import { UIInteractions, wait } from '../../test-utils/ui-interactions.spec';
9+
import { hasClass } from '../../test-utils/helper-utils.spec';
710

811
describe('IgxGrid - Cell merging #grid', () => {
912
let fix;
1013
let grid: IgxGridComponent;
14+
const MERGE_CELL_CSS_CLASS = '.igx-grid__td--merged';
15+
const CELL_CSS_CLASS = '.igx-grid__td';
16+
const CSS_CLASS_GRID_ROW = '.igx-grid__tr';
1117
beforeEach(waitForAsync(() => {
1218
TestBed.configureTestingModule({
1319
imports: [
@@ -121,6 +127,38 @@ describe('IgxGrid - Cell merging #grid', () => {
121127
]);
122128
});
123129
});
130+
131+
132+
describe('UI', () => {
133+
it ('should properly align merged cells with their spanned rows.', () => {
134+
const mergedCell = fix.debugElement.queryAll(By.css(MERGE_CELL_CSS_CLASS))[0].nativeNode;
135+
const endRow = fix.debugElement.queryAll(By.css(CSS_CLASS_GRID_ROW))[2].nativeNode;
136+
expect(mergedCell.getBoundingClientRect().bottom).toBe(endRow.getBoundingClientRect().bottom);
137+
});
138+
139+
it('should mark merged cell as hovered when hovering any row that intersects that cell.', () => {
140+
const secondRow = fix.debugElement.queryAll(By.css(CSS_CLASS_GRID_ROW))[2];
141+
UIInteractions.hoverElement(secondRow.nativeNode);
142+
fix.detectChanges();
143+
// hover 2nd row that intersects the merged cell in row 1
144+
const mergedCell = fix.debugElement.queryAll(By.css(MERGE_CELL_CSS_CLASS))[0].nativeNode;
145+
// merged cell should be marked as hovered
146+
hasClass(mergedCell, 'igx-grid__td--merged-hovered', true);
147+
});
148+
149+
it('should set correct size to merged cell that spans multiple rows that have different sizes.', () => {
150+
const col = grid.getColumnByName('ID');
151+
col.bodyTemplate = fix.componentInstance.customTemplate;
152+
fix.detectChanges();
153+
grid.verticalScrollContainer.recalcUpdateSizes();
154+
grid.dataRowList.toArray().forEach(x => x.cdr.detectChanges());
155+
const mergedCell = fix.debugElement.queryAll(By.css(MERGE_CELL_CSS_CLASS))[0].nativeNode;
156+
// one row is 100px, other is 200, 4px border
157+
expect(mergedCell.getBoundingClientRect().height).toBe(100 + 200 + 4);
158+
159+
160+
});
161+
});
124162
});
125163

126164
@Component({
@@ -130,13 +168,20 @@ describe('IgxGrid - Cell merging #grid', () => {
130168
<igx-column width="100px" [field]="col.field" [dataType]="col.dataType" [merge]="col.merge"></igx-column>
131169
}
132170
</igx-grid>
171+
<ng-template #customTemplate let-value let-cell="cell">
172+
<button [style.height.px]="cell.row.index % 2 === 0 ? 100 : 200" type="button">{{value}}</button>
173+
</ng-template>
133174
`,
134175
imports: [IgxGridComponent, IgxColumnComponent]
135176
})
136177
export class DefaultCellMergeGridComponent extends DataParent {
137178
public mergeMode: GridCellMergeMode = GridCellMergeMode.always;
138179
@ViewChild('grid', { read: IgxGridComponent, static: true })
139180
public grid: IgxGridComponent;
181+
182+
@ViewChild('customTemplate', { read: TemplateRef, static: true })
183+
public customTemplate: TemplateRef<any>;
184+
140185
public cols = [
141186
{ field:'ID', merge: false },
142187
{ field:'ProductName', dataType: GridColumnDataType.String, merge: true },

0 commit comments

Comments
 (0)