Fix tests, rename prop

This commit is contained in:
shamoon
2026-02-11 21:24:10 -08:00
parent 6758bba0c7
commit f2736b0524
3 changed files with 60 additions and 35 deletions

View File

@@ -5,19 +5,19 @@
[infoLink]="activeInfoLink"
[loading]="activeHeaderLoading"
>
@if (activeAttributeList) {
@if (activeManagementList) {
<div ngbDropdown class="btn-group flex-fill d-sm-none">
<button class="btn btn-sm btn-outline-primary" id="dropdownSelectMobile" ngbDropdownToggle>
<i-bs name="text-indent-left"></i-bs>
<div class="d-none d-sm-inline">&nbsp;<ng-container i18n>Select</ng-container></div>
@if (activeAttributeList.selectedObjects.size > 0) {
<pngx-clearable-badge [selected]="activeAttributeList.selectedObjects.size > 0" [number]="activeAttributeList.selectedObjects.size" (cleared)="activeAttributeList.selectNone()"></pngx-clearable-badge><span class="visually-hidden">selected</span>
@if (activeManagementList.selectedObjects.size > 0) {
<pngx-clearable-badge [selected]="activeManagementList.selectedObjects.size > 0" [number]="activeManagementList.selectedObjects.size" (cleared)="activeManagementList.selectNone()"></pngx-clearable-badge><span class="visually-hidden">selected</span>
}
</button>
<div ngbDropdownMenu aria-labelledby="dropdownSelectMobile" class="shadow">
<button ngbDropdownItem (click)="activeAttributeList.selectNone()" i18n>Select none</button>
<button ngbDropdownItem (click)="activeAttributeList.selectPage(true)" i18n>Select page</button>
<button ngbDropdownItem (click)="activeAttributeList.selectAll()" i18n>Select all</button>
<button ngbDropdownItem (click)="activeManagementList.selectNone()" i18n>Select none</button>
<button ngbDropdownItem (click)="activeManagementList.selectPage(true)" i18n>Select page</button>
<button ngbDropdownItem (click)="activeManagementList.selectAll()" i18n>Select all</button>
</div>
</div>
@@ -26,30 +26,30 @@
<span class="input-group-text border-0" i18n>Select:</span>
</div>
<div class="btn-group btn-group-sm flex-nowrap">
@if (activeAttributeList.selectedObjects.size > 0) {
<button class="btn btn-sm btn-outline-secondary" (click)="activeAttributeList.selectNone()">
@if (activeManagementList.selectedObjects.size > 0) {
<button class="btn btn-sm btn-outline-secondary" (click)="activeManagementList.selectNone()">
<i-bs name="slash-circle"></i-bs>&nbsp;<ng-container i18n>None</ng-container>
</button>
}
<button class="btn btn-sm btn-outline-primary" (click)="activeAttributeList.selectPage(true)">
<button class="btn btn-sm btn-outline-primary" (click)="activeManagementList.selectPage(true)">
<i-bs name="file-earmark-check"></i-bs>&nbsp;<ng-container i18n>Page</ng-container>
</button>
<button class="btn btn-sm btn-outline-primary" (click)="activeAttributeList.selectAll()">
<button class="btn btn-sm btn-outline-primary" (click)="activeManagementList.selectAll()">
<i-bs name="check-all"></i-bs>&nbsp;<ng-container i18n>All</ng-container>
</button>
</div>
</div>
<button type="button" class="btn btn-sm btn-outline-primary" (click)="activeAttributeList.setPermissions()"
[disabled]="!activeAttributeList.userCanBulkEdit(PermissionAction.Change) || activeAttributeList.selectedObjects.size === 0">
<button type="button" class="btn btn-sm btn-outline-primary" (click)="activeManagementList.setPermissions()"
[disabled]="!activeManagementList.userCanBulkEdit(PermissionAction.Change) || activeManagementList.selectedObjects.size === 0">
<i-bs name="person-fill-lock"></i-bs>&nbsp;<ng-container i18n>Permissions</ng-container>
</button>
<button type="button" class="btn btn-sm btn-outline-danger" (click)="activeAttributeList.delete()"
[disabled]="!activeAttributeList.userCanBulkEdit(PermissionAction.Delete) || activeAttributeList.selectedObjects.size === 0">
<button type="button" class="btn btn-sm btn-outline-danger" (click)="activeManagementList.delete()"
[disabled]="!activeManagementList.userCanBulkEdit(PermissionAction.Delete) || activeManagementList.selectedObjects.size === 0">
<i-bs name="trash"></i-bs>&nbsp;<ng-container i18n>Delete</ng-container>
</button>
<button type="button" class="btn btn-sm btn-outline-primary ms-md-5" (click)="activeAttributeList.openCreateDialog()"
*pngxIfPermissions="{ action: PermissionAction.Add, type: activeAttributeList.permissionType }">
<button type="button" class="btn btn-sm btn-outline-primary ms-md-5" (click)="activeManagementList.openCreateDialog()"
*pngxIfPermissions="{ action: PermissionAction.Add, type: activeManagementList.permissionType }">
<i-bs name="plus-circle"></i-bs>&nbsp;<ng-container i18n>Create</ng-container>
</button>
} @else if (activeCustomFields) {

View File

@@ -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()
})
})

View File

@@ -158,7 +158,7 @@ export class DocumentAttributesComponent
)
}
get activeAttributeList(): ManagementListComponent<any> | null {
get activeManagementList(): ManagementListComponent<any> | 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
)