[ACS-12098] firefox headless race condition viewer fix (#12023)

* [ACS-12098] firefox headless race condition viewer fix

* [ACS-12098] review fixes 1

* [ACS-12098] review fixes 2

* [ACS-12098] review fixes 3

* last firefox headless fixes
This commit is contained in:
Adam Świderski
2026-07-07 13:21:14 +02:00
committed by GitHub
parent 2f50af623d
commit 45d1818f04
8 changed files with 342 additions and 36 deletions
@@ -27,6 +27,7 @@ import { PdfThumbListComponent } from '../pdf-viewer-thumbnails/pdf-viewer-thumb
import { PDFJS_MODULE, PDFJS_VIEWER_MODULE, PdfViewerComponent } from './pdf-viewer.component';
import pdfjsLibraryMock, { annotations } from '../mock/pdfjs-lib.mock';
import { TranslateService } from '@ngx-translate/core';
import { PDFDocumentLoadingTask } from 'pdfjs-dist/types/src/display/api';
declare const pdfjsLib: {
PasswordResponses: {
@@ -354,6 +355,54 @@ describe('Test PdfViewer component', () => {
});
});
describe('Test PdfViewer - executePdf error handling', () => {
let fixture: ComponentFixture<PdfViewerComponent>;
let component: PdfViewerComponent;
beforeEach(() => {
const failingLoadingTask = {
promise: Promise.reject(new Error('PDF load failed')),
onPassword: null,
onProgress: null,
destroy: () => Promise.resolve()
} as PDFDocumentLoadingTask;
const pdfjsLibMock = {
GlobalWorkerOptions: {},
getDocument: () => failingLoadingTask
};
TestBed.configureTestingModule({
imports: [PdfViewerComponent],
providers: [
provideCoreAuthTesting(),
{
provide: MatDialog,
useValue: {
open: () => {}
}
},
RenderingQueueServices,
{ provide: PDFJS_MODULE, useValue: pdfjsLibMock }
]
});
fixture = TestBed.createComponent(PdfViewerComponent);
component = fixture.componentInstance;
});
it('should emit error event when PDF loading fails', fakeAsync(() => {
spyOn(component.error, 'emit');
// Pre-set the worker URL so the real setupPdfJsWorker logic runs without performing a network fetch
component.pdfJsWorkerUrl = URL.createObjectURL(new Blob([''], { type: 'application/javascript' }));
component.executePdf({ data: new ArrayBuffer(0) });
flush();
expect(component.error.emit).toHaveBeenCalled();
}));
});
describe('Test PdfViewer - Zoom customization', () => {
let fixture: ComponentFixture<PdfViewerComponent>;
let component: PdfViewerComponent;
@@ -292,7 +292,9 @@ export class PdfViewerComponent implements OnChanges, OnDestroy {
.then(() => {
setTimeout(() => this.scalePage('init'));
})
.catch(() => this.error.emit());
.catch(() => {
this.error.emit();
});
});
}