Update tests for new viewer
This commit is contained in:
parent
014c24b8cf
commit
312031e6f1
@ -79,7 +79,7 @@ test('should show a mobile preview', async ({ page }) => {
|
|||||||
await page.setViewportSize({ width: 400, height: 1000 })
|
await page.setViewportSize({ width: 400, height: 1000 })
|
||||||
await expect(page.getByRole('tab', { name: 'Preview' })).toBeVisible()
|
await expect(page.getByRole('tab', { name: 'Preview' })).toBeVisible()
|
||||||
await page.getByRole('tab', { name: 'Preview' }).click()
|
await page.getByRole('tab', { name: 'Preview' }).click()
|
||||||
await page.waitForSelector('pdf-viewer')
|
await page.waitForSelector('ngx-extended-pdf-viewer')
|
||||||
})
|
})
|
||||||
|
|
||||||
test('should show a list of notes', async ({ page }) => {
|
test('should show a list of notes', async ({ page }) => {
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
<div class="modal-header">
|
<div class="modal-header">
|
||||||
<h6 class="modal-title" id="modal-basic-title">Please wait</h6>
|
<h6 class="modal-title" id="modal-basic-title" i18n>Please wait</h6>
|
||||||
</div>
|
</div>
|
||||||
<div class="modal-body">
|
<div class="modal-body">
|
||||||
<div class="mb-2" i18n>{{verb}} {{current}} of {{total}}</div>
|
<div class="mb-2" i18n>{{verb}} {{current}} of {{total}}</div>
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
import { ComponentFixture, TestBed } from '@angular/core/testing'
|
import { ComponentFixture, TestBed } from '@angular/core/testing'
|
||||||
|
|
||||||
import { LoadingDialogComponent } from './loading-dialog.component'
|
import { LoadingDialogComponent } from './loading-dialog.component'
|
||||||
|
import { NgbActiveModal } from '@ng-bootstrap/ng-bootstrap'
|
||||||
|
|
||||||
describe('LoadingDialogComponent', () => {
|
describe('LoadingDialogComponent', () => {
|
||||||
let component: LoadingDialogComponent
|
let component: LoadingDialogComponent
|
||||||
@ -9,13 +10,20 @@ describe('LoadingDialogComponent', () => {
|
|||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
TestBed.configureTestingModule({
|
TestBed.configureTestingModule({
|
||||||
declarations: [LoadingDialogComponent],
|
declarations: [LoadingDialogComponent],
|
||||||
|
providers: [NgbActiveModal],
|
||||||
})
|
})
|
||||||
fixture = TestBed.createComponent(LoadingDialogComponent)
|
fixture = TestBed.createComponent(LoadingDialogComponent)
|
||||||
component = fixture.componentInstance
|
component = fixture.componentInstance
|
||||||
fixture.detectChanges()
|
fixture.detectChanges()
|
||||||
})
|
})
|
||||||
|
|
||||||
it('needs tests', () => {
|
it('should display verb, count and total', () => {
|
||||||
expect(false).toBeTruthy()
|
component.verb = 'Loading item'
|
||||||
|
component.current = 3
|
||||||
|
component.total = 10
|
||||||
|
fixture.detectChanges()
|
||||||
|
expect(fixture.debugElement.nativeElement.textContent).toContain(
|
||||||
|
'Loading item 3 of 10'
|
||||||
|
)
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
@ -19,7 +19,11 @@ import {
|
|||||||
NgbDateStruct,
|
NgbDateStruct,
|
||||||
} from '@ng-bootstrap/ng-bootstrap'
|
} from '@ng-bootstrap/ng-bootstrap'
|
||||||
import { NgSelectModule } from '@ng-select/ng-select'
|
import { NgSelectModule } from '@ng-select/ng-select'
|
||||||
import { PdfViewerComponent } from 'ng2-pdf-viewer'
|
import {
|
||||||
|
NgxExtendedPdfViewerModule,
|
||||||
|
NgxExtendedPdfViewerService,
|
||||||
|
} from 'ngx-extended-pdf-viewer'
|
||||||
|
import { pdfDefaultOptions } from 'ngx-extended-pdf-viewer'
|
||||||
import { of, throwError } from 'rxjs'
|
import { of, throwError } from 'rxjs'
|
||||||
import { routes } from 'src/app/app-routing.module'
|
import { routes } from 'src/app/app-routing.module'
|
||||||
import {
|
import {
|
||||||
@ -134,6 +138,7 @@ describe('DocumentDetailComponent', () => {
|
|||||||
let documentListViewService: DocumentListViewService
|
let documentListViewService: DocumentListViewService
|
||||||
let settingsService: SettingsService
|
let settingsService: SettingsService
|
||||||
let customFieldsService: CustomFieldsService
|
let customFieldsService: CustomFieldsService
|
||||||
|
let printService: NgxExtendedPdfViewerService
|
||||||
|
|
||||||
let currentUserCan = true
|
let currentUserCan = true
|
||||||
let currentUserHasObjectPermissions = true
|
let currentUserHasObjectPermissions = true
|
||||||
@ -160,7 +165,6 @@ describe('DocumentDetailComponent', () => {
|
|||||||
PermissionsFormComponent,
|
PermissionsFormComponent,
|
||||||
SafeHtmlPipe,
|
SafeHtmlPipe,
|
||||||
ConfirmDialogComponent,
|
ConfirmDialogComponent,
|
||||||
PdfViewerComponent,
|
|
||||||
SafeUrlPipe,
|
SafeUrlPipe,
|
||||||
ShareLinksDropdownComponent,
|
ShareLinksDropdownComponent,
|
||||||
CustomFieldsDropdownComponent,
|
CustomFieldsDropdownComponent,
|
||||||
@ -249,6 +253,7 @@ describe('DocumentDetailComponent', () => {
|
|||||||
FormsModule,
|
FormsModule,
|
||||||
ReactiveFormsModule,
|
ReactiveFormsModule,
|
||||||
NgbModalModule,
|
NgbModalModule,
|
||||||
|
NgxExtendedPdfViewerModule,
|
||||||
],
|
],
|
||||||
}).compileComponents()
|
}).compileComponents()
|
||||||
|
|
||||||
@ -264,6 +269,7 @@ describe('DocumentDetailComponent', () => {
|
|||||||
documentListViewService = TestBed.inject(DocumentListViewService)
|
documentListViewService = TestBed.inject(DocumentListViewService)
|
||||||
settingsService = TestBed.inject(SettingsService)
|
settingsService = TestBed.inject(SettingsService)
|
||||||
customFieldsService = TestBed.inject(CustomFieldsService)
|
customFieldsService = TestBed.inject(CustomFieldsService)
|
||||||
|
printService = TestBed.inject(NgxExtendedPdfViewerService)
|
||||||
fixture = TestBed.createComponent(DocumentDetailComponent)
|
fixture = TestBed.createComponent(DocumentDetailComponent)
|
||||||
component = fixture.componentInstance
|
component = fixture.componentInstance
|
||||||
})
|
})
|
||||||
@ -299,6 +305,7 @@ describe('DocumentDetailComponent', () => {
|
|||||||
component.titleSubject.next('Foo Bar')
|
component.titleSubject.next('Foo Bar')
|
||||||
tick(1000)
|
tick(1000)
|
||||||
expect(component.documentForm.get('title').value).toEqual('Foo Bar')
|
expect(component.documentForm.get('title').value).toEqual('Foo Bar')
|
||||||
|
component.titleKeyUp({}) // coverage
|
||||||
discardPeriodicTasks()
|
discardPeriodicTasks()
|
||||||
}))
|
}))
|
||||||
|
|
||||||
@ -652,34 +659,98 @@ describe('DocumentDetailComponent', () => {
|
|||||||
|
|
||||||
it('should support password-protected PDFs with a password field', () => {
|
it('should support password-protected PDFs with a password field', () => {
|
||||||
initNormally()
|
initNormally()
|
||||||
component.onError({ name: 'PasswordException' }) // normally dispatched by pdf viewer
|
pdfDefaultOptions.passwordPrompt.open() // normally called by pdf viewer
|
||||||
expect(component.showPasswordField).toBeTruthy()
|
expect(component.showPasswordField).toBeTruthy()
|
||||||
fixture.detectChanges()
|
fixture.detectChanges()
|
||||||
expect(
|
expect(
|
||||||
fixture.debugElement.query(By.css('input[type=password]'))
|
fixture.debugElement.query(By.css('input[type=password]'))
|
||||||
).not.toBeUndefined()
|
).not.toBeUndefined()
|
||||||
component.password = 'foo'
|
let passwordSet = false
|
||||||
component.pdfPreviewLoaded({ numPages: 1000 } as any)
|
const passwordCallback = (password) => {
|
||||||
expect(component.showPasswordField).toBeFalsy()
|
passwordSet = true
|
||||||
|
}
|
||||||
|
pdfDefaultOptions.passwordPrompt.setUpdateCallback(passwordCallback)
|
||||||
|
component.setPasswordCallback('foo')
|
||||||
|
expect(passwordSet).toBeTruthy()
|
||||||
})
|
})
|
||||||
|
|
||||||
it('should support Enter key in password field', () => {
|
it('should support Enter key in password field', () => {
|
||||||
initNormally()
|
initNormally()
|
||||||
component.onError({ name: 'PasswordException' }) // normally dispatched by pdf viewer
|
pdfDefaultOptions.passwordPrompt.open() // normally called by pdf viewer
|
||||||
|
expect(component.showPasswordField).toBeTruthy()
|
||||||
fixture.detectChanges()
|
fixture.detectChanges()
|
||||||
expect(component.password).toBeUndefined()
|
expect(
|
||||||
|
fixture.debugElement.query(By.css('input[type=password]'))
|
||||||
|
).not.toBeUndefined()
|
||||||
|
let passwordSet = false
|
||||||
|
const passwordCallback = (password) => {
|
||||||
|
passwordSet = true
|
||||||
|
}
|
||||||
|
pdfDefaultOptions.passwordPrompt.setUpdateCallback(passwordCallback)
|
||||||
const pwField = fixture.debugElement.query(By.css('input[type=password]'))
|
const pwField = fixture.debugElement.query(By.css('input[type=password]'))
|
||||||
pwField.nativeElement.value = 'foobar'
|
pwField.nativeElement.value = 'foobar'
|
||||||
pwField.nativeElement.dispatchEvent(
|
pwField.nativeElement.dispatchEvent(
|
||||||
new KeyboardEvent('keyup', { key: 'Enter' })
|
new KeyboardEvent('keyup', { key: 'Enter' })
|
||||||
)
|
)
|
||||||
expect(component.password).toEqual('foobar')
|
expect(passwordSet).toBeTruthy()
|
||||||
})
|
})
|
||||||
|
|
||||||
it('should update n pages after pdf loaded', () => {
|
it('should update n pages after pdf loaded', () => {
|
||||||
initNormally()
|
initNormally()
|
||||||
component.pdfPreviewLoaded({ numPages: 1000 } as any)
|
component.onPagesLoaded({ source: 'example.com', pagesCount: 100 })
|
||||||
expect(component.previewNumPages).toEqual(1000)
|
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()
|
||||||
})
|
})
|
||||||
|
|
||||||
it('should support updating notes dynamically', () => {
|
it('should support updating notes dynamically', () => {
|
||||||
@ -805,7 +876,9 @@ describe('DocumentDetailComponent', () => {
|
|||||||
jest.spyOn(settingsService, 'get').mockReturnValue(false)
|
jest.spyOn(settingsService, 'get').mockReturnValue(false)
|
||||||
expect(component.useNativePdfViewer).toBeFalsy()
|
expect(component.useNativePdfViewer).toBeFalsy()
|
||||||
fixture.detectChanges()
|
fixture.detectChanges()
|
||||||
expect(fixture.debugElement.query(By.css('pdf-viewer'))).not.toBeNull()
|
expect(
|
||||||
|
fixture.debugElement.query(By.css('ngx-extended-pdf-viewer'))
|
||||||
|
).not.toBeNull()
|
||||||
})
|
})
|
||||||
|
|
||||||
it('should display native pdf viewer if enabled', () => {
|
it('should display native pdf viewer if enabled', () => {
|
||||||
|
@ -798,7 +798,7 @@ export class DocumentDetailComponent
|
|||||||
return Object.values(ZoomSetting)
|
return Object.values(ZoomSetting)
|
||||||
}
|
}
|
||||||
|
|
||||||
getZoomSettingTitle(setting: ZoomSetting = null): string {
|
getZoomSettingTitle(setting: ZoomSetting): string {
|
||||||
switch (setting) {
|
switch (setting) {
|
||||||
case ZoomSetting.Auto:
|
case ZoomSetting.Auto:
|
||||||
return $localize`Auto`
|
return $localize`Auto`
|
||||||
|
Loading…
x
Reference in New Issue
Block a user