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

View File

@@ -14,7 +14,10 @@ import {
PermissionsService, PermissionsService,
PermissionType, PermissionType,
} from 'src/app/services/permissions.service' } from 'src/app/services/permissions.service'
import { DocumentAttributesComponent } from './document-attributes.component' import {
DocumentAttributesComponent,
DocumentAttributesSectionKind,
} from './document-attributes.component'
@Component({ @Component({
selector: 'pngx-dummy-section', selector: 'pngx-dummy-section',
@@ -69,7 +72,7 @@ describe('DocumentAttributesComponent', () => {
label: 'Tags', label: 'Tags',
icon: 'tags', icon: 'tags',
permissionType: PermissionType.Tag, permissionType: PermissionType.Tag,
kind: 'attributeList', kind: DocumentAttributesSectionKind.ManagementList,
component: DummySectionComponent, component: DummySectionComponent,
}, },
{ {
@@ -78,18 +81,18 @@ describe('DocumentAttributesComponent', () => {
label: 'Custom fields', label: 'Custom fields',
icon: 'ui-radios', icon: 'ui-radios',
permissionType: PermissionType.CustomField, permissionType: PermissionType.CustomField,
kind: 'customFields', kind: DocumentAttributesSectionKind.CustomFields,
component: DummySectionComponent, component: DummySectionComponent,
}, },
] ]
}) })
it('should navigate to default section when no section is provided', () => { it('should navigate to default section when no section is provided', () => {
;(permissionsService.currentUserCan as jest.Mock).mockImplementation( jest
(action, type) => { .spyOn(permissionsService, 'currentUserCan')
.mockImplementation((action, type) => {
return action === PermissionAction.View && type === PermissionType.Tag return action === PermissionAction.View && type === PermissionType.Tag
} })
)
fixture.detectChanges() fixture.detectChanges()
paramMapSubject.next(convertToParamMap({})) paramMapSubject.next(convertToParamMap({}))
@@ -101,14 +104,14 @@ describe('DocumentAttributesComponent', () => {
}) })
it('should set active section from route param when valid', () => { it('should set active section from route param when valid', () => {
;(permissionsService.currentUserCan as jest.Mock).mockImplementation( jest
(action, type) => { .spyOn(permissionsService, 'currentUserCan')
.mockImplementation((action, type) => {
return ( return (
action === PermissionAction.View && action === PermissionAction.View &&
type === PermissionType.CustomField type === PermissionType.CustomField
) )
} })
)
fixture.detectChanges() fixture.detectChanges()
paramMapSubject.next(convertToParamMap({ section: 'customfields' })) paramMapSubject.next(convertToParamMap({ section: 'customfields' }))
@@ -118,7 +121,7 @@ describe('DocumentAttributesComponent', () => {
}) })
it('should update active nav id when route section changes', () => { 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() fixture.detectChanges()
component.activeNavID = 1 component.activeNavID = 1
@@ -128,7 +131,7 @@ describe('DocumentAttributesComponent', () => {
}) })
it('should redirect to dashboard when no sections are visible', () => { 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() fixture.detectChanges()
paramMapSubject.next(convertToParamMap({})) paramMapSubject.next(convertToParamMap({}))
@@ -139,9 +142,9 @@ describe('DocumentAttributesComponent', () => {
}) })
it('should navigate when a nav change occurs', () => { it('should navigate when a nav change occurs', () => {
;(permissionsService.currentUserCan as jest.Mock).mockImplementation( jest
() => true .spyOn(permissionsService, 'currentUserCan')
) .mockImplementation(() => true)
fixture.detectChanges() fixture.detectChanges()
paramMapSubject.next(convertToParamMap({ section: 'tags' })) paramMapSubject.next(convertToParamMap({ section: 'tags' }))
@@ -152,7 +155,7 @@ describe('DocumentAttributesComponent', () => {
}) })
it('should ignore nav changes for unknown sections', () => { it('should ignore nav changes for unknown sections', () => {
;(permissionsService.currentUserCan as jest.Mock).mockReturnValue(true) jest.spyOn(permissionsService, 'currentUserCan').mockReturnValue(true)
fixture.detectChanges() fixture.detectChanges()
paramMapSubject.next(convertToParamMap({ section: 'tags' })) paramMapSubject.next(convertToParamMap({ section: 'tags' }))
@@ -161,4 +164,26 @@ describe('DocumentAttributesComponent', () => {
expect(router.navigate).not.toHaveBeenCalled() 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 ( if (
this.activeSection?.kind !== DocumentAttributesSectionKind.ManagementList this.activeSection?.kind !== DocumentAttributesSectionKind.ManagementList
) )
@@ -184,7 +184,7 @@ export class DocumentAttributesComponent
get activeHeaderLoading(): boolean { get activeHeaderLoading(): boolean {
return ( return (
this.activeAttributeList?.loading ?? this.activeManagementList?.loading ??
this.activeCustomFields?.loading ?? this.activeCustomFields?.loading ??
false false
) )