Frontend coverage, at least

This commit is contained in:
shamoon
2026-02-11 22:08:31 -08:00
parent addb369d32
commit 158aa46f9a
3 changed files with 56 additions and 0 deletions

View File

@@ -219,6 +219,25 @@ describe('PngxPdfViewerComponent', () => {
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', () => {
const applySpy = jest.spyOn(component as any, 'applyViewerState')
;(component as any).hasLoaded = true

View File

@@ -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', () => {
const docWithVersions = {
...doc,

View File

@@ -306,6 +306,14 @@ describe(`DocumentService`, () => {
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', () => {
subscription = service.deleteVersion(documents[0].id, 10).subscribe()
const req = httpTestingController.expectOne(