Clean pdf viewer unit (#4916)

* fix unit test pdf viewer

* add more clean unit test core

* add more clean unit test core

* Delete license-info-3.3.0.md
This commit is contained in:
Eugenio Romano 2019-07-10 20:03:05 +01:00 committed by GitHub
parent 3d336bf9bd
commit 7a70e88ae3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
9 changed files with 1472 additions and 1484 deletions

View File

@ -1,6 +1,8 @@
var PROXY_HOST_ADF = process.env.PROXY_HOST_ADF;
module.exports = {
"/alfresco": {
"target": "http://localhost:8080",
"target": (PROXY_HOST_ADF || "http://localhost:8080"),
"secure": false,
"pathRewrite": {
"^/alfresco/alfresco": ""
@ -15,7 +17,7 @@ module.exports = {
}
},
"/activiti-app": {
"target": "http://localhost:8080",
"target": (PROXY_HOST_ADF || "http://localhost:8080"),
"secure": false,
"pathRewrite": {
"^/activiti-app/activiti-app": ""

View File

@ -100,7 +100,7 @@ describe('DateTimeWidgetComponent', () => {
widget.field = field;
widget.onDateChanged({ value: moment('2008-09-15T15:53:00') });
widget.onDateChanged({ value: moment('1982-03-13T10:00:000Z') });
expect(widget.onFieldChanged).toHaveBeenCalledWith(field);
});

View File

@ -38,6 +38,7 @@ module.exports = function (config) {
{pattern: 'lib/config/app.config.json', included: false, served: true, watched: false},
{pattern: 'lib/core/viewer/assets/fake-test-file.pdf', included: false, served: true, watched: false},
{pattern: 'lib/core/viewer/assets/fake-test-file.txt', included: false, served: true, watched: false},
{pattern: 'lib/core/viewer/assets/fake-test-video.mp4', included: false, served: true, watched: false},
{
pattern: 'lib/core//viewer/assets/fake-test-password-file.pdf',
included: false,
@ -63,8 +64,15 @@ module.exports = function (config) {
'/assets/adf-core/i18n/en-GB.json': '/base/lib/core/i18n/en.json',
'/assets/adf-core/i18n/en-US.json': '/base/lib/core/i18n/en.json',
'/app.config.json': '/base/lib/config/app.config.json',
'/fake-content-img' : '/base/lib/core/assets/images/logo.png',
'/fake-content-img.bin' : '/base/lib/core/assets/images/logo.png',
'/fake-test-file.pdf': '/base/lib/core/viewer/assets/fake-test-file.pdf',
'/fake-content-pdf': '/base/lib/core/viewer/assets/fake-test-file.pdf',
'/fake-content-pdf.bin': '/base/lib/core/viewer/assets/fake-test-file.pdf',
'/fake-test-file.txt': '/base/lib/core/viewer/assets/fake-test-file.txt',
'/fake-content-video.bin': '/base/lib/core/viewer/assets/fake-test-video.mp4',
'/fake-content-video': '/base/lib/core/viewer/assets/fake-test-video.mp4',
'/fake-content-txt.bin': '/base/lib/core/viewer/assets/fake-test-file.txt',
'/fake-test-password-file.pdf': '/base/lib/core/viewer/assets/fake-test-password-file.pdf'
},

View File

@ -20,7 +20,6 @@ import { NodePaging, QueryBody } from '@alfresco/js-api';
import { Observable, Subject, from, throwError } from 'rxjs';
import { AlfrescoApiService } from './alfresco-api.service';
import { SearchConfigurationService } from './search-configuration.service';
import { catchError } from 'rxjs/operators';
@Injectable({
providedIn: 'root'
@ -44,11 +43,9 @@ export class SearchService {
promise.then((nodePaging: NodePaging) => {
this.dataLoaded.next(nodePaging);
});
}).catch((err) => this.handleError(err));
return from(promise).pipe(
catchError((err) => this.handleError(err))
);
return from(promise);
}
/**
@ -64,11 +61,9 @@ export class SearchService {
promise.then((nodePaging: NodePaging) => {
this.dataLoaded.next(nodePaging);
});
}).catch((err) => this.handleError(err));
return from(promise).pipe(
catchError((err) => this.handleError(err))
);
return from(promise);
}
/**
@ -81,11 +76,9 @@ export class SearchService {
promise.then((nodePaging: NodePaging) => {
this.dataLoaded.next(nodePaging);
});
}).catch((err) => this.handleError(err));
return from(promise).pipe(
catchError((err: any) => this.handleError(err))
);
return from(promise);
}
private handleError(error: any): Observable<any> {

Binary file not shown.

View File

@ -165,6 +165,7 @@ describe('Test PdfViewer component', () => {
done();
});
});
it('should Loader be present', () => {
expect(element.querySelector('.adf-loader-container')).not.toBeNull();
});
@ -206,18 +207,18 @@ describe('Test PdfViewer component', () => {
afterEach(() => {
document.body.removeChild(elementUrlTestComponent);
fixture.destroy();
});
it('should Canvas be present', fakeAsync(() => {
it('should Canvas be present', (done) => {
fixtureUrlTestComponent.detectChanges();
tick(250);
fixtureUrlTestComponent.whenStable().then(() => {
expect(elementUrlTestComponent.querySelector('.adf-pdfViewer')).not.toBeNull();
expect(elementUrlTestComponent.querySelector('.adf-viewer-pdf-viewer')).not.toBeNull();
done();
});
}));
}, 25000);
it('should Next an Previous Buttons be present', (done) => {
fixtureUrlTestComponent.detectChanges();
@ -226,7 +227,7 @@ describe('Test PdfViewer component', () => {
expect(elementUrlTestComponent.querySelector('#viewer-next-page-button')).not.toBeNull();
done();
});
}, 5000);
}, 25000);
it('should Input Page elements be present', (done) => {
@ -240,7 +241,7 @@ describe('Test PdfViewer component', () => {
expect(elementUrlTestComponent.querySelector('#viewer-next-page-button')).not.toBeNull();
done();
});
}, 5000);
}, 25000);
it('should Toolbar be hide if showToolbar is false', (done) => {
component.showToolbar = false;
@ -251,7 +252,7 @@ describe('Test PdfViewer component', () => {
expect(elementUrlTestComponent.querySelector('.viewer-toolbar-pagination')).toBeNull();
done();
});
}, 5000);
}, 25000);
});
describe('View with blob file', () => {
@ -276,6 +277,7 @@ describe('Test PdfViewer component', () => {
afterEach(() => {
document.body.removeChild(elementBlobTestComponent);
fixture.destroy();
});
it('should Canvas be present', () => {
@ -287,14 +289,15 @@ describe('Test PdfViewer component', () => {
});
});
it('should Next an Previous Buttons be present', () => {
it('should Next an Previous Buttons be present', (done) => {
fixtureBlobTestComponent.detectChanges();
fixtureBlobTestComponent.whenStable().then(() => {
expect(elementBlobTestComponent.querySelector('#viewer-previous-page-button')).not.toBeNull();
expect(elementBlobTestComponent.querySelector('#viewer-next-page-button')).not.toBeNull();
done();
});
});
}, 25000);
it('should Input Page elements be present', (done) => {
fixtureBlobTestComponent.detectChanges();
@ -308,7 +311,7 @@ describe('Test PdfViewer component', () => {
expect(elementBlobTestComponent.querySelector('#viewer-next-page-button')).not.toBeNull();
done();
});
}, 5000);
}, 25000);
it('should Toolbar be hide if showToolbar is false', (done) => {
componentBlobTestComponent.pdfViewerComponent.showToolbar = false;
@ -320,7 +323,7 @@ describe('Test PdfViewer component', () => {
expect(elementBlobTestComponent.querySelector('.viewer-toolbar-pagination')).toBeNull();
done();
});
}, 5000);
}, 25000);
});
describe('Password protection dialog', () => {
@ -421,7 +424,7 @@ describe('Test PdfViewer component', () => {
expect(componentUrlTestComponent.pdfViewerComponent.totalPages).toBe(6);
done();
});
}, 5000);
}, 25000);
it('should nextPage move to the next page', (done) => {
const nextPageButton: any = elementUrlTestComponent.querySelector('#viewer-next-page-button');
@ -433,7 +436,7 @@ describe('Test PdfViewer component', () => {
expect(componentUrlTestComponent.pdfViewerComponent.displayPage).toBe(2);
done();
});
}, 5000);
}, 25000);
it('should event RIGHT_ARROW keyboard change pages', (done) => {
EventMock.keyDown(RIGHT_ARROW);
@ -445,7 +448,7 @@ describe('Test PdfViewer component', () => {
expect(componentUrlTestComponent.pdfViewerComponent.displayPage).toBe(2);
done();
});
}, 5000);
}, 25000);
it('should event LEFT_ARROW keyboard change pages', (done) => {
component.inputPage('2');
@ -462,7 +465,7 @@ describe('Test PdfViewer component', () => {
done();
});
});
}, 5000);
}, 25000);
it('should previous page move to the previous page', (done) => {
const previousPageButton: any = elementUrlTestComponent.querySelector('#viewer-previous-page-button');
@ -477,7 +480,7 @@ describe('Test PdfViewer component', () => {
expect(componentUrlTestComponent.pdfViewerComponent.displayPage).toBe(2);
done();
});
}, 5000);
}, 25000);
it('should previous page not move to the previous page if is page 1', (done) => {
component.previousPage();
@ -487,7 +490,7 @@ describe('Test PdfViewer component', () => {
expect(componentUrlTestComponent.pdfViewerComponent.displayPage).toBe(1);
done();
});
}, 5000);
}, 25000);
it('should Input page move to the inserted page', (done) => {
componentUrlTestComponent.pdfViewerComponent.inputPage('2');
@ -497,7 +500,7 @@ describe('Test PdfViewer component', () => {
expect(componentUrlTestComponent.pdfViewerComponent.displayPage).toBe(2);
done();
});
}, 5000);
}, 25000);
describe('Resize interaction', () => {
@ -510,7 +513,7 @@ describe('Test PdfViewer component', () => {
done();
});
}, 5000);
}, 25000);
});
describe('Thumbnails', () => {
@ -522,7 +525,7 @@ describe('Test PdfViewer component', () => {
expect(componentUrlTestComponent.pdfViewerComponent.pdfThumbnailsContext.viewer).not.toBeNull();
done();
});
}, 5000);
}, 25000);
it('should open thumbnails panel', (done) => {
expect(elementUrlTestComponent.querySelector('.adf-pdf-viewer__thumbnails')).toBeNull();
@ -535,7 +538,7 @@ describe('Test PdfViewer component', () => {
expect(elementUrlTestComponent.querySelector('.adf-pdf-viewer__thumbnails')).not.toBeNull();
done();
});
}, 5000);
}, 25000);
});
describe('Viewer events', () => {
@ -560,7 +563,7 @@ describe('Test PdfViewer component', () => {
done();
});
});
}, 5000);
}, 25000);
it('should react on the emit of pagesLoaded event', (done) => {
fixtureUrlTestComponent.detectChanges();
@ -583,7 +586,7 @@ describe('Test PdfViewer component', () => {
done();
});
});
}, 5000);
}, 25000);
});

View File

@ -181,6 +181,10 @@ describe('ViewerComponent', () => {
describe('Extension Type Test', () => {
afterEach(() => {
fixture.destroy();
});
it('should extension file pdf be loaded', (done) => {
component.urlFile = 'fake-test-file.pdf';
component.ngOnChanges(null);
@ -269,34 +273,12 @@ describe('ViewerComponent', () => {
describe('MimeType handling', () => {
it('should display a PDF file identified by mimetype when the filename has no extension', (done) => {
component.urlFile = 'content';
component.mimeType = 'application/pdf';
fixture.detectChanges();
component.ngOnChanges(null);
fixture.whenStable().then(() => {
fixture.detectChanges();
expect(element.querySelector('adf-pdf-viewer')).not.toBeNull();
done();
});
});
it('should display a PDF file identified by mimetype when the file extension is wrong', (done) => {
component.urlFile = 'content.bin';
component.mimeType = 'application/pdf';
component.ngOnChanges(null);
fixture.detectChanges();
fixture.whenStable().then(() => {
fixture.detectChanges();
expect(element.querySelector('adf-pdf-viewer')).not.toBeNull();
done();
});
afterEach(() => {
fixture.destroy();
});
it('should display an image file identified by mimetype when the filename has no extension', (done) => {
component.urlFile = 'content';
component.urlFile = 'fake-content-img';
component.mimeType = 'image/png';
fixture.detectChanges();
component.ngOnChanges(null);
@ -309,7 +291,7 @@ describe('ViewerComponent', () => {
});
it('should display a image file identified by mimetype when the file extension is wrong', (done) => {
component.urlFile = 'content.bin';
component.urlFile = 'fake-content-img.bin';
component.mimeType = 'image/png';
fixture.detectChanges();
component.ngOnChanges(null);
@ -321,21 +303,8 @@ describe('ViewerComponent', () => {
});
});
it('should display the media player if the file identified by mimetype is a media when the filename has wrong extension', (done) => {
component.urlFile = 'content.bin';
component.mimeType = 'video/mp4';
fixture.detectChanges();
component.ngOnChanges(null);
fixture.whenStable().then(() => {
fixture.detectChanges();
expect(element.querySelector('adf-media-player')).not.toBeNull();
done();
});
});
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.urlFile = 'fake-content-txt.bin';
component.mimeType = 'text/plain';
fixture.detectChanges();
component.ngOnChanges(null);
@ -347,19 +316,6 @@ describe('ViewerComponent', () => {
});
});
xit('should display the media player if the file identified by mimetype is a media when the filename has no extension', (done) => {
component.urlFile = 'content';
component.mimeType = 'video/mp4';
fixture.detectChanges();
component.ngOnChanges(null);
fixture.whenStable().then(() => {
fixture.detectChanges();
expect(element.querySelector('adf-media-player')).not.toBeNull();
done();
});
});
it('should node without content show unkonwn', (done) => {
const displayName = 'the-name';
const nodeDetails = { name: displayName, id: '12' };
@ -367,7 +323,7 @@ describe('ViewerComponent', () => {
const alfrescoApiInstanceMock = {
nodes: {
getNodeInfo: () => Promise.resolve(nodeDetails),
getNode: () => Promise.resolve({ id: 'fake-node' })
getNode: () => Promise.resolve({ id: 'fake-node', entry: { content: {} } })
},
content: { getContentUrl: () => contentUrl }
};
@ -385,6 +341,58 @@ describe('ViewerComponent', () => {
});
});
it('should display the media player if the file identified by mimetype is a media when the filename has wrong extension', (done) => {
component.urlFile = 'fake-content-video.bin';
component.mimeType = 'video/mp4';
fixture.detectChanges();
component.ngOnChanges(null);
fixture.whenStable().then(() => {
fixture.detectChanges();
expect(element.querySelector('adf-media-player')).not.toBeNull();
done();
});
}, 25000);
it('should display the media player if the file identified by mimetype is a media when the filename has no extension', (done) => {
component.urlFile = 'fake-content-video';
component.mimeType = 'video/mp4';
fixture.detectChanges();
component.ngOnChanges(null);
fixture.whenStable().then(() => {
fixture.detectChanges();
expect(element.querySelector('adf-media-player')).not.toBeNull();
done();
});
}, 25000);
it('should display a PDF file identified by mimetype when the filename has no extension', (done) => {
component.urlFile = 'fake-content-pdf';
component.mimeType = 'application/pdf';
fixture.detectChanges();
component.ngOnChanges(null);
fixture.whenStable().then(() => {
fixture.detectChanges();
expect(element.querySelector('adf-pdf-viewer')).not.toBeNull();
done();
});
}, 25000);
it('should display a PDF file identified by mimetype when the file extension is wrong', (done) => {
component.urlFile = 'fake-content-pdf.bin';
component.mimeType = 'application/pdf';
component.ngOnChanges(null);
fixture.detectChanges();
fixture.whenStable().then(() => {
fixture.detectChanges();
expect(element.querySelector('adf-pdf-viewer')).not.toBeNull();
done();
});
}, 25000);
});
it('should change display name every time node changes', fakeAsync(() => {

2754
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@ -109,7 +109,7 @@
"moment-es6": "^1.0.0",
"ng2-charts": "1.6.0",
"ngx-monaco-editor": "^7.0.0",
"pdfjs-dist": "^2.0.489",
"pdfjs-dist": "2.0.489",
"raphael": "2.2.7",
"reflect-metadata": "0.1.13",
"remark-validate-links": "^8.0.0",