mirror of
https://github.com/Alfresco/alfresco-ng2-components.git
synced 2025-07-24 17:32:15 +00:00
[ADF-2240] fix e2e and test in demo shell (#3035)
* fix e2e and test in demo shell * test single run demo shell conf * fix script e2e * fix test lint problems * remove async from nested test * fix pdf test * modify url load pdf strategy test * SimpleChange import * pdf viewer test fix * remove force closing * refactor pdf viewer -remove promise approach -add event rendered -add destroy worker * increment timeout * use proxy files * remove require * fix viewer component test * remove last require * prefer use of done for txt viewer test
This commit is contained in:
@@ -18,6 +18,17 @@
|
||||
import { BaseEvent } from '../../../events';
|
||||
import { DataRow } from '../../data/data-row.model';
|
||||
|
||||
export class DataRowActionModel {
|
||||
|
||||
row: DataRow;
|
||||
action: any;
|
||||
|
||||
constructor(row: DataRow, action: any) {
|
||||
this.row = row;
|
||||
this.action = action;
|
||||
}
|
||||
}
|
||||
|
||||
export class DataRowActionEvent extends BaseEvent<DataRowActionModel> {
|
||||
|
||||
// backwards compatibility with 1.2.0 and earlier
|
||||
@@ -31,14 +42,3 @@ export class DataRowActionEvent extends BaseEvent<DataRowActionModel> {
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
export class DataRowActionModel {
|
||||
|
||||
row: DataRow;
|
||||
action: any;
|
||||
|
||||
constructor(row: DataRow, action: any) {
|
||||
this.row = row;
|
||||
this.action = action;
|
||||
}
|
||||
}
|
||||
|
@@ -33,29 +33,6 @@ export class BpmProductVersionModel {
|
||||
}
|
||||
}
|
||||
|
||||
export class EcmProductVersionModel {
|
||||
edition: string;
|
||||
version: VersionModel;
|
||||
license: LicenseModel;
|
||||
status: VersionStatusModel;
|
||||
modules: VersionModuleModel[] = [];
|
||||
|
||||
constructor(obj?: any) {
|
||||
if (obj && obj.entry && obj.entry.repository) {
|
||||
this.edition = obj.entry.repository.edition || null;
|
||||
this.version = new VersionModel(obj.entry.repository.version);
|
||||
this.license = new LicenseModel(obj.entry.repository.license);
|
||||
this.status = new VersionStatusModel(obj.entry.repository.status);
|
||||
if (obj.entry.repository.modules) {
|
||||
obj.entry.repository.modules.forEach((module) => {
|
||||
this.modules.push(new VersionModuleModel(module));
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
export class VersionModel {
|
||||
major: string;
|
||||
minor: string;
|
||||
@@ -139,3 +116,26 @@ export class VersionModuleModel {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
export class EcmProductVersionModel {
|
||||
edition: string;
|
||||
version: VersionModel;
|
||||
license: LicenseModel;
|
||||
status: VersionStatusModel;
|
||||
modules: VersionModuleModel[] = [];
|
||||
|
||||
constructor(obj?: any) {
|
||||
if (obj && obj.entry && obj.entry.repository) {
|
||||
this.edition = obj.entry.repository.edition || null;
|
||||
this.version = new VersionModel(obj.entry.repository.version);
|
||||
this.license = new LicenseModel(obj.entry.repository.license);
|
||||
this.status = new VersionStatusModel(obj.entry.repository.status);
|
||||
if (obj.entry.repository.modules) {
|
||||
obj.entry.repository.modules.forEach((module) => {
|
||||
this.modules.push(new VersionModuleModel(module));
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -15,6 +15,7 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import { Component, SimpleChange, ViewChild } from '@angular/core';
|
||||
import { async, ComponentFixture, TestBed } from '@angular/core/testing';
|
||||
import {
|
||||
AlfrescoApiService,
|
||||
@@ -28,36 +29,48 @@ import { RenderingQueueServices } from '../services/rendering-queue.services';
|
||||
import { PdfViewerComponent } from './pdfViewer.component';
|
||||
import { PdfThumbListComponent } from './pdfViewer-thumbnails.component';
|
||||
import { PdfThumbComponent } from './pdfViewer-thumb.component';
|
||||
import { RIGHT_ARROW, LEFT_ARROW } from '@angular/cdk/keycodes';
|
||||
|
||||
declare var require: any;
|
||||
@Component({
|
||||
template: `
|
||||
<adf-pdf-viewer [allowThumbnails]="true"
|
||||
[showToolbar]="true"
|
||||
[urlFile]="urlFile">
|
||||
</adf-pdf-viewer>
|
||||
`
|
||||
})
|
||||
class UrlTestComponent {
|
||||
|
||||
describe('Test PdfViewer component', () => {
|
||||
@ViewChild(PdfViewerComponent)
|
||||
pdfViewerComponent: PdfViewerComponent;
|
||||
|
||||
let component: PdfViewerComponent;
|
||||
let fixture: ComponentFixture<PdfViewerComponent>;
|
||||
let element: HTMLElement;
|
||||
urlFile: any;
|
||||
|
||||
beforeEach(async(() => {
|
||||
TestBed.configureTestingModule({
|
||||
imports: [
|
||||
ToolbarModule,
|
||||
MaterialModule
|
||||
],
|
||||
declarations: [
|
||||
PdfViewerComponent,
|
||||
PdfThumbListComponent,
|
||||
PdfThumbComponent
|
||||
],
|
||||
providers: [
|
||||
SettingsService,
|
||||
AuthenticationService,
|
||||
AlfrescoApiService,
|
||||
RenderingQueueServices
|
||||
]
|
||||
}).compileComponents();
|
||||
}));
|
||||
constructor() {
|
||||
this.urlFile = './fake-test-file.pdf';
|
||||
}
|
||||
}
|
||||
|
||||
function createFakeBlob(): Blob {
|
||||
@Component({
|
||||
template: `
|
||||
<adf-pdf-viewer [allowThumbnails]="true"
|
||||
[showToolbar]="true"
|
||||
[blobFile]="blobFile">
|
||||
</adf-pdf-viewer>
|
||||
`
|
||||
})
|
||||
class BlobTestComponent {
|
||||
|
||||
@ViewChild(PdfViewerComponent)
|
||||
pdfViewerComponent: PdfViewerComponent;
|
||||
|
||||
blobFile: any;
|
||||
|
||||
constructor() {
|
||||
this.blobFile = this.createFakeBlob();
|
||||
}
|
||||
|
||||
createFakeBlob(): Blob {
|
||||
let pdfData = atob(
|
||||
'JVBERi0xLjcKCjEgMCBvYmogICUgZW50cnkgcG9pbnQKPDwKICAvVHlwZSAvQ2F0YWxvZwog' +
|
||||
'IC9QYWdlcyAyIDAgUgo+PgplbmRvYmoKCjIgMCBvYmoKPDwKICAvVHlwZSAvUGFnZXMKICAv' +
|
||||
@@ -75,418 +88,408 @@ describe('Test PdfViewer component', () => {
|
||||
return new Blob([pdfData], { type: 'application/pdf' });
|
||||
}
|
||||
|
||||
beforeEach(() => {
|
||||
}
|
||||
|
||||
describe('Test PdfViewer component', () => {
|
||||
|
||||
let component: PdfViewerComponent;
|
||||
let fixture: ComponentFixture<PdfViewerComponent>;
|
||||
let element: HTMLElement;
|
||||
let change: any;
|
||||
|
||||
beforeEach(async(() => {
|
||||
TestBed.configureTestingModule({
|
||||
imports: [
|
||||
ToolbarModule,
|
||||
MaterialModule
|
||||
],
|
||||
declarations: [
|
||||
PdfViewerComponent,
|
||||
PdfThumbListComponent,
|
||||
PdfThumbComponent,
|
||||
UrlTestComponent,
|
||||
BlobTestComponent
|
||||
],
|
||||
providers: [
|
||||
SettingsService,
|
||||
AuthenticationService,
|
||||
AlfrescoApiService,
|
||||
RenderingQueueServices
|
||||
]
|
||||
}).compileComponents();
|
||||
}));
|
||||
|
||||
beforeEach((done) => {
|
||||
fixture = TestBed.createComponent(PdfViewerComponent);
|
||||
|
||||
element = fixture.nativeElement;
|
||||
component = fixture.componentInstance;
|
||||
|
||||
component.showToolbar = true;
|
||||
component.inputPage('1');
|
||||
component.currentScale = 1;
|
||||
|
||||
fixture.detectChanges();
|
||||
|
||||
fixture.whenStable().then(() => {
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('should Loader be present', () => {
|
||||
expect(element.querySelector('.loader-container')).not.toBeNull();
|
||||
});
|
||||
|
||||
describe('Required values', () => {
|
||||
it('should thrown an error If urlfile is not present', () => {
|
||||
change = new SimpleChange(null, null, true);
|
||||
|
||||
expect(() => {
|
||||
component.ngOnChanges({ 'urlFile': change });
|
||||
}).toThrow(new Error('Attribute urlFile or blobFile is required'));
|
||||
});
|
||||
|
||||
it('should If blobFile is not present thrown an error ', () => {
|
||||
change = new SimpleChange(null, null, true);
|
||||
|
||||
expect(() => {
|
||||
component.ngOnChanges({ 'blobFile': change });
|
||||
}).toThrow(new Error('Attribute urlFile or blobFile is required'));
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('View with url file', () => {
|
||||
beforeEach(() => {
|
||||
component.urlFile = require('../assets/fake-test-file.pdf');
|
||||
fixture.detectChanges();
|
||||
|
||||
let fixtureUrlTestComponent: ComponentFixture<UrlTestComponent>;
|
||||
let elementUrlTestComponent: HTMLElement;
|
||||
|
||||
beforeEach((done) => {
|
||||
fixtureUrlTestComponent = TestBed.createComponent(UrlTestComponent);
|
||||
elementUrlTestComponent = fixtureUrlTestComponent.nativeElement;
|
||||
|
||||
fixtureUrlTestComponent.detectChanges();
|
||||
|
||||
fixtureUrlTestComponent.whenStable().then(() => {
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('should thrown an error If urlfile is not present', () => {
|
||||
component.urlFile = undefined;
|
||||
it('should Canvas be present', (done) => {
|
||||
fixtureUrlTestComponent.detectChanges();
|
||||
fixtureUrlTestComponent.whenStable().then(() => {
|
||||
expect(elementUrlTestComponent.querySelector('.pdfViewer')).not.toBeNull();
|
||||
expect(elementUrlTestComponent.querySelector('.viewer-pdf-viewer')).not.toBeNull();
|
||||
done();
|
||||
});
|
||||
}, 5000);
|
||||
|
||||
fixture.detectChanges();
|
||||
it('should Next an Previous Buttons be present', (done) => {
|
||||
fixtureUrlTestComponent.detectChanges();
|
||||
fixtureUrlTestComponent.whenStable().then(() => {
|
||||
expect(elementUrlTestComponent.querySelector('#viewer-previous-page-button')).not.toBeNull();
|
||||
expect(elementUrlTestComponent.querySelector('#viewer-next-page-button')).not.toBeNull();
|
||||
done();
|
||||
});
|
||||
}, 5000);
|
||||
|
||||
expect(() => {
|
||||
component.ngOnChanges(null);
|
||||
}).toThrow(new Error('Attribute urlFile or blobFile is required'));
|
||||
});
|
||||
it('should Input Page elements be present', (done) => {
|
||||
|
||||
it('should Canvas be present', () => {
|
||||
expect(element.querySelector('.pdfViewer')).not.toBeNull();
|
||||
expect(element.querySelector('.viewer-pdf-viewer')).not.toBeNull();
|
||||
});
|
||||
fixtureUrlTestComponent.detectChanges();
|
||||
fixtureUrlTestComponent.whenStable().then(() => {
|
||||
expect(elementUrlTestComponent.querySelector('.viewer-pagenumber-input')).toBeDefined();
|
||||
expect(elementUrlTestComponent.querySelector('.viewer-total-pages')).toBeDefined();
|
||||
|
||||
it('should Loader be present', () => {
|
||||
expect(element.querySelector('.loader-container')).not.toBeNull();
|
||||
});
|
||||
expect(elementUrlTestComponent.querySelector('#viewer-previous-page-button')).not.toBeNull();
|
||||
expect(elementUrlTestComponent.querySelector('#viewer-next-page-button')).not.toBeNull();
|
||||
done();
|
||||
});
|
||||
}, 5000);
|
||||
|
||||
it('should Next an Previous Buttons be present', () => {
|
||||
expect(element.querySelector('#viewer-previous-page-button')).not.toBeNull();
|
||||
expect(element.querySelector('#viewer-next-page-button')).not.toBeNull();
|
||||
});
|
||||
|
||||
it('should Input Page elements be present', () => {
|
||||
expect(element.querySelector('.viewer-pagenumber-input')).toBeDefined();
|
||||
expect(element.querySelector('.viewer-total-pages')).toBeDefined();
|
||||
|
||||
expect(element.querySelector('#viewer-previous-page-button')).not.toBeNull();
|
||||
expect(element.querySelector('#viewer-next-page-button')).not.toBeNull();
|
||||
});
|
||||
|
||||
it('should Toolbar be hide if showToolbar is false', () => {
|
||||
it('should Toolbar be hide if showToolbar is false', (done) => {
|
||||
component.showToolbar = false;
|
||||
|
||||
fixture.detectChanges();
|
||||
|
||||
expect(element.querySelector('.viewer-toolbar-command')).toBeNull();
|
||||
expect(element.querySelector('.viewer-toolbar-pagination')).toBeNull();
|
||||
});
|
||||
fixtureUrlTestComponent.detectChanges();
|
||||
fixtureUrlTestComponent.whenStable().then(() => {
|
||||
expect(elementUrlTestComponent.querySelector('.viewer-toolbar-command')).toBeNull();
|
||||
expect(elementUrlTestComponent.querySelector('.viewer-toolbar-pagination')).toBeNull();
|
||||
done();
|
||||
});
|
||||
}, 5000);
|
||||
});
|
||||
|
||||
describe('View with blob file', () => {
|
||||
|
||||
beforeEach(() => {
|
||||
component.urlFile = undefined;
|
||||
component.blobFile = createFakeBlob();
|
||||
let fixtureBlobTestComponent: ComponentFixture<BlobTestComponent>;
|
||||
let componentBlobTestComponent: BlobTestComponent;
|
||||
let elementBlobTestComponent: HTMLElement;
|
||||
|
||||
fixture.detectChanges();
|
||||
beforeEach((done) => {
|
||||
fixtureBlobTestComponent = TestBed.createComponent(BlobTestComponent);
|
||||
componentBlobTestComponent = fixtureBlobTestComponent.componentInstance;
|
||||
elementBlobTestComponent = fixtureBlobTestComponent.nativeElement;
|
||||
|
||||
fixtureBlobTestComponent.detectChanges();
|
||||
|
||||
componentBlobTestComponent.pdfViewerComponent.rendered.subscribe(() => {
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('should If blobFile is not present thrown an error ', () => {
|
||||
component.blobFile = undefined;
|
||||
expect(() => {
|
||||
component.ngOnChanges(null);
|
||||
}).toThrow(new Error('Attribute urlFile or blobFile is required'));
|
||||
});
|
||||
it('should Canvas be present', (done) => {
|
||||
fixtureBlobTestComponent.detectChanges();
|
||||
|
||||
it('should Canvas be present', () => {
|
||||
expect(element.querySelector('.pdfViewer')).not.toBeNull();
|
||||
expect(element.querySelector('.viewer-pdf-viewer')).not.toBeNull();
|
||||
});
|
||||
fixtureBlobTestComponent.whenStable().then(() => {
|
||||
expect(elementBlobTestComponent.querySelector('.pdfViewer')).not.toBeNull();
|
||||
expect(elementBlobTestComponent.querySelector('.viewer-pdf-viewer')).not.toBeNull();
|
||||
done();
|
||||
};
|
||||
}, 5000);
|
||||
|
||||
it('should Loader be present', () => {
|
||||
expect(element.querySelector('.loader-container')).not.toBeNull();
|
||||
});
|
||||
it('should Next an Previous Buttons be present', (done) => {
|
||||
fixtureBlobTestComponent.detectChanges();
|
||||
|
||||
it('should Next an Previous Buttons be present', () => {
|
||||
expect(element.querySelector('#viewer-previous-page-button')).not.toBeNull();
|
||||
expect(element.querySelector('#viewer-next-page-button')).not.toBeNull();
|
||||
});
|
||||
fixtureBlobTestComponent.whenStable().then(() => {
|
||||
expect(elementBlobTestComponent.querySelector('#viewer-previous-page-button')).not.toBeNull();
|
||||
expect(elementBlobTestComponent.querySelector('#viewer-next-page-button')).not.toBeNull();
|
||||
done();
|
||||
};
|
||||
}, 5000);
|
||||
|
||||
it('should Input Page elements be present', () => {
|
||||
expect(element.querySelector('.viewer-pagenumber-input')).toBeDefined();
|
||||
expect(element.querySelector('.viewer-total-pages')).toBeDefined();
|
||||
it('should Input Page elements be present', (done) => {
|
||||
fixtureBlobTestComponent.detectChanges();
|
||||
|
||||
expect(element.querySelector('#viewer-previous-page-button')).not.toBeNull();
|
||||
expect(element.querySelector('#viewer-next-page-button')).not.toBeNull();
|
||||
});
|
||||
fixtureBlobTestComponent.whenStable().then(() => {
|
||||
expect(elementBlobTestComponent.querySelector('.viewer-pagenumber-input')).toBeDefined();
|
||||
expect(elementBlobTestComponent.querySelector('.viewer-total-pages')).toBeDefined();
|
||||
|
||||
it('should Toolbar be hide if showToolbar is false', () => {
|
||||
component.showToolbar = false;
|
||||
expect(elementBlobTestComponent.querySelector('#viewer-previous-page-button')).not.toBeNull();
|
||||
expect(elementBlobTestComponent.querySelector('#viewer-next-page-button')).not.toBeNull();
|
||||
done();
|
||||
};
|
||||
}, 5000);
|
||||
|
||||
fixture.detectChanges();
|
||||
it('should Toolbar be hide if showToolbar is false', (done) => {
|
||||
componentBlobTestComponent.pdfViewerComponent.showToolbar = false;
|
||||
|
||||
expect(element.querySelector('.viewer-toolbar-command')).toBeNull();
|
||||
expect(element.querySelector('.viewer-toolbar-pagination')).toBeNull();
|
||||
});
|
||||
fixtureBlobTestComponent.detectChanges();
|
||||
|
||||
fixtureBlobTestComponent.whenStable().then(() => {
|
||||
expect(elementBlobTestComponent.querySelector('.viewer-toolbar-command')).toBeNull();
|
||||
expect(elementBlobTestComponent.querySelector('.viewer-toolbar-pagination')).toBeNull();
|
||||
done();
|
||||
};
|
||||
}, 5000);
|
||||
});
|
||||
|
||||
describe('User interaction', () => {
|
||||
|
||||
beforeEach(async(() => {
|
||||
component.urlFile = require('../assets/fake-test-file.pdf');
|
||||
fixture.detectChanges();
|
||||
fixture.whenStable().then(() => {
|
||||
component.inputPage('1');
|
||||
let fixtureUrlTestComponent: ComponentFixture<UrlTestComponent>;
|
||||
let componentUrlTestComponent: UrlTestComponent;
|
||||
let elementUrlTestComponent: HTMLElement;
|
||||
|
||||
beforeEach((done) => {
|
||||
fixtureUrlTestComponent = TestBed.createComponent(UrlTestComponent);
|
||||
componentUrlTestComponent = fixtureUrlTestComponent.componentInstance;
|
||||
elementUrlTestComponent = fixtureUrlTestComponent.nativeElement;
|
||||
|
||||
fixtureUrlTestComponent.detectChanges();
|
||||
|
||||
componentUrlTestComponent.pdfViewerComponent.rendered.subscribe(() => {
|
||||
done();
|
||||
});
|
||||
}));
|
||||
});
|
||||
|
||||
it('should Total number of pages be loaded', (done) => {
|
||||
component.ngOnChanges(null).then(() => {
|
||||
fixture.detectChanges();
|
||||
fixture.whenStable().then(() => {
|
||||
expect(component.totalPages).toEqual(6);
|
||||
done();
|
||||
});
|
||||
});
|
||||
});
|
||||
fixtureUrlTestComponent.detectChanges();
|
||||
|
||||
it('should right arrow move to the next page', (done) => {
|
||||
component.ngOnChanges(null).then(() => {
|
||||
fixture.detectChanges();
|
||||
fixture.whenStable().then(() => {
|
||||
expect(component.displayPage).toBe(1);
|
||||
EventMock.keyDown(39);
|
||||
fixture.detectChanges();
|
||||
expect(component.displayPage).toBe(2);
|
||||
done();
|
||||
});
|
||||
fixtureUrlTestComponent.whenStable().then(() => {
|
||||
expect(componentUrlTestComponent.pdfViewerComponent.totalPages).toBe(6);
|
||||
done();
|
||||
});
|
||||
});
|
||||
}, 5000);
|
||||
|
||||
it('should nextPage move to the next page', (done) => {
|
||||
let nextPageButton: any = element.querySelector('#viewer-next-page-button');
|
||||
let nextPageButton: any = elementUrlTestComponent.querySelector('#viewer-next-page-button');
|
||||
nextPageButton.click();
|
||||
|
||||
component.ngOnChanges(null).then(() => {
|
||||
fixture.detectChanges();
|
||||
fixture.whenStable().then(() => {
|
||||
fixtureUrlTestComponent.detectChanges();
|
||||
|
||||
expect(component.displayPage).toBe(1);
|
||||
nextPageButton.click();
|
||||
fixture.detectChanges();
|
||||
expect(component.displayPage).toBe(2);
|
||||
fixtureUrlTestComponent.whenStable().then(() => {
|
||||
expect(componentUrlTestComponent.pdfViewerComponent.displayPage).toBe(2);
|
||||
done();
|
||||
});
|
||||
}, 5000);
|
||||
|
||||
it('should event RIGHT_ARROW keyboard change pages', (done) => {
|
||||
EventMock.keyDown(RIGHT_ARROW);
|
||||
|
||||
fixtureUrlTestComponent.detectChanges();
|
||||
|
||||
fixtureUrlTestComponent.whenStable().then(() => {
|
||||
expect(componentUrlTestComponent.pdfViewerComponent.displayPage).toBe(2);
|
||||
done();
|
||||
});
|
||||
}, 5000);
|
||||
|
||||
it('should event LEFT_ARROW keyboard change pages', (done) => {
|
||||
component.inputPage('2');
|
||||
|
||||
fixtureUrlTestComponent.detectChanges();
|
||||
|
||||
fixtureUrlTestComponent.whenStable().then(() => {
|
||||
EventMock.keyDown(LEFT_ARROW);
|
||||
|
||||
fixtureUrlTestComponent.detectChanges();
|
||||
|
||||
fixtureUrlTestComponent.whenStable().then(() => {
|
||||
expect(componentUrlTestComponent.pdfViewerComponent.displayPage).toBe(1);
|
||||
done();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
it('should event keyboard change pages', (done) => {
|
||||
component.ngOnChanges(null).then(() => {
|
||||
fixture.detectChanges();
|
||||
fixture.whenStable().then(() => {
|
||||
|
||||
expect(component.displayPage).toBe(1);
|
||||
EventMock.keyDown(39);
|
||||
EventMock.keyDown(39);
|
||||
EventMock.keyDown(37);
|
||||
fixture.detectChanges();
|
||||
expect(component.displayPage).toBe(2);
|
||||
done();
|
||||
});
|
||||
});
|
||||
});
|
||||
}, 5000);
|
||||
|
||||
it('should previous page move to the previous page', (done) => {
|
||||
let previousPageButton: any = element.querySelector('#viewer-previous-page-button');
|
||||
let nextPageButton: any = element.querySelector('#viewer-next-page-button');
|
||||
let previousPageButton: any = elementUrlTestComponent.querySelector('#viewer-previous-page-button');
|
||||
let nextPageButton: any = elementUrlTestComponent.querySelector('#viewer-next-page-button');
|
||||
|
||||
component.ngOnChanges(null).then(() => {
|
||||
fixture.detectChanges();
|
||||
fixture.whenStable().then(() => {
|
||||
nextPageButton.click();
|
||||
nextPageButton.click();
|
||||
previousPageButton.click();
|
||||
fixtureUrlTestComponent.detectChanges();
|
||||
|
||||
expect(component.displayPage).toBe(1);
|
||||
nextPageButton.click();
|
||||
nextPageButton.click();
|
||||
previousPageButton.click();
|
||||
fixture.detectChanges();
|
||||
expect(component.displayPage).toBe(2);
|
||||
done();
|
||||
});
|
||||
fixtureUrlTestComponent.whenStable().then(() => {
|
||||
expect(componentUrlTestComponent.pdfViewerComponent.displayPage).toBe(2);
|
||||
done();
|
||||
});
|
||||
});
|
||||
}, 5000);
|
||||
|
||||
it('should previous page not move to the previous page if is page 1', (done) => {
|
||||
component.ngOnChanges(null).then(() => {
|
||||
fixture.detectChanges();
|
||||
fixture.whenStable().then(() => {
|
||||
component.previousPage();
|
||||
fixtureUrlTestComponent.detectChanges();
|
||||
|
||||
expect(component.displayPage).toBe(1);
|
||||
component.previousPage();
|
||||
fixture.detectChanges();
|
||||
expect(component.displayPage).toBe(1);
|
||||
done();
|
||||
});
|
||||
fixtureUrlTestComponent.whenStable().then(() => {
|
||||
expect(componentUrlTestComponent.pdfViewerComponent.displayPage).toBe(1);
|
||||
done();
|
||||
});
|
||||
});
|
||||
}, 5000);
|
||||
|
||||
it('should Input page move to the inserted page', (done) => {
|
||||
component.ngOnChanges(null).then(() => {
|
||||
fixture.detectChanges();
|
||||
fixture.whenStable().then(() => {
|
||||
componentUrlTestComponent.pdfViewerComponent.inputPage('2');
|
||||
fixtureUrlTestComponent.detectChanges();
|
||||
|
||||
expect(component.displayPage).toBe(1);
|
||||
component.inputPage('2');
|
||||
fixture.detectChanges();
|
||||
expect(component.displayPage).toBe(2);
|
||||
done();
|
||||
});
|
||||
fixtureUrlTestComponent.whenStable().then(() => {
|
||||
expect(componentUrlTestComponent.pdfViewerComponent.displayPage).toBe(2);
|
||||
done();
|
||||
});
|
||||
});
|
||||
});
|
||||
}, 5000);
|
||||
|
||||
describe('Zoom', () => {
|
||||
describe('Zoom', () => {
|
||||
|
||||
beforeEach(async(() => {
|
||||
component.urlFile = require('../assets/fake-test-file.pdf');
|
||||
fixture.detectChanges();
|
||||
fixture.whenStable().then(() => {
|
||||
component.inputPage('1');
|
||||
component.currentScale = 1;
|
||||
});
|
||||
}));
|
||||
it('should zoom in increment the scale value', () => {
|
||||
let zoomInButton: any = elementUrlTestComponent.querySelector('#viewer-zoom-in-button');
|
||||
|
||||
it('should zoom in increment the scale value', (done) => {
|
||||
let zoomInButton: any = element.querySelector('#viewer-zoom-in-button');
|
||||
|
||||
component.ngOnChanges(null).then(() => {
|
||||
let zoomBefore = component.currentScale;
|
||||
let zoomBefore = componentUrlTestComponent.pdfViewerComponent.currentScale;
|
||||
zoomInButton.click();
|
||||
expect(component.currentScaleMode).toBe('auto');
|
||||
let currentZoom = component.currentScale;
|
||||
expect(componentUrlTestComponent.pdfViewerComponent.currentScaleMode).toBe('auto');
|
||||
let currentZoom = componentUrlTestComponent.pdfViewerComponent.currentScale;
|
||||
expect(zoomBefore < currentZoom).toBe(true);
|
||||
done();
|
||||
});
|
||||
});
|
||||
}, 5000);
|
||||
|
||||
it('should zoom out decrement the scale value', (done) => {
|
||||
let zoomOutButton: any = element.querySelector('#viewer-zoom-out-button');
|
||||
it('should zoom out decrement the scale value', () => {
|
||||
let zoomOutButton: any = elementUrlTestComponent.querySelector('#viewer-zoom-out-button');
|
||||
|
||||
component.ngOnChanges(null).then(() => {
|
||||
let zoomBefore = component.currentScale;
|
||||
let zoomBefore = componentUrlTestComponent.pdfViewerComponent.currentScale;
|
||||
zoomOutButton.click();
|
||||
expect(component.currentScaleMode).toBe('auto');
|
||||
let currentZoom = component.currentScale;
|
||||
expect(componentUrlTestComponent.pdfViewerComponent.currentScaleMode).toBe('auto');
|
||||
let currentZoom = componentUrlTestComponent.pdfViewerComponent.currentScale;
|
||||
expect(zoomBefore > currentZoom).toBe(true);
|
||||
done();
|
||||
});
|
||||
}, 5000);
|
||||
|
||||
it('should it-in button toggle page-fit and auto scale mode', () => {
|
||||
let itPage: any = elementUrlTestComponent.querySelector('#viewer-scale-page-button');
|
||||
|
||||
expect(componentUrlTestComponent.pdfViewerComponent.currentScaleMode).toBe('auto');
|
||||
itPage.click();
|
||||
expect(componentUrlTestComponent.pdfViewerComponent.currentScaleMode).toBe('page-fit');
|
||||
itPage.click();
|
||||
expect(componentUrlTestComponent.pdfViewerComponent.currentScaleMode).toBe('auto');
|
||||
}, 5000);
|
||||
});
|
||||
|
||||
it('should fit-in button toggle page-fit and auto scale mode', (done) => {
|
||||
let fitPage: any = element.querySelector('#viewer-scale-page-button');
|
||||
describe('Resize interaction', () => {
|
||||
|
||||
component.ngOnChanges(null).then(() => {
|
||||
expect(component.currentScaleMode).toBe('auto');
|
||||
fitPage.click();
|
||||
expect(component.currentScaleMode).toBe('page-fit');
|
||||
fitPage.click();
|
||||
expect(component.currentScaleMode).toBe('auto');
|
||||
done();
|
||||
});
|
||||
it('should resize event trigger setScaleUpdatePages', () => {
|
||||
spyOn(componentUrlTestComponent.pdfViewerComponent, 'onResize');
|
||||
EventMock.resizeMobileView();
|
||||
expect(componentUrlTestComponent.pdfViewerComponent.onResize).toHaveBeenCalled();
|
||||
}, 5000);
|
||||
});
|
||||
});
|
||||
|
||||
describe('Resize interaction', () => {
|
||||
describe('Thumbnails', () => {
|
||||
|
||||
beforeEach(async(() => {
|
||||
component.urlFile = require('../assets/fake-test-file.pdf');
|
||||
fixture.detectChanges();
|
||||
fixture.whenStable().then(() => {
|
||||
component.inputPage('1');
|
||||
component.currentScale = 1;
|
||||
});
|
||||
}));
|
||||
it('should have own context', () => {
|
||||
expect(componentUrlTestComponent.pdfViewerComponent.pdfThumbnailsContext.viewer).not.toBeNull();
|
||||
}, 5000);
|
||||
|
||||
it('should resize event trigger setScaleUpdatePages', (done) => {
|
||||
component.ngOnChanges(null).then(() => {
|
||||
fixture.detectChanges();
|
||||
fixture.whenStable().then(() => {
|
||||
it('should open thumbnails panel', (done) => {
|
||||
expect(elementUrlTestComponent.querySelector('.adf-pdf-viewer__thumbnails')).toBeNull();
|
||||
|
||||
spyOn(component, 'onResize');
|
||||
EventMock.resizeMobileView();
|
||||
expect(component.onResize).toHaveBeenCalled();
|
||||
componentUrlTestComponent.pdfViewerComponent.toggleThumbnails();
|
||||
fixtureUrlTestComponent.detectChanges();
|
||||
|
||||
fixtureUrlTestComponent.whenStable().then(() => {
|
||||
expect(elementUrlTestComponent.querySelector('.adf-pdf-viewer__thumbnails')).not.toBeNull();
|
||||
done();
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('scroll interaction', () => {
|
||||
|
||||
beforeEach(async(() => {
|
||||
component.urlFile = require('../assets/fake-test-file.pdf');
|
||||
fixture.detectChanges();
|
||||
fixture.whenStable().then(() => {
|
||||
component.inputPage('1');
|
||||
component.currentScale = 1;
|
||||
});
|
||||
}));
|
||||
|
||||
it('should scroll page return the current page', (done) => {
|
||||
component.ngOnChanges(null).then(() => {
|
||||
fixture.detectChanges();
|
||||
fixture.whenStable().then(() => {
|
||||
|
||||
expect(component.displayPage).toBe(1);
|
||||
|
||||
component.inputPage('2');
|
||||
fixture.detectChanges();
|
||||
expect(component.displayPage).toBe(2);
|
||||
|
||||
component.pdfViewer.currentPageNumber = 6;
|
||||
fixture.detectChanges();
|
||||
expect(component.displayPage).toBe(6);
|
||||
expect(component.page).toBe(6);
|
||||
done();
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('Thumbnails', () => {
|
||||
beforeEach(async () => {
|
||||
component.urlFile = require('../assets/fake-test-file.pdf');
|
||||
component.showThumbnails = false;
|
||||
fixture.detectChanges();
|
||||
fixture.whenStable().then(() => {
|
||||
component.inputPage('1');
|
||||
});
|
||||
}, 5000);
|
||||
});
|
||||
|
||||
it('should have own context', (done) => {
|
||||
component.ngOnChanges(null).then(() => {
|
||||
fixture.detectChanges();
|
||||
fixture.whenStable().then(() => {
|
||||
expect(component.pdfThumbnailsContext.viewer).not.toBeNull();
|
||||
done();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
it('should open thumbnails panel', (done) => {
|
||||
expect(element.querySelector('.adf-pdf-viewer__thumbnails')).toBeNull();
|
||||
|
||||
component.ngOnChanges(null).then(() => {
|
||||
fixture.detectChanges();
|
||||
fixture.whenStable().then(() => {
|
||||
component.toggleThumbnails();
|
||||
fixture.detectChanges();
|
||||
|
||||
expect(element.querySelector('.adf-pdf-viewer__thumbnails')).not.toBeNull();
|
||||
done();
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('Viewer events', () => {
|
||||
beforeEach(() => {
|
||||
component.urlFile = require('../assets/fake-test-file.pdf');
|
||||
fixture.detectChanges();
|
||||
});
|
||||
|
||||
it('should emit pagechange event', (done) => {
|
||||
component.ngOnChanges(null).then(() => {
|
||||
fixture.detectChanges();
|
||||
return fixture.whenStable().then(() => {
|
||||
expect(component.displayPage).toBe(1);
|
||||
describe('Viewer events', () => {
|
||||
|
||||
it('should react on the emit of pagechange event', (done) => {
|
||||
fixtureUrlTestComponent.detectChanges();
|
||||
fixtureUrlTestComponent.whenStable().then(() => {
|
||||
const args = {
|
||||
pageNumber: 6,
|
||||
source: {
|
||||
container: component.documentContainer
|
||||
container: componentUrlTestComponent.pdfViewerComponent.documentContainer
|
||||
}
|
||||
};
|
||||
|
||||
component.pdfViewer.eventBus.dispatch('pagechange', args);
|
||||
fixture.detectChanges();
|
||||
componentUrlTestComponent.pdfViewerComponent.pdfViewer.eventBus.dispatch('pagechange', args);
|
||||
fixtureUrlTestComponent.detectChanges();
|
||||
|
||||
expect(component.displayPage).toBe(6);
|
||||
expect(component.page).toBe(6);
|
||||
done();
|
||||
fixtureUrlTestComponent.whenStable().then(() => {
|
||||
expect(componentUrlTestComponent.pdfViewerComponent.displayPage).toBe(6);
|
||||
expect(componentUrlTestComponent.pdfViewerComponent.page).toBe(6);
|
||||
done();
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
}, 5000);
|
||||
|
||||
it('should emit pagesloaded event', (done) => {
|
||||
component.ngOnChanges(null).then(() => {
|
||||
fixture.detectChanges();
|
||||
return fixture.whenStable().then(() => {
|
||||
expect(component.isPanelDisabled).toBe(true);
|
||||
it('should react on the emit of pagesloaded event', (done) => {
|
||||
fixtureUrlTestComponent.detectChanges();
|
||||
fixtureUrlTestComponent.whenStable().then(() => {
|
||||
expect(componentUrlTestComponent.pdfViewerComponent.isPanelDisabled = false;
|
||||
|
||||
const args = {
|
||||
pagesCount: 10,
|
||||
source: {
|
||||
container: component.documentContainer
|
||||
container: componentUrlTestComponent.pdfViewerComponent.documentContainer
|
||||
}
|
||||
};
|
||||
|
||||
component.pdfViewer.eventBus.dispatch('pagesloaded', args);
|
||||
fixture.detectChanges();
|
||||
componentUrlTestComponent.pdfViewerComponent.pdfViewer.eventBus.dispatch('pagesloaded', args);
|
||||
fixtureUrlTestComponent.detectChanges();
|
||||
|
||||
expect(component.isPanelDisabled).toBe(false);
|
||||
done();
|
||||
fixtureUrlTestComponent.whenStable().then(() => {
|
||||
expect(componentUrlTestComponent.pdfViewerComponent.isPanelDisabled).toBe(false);
|
||||
done();
|
||||
});
|
||||
});
|
||||
});
|
||||
}, 5000);
|
||||
});
|
||||
|
||||
});
|
||||
});
|
||||
|
@@ -15,7 +15,17 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import { Component, TemplateRef, HostListener, Input, OnChanges, OnDestroy, ViewEncapsulation } from '@angular/core';
|
||||
import {
|
||||
Component,
|
||||
TemplateRef,
|
||||
HostListener,
|
||||
Output,
|
||||
Input,
|
||||
OnChanges,
|
||||
OnDestroy,
|
||||
ViewEncapsulation,
|
||||
EventEmitter
|
||||
} from '@angular/core';
|
||||
import { LogService } from '../../services/log.service';
|
||||
import { RenderingQueueServices } from '../services/rendering-queue.services';
|
||||
|
||||
@@ -52,6 +62,13 @@ export class PdfViewerComponent implements OnChanges, OnDestroy {
|
||||
@Input()
|
||||
thumbnailsTemplate: TemplateRef<any> = null;
|
||||
|
||||
@Output()
|
||||
rendered = new EventEmitter<any>();
|
||||
|
||||
@Output()
|
||||
error = new EventEmitter<any>();
|
||||
|
||||
loadingTask: any;
|
||||
currentPdfDocument: any;
|
||||
page: number;
|
||||
displayPage: number;
|
||||
@@ -80,37 +97,39 @@ export class PdfViewerComponent implements OnChanges, OnDestroy {
|
||||
// needed to preserve "this" context
|
||||
this.onPageChange = this.onPageChange.bind(this);
|
||||
this.onPagesLoaded = this.onPagesLoaded.bind(this);
|
||||
this.onPagerendered = this.onPagerendered.bind(this);
|
||||
}
|
||||
|
||||
ngOnChanges(changes) {
|
||||
let blobFile = changes['blobFile'];
|
||||
|
||||
if (blobFile && blobFile.currentValue) {
|
||||
let reader = new FileReader();
|
||||
reader.onload = () => {
|
||||
this.executePdf(reader.result);
|
||||
};
|
||||
reader.readAsArrayBuffer(blobFile.currentValue);
|
||||
}
|
||||
|
||||
let urlFile = changes['urlFile'];
|
||||
if (urlFile && urlFile.currentValue) {
|
||||
this.executePdf(urlFile.currentValue);
|
||||
}
|
||||
|
||||
if (!this.urlFile && !this.blobFile) {
|
||||
throw new Error('Attribute urlFile or blobFile is required');
|
||||
}
|
||||
|
||||
if (this.urlFile) {
|
||||
return new Promise((resolve, reject) => {
|
||||
this.executePdf(this.urlFile, resolve, reject);
|
||||
});
|
||||
} else {
|
||||
return new Promise((resolve, reject) => {
|
||||
let reader = new FileReader();
|
||||
reader.onload = () => {
|
||||
this.executePdf(reader.result, resolve, reject);
|
||||
};
|
||||
reader.readAsArrayBuffer(this.blobFile);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
executePdf(src, resolve, reject) {
|
||||
let loadingTask = this.getPDFJS().getDocument(src);
|
||||
executePdf(src) {
|
||||
this.loadingTask = this.getPDFJS().getDocument(src);
|
||||
|
||||
loadingTask.onProgress = (progressData) => {
|
||||
this.loadingTask.onProgress = (progressData) => {
|
||||
let level = progressData.loaded / progressData.total;
|
||||
this.loadingPercent = Math.round(level * 100);
|
||||
};
|
||||
|
||||
loadingTask.then((pdfDocument) => {
|
||||
this.loadingTask.then((pdfDocument) => {
|
||||
this.currentPdfDocument = pdfDocument;
|
||||
this.totalPages = pdfDocument.numPages;
|
||||
this.page = 1;
|
||||
@@ -119,13 +138,12 @@ export class PdfViewerComponent implements OnChanges, OnDestroy {
|
||||
|
||||
this.currentPdfDocument.getPage(1).then(() => {
|
||||
this.scalePage('auto');
|
||||
resolve();
|
||||
}, (error) => {
|
||||
reject(error);
|
||||
this.error.emit();
|
||||
});
|
||||
|
||||
}, (error) => {
|
||||
reject(error);
|
||||
this.error.emit();
|
||||
});
|
||||
}
|
||||
|
||||
@@ -145,6 +163,7 @@ export class PdfViewerComponent implements OnChanges, OnDestroy {
|
||||
this.documentContainer = document.getElementById('viewer-pdf-viewer');
|
||||
this.documentContainer.addEventListener('pagechange', this.onPageChange, true);
|
||||
this.documentContainer.addEventListener('pagesloaded', this.onPagesLoaded, true);
|
||||
this.documentContainer.addEventListener('textlayerrendered', this.onPagerendered, true);
|
||||
|
||||
this.pdfViewer = new PDFJS.PDFViewer({
|
||||
container: this.documentContainer,
|
||||
@@ -163,6 +182,11 @@ export class PdfViewerComponent implements OnChanges, OnDestroy {
|
||||
if (this.documentContainer) {
|
||||
this.documentContainer.removeEventListener('pagechange', this.onPageChange, true);
|
||||
this.documentContainer.removeEventListener('pagesloaded', this.onPagesLoaded, true);
|
||||
this.documentContainer.removeEventListener('textlayerrendered', this.onPagerendered, true);
|
||||
}
|
||||
|
||||
if (this.loadingTask) {
|
||||
this.loadingTask.destroy();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -373,6 +397,13 @@ export class PdfViewerComponent implements OnChanges, OnDestroy {
|
||||
this.displayPage = event.pageNumber;
|
||||
}
|
||||
|
||||
/**
|
||||
* Page Rendered Event
|
||||
*/
|
||||
onPagerendered() {
|
||||
this.rendered.emit();
|
||||
}
|
||||
|
||||
/**
|
||||
* Pages Loaded Event
|
||||
*
|
||||
|
@@ -24,8 +24,6 @@ import {
|
||||
} from '../../services';
|
||||
import { TxtViewerComponent } from './txtViewer.component';
|
||||
|
||||
declare var require: any;
|
||||
|
||||
describe('Text View component', () => {
|
||||
|
||||
let component: TxtViewerComponent;
|
||||
@@ -54,7 +52,7 @@ describe('Text View component', () => {
|
||||
|
||||
it('Should text container be present with urlfile', (done) => {
|
||||
fixture.detectChanges();
|
||||
let urlFile = require('../assets/fake-test-file.txt');
|
||||
let urlFile = './fake-test-file.txt';
|
||||
let change = new SimpleChange(null, urlFile, true);
|
||||
|
||||
component.ngOnChanges({ 'urlFile': change }).then(() => {
|
||||
|
@@ -127,8 +127,6 @@ class ViewerWithCustomOpenWithComponent {}
|
||||
})
|
||||
class ViewerWithCustomMoreActionsComponent {}
|
||||
|
||||
declare var require: any;
|
||||
|
||||
describe('ViewerComponent', () => {
|
||||
|
||||
let component: ViewerComponent;
|
||||
@@ -593,7 +591,7 @@ describe('ViewerComponent', () => {
|
||||
}));
|
||||
|
||||
it('should extension file txt be loaded', async(() => {
|
||||
component.urlFile = require('../assets/fake-test-file.txt');
|
||||
component.urlFile = 'fake-test-file.txt';
|
||||
component.ngOnChanges(null);
|
||||
fixture.detectChanges();
|
||||
|
||||
@@ -678,18 +676,18 @@ describe('ViewerComponent', () => {
|
||||
});
|
||||
}));
|
||||
|
||||
it('should display the txt viewer if the file identified by mimetype is a txt when the filename has wrong extension', async(() => {
|
||||
it('should display the txt viewer if the file identified by mimetype is a txt when the filename has wrong extension', (done) => {
|
||||
component.urlFile = 'content.bin';
|
||||
component.mimeType = 'text/plain';
|
||||
component.urlFile = require('../assets/fake-test-file.txt');
|
||||
fixture.detectChanges();
|
||||
component.ngOnChanges(null);
|
||||
|
||||
fixture.whenStable().then(() => {
|
||||
fixture.detectChanges();
|
||||
expect(element.querySelector('adf-txt-viewer')).not.toBeNull();
|
||||
done();
|
||||
});
|
||||
}));
|
||||
});
|
||||
|
||||
it('should display the media player if the file identified by mimetype is a media when the filename has no extension', async(() => {
|
||||
component.urlFile = 'content';
|
||||
|
Reference in New Issue
Block a user