From f2736b05248ac35a477455db388018c9c7633ae5 Mon Sep 17 00:00:00 2001
From: shamoon <4887959+shamoon@users.noreply.github.com>
Date: Wed, 11 Feb 2026 21:24:10 -0800
Subject: [PATCH] Fix tests, rename prop
---
.../document-attributes.component.html | 32 +++++-----
.../document-attributes.component.spec.ts | 59 +++++++++++++------
.../document-attributes.component.ts | 4 +-
3 files changed, 60 insertions(+), 35 deletions(-)
diff --git a/src-ui/src/app/components/manage/document-attributes/document-attributes.component.html b/src-ui/src/app/components/manage/document-attributes/document-attributes.component.html
index 3f5f2810c..1aa105b9d 100644
--- a/src-ui/src/app/components/manage/document-attributes/document-attributes.component.html
+++ b/src-ui/src/app/components/manage/document-attributes/document-attributes.component.html
@@ -5,19 +5,19 @@
[infoLink]="activeInfoLink"
[loading]="activeHeaderLoading"
>
- @if (activeAttributeList) {
+ @if (activeManagementList) {
-
-
-
+
+
+
@@ -26,30 +26,30 @@
Select:
- @if (activeAttributeList.selectedObjects.size > 0) {
-
-
+
Permissions
-
+
Delete
-
+
Create
} @else if (activeCustomFields) {
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 b9cb32de4..54017a7e0 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,7 +14,10 @@ import {
PermissionsService,
PermissionType,
} from 'src/app/services/permissions.service'
-import { DocumentAttributesComponent } from './document-attributes.component'
+import {
+ DocumentAttributesComponent,
+ DocumentAttributesSectionKind,
+} from './document-attributes.component'
@Component({
selector: 'pngx-dummy-section',
@@ -69,7 +72,7 @@ describe('DocumentAttributesComponent', () => {
label: 'Tags',
icon: 'tags',
permissionType: PermissionType.Tag,
- kind: 'attributeList',
+ kind: DocumentAttributesSectionKind.ManagementList,
component: DummySectionComponent,
},
{
@@ -78,18 +81,18 @@ describe('DocumentAttributesComponent', () => {
label: 'Custom fields',
icon: 'ui-radios',
permissionType: PermissionType.CustomField,
- kind: 'customFields',
+ kind: DocumentAttributesSectionKind.CustomFields,
component: DummySectionComponent,
},
]
})
it('should navigate to default section when no section is provided', () => {
- ;(permissionsService.currentUserCan as jest.Mock).mockImplementation(
- (action, type) => {
+ jest
+ .spyOn(permissionsService, 'currentUserCan')
+ .mockImplementation((action, type) => {
return action === PermissionAction.View && type === PermissionType.Tag
- }
- )
+ })
fixture.detectChanges()
paramMapSubject.next(convertToParamMap({}))
@@ -101,14 +104,14 @@ describe('DocumentAttributesComponent', () => {
})
it('should set active section from route param when valid', () => {
- ;(permissionsService.currentUserCan as jest.Mock).mockImplementation(
- (action, type) => {
+ jest
+ .spyOn(permissionsService, 'currentUserCan')
+ .mockImplementation((action, type) => {
return (
action === PermissionAction.View &&
type === PermissionType.CustomField
)
- }
- )
+ })
fixture.detectChanges()
paramMapSubject.next(convertToParamMap({ section: 'customfields' }))
@@ -118,7 +121,7 @@ describe('DocumentAttributesComponent', () => {
})
it('should update active nav id when route section changes', () => {
- ;(permissionsService.currentUserCan as jest.Mock).mockReturnValue(true)
+ jest.spyOn(permissionsService, 'currentUserCan').mockReturnValue(true)
fixture.detectChanges()
component.activeNavID = 1
@@ -128,7 +131,7 @@ describe('DocumentAttributesComponent', () => {
})
it('should redirect to dashboard when no sections are visible', () => {
- ;(permissionsService.currentUserCan as jest.Mock).mockReturnValue(false)
+ jest.spyOn(permissionsService, 'currentUserCan').mockReturnValue(false)
fixture.detectChanges()
paramMapSubject.next(convertToParamMap({}))
@@ -139,9 +142,9 @@ describe('DocumentAttributesComponent', () => {
})
it('should navigate when a nav change occurs', () => {
- ;(permissionsService.currentUserCan as jest.Mock).mockImplementation(
- () => true
- )
+ jest
+ .spyOn(permissionsService, 'currentUserCan')
+ .mockImplementation(() => true)
fixture.detectChanges()
paramMapSubject.next(convertToParamMap({ section: 'tags' }))
@@ -152,7 +155,7 @@ describe('DocumentAttributesComponent', () => {
})
it('should ignore nav changes for unknown sections', () => {
- ;(permissionsService.currentUserCan as jest.Mock).mockReturnValue(true)
+ jest.spyOn(permissionsService, 'currentUserCan').mockReturnValue(true)
fixture.detectChanges()
paramMapSubject.next(convertToParamMap({ section: 'tags' }))
@@ -161,4 +164,26 @@ describe('DocumentAttributesComponent', () => {
expect(router.navigate).not.toHaveBeenCalled()
})
+
+ it('should return activeManagementList correctly', () => {
+ jest.spyOn(permissionsService, 'currentUserCan').mockReturnValue(true)
+ expect(component.activeManagementList).toBeNull()
+
+ component.activeNavID = 1
+ expect(component.activeSection.kind).toBe(
+ DocumentAttributesSectionKind.ManagementList
+ )
+ expect(component.activeManagementList).toBeDefined()
+ })
+
+ it('should return activeCustomFields correctly', () => {
+ jest.spyOn(permissionsService, 'currentUserCan').mockReturnValue(true)
+ expect(component.activeCustomFields).toBeNull()
+
+ component.activeNavID = 2
+ expect(component.activeSection.kind).toBe(
+ DocumentAttributesSectionKind.CustomFields
+ )
+ expect(component.activeCustomFields).toBeDefined()
+ })
})
diff --git a/src-ui/src/app/components/manage/document-attributes/document-attributes.component.ts b/src-ui/src/app/components/manage/document-attributes/document-attributes.component.ts
index 5048ce836..8396ca6b2 100644
--- a/src-ui/src/app/components/manage/document-attributes/document-attributes.component.ts
+++ b/src-ui/src/app/components/manage/document-attributes/document-attributes.component.ts
@@ -158,7 +158,7 @@ export class DocumentAttributesComponent
)
}
- get activeAttributeList(): ManagementListComponent | null {
+ get activeManagementList(): ManagementListComponent | null {
if (
this.activeSection?.kind !== DocumentAttributesSectionKind.ManagementList
)
@@ -184,7 +184,7 @@ export class DocumentAttributesComponent
get activeHeaderLoading(): boolean {
return (
- this.activeAttributeList?.loading ??
+ this.activeManagementList?.loading ??
this.activeCustomFields?.loading ??
false
)