mirror of
https://github.com/Alfresco/alfresco-ng2-components.git
synced 2025-07-24 17:32:15 +00:00
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:
BIN
lib/core/viewer/assets/fake-test-video.mp4
Normal file
BIN
lib/core/viewer/assets/fake-test-video.mp4
Normal file
Binary file not shown.
@@ -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);
|
||||
|
||||
});
|
||||
|
||||
|
@@ -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(() => {
|
||||
|
Reference in New Issue
Block a user