Skip to content

Commit 921f13d

Browse files
HristoP96HristoP96
authored andcommitted
Merge branch 'master' of https://github.com/IgniteUI/igniteui-angular into hPopov/refactor-grid-paging-tests-master
2 parents 572320c + 4e67b5f commit 921f13d

File tree

11 files changed

+162
-95
lines changed

11 files changed

+162
-95
lines changed

projects/igniteui-angular/src/lib/grids/grid/grid-row-selection.spec.ts

Lines changed: 58 additions & 77 deletions
Large diffs are not rendered by default.

projects/igniteui-angular/src/lib/services/excel/excel-exporter-grid.spec.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -214,6 +214,17 @@ describe('Excel Exporter', () => {
214214
await wrapper.verifyDataFilesContent(actualData.gridJobTitleIdFrozen, 'Not all pinned columns are frozen in the export!');
215215
});
216216

217+
it('should honor all pinned rows.', async() => {
218+
const result = await TestMethods.createGridAndPinRow(0, 2);
219+
const fix = result.fixture;
220+
const grid = result.grid;
221+
222+
const wrapper = await getExportedData(grid, options);
223+
wrapper.verifyStructure();
224+
await wrapper.verifyPinRowData('<pane ySplit="3" topLeftCell="A4" activePane="topRight" state="frozen"/>',
225+
'Not all pinned rows are frozen in the export!');
226+
});
227+
217228
it('should honor applied sorting.', async () => {
218229
const fix = TestBed.createComponent(GridIDNameJobTitleComponent);
219230
fix.detectChanges();

projects/igniteui-angular/src/lib/services/excel/excel-exporter.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,8 @@ export class IgxExcelExporterService extends IgxBaseExporter {
7777
}
7878
}
7979

80-
const worksheetData = new WorksheetData(data, options, this._indexOfLastPinnedColumn, this._sort, this._isTreeGrid);
80+
const worksheetData = new WorksheetData(data, options, this._indexOfLastPinnedColumn,
81+
this._indexOfLastPinnedRow, this._sort, this._isTreeGrid);
8182
this._xlsx = new JSZip();
8283

8384
const rootFolder = ExcelElementsFactory.getExcelFolder(ExcelFolderTypes.RootExcelFolder);

projects/igniteui-angular/src/lib/services/excel/excel-files.ts

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -116,12 +116,23 @@ export class WorksheetFile implements IExcelFile {
116116

117117
cols.push('</cols>');
118118

119-
if (worksheetData.indexOfLastPinnedColumn !== -1 &&
120-
!worksheetData.options.ignorePinning &&
121-
!worksheetData.options.ignoreColumnsOrder) {
122-
const frozenColumnCount = worksheetData.indexOfLastPinnedColumn + 1;
123-
const firstCell = ExcelStrings.getExcelColumn(frozenColumnCount) + '1';
124-
freezePane = `<pane xSplit="${frozenColumnCount}" topLeftCell="${firstCell}" activePane="topRight" state="frozen"/>`;
119+
const hasFrozenElements = !worksheetData.options.ignorePinning &&
120+
(worksheetData.indexOfLastPinnedColumn !== -1 || worksheetData.indexOfLastPinnedRow !== -1);
121+
122+
if (hasFrozenElements) {
123+
const hasFrozenCols = !worksheetData.options.ignoreColumnsOrder && worksheetData.indexOfLastPinnedColumn !== -1;
124+
const hasFrozenRows = worksheetData.indexOfLastPinnedRow !== -1;
125+
126+
const frozenColumnCount = hasFrozenCols ? worksheetData.indexOfLastPinnedColumn + 1 : null;
127+
const frozenRowCount = hasFrozenRows ? worksheetData.indexOfLastPinnedRow + 2 : null;
128+
129+
const frozenColumn = !hasFrozenCols ? 'A' : ExcelStrings.getExcelColumn(frozenColumnCount);
130+
const firstCell = frozenColumn + (frozenRowCount + 1);
131+
132+
const xSplit = hasFrozenCols ? `xSplit="${frozenColumnCount}" ` : '';
133+
const ySplit = hasFrozenRows ? `ySplit="${frozenRowCount}" ` : '';
134+
const xySplit = (xSplit + ySplit).trim();
135+
freezePane = `<pane ${xySplit} topLeftCell="${firstCell}" activePane="topRight" state="frozen"/>`;
125136
}
126137
}
127138
const hasTable = !worksheetData.isEmpty && worksheetData.options.exportAsTable;

projects/igniteui-angular/src/lib/services/excel/jszip-verification-wrapper.spec.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,14 @@ export class JSZipWrapper {
141141
});
142142
}
143143

