Skip to content

Commit

Permalink
ACS-6252 Hide link to category action if categories feature is disabled
Browse files Browse the repository at this point in the history
  • Loading branch information
AleksanderSklorz committed Nov 28, 2023
1 parent 5375341 commit fc41925
Show file tree
Hide file tree
Showing 2 changed files with 77 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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<RuleDetailsUiComponent>;
Expand Down Expand Up @@ -140,4 +142,74 @@ describe('RuleDetailsUiComponent', () => {

expect(getComponentInstance<RuleOptionsUiComponent>('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);
});
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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),
Expand Down

0 comments on commit fc41925

Please sign in to comment.