Fix tests

This commit is contained in:
shamoon 2024-11-19 18:52:35 -08:00
parent 6510acc158
commit 17af7541a1

View File

@ -20,6 +20,8 @@ import {
withInterceptorsFromDi, withInterceptorsFromDi,
} from '@angular/common/http' } from '@angular/common/http'
import { of, throwError } from 'rxjs' import { of, throwError } from 'rxjs'
import { NgbPopoverModule } from '@ng-bootstrap/ng-bootstrap'
import { DocumentTitlePipe } from 'src/app/pipes/document-title.pipe'
const doc = { const doc = {
id: 10, id: 10,
@ -39,8 +41,12 @@ describe('PreviewPopupComponent', () => {
beforeEach(() => { beforeEach(() => {
TestBed.configureTestingModule({ TestBed.configureTestingModule({
declarations: [PreviewPopupComponent, SafeUrlPipe], declarations: [PreviewPopupComponent, SafeUrlPipe, DocumentTitlePipe],
imports: [NgxBootstrapIconsModule.pick(allIcons), PdfViewerModule], imports: [
NgxBootstrapIconsModule.pick(allIcons),
PdfViewerModule,
NgbPopoverModule,
],
providers: [ providers: [
provideHttpClient(withInterceptorsFromDi()), provideHttpClient(withInterceptorsFromDi()),
provideHttpClientTesting(), provideHttpClientTesting(),
@ -75,12 +81,14 @@ describe('PreviewPopupComponent', () => {
it('should render object if native PDF viewer enabled', () => { it('should render object if native PDF viewer enabled', () => {
settingsService.set(SETTINGS_KEYS.USE_NATIVE_PDF_VIEWER, true) settingsService.set(SETTINGS_KEYS.USE_NATIVE_PDF_VIEWER, true)
component.popover.open()
fixture.detectChanges() fixture.detectChanges()
expect(fixture.debugElement.query(By.css('object'))).not.toBeNull() expect(fixture.debugElement.query(By.css('object'))).not.toBeNull()
}) })
it('should render pngx viewer if native PDF viewer disabled', () => { it('should render pngx viewer if native PDF viewer disabled', () => {
settingsService.set(SETTINGS_KEYS.USE_NATIVE_PDF_VIEWER, false) settingsService.set(SETTINGS_KEYS.USE_NATIVE_PDF_VIEWER, false)
component.popover.open()
fixture.detectChanges() fixture.detectChanges()
expect(fixture.debugElement.query(By.css('object'))).toBeNull() expect(fixture.debugElement.query(By.css('object'))).toBeNull()
expect(fixture.debugElement.query(By.css('pdf-viewer'))).not.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', () => { it('should show lock icon on password error', () => {
settingsService.set(SETTINGS_KEYS.USE_NATIVE_PDF_VIEWER, false) settingsService.set(SETTINGS_KEYS.USE_NATIVE_PDF_VIEWER, false)
component.popover.open()
component.onError({ name: 'PasswordException' }) component.onError({ name: 'PasswordException' })
fixture.detectChanges() fixture.detectChanges()
expect(component.requiresPassword).toBeTruthy() expect(component.requiresPassword).toBeTruthy()
@ -98,16 +107,18 @@ describe('PreviewPopupComponent', () => {
component.document.original_file_name = 'sample.png' component.document.original_file_name = 'sample.png'
component.document.mime_type = 'image/png' component.document.mime_type = 'image/png'
component.document.archived_file_name = undefined component.document.archived_file_name = undefined
component.popover.open()
fixture.detectChanges() fixture.detectChanges()
expect(fixture.debugElement.query(By.css('object'))).not.toBeNull() expect(fixture.debugElement.query(By.css('object'))).not.toBeNull()
}) })
it('should show message on error', () => { it('should show message on error', () => {
component.popover.open()
component.onError({}) component.onError({})
fixture.detectChanges() fixture.detectChanges()
expect(fixture.debugElement.nativeElement.textContent).toContain( expect(
'Error loading preview' fixture.debugElement.query(By.css('.popover')).nativeElement.textContent
) ).toContain('Error loading preview')
}) })
it('should get text content from http if appropriate', () => { it('should get text content from http if appropriate', () => {