Skip to content

Commit

Permalink
fix(Exporter): #3332 Adding a test.
Browse files Browse the repository at this point in the history
  • Loading branch information
gedinakova committed Dec 27, 2018
1 parent 179caac commit 6062580
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import { configureTestSuite } from '../../test-utils/configure-suite';
import { IgxTreeGridPrimaryForeignKeyComponent } from '../../test-utils/tree-grid-components.spec';
import { IgxTreeGridModule, IgxTreeGridComponent } from '../../grids/tree-grid';
import { IgxNumberFilteringOperand } from '../../data-operations/filtering-condition';
import { wait } from '../../test-utils/ui-interactions.spec';

describe('Excel Exporter', () => {
configureTestSuite();
Expand Down Expand Up @@ -449,6 +450,27 @@ describe('Excel Exporter', () => {
fix.detectChanges();
await exportAndVerify(treeGrid, options, actualData.treeGridDataExpDepth(0));
});

it('should throw an exception when nesting level is greater than 8.', async () => {
const nestedData = SampleTestData.employeePrimaryForeignKeyTreeData();
for (let i = 1; i < 9; i++) {
nestedData[i - 1].ID = i;
nestedData[i - 1].ParentID = i - 1;
}
nestedData.push({ ID: 9, ParentID: 8, Name: 'Test', JobTitle: '', Age: 49 });
treeGrid.data = nestedData;
fix.detectChanges();
await wait(16);

let error = '';
try {
exporter.export(treeGrid, options);
await wait();
} catch (ex) {
error = ex.message;
}
expect(error).toMatch('Can create an outline of up to eight levels!');
});
});

function getExportedData(grid, exportOptions: IgxExcelExporterOptions) {
Expand Down
28 changes: 11 additions & 17 deletions projects/igniteui-angular/src/lib/services/excel/excel-exporter.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,10 @@
import * as JSZip from 'jszip/dist/jszip';

import { CommonModule } from '@angular/common';
import { Directive, EventEmitter, Injectable, NgModule, Output } from '@angular/core';

import { EventEmitter, Injectable, Output } from '@angular/core';
import { ExcelElementsFactory } from './excel-elements-factory';
import { ExcelFolderTypes } from './excel-enums';
import { IgxExcelExporterOptions } from './excel-exporter-options';

import {
IExcelFile,
IExcelFolder
} from './excel-interfaces';

import { IExcelFolder } from './excel-interfaces';
import { IgxBaseExporter } from '../exporter-common/base-export-service';
import { ExportUtilities } from '../exporter-common/export-utilities';
import { WorksheetData } from './worksheet-data';
Expand Down Expand Up @@ -45,8 +38,6 @@ export interface IExcelExportEndedEventArgs {
export class IgxExcelExporterService extends IgxBaseExporter {

private static ZIP_OPTIONS = { compression: 'DEFLATE', type: 'base64' };
private static DATA_URL_PREFIX = 'data:application/vnd.openxmlformats-officedocument.spreadsheetml.sheet;base64,';

private _xlsx: JSZip;

/**
Expand Down Expand Up @@ -75,13 +66,16 @@ export class IgxExcelExporterService extends IgxBaseExporter {
}

protected exportDataImplementation(data: any[], options: IgxExcelExporterOptions): void {
let maxLevel = 0;
data.forEach((r) => {
maxLevel = Math.max(maxLevel, r.originalRowData.level);
});
if (maxLevel > 7) {
throw Error('Can create an outline of up to eight levels!');
if (this._isTreeGrid) {
let maxLevel = 0;
data.forEach((r) => {
maxLevel = Math.max(maxLevel, r.originalRowData.level);
});
if (maxLevel > 7) {
throw Error('Can create an outline of up to eight levels!');
}
}

const worksheetData = new WorksheetData(data, options, this._indexOfLastPinnedColumn, this._sort, this._isTreeGrid);
this._xlsx = new JSZip();

Expand Down

0 comments on commit 6062580

Please sign in to comment.