From fc419257ffb0705921ecc49d3c326fe76ec4f228 Mon Sep 17 00:00:00 2001 From: Aleksander Sklorz Date: Thu, 23 Nov 2023 12:42:38 +0100 Subject: [PATCH] ACS-6252 Hide link to category action if categories feature is disabled --- .../rule-details.ui-component.spec.ts | 72 +++++++++++++++++++ .../rule-details/rule-details.ui-component.ts | 5 ++ 2 files changed, 77 insertions(+) diff --git a/projects/aca-content/folder-rules/src/rule-details/rule-details.ui-component.spec.ts b/projects/aca-content/folder-rules/src/rule-details/rule-details.ui-component.spec.ts index 959239e626..e9ba8c231e 100644 --- a/projects/aca-content/folder-rules/src/rule-details/rule-details.ui-component.spec.ts +++ b/projects/aca-content/folder-rules/src/rule-details/rule-details.ui-component.spec.ts @@ -29,6 +29,8 @@ import { Rule } from '../model/rule.model'; import { By } from '@angular/platform-browser'; import { RuleTriggersUiComponent } from './triggers/rule-triggers.ui-component'; import { RuleOptionsUiComponent } from './options/rule-options.ui-component'; +import { RuleActionListUiComponent } from './actions/rule-action-list.ui-component'; +import { CategoryService } from '@alfresco/adf-content-services'; describe('RuleDetailsUiComponent', () => { let fixture: ComponentFixture; @@ -140,4 +142,74 @@ describe('RuleDetailsUiComponent', () => { expect(getComponentInstance('rule-details-options-component')).toBeFalsy(); }); + + describe('RuleActionListUiComponent', () => { + let categoryService: CategoryService; + + const getRuleActionsListComponent = (): RuleActionListUiComponent => + fixture.debugElement.query(By.directive(RuleActionListUiComponent)).componentInstance; + + beforeEach(() => { + categoryService = TestBed.inject(CategoryService); + }); + + it('should have assigned not filtered out category related actions from actionDefinitions if categoryService.areCategoriesEnabled returns true', () => { + spyOn(categoryService, 'areCategoriesEnabled').and.returnValue(true); + component.actionDefinitions = [ + { + id: 'link-category', + name: 'test name', + description: 'some description', + title: 'some title', + applicableTypes: [], + trackStatus: false, + parameterDefinitions: [] + }, + { + id: 'test id', + name: 'test name 2', + description: 'some description', + title: 'some title', + applicableTypes: [], + trackStatus: false, + parameterDefinitions: [] + } + ]; + + fixture.detectChanges(); + expect(categoryService.areCategoriesEnabled).toHaveBeenCalled(); + expect(component.actionDefinitions.length).toBe(2); + expect(getRuleActionsListComponent().actionDefinitions).toBe(component.actionDefinitions); + }); + + it('should have assigned filter out category related actions from actionDefinitions if categoryService.areCategoriesEnabled returns false', () => { + spyOn(categoryService, 'areCategoriesEnabled').and.returnValue(false); + component.actionDefinitions = [ + { + id: 'link-category', + name: 'test name', + description: 'some description', + title: 'some title', + applicableTypes: [], + trackStatus: false, + parameterDefinitions: [] + }, + { + id: 'test id', + name: 'test name 2', + description: 'some description', + title: 'some title', + applicableTypes: [], + trackStatus: false, + parameterDefinitions: [] + } + ]; + + fixture.detectChanges(); + expect(categoryService.areCategoriesEnabled).toHaveBeenCalled(); + expect(component.actionDefinitions.length).toBe(1); + expect(component.actionDefinitions[0].id).toBe('test id'); + expect(getRuleActionsListComponent().actionDefinitions).toBe(component.actionDefinitions); + }); + }); }); diff --git a/projects/aca-content/folder-rules/src/rule-details/rule-details.ui-component.ts b/projects/aca-content/folder-rules/src/rule-details/rule-details.ui-component.ts index 40dace9d23..d133756f3c 100644 --- a/projects/aca-content/folder-rules/src/rule-details/rule-details.ui-component.ts +++ b/projects/aca-content/folder-rules/src/rule-details/rule-details.ui-component.ts @@ -40,6 +40,7 @@ import { RuleTriggersUiComponent } from './triggers/rule-triggers.ui-component'; import { RuleCompositeConditionUiComponent } from './conditions/rule-composite-condition.ui-component'; import { RuleActionListUiComponent } from './actions/rule-action-list.ui-component'; import { RuleOptionsUiComponent } from './options/rule-options.ui-component'; +import { CategoryService } from '@alfresco/adf-content-services'; @Component({ standalone: true, @@ -136,7 +137,11 @@ export class RuleDetailsUiComponent implements OnInit, OnDestroy { return !this.readOnly || this.value.isAsynchronous || this.value.isInheritable; } + constructor(private categoryService: CategoryService) {} + ngOnInit() { + const disabledCategory = !this.categoryService.areCategoriesEnabled(); + this.actionDefinitions = this.actionDefinitions.filter((action) => !(disabledCategory && action.id === 'link-category')); this.form = new UntypedFormGroup({ id: new UntypedFormControl(this.value.id), name: new UntypedFormControl(this.value.name || '', Validators.required),