Skip to content

Commit 6be0ac5

Browse files
committed
chore(*): Fixed failing tests for PivotGrid PDF exporter
1 parent f3e2a5b commit 6be0ac5

File tree

1 file changed

+29
-59
lines changed

1 file changed

+29
-59
lines changed

projects/igniteui-angular/grids/core/src/services/pdf/pdf-exporter-grid.spec.ts

Lines changed: 29 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import { IgxHierarchicalGridComponent } from 'igniteui-angular/grids/hierarchica
1313
import { IgxPivotGridMultipleRowComponent, IgxPivotGridTestComplexHierarchyComponent } from '../../../../../test-utils/pivot-grid-samples.spec';
1414
import { IgxPivotGridComponent } from 'igniteui-angular/grids/pivot-grid';
1515
import { PivotRowLayoutType } from 'igniteui-angular/grids/core';
16+
import { wait } from 'igniteui-angular/test-utils/ui-interactions.spec';
1617

1718
describe('PDF Grid Exporter', () => {
1819
let exporter: IgxPdfExporterService;
@@ -396,17 +397,17 @@ describe('PDF Grid Exporter', () => {
396397

397398
describe('Pivot Grid PDF Export', () => {
398399
let pivotGrid: IgxPivotGridComponent;
399-
400-
// Helper function to wait for async operations
401-
const wait = (ms: number) => new Promise(resolve => setTimeout(resolve, ms));
402-
403-
it('should export basic pivot grid', async (done) => {
404-
const fix = TestBed.createComponent(IgxPivotGridMultipleRowComponent);
400+
let fix;
401+
beforeEach(async () => {
402+
fix = TestBed.createComponent(IgxPivotGridMultipleRowComponent);
405403
fix.detectChanges();
406-
await wait(300);
404+
await wait();
407405

408406
pivotGrid = fix.componentInstance.pivotGrid;
407+
spyOn(ExportUtilities as any, 'saveBlobToFile');
408+
});
409409

410+
it('should export basic pivot grid', (done) => {
410411
exporter.exportEnded.pipe(first()).subscribe(() => {
411412
expect(ExportUtilities.saveBlobToFile).toHaveBeenCalledTimes(1);
412413
done();
@@ -415,14 +416,8 @@ describe('PDF Grid Exporter', () => {
415416
exporter.export(pivotGrid, options);
416417
});
417418

418-
it('should export pivot grid with row headers', async (done) => {
419-
const fix = TestBed.createComponent(IgxPivotGridMultipleRowComponent);
420-
fix.detectChanges();
421-
422-
pivotGrid = fix.componentInstance.pivotGrid;
419+
it('should export pivot grid with row headers', (done) => {
423420
pivotGrid.pivotUI.showRowHeaders = true;
424-
fix.detectChanges();
425-
await wait(300);
426421

427422
exporter.exportEnded.pipe(first()).subscribe(() => {
428423
expect(ExportUtilities.saveBlobToFile).toHaveBeenCalledTimes(1);
@@ -432,11 +427,7 @@ describe('PDF Grid Exporter', () => {
432427
exporter.export(pivotGrid, options);
433428
});
434429

435-
it('should export pivot grid with horizontal row layout', async (done) => {
436-
const fix = TestBed.createComponent(IgxPivotGridMultipleRowComponent);
437-
fix.detectChanges();
438-
439-
pivotGrid = fix.componentInstance.pivotGrid;
430+
it('should export pivot grid with horizontal row layout', (done) => {
440431
pivotGrid.pivotUI.showRowHeaders = true;
441432
pivotGrid.pivotUI.rowLayout = PivotRowLayoutType.Horizontal;
442433
pivotGrid.pivotConfiguration.rows = [{
@@ -453,22 +444,17 @@ describe('PDF Grid Exporter', () => {
453444
}
454445
}];
455446
fix.detectChanges();
456-
await wait(300);
457447

458448
exporter.exportEnded.pipe(first()).subscribe(() => {
459-
expect(ExportUtilities.saveBlobToFile).toHaveBeenCalledTimes(1);
460-
done();
449+
expect(ExportUtilities.saveBlobToFile).toHaveBeenCalledTimes(1);
450+
done();
461451
});
462452

463453
exporter.export(pivotGrid, options);
464454
});
465455

466-
it('should export hierarchical pivot grid', async (done) => {
467-
const fix = TestBed.createComponent(IgxPivotGridTestComplexHierarchyComponent);
468-
fix.detectChanges();
469-
await wait(300);
470-
471-
pivotGrid = fix.componentInstance.pivotGrid;
456+
it('should export pivot grid with custom page size', (done) => {
457+
options.pageSize = 'letter';
472458

473459
exporter.exportEnded.pipe(first()).subscribe(() => {
474460
expect(ExportUtilities.saveBlobToFile).toHaveBeenCalledTimes(1);
@@ -478,13 +464,8 @@ describe('PDF Grid Exporter', () => {
478464
exporter.export(pivotGrid, options);
479465
});
480466

481-
it('should export pivot grid with custom page size', async (done) => {
482-
const fix = TestBed.createComponent(IgxPivotGridMultipleRowComponent);
483-
fix.detectChanges();
484-
await wait(300);
485-
486-
pivotGrid = fix.componentInstance.pivotGrid;
487-
options.pageSize = 'letter';
467+
it('should export pivot grid with landscape orientation', (done) => {
468+
options.pageOrientation = 'landscape';
488469

489470
exporter.exportEnded.pipe(first()).subscribe(() => {
490471
expect(ExportUtilities.saveBlobToFile).toHaveBeenCalledTimes(1);
@@ -494,13 +475,8 @@ describe('PDF Grid Exporter', () => {
494475
exporter.export(pivotGrid, options);
495476
});
496477

497-
it('should export pivot grid with landscape orientation', async (done) => {
498-
const fix = TestBed.createComponent(IgxPivotGridMultipleRowComponent);
499-
fix.detectChanges();
500-
await wait(300);
501-
502-
pivotGrid = fix.componentInstance.pivotGrid;
503-
options.pageOrientation = 'landscape';
478+
it('should export pivot grid without table borders', (done) => {
479+
options.showTableBorders = false;
504480

505481
exporter.exportEnded.pipe(first()).subscribe(() => {
506482
expect(ExportUtilities.saveBlobToFile).toHaveBeenCalledTimes(1);
@@ -510,13 +486,8 @@ describe('PDF Grid Exporter', () => {
510486
exporter.export(pivotGrid, options);
511487
});
512488

513-
it('should export pivot grid without table borders', async (done) => {
514-
const fix = TestBed.createComponent(IgxPivotGridMultipleRowComponent);
515-
fix.detectChanges();
516-
await wait(300);
517-
518-
pivotGrid = fix.componentInstance.pivotGrid;
519-
options.showTableBorders = false;
489+
it('should export pivot grid with custom font size', (done) => {
490+
options.fontSize = 14;
520491

521492
exporter.exportEnded.pipe(first()).subscribe(() => {
522493
expect(ExportUtilities.saveBlobToFile).toHaveBeenCalledTimes(1);
@@ -526,20 +497,19 @@ describe('PDF Grid Exporter', () => {
526497
exporter.export(pivotGrid, options);
527498
});
528499

529-
it('should export pivot grid with custom font size', async (done) => {
530-
const fix = TestBed.createComponent(IgxPivotGridMultipleRowComponent);
500+
it('should export hierarchical pivot grid', (done) => {
501+
const fix = TestBed.createComponent(IgxPivotGridTestComplexHierarchyComponent);
531502
fix.detectChanges();
532-
await wait(300);
503+
fix.whenStable().then(() => {
504+
pivotGrid = fix.componentInstance.pivotGrid;
533505

534-
pivotGrid = fix.componentInstance.pivotGrid;
535-
options.fontSize = 14;
506+
exporter.exportEnded.pipe(first()).subscribe(() => {
507+
expect(ExportUtilities.saveBlobToFile).toHaveBeenCalledTimes(1);
508+
done();
509+
});
536510

537-
exporter.exportEnded.pipe(first()).subscribe(() => {
538-
expect(ExportUtilities.saveBlobToFile).toHaveBeenCalledTimes(1);
539-
done();
511+
exporter.export(pivotGrid, options);
540512
});
541-
542-
exporter.export(pivotGrid, options);
543513
});
544514
});
545515
});

0 commit comments

Comments
 (0)