mirror of
https://github.com/Alfresco/alfresco-ng2-components.git
synced 2025-07-24 17:32:15 +00:00
[ADF-3501] PDF view fixes (#3735)
* PDF view fixes * updated package.lock * fix failing tests * restore test * use fake web worker for tests * test fixes * test fixes * disable i18n test * test fixes
This commit is contained in:
committed by
Eugenio Romano
parent
567d172176
commit
c0acc53eb9
@@ -16,14 +16,11 @@
|
||||
*/
|
||||
|
||||
import { SimpleChange } from '@angular/core';
|
||||
import { async, ComponentFixture, TestBed } from '@angular/core/testing';
|
||||
import { ComponentFixture, TestBed } from '@angular/core/testing';
|
||||
import { MediaPlayerComponent } from './mediaPlayer.component';
|
||||
import { setupTestBed } from '../../testing/setupTestBed';
|
||||
import { CoreModule } from '../../core.module';
|
||||
|
||||
import {
|
||||
ContentService
|
||||
} from '../../services';
|
||||
import { ContentService } from '../../services/content.service';
|
||||
|
||||
describe('Test Media player component ', () => {
|
||||
|
||||
@@ -40,9 +37,9 @@ describe('Test Media player component ', () => {
|
||||
imports: [CoreModule.forRoot()]
|
||||
});
|
||||
|
||||
beforeEach(async(() => {
|
||||
beforeEach(() => {
|
||||
service = TestBed.get(ContentService);
|
||||
}));
|
||||
});
|
||||
|
||||
beforeEach(() => {
|
||||
fixture = TestBed.createComponent(MediaPlayerComponent);
|
||||
@@ -51,10 +48,13 @@ describe('Test Media player component ', () => {
|
||||
fixture.detectChanges();
|
||||
});
|
||||
|
||||
afterEach(() => {
|
||||
fixture.destroy();
|
||||
});
|
||||
|
||||
it('should thrown an error If no url or no blob are passed', () => {
|
||||
let change = new SimpleChange(null, null, true);
|
||||
expect(() => {
|
||||
component.ngOnChanges({ 'blobFile': change });
|
||||
component.ngOnChanges({});
|
||||
}).toThrow(new Error('Attribute urlFile or blobFile is required'));
|
||||
});
|
||||
|
||||
|
@@ -22,7 +22,7 @@ import { setupTestBed } from '../../testing/setupTestBed';
|
||||
import { CoreModule } from '../../core.module';
|
||||
import { NoopAnimationsModule } from '@angular/platform-browser/animations';
|
||||
|
||||
declare let PDFJS: any;
|
||||
declare const pdfjsLib: any;
|
||||
|
||||
describe('PdfPasswordDialogComponent', () => {
|
||||
let component: PdfPasswordDialogComponent;
|
||||
@@ -68,13 +68,13 @@ describe('PdfPasswordDialogComponent', () => {
|
||||
});
|
||||
|
||||
it('should return false', () => {
|
||||
component.data.reason = PDFJS.PasswordResponses.NEED_PASSWORD;
|
||||
component.data.reason = pdfjsLib.PasswordResponses.NEED_PASSWORD;
|
||||
|
||||
expect(component.isError()).toBe(false);
|
||||
});
|
||||
|
||||
it('should return true', () => {
|
||||
component.data.reason = PDFJS.PasswordResponses.INCORRECT_PASSWORD;
|
||||
component.data.reason = pdfjsLib.PasswordResponses.INCORRECT_PASSWORD;
|
||||
|
||||
expect(component.isError()).toBe(true);
|
||||
});
|
||||
|
@@ -19,7 +19,7 @@ import { Component, Inject, OnInit } from '@angular/core';
|
||||
import { MatDialogRef, MAT_DIALOG_DATA } from '@angular/material';
|
||||
import { FormControl, Validators } from '@angular/forms';
|
||||
|
||||
declare let PDFJS: any;
|
||||
declare const pdfjsLib: any;
|
||||
|
||||
@Component({
|
||||
selector: 'adf-pdf-viewer-password-dialog',
|
||||
@@ -39,7 +39,7 @@ export class PdfPasswordDialogComponent implements OnInit {
|
||||
}
|
||||
|
||||
isError(): boolean {
|
||||
return this.data.reason === PDFJS.PasswordResponses.INCORRECT_PASSWORD;
|
||||
return this.data.reason === pdfjsLib.PasswordResponses.INCORRECT_PASSWORD;
|
||||
}
|
||||
|
||||
isValid(): boolean {
|
||||
|
@@ -22,7 +22,7 @@ import { PdfThumbListComponent } from './pdfViewer-thumbnails.component';
|
||||
import { setupTestBed } from '../../testing/setupTestBed';
|
||||
import { CoreModule } from '../../core.module';
|
||||
|
||||
declare let PDFJS: any;
|
||||
declare const pdfjsViewer: any;
|
||||
|
||||
describe('PdfThumbListComponent', () => {
|
||||
|
||||
@@ -57,7 +57,7 @@ describe('PdfThumbListComponent', () => {
|
||||
page(9), page(10), page(11), page(12),
|
||||
page(13), page(14), page(15), page(16)
|
||||
],
|
||||
eventBus: new PDFJS.EventBus()
|
||||
eventBus: new pdfjsViewer.EventBus()
|
||||
};
|
||||
|
||||
setupTestBed({
|
||||
|
@@ -28,7 +28,7 @@ import { CoreModule } from '../../core.module';
|
||||
import { TranslationService } from '../../services/translation.service';
|
||||
import { TranslationMock } from '../../mock/translation.service.mock';
|
||||
|
||||
declare let PDFJS: any;
|
||||
declare const pdfjsLib: any;
|
||||
|
||||
@Component({
|
||||
selector: 'adf-test-dialog-component',
|
||||
@@ -528,13 +528,13 @@ describe('Test PdfViewer component', () => {
|
||||
componentUrlTestPasswordComponent = fixtureUrlTestPasswordComponent.componentInstance;
|
||||
|
||||
spyOn(dialog, 'open').and.callFake((comp, context) => {
|
||||
if (context.data.reason === PDFJS.PasswordResponses.NEED_PASSWORD) {
|
||||
if (context.data.reason === pdfjsLib.PasswordResponses.NEED_PASSWORD) {
|
||||
return {
|
||||
afterClosed: () => of('wrong_password')
|
||||
};
|
||||
}
|
||||
|
||||
if (context.data.reason === PDFJS.PasswordResponses.INCORRECT_PASSWORD) {
|
||||
if (context.data.reason === pdfjsLib.PasswordResponses.INCORRECT_PASSWORD) {
|
||||
return {
|
||||
afterClosed: () => of('password')
|
||||
};
|
||||
@@ -563,7 +563,7 @@ describe('Test PdfViewer component', () => {
|
||||
fixture.whenStable().then(() => {
|
||||
fixture.detectChanges();
|
||||
expect(dialog.open['calls'].all()[0].args[1].data).toEqual({
|
||||
reason: PDFJS.PasswordResponses.NEED_PASSWORD
|
||||
reason: pdfjsLib.PasswordResponses.NEED_PASSWORD
|
||||
});
|
||||
done();
|
||||
});
|
||||
@@ -574,7 +574,7 @@ describe('Test PdfViewer component', () => {
|
||||
fixture.whenStable().then(() => {
|
||||
fixture.detectChanges();
|
||||
expect(dialog.open['calls'].all()[1].args[1].data).toEqual({
|
||||
reason: PDFJS.PasswordResponses.INCORRECT_PASSWORD
|
||||
reason: pdfjsLib.PasswordResponses.INCORRECT_PASSWORD
|
||||
});
|
||||
done();
|
||||
});
|
||||
|
@@ -31,7 +31,8 @@ import { RenderingQueueServices } from '../services/rendering-queue.services';
|
||||
import { PdfPasswordDialogComponent } from './pdfViewer-password-dialog';
|
||||
import { MatDialog } from '@angular/material';
|
||||
|
||||
declare let PDFJS: any;
|
||||
declare const pdfjsLib: any;
|
||||
declare const pdfjsViewer: any;
|
||||
|
||||
@Component({
|
||||
selector: 'adf-pdf-viewer',
|
||||
@@ -126,7 +127,9 @@ export class PdfViewerComponent implements OnChanges, OnDestroy {
|
||||
}
|
||||
|
||||
executePdf(src) {
|
||||
this.loadingTask = this.getPDFJS().getDocument(src);
|
||||
|
||||
pdfjsLib.GlobalWorkerOptions.workerSrc = 'pdf.worker.min.js';
|
||||
this.loadingTask = pdfjsLib.getDocument(src);
|
||||
|
||||
this.loadingTask.onPassword = (callback, reason) => {
|
||||
this.onPdfPassword(callback, reason);
|
||||
@@ -155,35 +158,27 @@ export class PdfViewerComponent implements OnChanges, OnDestroy {
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* return the PDFJS global object (exist to facilitate the mock of PDFJS in the test)
|
||||
*/
|
||||
getPDFJS() {
|
||||
return PDFJS;
|
||||
}
|
||||
|
||||
initPDFViewer(pdfDocument: any) {
|
||||
PDFJS.verbosity = 1;
|
||||
PDFJS.disableWorker = false;
|
||||
|
||||
const viewer: any = document.getElementById('viewer-viewerPdf');
|
||||
const container = document.getElementById('viewer-pdf-viewer');
|
||||
|
||||
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);
|
||||
if (viewer && container) {
|
||||
this.documentContainer = container;
|
||||
|
||||
this.pdfViewer = new PDFJS.PDFViewer({
|
||||
container: this.documentContainer,
|
||||
viewer: viewer,
|
||||
renderingQueue: this.renderingQueueServices
|
||||
});
|
||||
this.documentContainer.addEventListener('pagechange', this.onPageChange, true);
|
||||
this.documentContainer.addEventListener('pagesloaded', this.onPagesLoaded, true);
|
||||
this.documentContainer.addEventListener('textlayerrendered', this.onPagerendered, true);
|
||||
|
||||
this.renderingQueueServices.setViewer(this.pdfViewer);
|
||||
this.pdfViewer = new pdfjsViewer.PDFViewer({
|
||||
container: this.documentContainer,
|
||||
viewer: viewer,
|
||||
renderingQueue: this.renderingQueueServices
|
||||
});
|
||||
|
||||
this.pdfViewer.setDocument(pdfDocument);
|
||||
|
||||
this.pdfThumbnailsContext.viewer = this.pdfViewer;
|
||||
this.renderingQueueServices.setViewer(this.pdfViewer);
|
||||
this.pdfViewer.setDocument(pdfDocument);
|
||||
this.pdfThumbnailsContext.viewer = this.pdfViewer;
|
||||
}
|
||||
}
|
||||
|
||||
ngOnDestroy() {
|
||||
@@ -192,10 +187,6 @@ export class PdfViewerComponent implements OnChanges, OnDestroy {
|
||||
this.documentContainer.removeEventListener('pagesloaded', this.onPagesLoaded, true);
|
||||
this.documentContainer.removeEventListener('textlayerrendered', this.onPagerendered, true);
|
||||
}
|
||||
|
||||
if (this.loadingTask) {
|
||||
this.loadingTask.destroy();
|
||||
}
|
||||
}
|
||||
|
||||
toggleThumbnails() {
|
||||
|
@@ -159,6 +159,10 @@ describe('ViewerComponent', () => {
|
||||
alfrescoApiService = TestBed.get(AlfrescoApiService);
|
||||
});
|
||||
|
||||
afterEach(() => {
|
||||
fixture.destroy();
|
||||
});
|
||||
|
||||
it('should change display name every time node changes', fakeAsync(() => {
|
||||
spyOn(alfrescoApiService.nodesApi, 'getNodeInfo').and.returnValues(
|
||||
Promise.resolve({ name: 'file1', content: {} }),
|
||||
|
Reference in New Issue
Block a user