From 98ad4e57267716daa824b1238c5d37cfe4f67163 Mon Sep 17 00:00:00 2001 From: shamoon <4887959+shamoon@users.noreply.github.com> Date: Sun, 22 Feb 2026 15:42:15 -0800 Subject: [PATCH] Frontend coverage --- .../document-list.component.spec.ts | 79 ++++++++++++++++++- .../saved-views/saved-views.component.spec.ts | 19 +++++ 2 files changed, 96 insertions(+), 2 deletions(-) diff --git a/src-ui/src/app/components/document-list/document-list.component.spec.ts b/src-ui/src/app/components/document-list/document-list.component.spec.ts index 52681fe30..94dbd5acf 100644 --- a/src-ui/src/app/components/document-list/document-list.component.spec.ts +++ b/src-ui/src/app/components/document-list/document-list.component.spec.ts @@ -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, diff --git a/src-ui/src/app/components/manage/saved-views/saved-views.component.spec.ts b/src-ui/src/app/components/manage/saved-views/saved-views.component.spec.ts index 22a693b3e..de6c88f9a 100644 --- a/src-ui/src/app/components/manage/saved-views/saved-views.component.spec.ts +++ b/src-ui/src/app/components/manage/saved-views/saved-views.component.spec.ts @@ -175,6 +175,25 @@ describe('SavedViewsComponent', () => { expect(updateVisibilitySpy).toHaveBeenCalledWith([], [savedViews[0].id]) }) + it('should skip model updates for views that cannot be edited', () => { + const patchSpy = jest.spyOn(savedViewService, 'patchMany') + const updateVisibilitySpy = jest.spyOn( + settingsService, + 'updateSavedViewsVisibility' + ) + const nameControl = component.savedViewsForm + .get('savedViews') + .get(savedViews[0].id.toString()) + .get('name') + + nameControl.disable() + + component.save() + + expect(patchSpy).not.toHaveBeenCalled() + expect(updateVisibilitySpy).not.toHaveBeenCalled() + }) + it('should support delete saved view', () => { const toastSpy = jest.spyOn(toastService, 'showInfo') const deleteSpy = jest.spyOn(savedViewService, 'delete')