144+
public async verifyPinRowData(pinData: string, message = '') {
145+
let result;
146+
await this.readDataFiles().then(() => {
147+
result = this.dataFilesContent[1];
148+
expect(result.fileContent.indexOf(pinData) !== -1).toBeTruthy(message);
149+
});
150+
}
151+
144152
/* Verifies the contents of all files and asserts the result.
145153
Optionally, a message can be passed in, which, if specified, will be shown in the beginning of the comparison result. */
146154
public async verifyFilesContent(expectedData: IFileContent[], message = '') {

projects/igniteui-angular/src/lib/services/excel/worksheet-data.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ export class WorksheetData {
1111
private _isSpecialData: boolean;
1212

1313
constructor(private _data: any[], public options: IgxExcelExporterOptions, public indexOfLastPinnedColumn,
14-
public sort: any, public isTreeGridData = false) {
14+
public indexOfLastPinnedRow, public sort: any, public isTreeGridData = false) {
1515
this.initializeData();
1616
}
1717

projects/igniteui-angular/src/lib/services/exporter-common/base-export-service.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ export abstract class IgxBaseExporter {
7272

7373
protected _isTreeGrid = false;
7474
protected _indexOfLastPinnedColumn = -1;
75+
protected _indexOfLastPinnedRow = -1;
7576
protected _sort = null;
7677

7778
/**
@@ -289,6 +290,14 @@ export abstract class IgxBaseExporter {
289290
}
290291
}
291292

293+
if (grid.hasPinnedRecords) {
294+
295+
const pinnedRecs = data.filter(x => grid.isRecordPinned(x));
296+
const unpinnedRecs = data.filter(x => !grid.isRecordPinned(x));
297+
data = [ ...pinnedRecs, ... unpinnedRecs];
298+
this._indexOfLastPinnedRow = pinnedRecs.length - 1;
299+
}
300+
292301
return data;
293302
}
294303

@@ -307,6 +316,7 @@ export abstract class IgxBaseExporter {
307316
private resetDefaults() {
308317
this._columnList = [];
309318
this._indexOfLastPinnedColumn = -1;
319+
this._indexOfLastPinnedRow = -1;
310320
this._sort = null;
311321
this.flatRecords = [];
312322
}

projects/igniteui-angular/src/lib/services/exporter-common/test-methods.spec.ts

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,4 +50,21 @@ export class TestMethods {
5050
return { fixture: fix, grid: myGrid };
5151
}
5252

53+
54+
/* Creates an instance of GridDeclarationComponent and pins the rows with the specified indices. */
55+
public static async createGridAndPinRow(...rowIndices: any[]) {
56+
const fix = TestBed.createComponent(GridIDNameJobTitleComponent);
57+
fix.detectChanges();
58+
await wait(16);
59+
60+
const myGrid = fix.componentInstance.grid;
61+
62+
// Pin columns
63+
rowIndices.forEach((i) => {
64+
myGrid.getRowByIndex(i).pin();
65+
});
66+
67+
return { fixture: fix, grid: myGrid };
68+
}
69+
5370
}

projects/igniteui-angular/src/lib/test-utils/ui-interactions.spec.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,18 @@ export class UIInteractions {
2525
return new KeyboardEvent(eventType, keyboardEvent);
2626
}
2727

28+
public static getMouseEvent(eventType, altKey = false, shift = false, ctrl = false) {
29+
const clickEvent = {
30+
altKey: altKey,
31+
shiftKey: shift,
32+
ctrlKey: ctrl,
33+
stopPropagation: () => { },
34+
stopImmediatePropagation: () => { },
35+
preventDefault: () => { }
36+
};
37+
return new MouseEvent(eventType, clickEvent);
38+
}
39+
2840
public static triggerEventHandlerKeyDown(keyPressed: string, elem: DebugElement, altKey = false, shift = false, ctrl = false) {
2941
const event = {
3042
key: keyPressed,

src/app/grid-row-pinning/grid-row-pinning.sample.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
Allows rows to be pinned to the beginning/end of the grid.
44
</app-page-header>
55
<button (click)="grid1.addRow({'ID': 'TEST', 'CompanyName': 'Test'})">Add Row</button>
6+
<button (click)="exportButtonHandler()">Export</button>
67
<div class="sample-content">
78
<div class="sample-column">
89
<div class="sample-buttons">

0 commit comments

Comments
 (0)