|
| 1 | +import { TestBed, waitForAsync } from '@angular/core/testing'; |
| 2 | +import { IgxGridComponent } from '../../grids/grid/grid.component'; |
| 3 | +import { ExportUtilities } from '../exporter-common/export-utilities'; |
| 4 | +import { IgxPdfExporterService } from './pdf-exporter'; |
| 5 | +import { IgxPdfExporterOptions } from './pdf-exporter-options'; |
| 6 | +import { GridIDNameJobTitleComponent } from '../../test-utils/grid-samples.spec'; |
| 7 | +import { first } from 'rxjs/operators'; |
| 8 | +import { NoopAnimationsModule } from '@angular/platform-browser/animations'; |
| 9 | + |
| 10 | +describe('PDF Grid Exporter', () => { |
| 11 | + let exporter: IgxPdfExporterService; |
| 12 | + let options: IgxPdfExporterOptions; |
| 13 | + |
| 14 | + beforeEach(waitForAsync(() => { |
| 15 | + TestBed.configureTestingModule({ |
| 16 | + imports: [ |
| 17 | + NoopAnimationsModule, |
| 18 | + GridIDNameJobTitleComponent |
| 19 | + ] |
| 20 | + }).compileComponents(); |
| 21 | + })); |
| 22 | + |
| 23 | + beforeEach(() => { |
| 24 | + exporter = new IgxPdfExporterService(); |
| 25 | + options = new IgxPdfExporterOptions('PdfGridExport'); |
| 26 | + |
| 27 | + // Spy the saveBlobToFile method so the files are not really created |
| 28 | + spyOn(ExportUtilities as any, 'saveBlobToFile'); |
| 29 | + }); |
| 30 | + |
| 31 | + afterEach(() => { |
| 32 | + exporter.columnExporting.unsubscribe(); |
| 33 | + exporter.rowExporting.unsubscribe(); |
| 34 | + }); |
| 35 | + |
| 36 | + it('should export grid as displayed.', (done) => { |
| 37 | + const fix = TestBed.createComponent(GridIDNameJobTitleComponent); |
| 38 | + fix.detectChanges(); |
| 39 | + |
| 40 | + const grid = fix.componentInstance.grid; |
| 41 | + |
| 42 | + exporter.exportEnded.pipe(first()).subscribe(() => { |
| 43 | + expect(ExportUtilities.saveBlobToFile).toHaveBeenCalledTimes(1); |
| 44 | + done(); |
| 45 | + }); |
| 46 | + |
| 47 | + exporter.export(grid, options); |
| 48 | + }); |
| 49 | + |
| 50 | + it('should export grid with custom page orientation', (done) => { |
| 51 | + const fix = TestBed.createComponent(GridIDNameJobTitleComponent); |
| 52 | + fix.detectChanges(); |
| 53 | + |
| 54 | + const grid = fix.componentInstance.grid; |
| 55 | + options.pageOrientation = 'landscape'; |
| 56 | + |
| 57 | + exporter.exportEnded.pipe(first()).subscribe(() => { |
| 58 | + expect(ExportUtilities.saveBlobToFile).toHaveBeenCalledTimes(1); |
| 59 | + done(); |
| 60 | + }); |
| 61 | + |
| 62 | + exporter.export(grid, options); |
| 63 | + }); |
| 64 | + |
| 65 | + it('should honor ignoreColumnsVisibility option', (done) => { |
| 66 | + const fix = TestBed.createComponent(GridIDNameJobTitleComponent); |
| 67 | + fix.detectChanges(); |
| 68 | + |
| 69 | + const grid = fix.componentInstance.grid; |
| 70 | + grid.columnList.get(0).hidden = true; |
| 71 | + options.ignoreColumnsVisibility = false; |
| 72 | + |
| 73 | + fix.detectChanges(); |
| 74 | + |
| 75 | + exporter.exportEnded.pipe(first()).subscribe(() => { |
| 76 | + expect(ExportUtilities.saveBlobToFile).toHaveBeenCalledTimes(1); |
| 77 | + done(); |
| 78 | + }); |
| 79 | + |
| 80 | + exporter.export(grid, options); |
| 81 | + }); |
| 82 | + |
| 83 | + it('should handle empty grid', (done) => { |
| 84 | + const fix = TestBed.createComponent(GridIDNameJobTitleComponent); |
| 85 | + fix.detectChanges(); |
| 86 | + |
| 87 | + const grid = fix.componentInstance.grid; |
| 88 | + grid.data = []; |
| 89 | + fix.detectChanges(); |
| 90 | + |
| 91 | + exporter.exportEnded.pipe(first()).subscribe(() => { |
| 92 | + expect(ExportUtilities.saveBlobToFile).toHaveBeenCalledTimes(1); |
| 93 | + done(); |
| 94 | + }); |
| 95 | + |
| 96 | + exporter.export(grid, options); |
| 97 | + }); |
| 98 | +}); |
0 commit comments