[ACS-5284] - updating a folder rule options has no effect when multiple rules exist and clicking between them (#3409)

* [ACS-5284] - updating a folder rule options has no effect when multiple rules exist and clicking between them
This commit is contained in:
DominikIwanek
2023-08-30 12:32:18 +02:00
committed by GitHub
parent cc484d792e
commit 303a86268b
4 changed files with 72 additions and 34 deletions

View File

@@ -106,6 +106,7 @@
<div class="aca-manage-rules__container__rule-details__content" *ngIf="(selectedRule$ | async) as selectedRule"> <div class="aca-manage-rules__container__rule-details__content" *ngIf="(selectedRule$ | async) as selectedRule">
<aca-rule-details <aca-rule-details
[actionDefinitions]="actionDefinitions$ | async" [actionDefinitions]="actionDefinitions$ | async"
[parameterConstraints]="parameterConstraints$ | async"
[readOnly]="true" [readOnly]="true"
[preview]="true" [preview]="true"
[value]="selectedRule" [value]="selectedRule"

View File

@@ -13,6 +13,6 @@
} }
.hide-error-script-dropdown { .hide-error-script-dropdown {
opacity: 0; visibility: hidden;
} }
} }

View File

@@ -23,7 +23,7 @@
*/ */
import { ComponentFixture, TestBed } from '@angular/core/testing'; import { ComponentFixture, TestBed } from '@angular/core/testing';
import { CUSTOM_ELEMENTS_SCHEMA, DebugElement } from '@angular/core'; import { CUSTOM_ELEMENTS_SCHEMA, DebugElement, SimpleChange } from '@angular/core';
import { FormsModule, ReactiveFormsModule } from '@angular/forms'; import { FormsModule, ReactiveFormsModule } from '@angular/forms';
import { RuleOptionsUiComponent } from './rule-options.ui-component'; import { RuleOptionsUiComponent } from './rule-options.ui-component';
import { CoreTestingModule } from '@alfresco/adf-core'; import { CoreTestingModule } from '@alfresco/adf-core';
@@ -42,6 +42,18 @@ describe('RuleOptionsUiComponent', () => {
((getByDataAutomationId(dataAutomationId).nativeElement as HTMLElement).children[0] as HTMLElement).click(); ((getByDataAutomationId(dataAutomationId).nativeElement as HTMLElement).children[0] as HTMLElement).click();
}; };
const testErrorScriptFormFieldVisibility = (isVisible: boolean) => {
if (isVisible) {
expect((getByDataAutomationId('rule-option-form-field-errorScript').nativeElement as HTMLElement).classList).not.toContain(
'hide-error-script-dropdown'
);
} else {
expect((getByDataAutomationId('rule-option-form-field-errorScript').nativeElement as HTMLElement).classList).toContain(
'hide-error-script-dropdown'
);
}
};
beforeEach(() => { beforeEach(() => {
TestBed.configureTestingModule({ TestBed.configureTestingModule({
schemas: [CUSTOM_ELEMENTS_SCHEMA], schemas: [CUSTOM_ELEMENTS_SCHEMA],
@@ -66,7 +78,7 @@ describe('RuleOptionsUiComponent', () => {
expect(getByDataAutomationId('rule-option-checkbox-asynchronous').componentInstance.checked).toBeFalsy(); expect(getByDataAutomationId('rule-option-checkbox-asynchronous').componentInstance.checked).toBeFalsy();
expect(getByDataAutomationId('rule-option-checkbox-inheritable').componentInstance.checked).toBeFalsy(); expect(getByDataAutomationId('rule-option-checkbox-inheritable').componentInstance.checked).toBeFalsy();
expect(getByDataAutomationId('rule-option-checkbox-disabled').componentInstance.checked).toBeFalsy(); expect(getByDataAutomationId('rule-option-checkbox-disabled').componentInstance.checked).toBeFalsy();
expect(getByDataAutomationId('rule-option-select-errorScript').componentInstance.disabled).toBeTruthy(); testErrorScriptFormFieldVisibility(false);
component.writeValue({ component.writeValue({
isEnabled: false, isEnabled: false,
@@ -79,7 +91,7 @@ describe('RuleOptionsUiComponent', () => {
expect(getByDataAutomationId('rule-option-checkbox-asynchronous').componentInstance.checked).toBeTruthy(); expect(getByDataAutomationId('rule-option-checkbox-asynchronous').componentInstance.checked).toBeTruthy();
expect(getByDataAutomationId('rule-option-checkbox-inheritable').componentInstance.checked).toBeTruthy(); expect(getByDataAutomationId('rule-option-checkbox-inheritable').componentInstance.checked).toBeTruthy();
expect(getByDataAutomationId('rule-option-checkbox-disabled').componentInstance.checked).toBeTruthy(); expect(getByDataAutomationId('rule-option-checkbox-disabled').componentInstance.checked).toBeTruthy();
expect(getByDataAutomationId('rule-option-select-errorScript').componentInstance.disabled).toBeFalsy(); testErrorScriptFormFieldVisibility(true);
}); });
it('should enable selector when async checkbox is truthy', () => { it('should enable selector when async checkbox is truthy', () => {
@@ -122,6 +134,7 @@ describe('RuleOptionsUiComponent', () => {
errorScript: '' errorScript: ''
}); });
component.errorScriptConstraint = errorScriptConstraintMock; component.errorScriptConstraint = errorScriptConstraintMock;
component.ngOnChanges({ errorScriptConstraint: {} as SimpleChange });
fixture.detectChanges(); fixture.detectChanges();
(getByDataAutomationId('rule-option-select-errorScript').nativeElement as HTMLElement).click(); (getByDataAutomationId('rule-option-select-errorScript').nativeElement as HTMLElement).click();
@@ -149,4 +162,33 @@ describe('RuleOptionsUiComponent', () => {
expect(matFormField).not.toBeNull(); expect(matFormField).not.toBeNull();
expect(matFormField.componentInstance['floatLabel']).toBe('always'); expect(matFormField.componentInstance['floatLabel']).toBe('always');
}); });
it('should properly update formFields on only isAsynchronous and errorScript changes', () => {
fixture.detectChanges();
component.writeValue({
isEnabled: false,
isInheritable: true,
isAsynchronous: true,
errorScript: '1234'
});
fixture.detectChanges();
expect(getByDataAutomationId('rule-option-checkbox-asynchronous').componentInstance.checked).toBeTrue();
expect(getByDataAutomationId('rule-option-checkbox-inheritable').componentInstance.checked).toBeTrue();
expect(getByDataAutomationId('rule-option-checkbox-disabled').componentInstance.checked).toBeTrue();
expect(getByDataAutomationId('rule-option-select-errorScript').componentInstance.value).toEqual('1234');
component.writeValue({
isEnabled: false,
isInheritable: true,
isAsynchronous: false,
errorScript: ''
});
fixture.detectChanges();
expect(getByDataAutomationId('rule-option-checkbox-asynchronous').componentInstance.checked).toBeFalse();
expect(getByDataAutomationId('rule-option-checkbox-inheritable').componentInstance.checked).toBeTrue();
expect(getByDataAutomationId('rule-option-checkbox-disabled').componentInstance.checked).toBeTrue();
testErrorScriptFormFieldVisibility(false);
});
}); });

View File

@@ -22,8 +22,8 @@
* from Hyland Software. If not, see <http://www.gnu.org/licenses/>. * from Hyland Software. If not, see <http://www.gnu.org/licenses/>.
*/ */
import { Component, forwardRef, HostBinding, Input, OnDestroy, OnInit, ViewEncapsulation } from '@angular/core'; import { Component, forwardRef, HostBinding, Input, OnChanges, OnDestroy, SimpleChanges, ViewEncapsulation } from '@angular/core';
import { AbstractControl, ControlValueAccessor, FormControl, FormGroup, NG_VALUE_ACCESSOR, ReactiveFormsModule } from '@angular/forms'; import { ControlValueAccessor, FormControl, FormGroup, NG_VALUE_ACCESSOR, ReactiveFormsModule } from '@angular/forms';
import { MatCheckboxChange, MatCheckboxModule } from '@angular/material/checkbox'; import { MatCheckboxChange, MatCheckboxModule } from '@angular/material/checkbox';
import { RuleOptions } from '../../model/rule.model'; import { RuleOptions } from '../../model/rule.model';
import { ActionParameterConstraint, ConstraintValue } from '../../model/action-parameter-constraint.model'; import { ActionParameterConstraint, ConstraintValue } from '../../model/action-parameter-constraint.model';
@@ -48,7 +48,7 @@ import { MatSelectModule } from '@angular/material/select';
} }
] ]
}) })
export class RuleOptionsUiComponent implements ControlValueAccessor, OnInit, OnDestroy { export class RuleOptionsUiComponent implements ControlValueAccessor, OnChanges, OnDestroy {
form = new FormGroup({ form = new FormGroup({
isDisabled: new FormControl(), isDisabled: new FormControl(),
isInheritable: new FormControl(), isInheritable: new FormControl(),
@@ -57,13 +57,14 @@ export class RuleOptionsUiComponent implements ControlValueAccessor, OnInit, OnD
}); });
formSubscription = this.form.valueChanges.subscribe((value: any) => { formSubscription = this.form.valueChanges.subscribe((value: any) => {
const formValue = { ...this.form.value, ...value };
this.isAsynchronousChecked = value.isAsynchronous; this.isAsynchronousChecked = value.isAsynchronous;
this.isInheritableChecked = value.isInheritable; this.isInheritableChecked = value.isInheritable;
this.onChange({ this.onChange({
isEnabled: !value.isDisabled, isEnabled: !formValue.isDisabled,
isInheritable: value.isInheritable, isInheritable: formValue.isInheritable,
isAsynchronous: value.isAsynchronous, isAsynchronous: formValue.isAsynchronous,
errorScript: value.errorScript ?? '' errorScript: formValue.errorScript ?? ''
}); });
this.onTouch(); this.onTouch();
}); });
@@ -85,19 +86,18 @@ export class RuleOptionsUiComponent implements ControlValueAccessor, OnInit, OnD
errorScriptOptions: ConstraintValue[] = []; errorScriptOptions: ConstraintValue[] = [];
writeValue(options: RuleOptions) { writeValue(options: RuleOptions) {
const isAsynchronousFormControl = this.form.get('isAsynchronous'); this.form.setValue(
const errorScriptFormControl = this.form.get('errorScript'); {
this.form.get('isDisabled').setValue(!options.isEnabled); isDisabled: !options.isEnabled,
this.form.get('isInheritable').setValue(options.isInheritable); isAsynchronous: options.isAsynchronous,
this.form.get('isAsynchronous').setValue(options.isAsynchronous); isInheritable: options.isInheritable,
errorScriptFormControl.setValue(options.errorScript ?? ''); errorScript: options.errorScript ?? ''
if (isAsynchronousFormControl.value) { },
this.hideErrorScriptDropdown = false; { emitEvent: false }
errorScriptFormControl.enable(); );
} else { this.isAsynchronousChecked = options.isAsynchronous;
this.hideErrorScriptDropdown = true; this.isInheritableChecked = options.isInheritable;
errorScriptFormControl.disable(); this.hideErrorScriptDropdown = !this.isAsynchronousChecked;
}
} }
registerOnChange(fn: () => void) { registerOnChange(fn: () => void) {
@@ -118,8 +118,10 @@ export class RuleOptionsUiComponent implements ControlValueAccessor, OnInit, OnD
} }
} }
ngOnInit(): void { ngOnChanges(changes: SimpleChanges): void {
this.errorScriptOptions = this.errorScriptConstraint?.constraints ?? []; if (changes['errorScriptConstraint']) {
this.errorScriptOptions = this.errorScriptConstraint?.constraints ?? [];
}
} }
ngOnDestroy() { ngOnDestroy() {
@@ -127,13 +129,6 @@ export class RuleOptionsUiComponent implements ControlValueAccessor, OnInit, OnD
} }
toggleErrorScriptDropdown(value: MatCheckboxChange) { toggleErrorScriptDropdown(value: MatCheckboxChange) {
const formControl: AbstractControl = this.form.get('errorScript'); this.hideErrorScriptDropdown = !value.checked;
if (value.checked) {
this.hideErrorScriptDropdown = false;
formControl.enable();
} else {
this.hideErrorScriptDropdown = true;
formControl.disable();
}
} }
} }