mirror of
https://github.com/paperless-ngx/paperless-ngx.git
synced 2026-02-24 00:59:35 -06:00
Frontend coverage
This commit is contained in:
@@ -168,6 +168,10 @@ describe('DocumentListComponent', () => {
|
||||
)
|
||||
})
|
||||
|
||||
it('should not allow changing a saved view when none is active', () => {
|
||||
expect(component.activeSavedViewCanChange).toBeFalsy()
|
||||
})
|
||||
|
||||
it('should determine if filtered, support reset', () => {
|
||||
fixture.detectChanges()
|
||||
documentListService.filterRules = [
|
||||
@@ -285,6 +289,19 @@ describe('DocumentListComponent', () => {
|
||||
expect(setCountSpy).toHaveBeenCalledWith(expect.any(Object), 3)
|
||||
})
|
||||
|
||||
it('should reset active saved view when loading unknown view config', () => {
|
||||
component['activeSavedView'] = { id: 1 } as SavedView
|
||||
const activateSpy = jest.spyOn(documentListService, 'activateSavedView')
|
||||
const reloadSpy = jest.spyOn(documentListService, 'reload')
|
||||
jest.spyOn(savedViewService, 'getCached').mockReturnValue(of(null))
|
||||
|
||||
component.loadViewConfig(10)
|
||||
|
||||
expect(component['activeSavedView']).toBeNull()
|
||||
expect(activateSpy).not.toHaveBeenCalled()
|
||||
expect(reloadSpy).not.toHaveBeenCalled()
|
||||
})
|
||||
|
||||
it('should support 3 different display modes', () => {
|
||||
jest.spyOn(documentListService, 'documents', 'get').mockReturnValue(docs)
|
||||
fixture.detectChanges()
|
||||
@@ -549,6 +566,12 @@ describe('DocumentListComponent', () => {
|
||||
const modalSpy = jest.spyOn(modalService, 'open')
|
||||
const toastSpy = jest.spyOn(toastService, 'showInfo')
|
||||
const savedViewServiceCreate = jest.spyOn(savedViewService, 'create')
|
||||
jest
|
||||
.spyOn(savedViewService, 'dashboardViews', 'get')
|
||||
.mockReturnValue([{ id: 77 } as SavedView])
|
||||
jest
|
||||
.spyOn(savedViewService, 'sidebarViews', 'get')
|
||||
.mockReturnValue([{ id: 88 } as SavedView])
|
||||
const updateVisibilitySpy = jest
|
||||
.spyOn(settingsService, 'updateSavedViewsVisibility')
|
||||
.mockReturnValue(of({ success: true }))
|
||||
@@ -584,14 +607,66 @@ describe('DocumentListComponent', () => {
|
||||
})
|
||||
)
|
||||
expect(updateVisibilitySpy).toHaveBeenCalledWith(
|
||||
expect.arrayContaining([modifiedView.id]),
|
||||
expect.arrayContaining([modifiedView.id])
|
||||
expect.arrayContaining([77, modifiedView.id]),
|
||||
expect.arrayContaining([88, modifiedView.id])
|
||||
)
|
||||
expect(modalSpy).toHaveBeenCalled()
|
||||
expect(toastSpy).toHaveBeenCalled()
|
||||
expect(modalCloseSpy).toHaveBeenCalled()
|
||||
})
|
||||
|
||||
it('should show error when visibility update fails after creating a view', () => {
|
||||
const view: SavedView = {
|
||||
id: 10,
|
||||
name: 'Saved View 10',
|
||||
sort_field: 'added',
|
||||
sort_reverse: true,
|
||||
filter_rules: [
|
||||
{
|
||||
rule_type: FILTER_HAS_TAGS_ANY,
|
||||
value: '20',
|
||||
},
|
||||
],
|
||||
}
|
||||
jest.spyOn(savedViewService, 'getCached').mockReturnValue(of(view))
|
||||
const queryParams = { view: view.id.toString() }
|
||||
jest
|
||||
.spyOn(activatedRoute, 'queryParamMap', 'get')
|
||||
.mockReturnValue(of(convertToParamMap(queryParams)))
|
||||
activatedRoute.snapshot.queryParams = queryParams
|
||||
router.routerState.snapshot.url = '/view/10/'
|
||||
fixture.detectChanges()
|
||||
|
||||
let openModal: NgbModalRef
|
||||
modalService.activeInstances.subscribe((modal) => (openModal = modal[0]))
|
||||
jest
|
||||
.spyOn(savedViewService, 'create')
|
||||
.mockReturnValueOnce(of({ ...view, id: 42, name: 'Foo Bar' }))
|
||||
jest.spyOn(savedViewService, 'dashboardViews', 'get').mockReturnValue([])
|
||||
jest.spyOn(savedViewService, 'sidebarViews', 'get').mockReturnValue([])
|
||||
jest
|
||||
.spyOn(settingsService, 'updateSavedViewsVisibility')
|
||||
.mockReturnValueOnce(
|
||||
throwError(() => new Error('unable to save visibility settings'))
|
||||
)
|
||||
const toastErrorSpy = jest.spyOn(toastService, 'showError')
|
||||
|
||||
component.saveViewConfigAs()
|
||||
|
||||
const modalCloseSpy = jest.spyOn(openModal, 'close')
|
||||
openModal.componentInstance.saveClicked.next({
|
||||
name: 'Foo Bar',
|
||||
showOnDashboard: true,
|
||||
showInSideBar: false,
|
||||
})
|
||||
|
||||
expect(modalCloseSpy).toHaveBeenCalled()
|
||||
expect(toastErrorSpy).toHaveBeenCalledWith(
|
||||
'View "Foo Bar" created successfully, but could not update visibility settings.',
|
||||
expect.any(Error)
|
||||
)
|
||||
})
|
||||
|
||||
it('should handle error on edited view saving as', () => {
|
||||
const view: SavedView = {
|
||||
id: 10,
|
||||
|
||||
Reference in New Issue
Block a user