From 0fc504b69e617b8f580f8440e65a199037fb0723 Mon Sep 17 00:00:00 2001 From: Eugenio Romano Date: Tue, 16 Oct 2018 08:35:05 +0100 Subject: [PATCH] reintroduce viewer test (#3888) --- .../content-node-share.dialog.spec.ts | 11 +-- lib/content-services/karma.conf.js | 5 +- lib/core/karma.conf.js | 5 +- .../components/mediaPlayer.component.spec.ts | 2 +- .../components/pdfViewer.component.spec.ts | 36 ++++----- .../components/viewer.component.spec.ts | 73 +++++++++++-------- lib/insights/karma.conf.js | 5 +- .../task-attachment-list.component.spec.ts | 10 ++- lib/process-services/karma.conf.js | 5 +- 9 files changed, 77 insertions(+), 75 deletions(-) diff --git a/lib/content-services/content-node-share/content-node-share.dialog.spec.ts b/lib/content-services/content-node-share/content-node-share.dialog.spec.ts index c1f6195780..527d180924 100644 --- a/lib/content-services/content-node-share/content-node-share.dialog.spec.ts +++ b/lib/content-services/content-node-share/content-node-share.dialog.spec.ts @@ -16,7 +16,7 @@ */ import { NoopAnimationsModule } from '@angular/platform-browser/animations'; -import { TestBed, fakeAsync, async } from '@angular/core/testing'; +import { TestBed, fakeAsync } from '@angular/core/testing'; import { MatDialogRef, MAT_DIALOG_DATA, MatDialog } from '@angular/material'; import { of } from 'rxjs'; import { @@ -27,7 +27,7 @@ import { NotificationService } from '@alfresco/adf-core'; import { ContentNodeShareModule } from './content-node-share.module'; -import { ShareDialogComponent } from './content-node-share.dialog'; +import { ShareDialogComponent } from './content-node-share.dialog'; import moment from 'moment-es6'; describe('ShareDialogComponent', () => { @@ -113,7 +113,7 @@ describe('ShareDialogComponent', () => { expect(fixture.nativeElement.querySelector('.mat-slide-toggle').classList).toContain('mat-checked'); }); - it(`should copy shared link and notify on button event`, async(() => { + it(`should copy shared link and notify on button event`, (done) => { node.entry.properties['qshare:sharedId'] = 'sharedId'; spyOn(document, 'execCommand').and.callThrough(); @@ -128,14 +128,15 @@ describe('ShareDialogComponent', () => { fixture.detectChanges(); fixture.nativeElement.querySelector('.input-action') - .dispatchEvent(new MouseEvent('click')); + .dispatchEvent(new MouseEvent('click')); fixture.detectChanges(); expect(document.execCommand).toHaveBeenCalledWith('copy'); expect(notificationServiceMock.openSnackMessage).toHaveBeenCalledWith('SHARE.CLIPBOARD-MESSAGE'); + done(); }); - })); + }); it('should open a confirmation dialog when unshare button is triggered', () => { spyOn(matDialog, 'open').and.returnValue({ beforeClose: () => of(false) }); diff --git a/lib/content-services/karma.conf.js b/lib/content-services/karma.conf.js index fafa3944b7..abe03142cf 100644 --- a/lib/content-services/karma.conf.js +++ b/lib/content-services/karma.conf.js @@ -62,7 +62,7 @@ module.exports = function (config) { }, // possible values: config.LOG_DISABLE || config.LOG_ERROR || config.LOG_WARN || config.LOG_INFO || config.LOG_DEBUG - logLevel: config.LOG_DEBUG, + logLevel: config.LOG_INFO, colors: true, @@ -86,9 +86,6 @@ module.exports = function (config) { reporters: ['mocha', 'kjhtml'], port: 9876, - colors: true, - logLevel: config.LOG_INFO, - autoWatch: true, browsers: ['Chrome'], singleRun: false }); diff --git a/lib/core/karma.conf.js b/lib/core/karma.conf.js index a42b62dafd..f8de055666 100644 --- a/lib/core/karma.conf.js +++ b/lib/core/karma.conf.js @@ -77,7 +77,7 @@ module.exports = function (config) { }, // possible values: config.LOG_DISABLE || config.LOG_ERROR || config.LOG_WARN || config.LOG_INFO || config.LOG_DEBUG - logLevel: config.LOG_DEBUG, + logLevel: config.LOG_INFO, colors: true, @@ -101,9 +101,6 @@ module.exports = function (config) { reporters: ['mocha', 'kjhtml'], port: 9876, - colors: true, - logLevel: config.LOG_INFO, - autoWatch: true, browsers: ['Chrome'], singleRun: false }); diff --git a/lib/core/viewer/components/mediaPlayer.component.spec.ts b/lib/core/viewer/components/mediaPlayer.component.spec.ts index db93d3ddee..1664ca196d 100644 --- a/lib/core/viewer/components/mediaPlayer.component.spec.ts +++ b/lib/core/viewer/components/mediaPlayer.component.spec.ts @@ -22,7 +22,7 @@ import { setupTestBed } from '../../testing/setupTestBed'; import { CoreModule } from '../../core.module'; import { ContentService } from '../../services/content.service'; -describe('Test Media player component ', () => { +xdescribe('Test Media player component ', () => { let component: MediaPlayerComponent; let service: ContentService; diff --git a/lib/core/viewer/components/pdfViewer.component.spec.ts b/lib/core/viewer/components/pdfViewer.component.spec.ts index 3df61a96cc..366f22e23b 100644 --- a/lib/core/viewer/components/pdfViewer.component.spec.ts +++ b/lib/core/viewer/components/pdfViewer.component.spec.ts @@ -16,7 +16,7 @@ */ import { Component, SimpleChange, ViewChild } from '@angular/core'; -import { ComponentFixture, TestBed, async } from '@angular/core/testing'; +import { ComponentFixture, TestBed } from '@angular/core/testing'; import { EventMock } from '../../mock/event.mock'; import { RenderingQueueServices } from '../services/rendering-queue.services'; import { PdfViewerComponent } from './pdfViewer.component'; @@ -117,7 +117,7 @@ class BlobTestComponent { } -xdescribe('Test PdfViewer component', () => { +describe('Test PdfViewer component', () => { let component: PdfViewerComponent; let fixture: ComponentFixture; @@ -158,11 +158,6 @@ xdescribe('Test PdfViewer component', () => { done(); }); }); - - afterEach(() => { - fixture.destroy(); - }); - it('should Loader be present', () => { expect(element.querySelector('.loader-container')).not.toBeNull(); }); @@ -203,7 +198,7 @@ xdescribe('Test PdfViewer component', () => { }); afterEach(() => { - fixtureUrlTestComponent.destroy(); + document.body.removeChild(elementUrlTestComponent); }); it('should Canvas be present', (done) => { @@ -270,26 +265,28 @@ xdescribe('Test PdfViewer component', () => { }); afterEach(() => { - fixtureBlobTestComponent.destroy(); + document.body.removeChild(elementBlobTestComponent); }); - it('should Canvas be present', async(() => { + it('should Canvas be present', (done) => { fixtureBlobTestComponent.detectChanges(); fixtureBlobTestComponent.whenStable().then(() => { expect(elementBlobTestComponent.querySelector('.pdfViewer')).not.toBeNull(); expect(elementBlobTestComponent.querySelector('.viewer-pdf-viewer')).not.toBeNull(); + done(); }); - })); + }); - it('should Next an Previous Buttons be present', async(() => { + 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(); }); - })); + }); it('should Input Page elements be present', (done) => { fixtureBlobTestComponent.detectChanges(); @@ -338,7 +335,7 @@ xdescribe('Test PdfViewer component', () => { }); afterEach(() => { - fixtureUrlTestComponent.destroy(); + document.body.removeChild(elementUrlTestComponent); }); it('should Total number of pages be loaded', (done) => { @@ -362,7 +359,7 @@ xdescribe('Test PdfViewer component', () => { }); }, 5000); - xit('should event RIGHT_ARROW keyboard change pages', async(() => { + it('should event RIGHT_ARROW keyboard change pages', (done) => { EventMock.keyDown(RIGHT_ARROW); fixtureUrlTestComponent.detectChanges(); @@ -370,10 +367,11 @@ xdescribe('Test PdfViewer component', () => { fixtureUrlTestComponent.whenStable().then(() => { fixtureUrlTestComponent.detectChanges(); expect(componentUrlTestComponent.pdfViewerComponent.displayPage).toBe(2); + done(); }); - }), 5000); + }, 5000); - xit('should event LEFT_ARROW keyboard change pages', (done) => { + it('should event LEFT_ARROW keyboard change pages', (done) => { component.inputPage('2'); fixtureUrlTestComponent.detectChanges(); @@ -565,6 +563,10 @@ xdescribe('Test PdfViewer component', () => { }); }); + afterEach(() => { + document.body.removeChild(fixtureUrlTestPasswordComponent.nativeElement); + }); + it('should try to access protected pdf', (done) => { fixture.detectChanges(); fixture.whenStable().then(() => { diff --git a/lib/core/viewer/components/viewer.component.spec.ts b/lib/core/viewer/components/viewer.component.spec.ts index 1e2110aea4..368405820f 100644 --- a/lib/core/viewer/components/viewer.component.spec.ts +++ b/lib/core/viewer/components/viewer.component.spec.ts @@ -18,7 +18,7 @@ import { Location } from '@angular/common'; import { SpyLocation } from '@angular/common/testing'; import { Component } from '@angular/core'; -import { async, ComponentFixture, TestBed, fakeAsync, tick } from '@angular/core/testing'; +import { ComponentFixture, TestBed, fakeAsync, tick } from '@angular/core/testing'; import { AlfrescoApiService, RenditionsService } from '../../services'; import { CoreModule } from '../../core.module'; @@ -119,7 +119,7 @@ class ViewerWithCustomOpenWithComponent { class ViewerWithCustomMoreActionsComponent { } -xdescribe('ViewerComponent', () => { +describe('ViewerComponent', () => { let component: ViewerComponent; let fixture: ComponentFixture; @@ -159,10 +159,6 @@ xdescribe('ViewerComponent', () => { alfrescoApiService = TestBed.get(AlfrescoApiService); }); - afterEach(() => { - fixture.destroy(); - }); - describe('Extension Type Test', () => { it('should extension file pdf be loaded', (done) => { @@ -201,7 +197,7 @@ xdescribe('ViewerComponent', () => { }); }); - it('should extension file mp3 be loaded', (done) => { + xit('should extension file mp3 be loaded', (done) => { component.urlFile = 'fake-url-file.mp3'; component.ngOnChanges(null); fixture.detectChanges(); @@ -213,7 +209,7 @@ xdescribe('ViewerComponent', () => { }); }); - it('should extension file wav be loaded', (done) => { + xit('should extension file wav be loaded', (done) => { component.urlFile = 'fake-url-file.wav'; component.ngOnChanges(null); fixture.detectChanges(); @@ -331,7 +327,7 @@ xdescribe('ViewerComponent', () => { }); }); - it('should display the media player if the file identified by mimetype is a media when the filename has no extension', (done) => { + 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(); @@ -344,7 +340,7 @@ xdescribe('ViewerComponent', () => { }); }); - it('should node without content show unkonwn', async(() => { + it('should node without content show unkonwn', (done) => { const displayName = 'the-name'; const nodeDetails = { name: displayName, id: '12' }; const contentUrl = '/content/url/path'; @@ -362,8 +358,9 @@ xdescribe('ViewerComponent', () => { fixture.whenStable().then(() => { fixture.detectChanges(); expect(element.querySelector('adf-viewer-unknown-format')).toBeDefined(); + done(); }); - })); + }); }); @@ -393,7 +390,7 @@ xdescribe('ViewerComponent', () => { expect(component.fileTitle).toBe('file2'); })); - xdescribe('Viewer Example Component Rendering', () => { + describe('Viewer Example Component Rendering', () => { it('should use custom toolbar', (done) => { let customFixture = TestBed.createComponent(ViewerWithCustomToolbarComponent); @@ -566,17 +563,20 @@ xdescribe('ViewerComponent', () => { }); }); - it('should raise download event with the toolbar button', async(() => { + it('should raise download event with the toolbar button', (done) => { component.allowDownload = true; + component.downloadUrl = 'URL'; + component.fileName = 'fileName'; fixture.detectChanges(); component.download.subscribe(e => { expect(e).not.toBeNull(); + done(); }); const button: HTMLButtonElement = element.querySelector('[data-automation-id="adf-toolbar-download"]') as HTMLButtonElement; button.click(); - })); + }); it('should render default print button', (done) => { component.allowPrint = true; @@ -613,17 +613,18 @@ xdescribe('ViewerComponent', () => { }); }); - it('should raise the print event with the toolbar button', async(() => { + it('should raise the print event with the toolbar button', (done) => { component.allowPrint = true; fixture.detectChanges(); component.print.subscribe(e => { expect(e).not.toBeNull(); + done(); }); const button: HTMLButtonElement = element.querySelector('[data-automation-id="adf-toolbar-print"]') as HTMLButtonElement; button.click(); - })); + }); it('should render default share button', (done) => { component.allowShare = true; @@ -660,17 +661,18 @@ xdescribe('ViewerComponent', () => { }); }); - it('should raise share event with the toolbar button', async(() => { + it('should raise share event with the toolbar button', (done) => { component.allowShare = true; fixture.detectChanges(); component.share.subscribe(e => { expect(e).not.toBeNull(); + done(); }); const button: HTMLButtonElement = element.querySelector('[data-automation-id="adf-toolbar-share"]') as HTMLButtonElement; button.click(); - })); + }); }); @@ -687,14 +689,15 @@ xdescribe('ViewerComponent', () => { expect(element.querySelector('.adf-viewer-toolbar')).not.toBeNull(); }); - it('should Name File be present if is overlay mode ', async(() => { + it('should Name File be present if is overlay mode ', (done) => { component.ngOnChanges(null); fixture.detectChanges(); fixture.whenStable().then(() => { fixture.detectChanges(); expect(element.querySelector('#adf-viewer-display-name').textContent).toEqual('fake-test-file.pdf'); + done(); }); - })); + }); it('should Close button be present if overlay mode', (done) => { fixture.detectChanges(); @@ -843,21 +846,22 @@ xdescribe('ViewerComponent', () => { describe('Events', () => { - it('should if the extension change extension Change event be fired ', async(() => { + it('should if the extension change extension Change event be fired ', (done) => { component.extensionChange.subscribe((fileExtension) => { expect(fileExtension).toEqual('png'); + done(); }); component.urlFile = 'fake-url-file.png'; component.ngOnChanges(null); - })); + }); }); describe('display name property override by urlFile', () => { - it('should displayName override the default name if is present and urlFile is set', async(() => { + it('should displayName override the default name if is present and urlFile is set', (done) => { component.urlFile = 'fake-test-file.pdf'; component.displayName = 'test name'; fixture.detectChanges(); @@ -866,10 +870,11 @@ xdescribe('ViewerComponent', () => { fixture.whenStable().then(() => { fixture.detectChanges(); expect(element.querySelector('#adf-viewer-display-name').textContent).toEqual('test name'); + done(); }); - })); + }); - it('should use the urlFile name if displayName is NOT set and urlFile is set', async(() => { + it('should use the urlFile name if displayName is NOT set and urlFile is set', (done) => { component.urlFile = 'fake-test-file.pdf'; component.displayName = null; fixture.detectChanges(); @@ -878,13 +883,14 @@ xdescribe('ViewerComponent', () => { fixture.whenStable().then(() => { fixture.detectChanges(); expect(element.querySelector('#adf-viewer-display-name').textContent).toEqual('fake-test-file.pdf'); + done(); }); - })); + }); }); describe('display name property override by blobFile', () => { - it('should displayName override the name if is present and blobFile is set', async(() => { + it('should displayName override the name if is present and blobFile is set', (done) => { component.displayName = 'blob file display name'; component.blobFile = new Blob(['This is my blob content'], { type: 'text/plain' }); fixture.detectChanges(); @@ -893,10 +899,11 @@ xdescribe('ViewerComponent', () => { fixture.whenStable().then(() => { fixture.detectChanges(); expect(element.querySelector('#adf-viewer-display-name').textContent).toEqual('blob file display name'); + done(); }); - })); + }); - it('should show uknownn name if displayName is NOT set and blobFile is set', async(() => { + it('should show uknownn name if displayName is NOT set and blobFile is set', (done) => { component.displayName = null; component.blobFile = new Blob(['This is my blob content'], { type: 'text/plain' }); fixture.detectChanges(); @@ -905,8 +912,9 @@ xdescribe('ViewerComponent', () => { fixture.whenStable().then(() => { fixture.detectChanges(); expect(element.querySelector('#adf-viewer-display-name').textContent).toEqual('Unknown'); + done(); }); - })); + }); }); describe('display name property override by nodeId', () => { @@ -919,7 +927,7 @@ xdescribe('ViewerComponent', () => { content: { getContentUrl: () => contentUrl } }; - it('should use the node name if displayName is NOT set and fileNodeId is set', async(() => { + it('should use the node name if displayName is NOT set and fileNodeId is set', (done) => { component.fileNodeId = '12'; component.urlFile = null; component.displayName = null; @@ -929,8 +937,9 @@ xdescribe('ViewerComponent', () => { fixture.whenStable().then(() => { fixture.detectChanges(); expect(element.querySelector('#adf-viewer-display-name').textContent).toEqual(displayName); + done(); }); - })); + }); }); }); diff --git a/lib/insights/karma.conf.js b/lib/insights/karma.conf.js index 4c6bbefce2..63d7b39885 100644 --- a/lib/insights/karma.conf.js +++ b/lib/insights/karma.conf.js @@ -68,7 +68,7 @@ module.exports = function (config) { }, // possible values: config.LOG_DISABLE || config.LOG_ERROR || config.LOG_WARN || config.LOG_INFO || config.LOG_DEBUG - logLevel: config.LOG_DEBUG, + logLevel: config.LOG_INFO, colors: true, @@ -92,9 +92,6 @@ module.exports = function (config) { reporters: ['mocha', 'kjhtml'], port: 9876, - colors: true, - logLevel: config.LOG_INFO, - autoWatch: true, browsers: ['Chrome'], singleRun: false }); diff --git a/lib/process-services/attachment/task-attachment-list.component.spec.ts b/lib/process-services/attachment/task-attachment-list.component.spec.ts index 615ba5d972..876210a37b 100644 --- a/lib/process-services/attachment/task-attachment-list.component.spec.ts +++ b/lib/process-services/attachment/task-attachment-list.component.spec.ts @@ -130,15 +130,16 @@ describe('TaskAttachmentList', () => { expect(getTaskRelatedContentSpy).not.toHaveBeenCalled(); }); - it('should display attachments when the task has attachments', async(() => { + it('should display attachments when the task has attachments', (done) => { let change = new SimpleChange(null, '123', true); component.ngOnChanges({ 'taskId': change }); fixture.detectChanges(); fixture.whenStable().then(() => { expect(fixture.debugElement.queryAll(By.css('.adf-datatable-body > .adf-datatable-row')).length).toBe(2); + done(); }); - })); + }); it('emit document when a user wants to view the document', () => { component.emitDocumentContent(mockAttachment.data[1]); @@ -271,13 +272,14 @@ describe('TaskAttachmentList', () => { }); })); - it('should fetch new attachments when taskId changed', async(() => { + it('should fetch new attachments when taskId changed', (done) => { fixture.detectChanges(); fixture.whenStable().then(() => { component.ngOnChanges({ 'taskId': change }); expect(getTaskRelatedContentSpy).toHaveBeenCalledWith('456'); + done(); }); - })); + }); it('should NOT fetch new attachments when empty change set made', () => { component.ngOnChanges({}); diff --git a/lib/process-services/karma.conf.js b/lib/process-services/karma.conf.js index eafdfddc61..10a55ad097 100644 --- a/lib/process-services/karma.conf.js +++ b/lib/process-services/karma.conf.js @@ -71,7 +71,7 @@ module.exports = function (config) { }, // possible values: config.LOG_DISABLE || config.LOG_ERROR || config.LOG_WARN || config.LOG_INFO || config.LOG_DEBUG - logLevel: config.LOG_DEBUG, + logLevel: config.LOG_INFO, colors: true, @@ -95,9 +95,6 @@ module.exports = function (config) { reporters: ['mocha', 'kjhtml'], port: 9876, - colors: true, - logLevel: config.LOG_INFO, - autoWatch: true, browsers: ['Chrome'], singleRun: false });