From 17af7541a1921ba6e2b072decea4e2cdf57e699b Mon Sep 17 00:00:00 2001 From: shamoon <4887959+shamoon@users.noreply.github.com> Date: Tue, 19 Nov 2024 18:52:35 -0800 Subject: [PATCH] Fix tests --- .../preview-popup.component.spec.ts | 21 ++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/src-ui/src/app/components/common/preview-popup/preview-popup.component.spec.ts b/src-ui/src/app/components/common/preview-popup/preview-popup.component.spec.ts index dd600642f..12021fc90 100644 --- a/src-ui/src/app/components/common/preview-popup/preview-popup.component.spec.ts +++ b/src-ui/src/app/components/common/preview-popup/preview-popup.component.spec.ts @@ -20,6 +20,8 @@ import { withInterceptorsFromDi, } from '@angular/common/http' import { of, throwError } from 'rxjs' +import { NgbPopoverModule } from '@ng-bootstrap/ng-bootstrap' +import { DocumentTitlePipe } from 'src/app/pipes/document-title.pipe' const doc = { id: 10, @@ -39,8 +41,12 @@ describe('PreviewPopupComponent', () => { beforeEach(() => { TestBed.configureTestingModule({ - declarations: [PreviewPopupComponent, SafeUrlPipe], - imports: [NgxBootstrapIconsModule.pick(allIcons), PdfViewerModule], + declarations: [PreviewPopupComponent, SafeUrlPipe, DocumentTitlePipe], + imports: [ + NgxBootstrapIconsModule.pick(allIcons), + PdfViewerModule, + NgbPopoverModule, + ], providers: [ provideHttpClient(withInterceptorsFromDi()), provideHttpClientTesting(), @@ -75,12 +81,14 @@ describe('PreviewPopupComponent', () => { it('should render object if native PDF viewer enabled', () => { settingsService.set(SETTINGS_KEYS.USE_NATIVE_PDF_VIEWER, true) + component.popover.open() fixture.detectChanges() expect(fixture.debugElement.query(By.css('object'))).not.toBeNull() }) it('should render pngx viewer if native PDF viewer disabled', () => { settingsService.set(SETTINGS_KEYS.USE_NATIVE_PDF_VIEWER, false) + component.popover.open() fixture.detectChanges() expect(fixture.debugElement.query(By.css('object'))).toBeNull() expect(fixture.debugElement.query(By.css('pdf-viewer'))).not.toBeNull() @@ -88,6 +96,7 @@ describe('PreviewPopupComponent', () => { it('should show lock icon on password error', () => { settingsService.set(SETTINGS_KEYS.USE_NATIVE_PDF_VIEWER, false) + component.popover.open() component.onError({ name: 'PasswordException' }) fixture.detectChanges() expect(component.requiresPassword).toBeTruthy() @@ -98,16 +107,18 @@ describe('PreviewPopupComponent', () => { component.document.original_file_name = 'sample.png' component.document.mime_type = 'image/png' component.document.archived_file_name = undefined + component.popover.open() fixture.detectChanges() expect(fixture.debugElement.query(By.css('object'))).not.toBeNull() }) it('should show message on error', () => { + component.popover.open() component.onError({}) fixture.detectChanges() - expect(fixture.debugElement.nativeElement.textContent).toContain( - 'Error loading preview' - ) + expect( + fixture.debugElement.query(By.css('.popover')).nativeElement.textContent + ).toContain('Error loading preview') }) it('should get text content from http if appropriate', () => {