Update preview-popup.component.spec.ts

This commit is contained in:
shamoon 2024-10-15 13:05:06 -07:00
parent d77cb8ec00
commit a2c9e0254c

View File

@ -7,7 +7,7 @@ import { SettingsService } from 'src/app/services/settings.service'
import { SETTINGS_KEYS } from 'src/app/data/ui-settings'
import { provideHttpClientTesting } from '@angular/common/http/testing'
import { DocumentService } from 'src/app/services/rest/document.service'
import { NgxBootstrapIconsModule, allIcons } from 'ngx-bootstrap-icons'
import { NgxBootstrapIconsModule, allIcons, archive } from 'ngx-bootstrap-icons'
import { PdfViewerModule } from 'ng2-pdf-viewer'
import {
HttpClient,
@ -21,6 +21,8 @@ const doc = {
title: 'Document 10',
content: 'Cupcake ipsum dolor sit amet ice cream.',
original_file_name: 'sample.pdf',
archived_file_name: 'sample.pdf',
mime_type: 'application/pdf',
}
describe('PreviewPopupComponent', () => {
@ -47,18 +49,16 @@ describe('PreviewPopupComponent', () => {
.mockImplementation((id) => doc.original_file_name)
fixture = TestBed.createComponent(PreviewPopupComponent)
component = fixture.componentInstance
component.document = doc
component.document = { ...doc }
fixture.detectChanges()
})
it('should guess if file is pdf by file name', () => {
expect(component.isPdf).toBeTruthy()
component.document.archived_file_name = 'sample.pdf'
it('should correctly report if document is pdf', () => {
expect(component.isPdf).toBeTruthy()
component.document.mime_type = 'application/msword'
expect(component.isPdf).toBeTruthy() // still has archive file
component.document.archived_file_name = undefined
component.document.original_file_name = 'sample.txt'
expect(component.isPdf).toBeFalsy()
component.document.original_file_name = 'sample.pdf'
})
it('should return settings for native PDF viewer', () => {
@ -91,6 +91,8 @@ describe('PreviewPopupComponent', () => {
it('should fall back to object for non-pdf', () => {
component.document.original_file_name = 'sample.png'
component.document.mime_type = 'image/png'
component.document.archived_file_name = undefined
fixture.detectChanges()
expect(fixture.debugElement.query(By.css('object'))).not.toBeNull()
})