From 6e230adaa51eece1b33f61c59c9518df07fc940b Mon Sep 17 00:00:00 2001 From: VitoAlbano Date: Wed, 5 Mar 2025 18:27:54 +0000 Subject: [PATCH] [ci:force][AAE-30877] - fixing core pdf test --- lib/core/karma.conf.js | 1 - .../pdf-viewer/pdf-viewer.component.spec.ts | 84 +++++++++---------- 2 files changed, 40 insertions(+), 45 deletions(-) diff --git a/lib/core/karma.conf.js b/lib/core/karma.conf.js index dbd3f7e463..1c945cbaab 100644 --- a/lib/core/karma.conf.js +++ b/lib/core/karma.conf.js @@ -7,7 +7,6 @@ const { constants } = require('karma'); module.exports = function (config) { config.set({ basePath: '../../', - files: [ { pattern: 'node_modules/pdfjs-dist/build/pdf.min.mjs', type: 'module', included: true, watched: false }, { pattern: 'node_modules/pdfjs-dist/build/pdf.worker.min.mjs', type: 'module', included: true, watched: false }, diff --git a/lib/core/src/lib/viewer/components/pdf-viewer/pdf-viewer.component.spec.ts b/lib/core/src/lib/viewer/components/pdf-viewer/pdf-viewer.component.spec.ts index 40259428be..836afdbe4c 100644 --- a/lib/core/src/lib/viewer/components/pdf-viewer/pdf-viewer.component.spec.ts +++ b/lib/core/src/lib/viewer/components/pdf-viewer/pdf-viewer.component.spec.ts @@ -20,11 +20,11 @@ import { Component, SimpleChange, ViewChild } from '@angular/core'; import { ComponentFixture, fakeAsync, TestBed, tick } from '@angular/core/testing'; import { MatDialog } from '@angular/material/dialog'; import { By } from '@angular/platform-browser'; -import { of } from 'rxjs'; +import { firstValueFrom, of } from 'rxjs'; import { take } from 'rxjs/operators'; import { AppConfigService } from '../../../app-config'; import { EventMock } from '../../../mock'; -import { CoreTestingModule, UnitTestingUtils } from '../../../testing'; +import { NoopAuthModule, NoopTranslateModule, UnitTestingUtils } from '../../../testing'; import { RenderingQueueServices } from '../../services/rendering-queue.services'; import { PdfThumbListComponent } from '../pdf-viewer-thumbnails/pdf-viewer-thumbnails.component'; import { PdfViewerComponent } from './pdf-viewer.component'; @@ -40,6 +40,7 @@ declare const pdfjsLib: any; class TestDialogComponent {} @Component({ + selector: 'adf-url-test-component', standalone: true, imports: [PdfViewerComponent], template: ` ` @@ -56,6 +57,7 @@ class UrlTestComponent { } @Component({ + selector: 'adf-url-test-password-component', standalone: true, imports: [PdfViewerComponent], template: ` ` @@ -115,7 +117,7 @@ describe('Test PdfViewer component', () => { beforeEach(async () => { TestBed.configureTestingModule({ - imports: [CoreTestingModule, UrlTestComponent, TestDialogComponent, UrlTestPasswordComponent, BlobTestComponent], + imports: [NoopAuthModule, NoopTranslateModule, UrlTestComponent, TestDialogComponent, UrlTestPasswordComponent, BlobTestComponent], providers: [ { provide: MatDialog, @@ -138,6 +140,10 @@ describe('Test PdfViewer component', () => { await fixture.whenStable(); }); + afterEach(() => { + fixture.destroy(); + }); + describe('User interaction', () => { let fixtureUrlTestComponent: ComponentFixture; let componentUrlTestComponent: UrlTestComponent; @@ -148,6 +154,8 @@ describe('Test PdfViewer component', () => { componentUrlTestComponent = fixtureUrlTestComponent.componentInstance; elementUrlTestComponent = fixtureUrlTestComponent.nativeElement; testingUtils.setDebugElement(fixtureUrlTestComponent.debugElement); + const appConfig: AppConfigService = TestBed.inject(AppConfigService); + appConfig.config['adf-viewer.pdf-viewer-scaling'] = 10; fixtureUrlTestComponent.detectChanges(); @@ -160,34 +168,26 @@ describe('Test PdfViewer component', () => { document.body.removeChild(elementUrlTestComponent); }); - it('should init the viewer with annotation mode disabled', (done) => { + it('should init the viewer with annotation mode disabled', fakeAsync(() => { fixtureUrlTestComponent.detectChanges(); + tick(400); + expect(componentUrlTestComponent.pdfViewerComponent.pdfViewer.annotationEditorMode).toBe(AnnotationMode.DISABLE); + })); - fixtureUrlTestComponent.whenStable().then(() => { - expect(componentUrlTestComponent.pdfViewerComponent.pdfViewer.annotationEditorMode).toBe(AnnotationMode.DISABLE); - done(); - }); - }, 55000); - - it('should Total number of pages be loaded', (done) => { + it('should Total number of pages be loaded', fakeAsync(() => { fixtureUrlTestComponent.detectChanges(); + tick(400); + expect(componentUrlTestComponent.pdfViewerComponent.totalPages).toBe(6); + })); - fixtureUrlTestComponent.whenStable().then(() => { - expect(componentUrlTestComponent.pdfViewerComponent.totalPages).toBe(6); - done(); - }); - }, 55000); - - it('should nextPage move to the next page', (done) => { + it('should nextPage move to the next page', fakeAsync(() => { testingUtils.clickByCSS('#viewer-next-page-button'); fixtureUrlTestComponent.detectChanges(); + tick(400); - fixtureUrlTestComponent.whenStable().then(() => { - expect(componentUrlTestComponent.pdfViewerComponent.displayPage).toBe(2); - done(); - }); - }, 55000); + expect(componentUrlTestComponent.pdfViewerComponent.displayPage).toBe(2); + })); it('should event RIGHT_ARROW keyboard change pages', fakeAsync(() => { fixtureUrlTestComponent.whenStable(); @@ -249,31 +249,33 @@ describe('Test PdfViewer component', () => { }, 55000); describe('Zoom', () => { - it('should zoom in increment the scale value', (done) => { + it('should zoom in increment the scale value', async () => { spyOn(componentUrlTestComponent.pdfViewerComponent.pdfViewer, 'forceRendering').and.callFake(() => {}); const zoomBefore = componentUrlTestComponent.pdfViewerComponent.pdfViewer.currentScaleValue; testingUtils.clickByCSS('#viewer-zoom-in-button'); fixtureUrlTestComponent.detectChanges(); + await fixtureUrlTestComponent.whenRenderingDone(); expect(componentUrlTestComponent.pdfViewerComponent.currentScaleMode).toBe('auto'); const currentZoom = componentUrlTestComponent.pdfViewerComponent.pdfViewer.currentScaleValue; expect(zoomBefore < currentZoom).toBe(true); - done(); - }, 55000); + }); - it('should zoom out decrement the scale value', (done) => { + it('should zoom out decrement the scale value', async () => { spyOn(componentUrlTestComponent.pdfViewerComponent.pdfViewer, 'forceRendering').and.callFake(() => {}); - + testingUtils.clickByCSS('#viewer-zoom-in-button'); + fixtureUrlTestComponent.detectChanges(); const zoomBefore = componentUrlTestComponent.pdfViewerComponent.pdfViewer.currentScaleValue; + testingUtils.clickByCSS('#viewer-zoom-out-button'); fixtureUrlTestComponent.detectChanges(); + await fixtureUrlTestComponent.whenRenderingDone(); expect(componentUrlTestComponent.pdfViewerComponent.currentScaleMode).toBe('auto'); const currentZoom = componentUrlTestComponent.pdfViewerComponent.pdfViewer.currentScaleValue; expect(zoomBefore > currentZoom).toBe(true); - done(); - }, 55000); + }); it('should it-in button toggle page-fit and auto scale mode', fakeAsync(() => { spyOn(componentUrlTestComponent.pdfViewerComponent.pdfViewer, 'forceRendering').and.callFake(() => {}); @@ -286,7 +288,7 @@ describe('Test PdfViewer component', () => { expect(componentUrlTestComponent.pdfViewerComponent.currentScaleMode).toBe('auto'); testingUtils.clickByCSS('#viewer-scale-page-button'); expect(componentUrlTestComponent.pdfViewerComponent.currentScaleMode).toBe('page-fit'); - }), 55000); + }), 300); }); describe('Resize interaction', () => { @@ -454,14 +456,13 @@ describe('Test PdfViewer component', () => { }); }); }); - // TODO: https://alfresco.atlassian.net/browse/ACS-6061 - // eslint-disable-next-line - xdescribe('greater than the maximum allowed value', () => { + + describe('greater than the maximum allowed value', () => { let fixtureUrlTestComponent: ComponentFixture; let componentUrlTestComponent: UrlTestComponent; let elementUrlTestComponent: HTMLElement; - beforeEach((done) => { + beforeEach(() => { const appConfig: AppConfigService = TestBed.inject(AppConfigService); appConfig.config['adf-viewer.pdf-viewer-scaling'] = 55555; @@ -470,24 +471,19 @@ describe('Test PdfViewer component', () => { elementUrlTestComponent = fixtureUrlTestComponent.nativeElement; fixtureUrlTestComponent.detectChanges(); - - componentUrlTestComponent.pdfViewerComponent.rendered.pipe(take(1)).subscribe(() => { - done(); - }); }); afterEach(() => { document.body.removeChild(elementUrlTestComponent); }); - it('should use the maximum scale zoom if the value given in app.config is greater than the maximum allowed scale', (done) => { + it('should use the maximum scale zoom if the value given in app.config is greater than the maximum allowed scale', async () => { + await firstValueFrom(componentUrlTestComponent.pdfViewerComponent.rendered) spyOn(componentUrlTestComponent.pdfViewerComponent.pdfViewer, 'forceRendering').and.callFake(() => {}); fixtureUrlTestComponent.detectChanges(); - fixtureUrlTestComponent.whenStable().then(() => { - expect(componentUrlTestComponent.pdfViewerComponent.pdfViewer.currentScale).toBe(10); - done(); - }); + await fixtureUrlTestComponent.whenStable(); + expect(componentUrlTestComponent.pdfViewerComponent.pdfViewer.currentScale).toBe(10); }); }); });