From 3b1ac7a1447bb45508bedf2204be37da205f8ca5 Mon Sep 17 00:00:00 2001
From: shamoon <4887959+shamoon@users.noreply.github.com>
Date: Thu, 30 Nov 2023 14:23:40 -0800
Subject: [PATCH] Revert "Update tests for new viewer"
This reverts commit 312031e6f1846cf671ec51a175fe8288e9b7d0c8.
---
.../document-detail/document-detail.spec.ts | 2 +-
.../loading-dialog.component.html | 2 +-
.../loading-dialog.component.spec.ts | 12 +--
.../document-detail.component.spec.ts | 97 +++----------------
.../document-detail.component.ts | 2 +-
5 files changed, 17 insertions(+), 98 deletions(-)
diff --git a/src-ui/e2e/document-detail/document-detail.spec.ts b/src-ui/e2e/document-detail/document-detail.spec.ts
index d5f29b847..1bc2b6aa9 100644
--- a/src-ui/e2e/document-detail/document-detail.spec.ts
+++ b/src-ui/e2e/document-detail/document-detail.spec.ts
@@ -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 }) => {
diff --git a/src-ui/src/app/components/common/loading-dialog/loading-dialog.component.html b/src-ui/src/app/components/common/loading-dialog/loading-dialog.component.html
index d086f7edf..1247452e4 100644
--- a/src-ui/src/app/components/common/loading-dialog/loading-dialog.component.html
+++ b/src-ui/src/app/components/common/loading-dialog/loading-dialog.component.html
@@ -1,5 +1,5 @@
{{verb}} {{current}} of {{total}}
diff --git a/src-ui/src/app/components/common/loading-dialog/loading-dialog.component.spec.ts b/src-ui/src/app/components/common/loading-dialog/loading-dialog.component.spec.ts
index c0edeb229..3045242f6 100644
--- a/src-ui/src/app/components/common/loading-dialog/loading-dialog.component.spec.ts
+++ b/src-ui/src/app/components/common/loading-dialog/loading-dialog.component.spec.ts
@@ -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()
})
})
diff --git a/src-ui/src/app/components/document-detail/document-detail.component.spec.ts b/src-ui/src/app/components/document-detail/document-detail.component.spec.ts
index 81630fe3b..871c8ec71 100644
--- a/src-ui/src/app/components/document-detail/document-detail.component.spec.ts
+++ b/src-ui/src/app/components/document-detail/document-detail.component.spec.ts
@@ -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', () => {
diff --git a/src-ui/src/app/components/document-detail/document-detail.component.ts b/src-ui/src/app/components/document-detail/document-detail.component.ts
index 7fd77f8bc..52655e733 100644
--- a/src-ui/src/app/components/document-detail/document-detail.component.ts
+++ b/src-ui/src/app/components/document-detail/document-detail.component.ts
@@ -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`