mirror of
https://github.com/paperless-ngx/paperless-ngx.git
synced 2026-02-14 00:09:35 -06:00
Frontend coverage, at least
This commit is contained in:
@@ -219,6 +219,25 @@ describe('PngxPdfViewerComponent', () => {
|
|||||||
expect(scaleSpy).not.toHaveBeenCalled()
|
expect(scaleSpy).not.toHaveBeenCalled()
|
||||||
})
|
})
|
||||||
|
|
||||||
|
it('resets viewer state on src change', () => {
|
||||||
|
const mockViewer = {
|
||||||
|
setDocument: jest.fn(),
|
||||||
|
currentPageNumber: 7,
|
||||||
|
cleanup: jest.fn(),
|
||||||
|
}
|
||||||
|
;(component as any).pdfViewer = mockViewer
|
||||||
|
;(component as any).loadingTask = { destroy: jest.fn() }
|
||||||
|
jest.spyOn(component as any, 'loadDocument').mockImplementation(() => {})
|
||||||
|
|
||||||
|
component.src = 'test.pdf'
|
||||||
|
component.ngOnChanges({
|
||||||
|
src: new SimpleChange(undefined, 'test.pdf', true),
|
||||||
|
})
|
||||||
|
|
||||||
|
expect(mockViewer.setDocument).toHaveBeenCalledWith(null)
|
||||||
|
expect(mockViewer.currentPageNumber).toBe(1)
|
||||||
|
})
|
||||||
|
|
||||||
it('applies viewer state after view init when already loaded', () => {
|
it('applies viewer state after view init when already loaded', () => {
|
||||||
const applySpy = jest.spyOn(component as any, 'applyViewerState')
|
const applySpy = jest.spyOn(component as any, 'applyViewerState')
|
||||||
;(component as any).hasLoaded = true
|
;(component as any).hasLoaded = true
|
||||||
|
|||||||
@@ -410,6 +410,35 @@ describe('DocumentDetailComponent', () => {
|
|||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
|
it('should navigate to 404 when root lookup fails', () => {
|
||||||
|
const navigateSpy = jest.spyOn(router, 'navigate')
|
||||||
|
jest
|
||||||
|
.spyOn(activatedRoute, 'paramMap', 'get')
|
||||||
|
.mockReturnValue(of(convertToParamMap({ id: 10, section: 'details' })))
|
||||||
|
jest
|
||||||
|
.spyOn(documentService, 'get')
|
||||||
|
.mockReturnValueOnce(throwError(() => ({ status: 404 }) as any))
|
||||||
|
jest
|
||||||
|
.spyOn(documentService, 'getRootId')
|
||||||
|
.mockReturnValue(throwError(() => new Error('boom')))
|
||||||
|
jest.spyOn(openDocumentsService, 'getOpenDocument').mockReturnValue(null)
|
||||||
|
jest
|
||||||
|
.spyOn(openDocumentsService, 'openDocument')
|
||||||
|
.mockReturnValueOnce(of(true))
|
||||||
|
jest.spyOn(customFieldsService, 'listAll').mockReturnValue(
|
||||||
|
of({
|
||||||
|
count: customFields.length,
|
||||||
|
all: customFields.map((f) => f.id),
|
||||||
|
results: customFields,
|
||||||
|
})
|
||||||
|
)
|
||||||
|
|
||||||
|
fixture.detectChanges()
|
||||||
|
httpTestingController.expectOne(component.previewUrl).flush('preview')
|
||||||
|
|
||||||
|
expect(navigateSpy).toHaveBeenCalledWith(['404'], { replaceUrl: true })
|
||||||
|
})
|
||||||
|
|
||||||
it('should not render a delete button for the root/original version', () => {
|
it('should not render a delete button for the root/original version', () => {
|
||||||
const docWithVersions = {
|
const docWithVersions = {
|
||||||
...doc,
|
...doc,
|
||||||
|
|||||||
@@ -306,6 +306,14 @@ describe(`DocumentService`, () => {
|
|||||||
req.flush({ root_id: documents[0].id })
|
req.flush({ root_id: documents[0].id })
|
||||||
})
|
})
|
||||||
|
|
||||||
|
it('should call appropriate api endpoint for getting document versions', () => {
|
||||||
|
subscription = service.getVersions(documents[0].id).subscribe()
|
||||||
|
const req = httpTestingController.expectOne(
|
||||||
|
`${environment.apiBaseUrl}${endpoint}/${documents[0].id}/?fields=id,versions`
|
||||||
|
)
|
||||||
|
expect(req.request.method).toEqual('GET')
|
||||||
|
})
|
||||||
|
|
||||||
it('should call appropriate api endpoint for deleting a document version', () => {
|
it('should call appropriate api endpoint for deleting a document version', () => {
|
||||||
subscription = service.deleteVersion(documents[0].id, 10).subscribe()
|
subscription = service.deleteVersion(documents[0].id, 10).subscribe()
|
||||||
const req = httpTestingController.expectOne(
|
const req = httpTestingController.expectOne(
|
||||||
|
|||||||
Reference in New Issue
Block a user