From 6758bba0c732481a278582bb04082f39dc678c19 Mon Sep 17 00:00:00 2001 From: shamoon <4887959+shamoon@users.noreply.github.com> Date: Sun, 8 Feb 2026 23:55:08 -0800 Subject: [PATCH] Bit more coverage --- .../app-frame/app-frame.component.spec.ts | 67 +++++++++++++++++++ .../document-attributes.component.spec.ts | 30 +++++++-- 2 files changed, 91 insertions(+), 6 deletions(-) diff --git a/src-ui/src/app/components/app-frame/app-frame.component.spec.ts b/src-ui/src/app/components/app-frame/app-frame.component.spec.ts index 7893a6e4a..15151782d 100644 --- a/src-ui/src/app/components/app-frame/app-frame.component.spec.ts +++ b/src-ui/src/app/components/app-frame/app-frame.component.spec.ts @@ -387,6 +387,73 @@ describe('AppFrameComponent', () => { expect(component.canManageAttributes).toBe(true) }) + it('should indicate attributes management availability for other permission types', () => { + const canSpy = jest + .spyOn(permissionsService, 'currentUserCan') + .mockImplementation((action, type) => { + return type === PermissionType.Correspondent + }) + expect(component.canManageAttributes).toBe(true) + + canSpy.mockImplementation((action, type) => { + return type === PermissionType.DocumentType + }) + expect(component.canManageAttributes).toBe(true) + + canSpy.mockImplementation((action, type) => { + return type === PermissionType.StoragePath + }) + expect(component.canManageAttributes).toBe(true) + + canSpy.mockImplementation((action, type) => { + return type === PermissionType.CustomField + }) + expect(component.canManageAttributes).toBe(true) + }) + + it('should toggle attributes sections and stop event bubbling', () => { + const preventDefault = jest.fn() + const stopPropagation = jest.fn() + const setSpy = jest.spyOn(settingsService, 'set') + jest.spyOn(settingsService, 'storeSettings').mockReturnValue(of(true)) + + component.toggleAttributesSections({ + preventDefault, + stopPropagation, + } as any) + + expect(preventDefault).toHaveBeenCalled() + expect(stopPropagation).toHaveBeenCalled() + expect(setSpy).toHaveBeenCalledWith( + SETTINGS_KEYS.ATTRIBUTES_SECTIONS_COLLAPSED, + ['attributes'] + ) + }) + + it('should show error when saving slim sidebar setting fails', () => { + const toastSpy = jest.spyOn(toastService, 'showError') + jest.spyOn(console, 'warn').mockImplementation(() => {}) + jest + .spyOn(settingsService, 'storeSettings') + .mockReturnValue(throwError(() => new Error('boom'))) + + component.slimSidebarEnabled = true + + expect(toastSpy).toHaveBeenCalled() + }) + + it('should show error when saving attributes collapsed setting fails', () => { + const toastSpy = jest.spyOn(toastService, 'showError') + jest.spyOn(console, 'warn').mockImplementation(() => {}) + jest + .spyOn(settingsService, 'storeSettings') + .mockReturnValue(throwError(() => new Error('boom'))) + + component.attributesSectionsCollapsed = true + + expect(toastSpy).toHaveBeenCalled() + }) + it('should persist attributes section collapse state', () => { const setSpy = jest.spyOn(settingsService, 'set') jest.spyOn(settingsService, 'storeSettings').mockReturnValue(of(true)) diff --git a/src-ui/src/app/components/manage/document-attributes/document-attributes.component.spec.ts b/src-ui/src/app/components/manage/document-attributes/document-attributes.component.spec.ts index b2dc68405..b9cb32de4 100644 --- a/src-ui/src/app/components/manage/document-attributes/document-attributes.component.spec.ts +++ b/src-ui/src/app/components/manage/document-attributes/document-attributes.component.spec.ts @@ -14,10 +14,7 @@ import { PermissionsService, PermissionType, } from 'src/app/services/permissions.service' -import { - DocumentAttributesComponent, - DocumentAttributesSectionKind, -} from './document-attributes.component' +import { DocumentAttributesComponent } from './document-attributes.component' @Component({ selector: 'pngx-dummy-section', @@ -72,7 +69,7 @@ describe('DocumentAttributesComponent', () => { label: 'Tags', icon: 'tags', permissionType: PermissionType.Tag, - kind: DocumentAttributesSectionKind.ManagementList, + kind: 'attributeList', component: DummySectionComponent, }, { @@ -81,7 +78,7 @@ describe('DocumentAttributesComponent', () => { label: 'Custom fields', icon: 'ui-radios', permissionType: PermissionType.CustomField, - kind: DocumentAttributesSectionKind.CustomFields, + kind: 'customFields', component: DummySectionComponent, }, ] @@ -120,6 +117,16 @@ describe('DocumentAttributesComponent', () => { expect(router.navigate).not.toHaveBeenCalled() }) + it('should update active nav id when route section changes', () => { + ;(permissionsService.currentUserCan as jest.Mock).mockReturnValue(true) + + fixture.detectChanges() + component.activeNavID = 1 + paramMapSubject.next(convertToParamMap({ section: 'customfields' })) + + expect(component.activeNavID).toBe(2) + }) + it('should redirect to dashboard when no sections are visible', () => { ;(permissionsService.currentUserCan as jest.Mock).mockReturnValue(false) @@ -143,4 +150,15 @@ describe('DocumentAttributesComponent', () => { expect(router.navigate).toHaveBeenCalledWith(['attributes', 'customfields']) }) + + it('should ignore nav changes for unknown sections', () => { + ;(permissionsService.currentUserCan as jest.Mock).mockReturnValue(true) + + fixture.detectChanges() + paramMapSubject.next(convertToParamMap({ section: 'tags' })) + + component.onNavChange({ nextId: 999 } as any) + + expect(router.navigate).not.toHaveBeenCalled() + }) })