Revert "Update tests for new viewer"

This reverts commit 312031e6f1846cf671ec51a175fe8288e9b7d0c8.
This commit is contained in:
shamoon 2023-11-30 14:23:40 -08:00
parent 1709ba1f36
commit 3b1ac7a144
5 changed files with 17 additions and 98 deletions

View File

@ -79,7 +79,7 @@ test('should show a mobile preview', async ({ page }) => {
await page.setViewportSize({ width: 400, height: 1000 })
await expect(page.getByRole('tab', { name: 'Preview' })).toBeVisible()
await page.getByRole('tab', { name: 'Preview' }).click()
await page.waitForSelector('ngx-extended-pdf-viewer')
await page.waitForSelector('pdf-viewer')
})
test('should show a list of notes', async ({ page }) => {

View File

@ -1,5 +1,5 @@
<div class="modal-header">
<h6 class="modal-title" id="modal-basic-title" i18n>Please wait</h6>
<h6 class="modal-title" id="modal-basic-title">Please wait</h6>
</div>
<div class="modal-body">
<div class="mb-2" i18n>{{verb}} {{current}} of {{total}}</div>

View File

@ -1,7 +1,6 @@
import { ComponentFixture, TestBed } from '@angular/core/testing'
import { LoadingDialogComponent } from './loading-dialog.component'
import { NgbActiveModal } from '@ng-bootstrap/ng-bootstrap'
describe('LoadingDialogComponent', () => {
let component: LoadingDialogComponent
@ -10,20 +9,13 @@ describe('LoadingDialogComponent', () => {
beforeEach(() => {
TestBed.configureTestingModule({
declarations: [LoadingDialogComponent],
providers: [NgbActiveModal],
})
fixture = TestBed.createComponent(LoadingDialogComponent)
component = fixture.componentInstance
fixture.detectChanges()
})
it('should display verb, count and total', () => {
component.verb = 'Loading item'
component.current = 3
component.total = 10
fixture.detectChanges()
expect(fixture.debugElement.nativeElement.textContent).toContain(
'Loading item 3 of 10'
)
it('needs tests', () => {
expect(false).toBeTruthy()
})
})

View File

@ -19,11 +19,7 @@ import {
NgbDateStruct,
} from '@ng-bootstrap/ng-bootstrap'
import { NgSelectModule } from '@ng-select/ng-select'
import {
NgxExtendedPdfViewerModule,
NgxExtendedPdfViewerService,
} from 'ngx-extended-pdf-viewer'
import { pdfDefaultOptions } from 'ngx-extended-pdf-viewer'
import { PdfViewerComponent } from 'ng2-pdf-viewer'
import { of, throwError } from 'rxjs'
import { routes } from 'src/app/app-routing.module'
import {
@ -138,7 +134,6 @@ describe('DocumentDetailComponent', () => {
let documentListViewService: DocumentListViewService
let settingsService: SettingsService
let customFieldsService: CustomFieldsService
let printService: NgxExtendedPdfViewerService
let currentUserCan = true
let currentUserHasObjectPermissions = true
@ -165,6 +160,7 @@ describe('DocumentDetailComponent', () => {
PermissionsFormComponent,
SafeHtmlPipe,
ConfirmDialogComponent,
PdfViewerComponent,
SafeUrlPipe,
ShareLinksDropdownComponent,
CustomFieldsDropdownComponent,
@ -253,7 +249,6 @@ describe('DocumentDetailComponent', () => {
FormsModule,
ReactiveFormsModule,
NgbModalModule,
NgxExtendedPdfViewerModule,
],
}).compileComponents()
@ -269,7 +264,6 @@ describe('DocumentDetailComponent', () => {
documentListViewService = TestBed.inject(DocumentListViewService)
settingsService = TestBed.inject(SettingsService)
customFieldsService = TestBed.inject(CustomFieldsService)
printService = TestBed.inject(NgxExtendedPdfViewerService)
fixture = TestBed.createComponent(DocumentDetailComponent)
component = fixture.componentInstance
})
@ -305,7 +299,6 @@ describe('DocumentDetailComponent', () => {
component.titleSubject.next('Foo Bar')
tick(1000)
expect(component.documentForm.get('title').value).toEqual('Foo Bar')
component.titleKeyUp({}) // coverage
discardPeriodicTasks()
}))
@ -659,98 +652,34 @@ describe('DocumentDetailComponent', () => {
it('should support password-protected PDFs with a password field', () => {
initNormally()
pdfDefaultOptions.passwordPrompt.open() // normally called by pdf viewer
component.onError({ name: 'PasswordException' }) // normally dispatched by pdf viewer
expect(component.showPasswordField).toBeTruthy()
fixture.detectChanges()
expect(
fixture.debugElement.query(By.css('input[type=password]'))
).not.toBeUndefined()
let passwordSet = false
const passwordCallback = (password) => {
passwordSet = true
}
pdfDefaultOptions.passwordPrompt.setUpdateCallback(passwordCallback)
component.setPasswordCallback('foo')
expect(passwordSet).toBeTruthy()
component.password = 'foo'
component.pdfPreviewLoaded({ numPages: 1000 } as any)
expect(component.showPasswordField).toBeFalsy()
})
it('should support Enter key in password field', () => {
initNormally()
pdfDefaultOptions.passwordPrompt.open() // normally called by pdf viewer
expect(component.showPasswordField).toBeTruthy()
component.onError({ name: 'PasswordException' }) // normally dispatched by pdf viewer
fixture.detectChanges()
expect(
fixture.debugElement.query(By.css('input[type=password]'))
).not.toBeUndefined()
let passwordSet = false
const passwordCallback = (password) => {
passwordSet = true
}
pdfDefaultOptions.passwordPrompt.setUpdateCallback(passwordCallback)
expect(component.password).toBeUndefined()
const pwField = fixture.debugElement.query(By.css('input[type=password]'))
pwField.nativeElement.value = 'foobar'
pwField.nativeElement.dispatchEvent(
new KeyboardEvent('keyup', { key: 'Enter' })
)
expect(passwordSet).toBeTruthy()
expect(component.password).toEqual('foobar')
})
it('should update n pages after pdf loaded', () => {
initNormally()
component.onPagesLoaded({ source: 'example.com', pagesCount: 100 })
expect(component.previewNumPages).toEqual(100)
})
it('should show toast if error loading pdf', () => {
const toastSpy = jest.spyOn(toastService, 'showError')
const error = { message: 'Error loading PDF', name: 'ErrorLoading' }
initNormally()
component.onPdfLoadingFailed(error)
expect(toastSpy).toHaveBeenCalledWith(error.message, {
error: error.message,
})
})
it('should support zoom controls', () => {
initNormally()
component.onZoomSelect({ target: { value: 'auto' } } as any) // from select
expect(component.previewZoomSetting).toEqual('auto')
component.increaseZoom()
expect(component.previewZoomSetting).toEqual('150%')
component.increaseZoom()
expect(component.previewZoomSetting).toEqual('200%')
component.decreaseZoom()
expect(component.previewZoomSetting).toEqual('150%')
component.onZoomSelect({ target: { value: 'page-width' } } as any) // from select
component.decreaseZoom()
expect(component.previewZoomSetting).toEqual('75%')
})
it('should support print', () => {
initNormally()
const printSpy = jest.spyOn(printService, 'print')
try {
// fails without a PDF loaded
component.print()
} catch (e) {}
expect(printSpy).toHaveBeenCalled()
})
it('should show loading dialog on print start, close after', () => {
initNormally()
let openModal: NgbModalRef
modalService.activeInstances.subscribe((modal) => (openModal = modal[0]))
const modalSpy = jest.spyOn(modalService, 'open')
component.onBeforePrint()
expect(modalSpy).toHaveBeenCalled()
component.onProgress({ type: 'print', total: 100 } as any)
expect(openModal.componentInstance.current).toEqual(0)
component.onProgress({ type: 'print', total: 100, page: 10 } as any)
expect(openModal.componentInstance.verb).toEqual('Processing page')
expect(openModal.componentInstance.current).toEqual(10)
expect(openModal.componentInstance.total).toEqual(100)
component.onAfterPrint()
expect(openModal.closed).toBeTruthy()
component.pdfPreviewLoaded({ numPages: 1000 } as any)
expect(component.previewNumPages).toEqual(1000)
})
it('should support updating notes dynamically', () => {
@ -876,9 +805,7 @@ describe('DocumentDetailComponent', () => {
jest.spyOn(settingsService, 'get').mockReturnValue(false)
expect(component.useNativePdfViewer).toBeFalsy()
fixture.detectChanges()
expect(
fixture.debugElement.query(By.css('ngx-extended-pdf-viewer'))
).not.toBeNull()
expect(fixture.debugElement.query(By.css('pdf-viewer'))).not.toBeNull()
})
it('should display native pdf viewer if enabled', () => {

View File

@ -798,7 +798,7 @@ export class DocumentDetailComponent
return Object.values(ZoomSetting)
}
getZoomSettingTitle(setting: ZoomSetting): string {
getZoomSettingTitle(setting: ZoomSetting = null): string {
switch (setting) {
case ZoomSetting.Auto:
return $localize`Auto`