Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

<div class="aca-page-layout-header">
<adf-toolbar class="adf-toolbar--inline">
<button mat-icon-button (click)="goBack()">

Check warning on line 5 in projects/aca-content/folder-rules/src/manage-rules/manage-rules.smart-component.html

View workflow job for this annotation

GitHub Actions / lint

Avoid calling expressions in templates
<mat-icon>arrow_back</mat-icon>
</button>
</adf-toolbar>
Expand All @@ -28,7 +28,7 @@
<mat-slide-toggle
data-automation-id="manage-rules-inheritance-toggle-button"
[checked]="isInheritanceEnabled"
(change)="onInheritanceToggleChange($event)"

Check warning on line 31 in projects/aca-content/folder-rules/src/manage-rules/manage-rules.smart-component.html

View workflow job for this annotation

GitHub Actions / lint

Avoid calling expressions in templates
[disabled]="isInheritanceToggleDisabled"
[labelPosition]="'before'">
{{ 'ACA_FOLDER_RULES.MANAGE_RULES.TOOLBAR.ACTIONS.INHERIT_RULES' | translate }}
Expand Down Expand Up @@ -106,6 +106,7 @@
<div class="aca-manage-rules__container__rule-details__content" *ngIf="(selectedRule$ | async) as selectedRule">
<aca-rule-details
[actionDefinitions]="actionDefinitions$ | async"
[parameterConstraints]="parameterConstraints$ | async"
[readOnly]="true"
[preview]="true"
[value]="selectedRule"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,6 @@
}

.hide-error-script-dropdown {
opacity: 0;
visibility: hidden;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
*/

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 { RuleOptionsUiComponent } from './rule-options.ui-component';
import { CoreTestingModule } from '@alfresco/adf-core';
Expand All @@ -42,6 +42,18 @@ describe('RuleOptionsUiComponent', () => {
((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(() => {
TestBed.configureTestingModule({
schemas: [CUSTOM_ELEMENTS_SCHEMA],
Expand All @@ -66,7 +78,7 @@ describe('RuleOptionsUiComponent', () => {
expect(getByDataAutomationId('rule-option-checkbox-asynchronous').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-select-errorScript').componentInstance.disabled).toBeTruthy();
testErrorScriptFormFieldVisibility(false);

component.writeValue({
isEnabled: false,
Expand All @@ -79,7 +91,7 @@ describe('RuleOptionsUiComponent', () => {
expect(getByDataAutomationId('rule-option-checkbox-asynchronous').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-select-errorScript').componentInstance.disabled).toBeFalsy();
testErrorScriptFormFieldVisibility(true);
});

it('should enable selector when async checkbox is truthy', () => {
Expand Down Expand Up @@ -122,6 +134,7 @@ describe('RuleOptionsUiComponent', () => {
errorScript: ''
});
component.errorScriptConstraint = errorScriptConstraintMock;
component.ngOnChanges({ errorScriptConstraint: {} as SimpleChange });
fixture.detectChanges();

(getByDataAutomationId('rule-option-select-errorScript').nativeElement as HTMLElement).click();
Expand Down Expand Up @@ -149,4 +162,33 @@ describe('RuleOptionsUiComponent', () => {
expect(matFormField).not.toBeNull();
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);
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@
* from Hyland Software. If not, see <http://www.gnu.org/licenses/>.
*/

import { Component, forwardRef, HostBinding, Input, OnDestroy, OnInit, ViewEncapsulation } from '@angular/core';
import { AbstractControl, ControlValueAccessor, FormControl, FormGroup, NG_VALUE_ACCESSOR, ReactiveFormsModule } from '@angular/forms';
import { Component, forwardRef, HostBinding, Input, OnChanges, OnDestroy, SimpleChanges, ViewEncapsulation } from '@angular/core';
import { ControlValueAccessor, FormControl, FormGroup, NG_VALUE_ACCESSOR, ReactiveFormsModule } from '@angular/forms';
import { MatCheckboxChange, MatCheckboxModule } from '@angular/material/checkbox';
import { RuleOptions } from '../../model/rule.model';
import { ActionParameterConstraint, ConstraintValue } from '../../model/action-parameter-constraint.model';
Expand All @@ -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({
isDisabled: new FormControl(),
isInheritable: new FormControl(),
Expand All @@ -57,13 +57,14 @@ export class RuleOptionsUiComponent implements ControlValueAccessor, OnInit, OnD
});

formSubscription = this.form.valueChanges.subscribe((value: any) => {
const formValue = { ...this.form.value, ...value };
this.isAsynchronousChecked = value.isAsynchronous;
this.isInheritableChecked = value.isInheritable;
this.onChange({
isEnabled: !value.isDisabled,
isInheritable: value.isInheritable,
isAsynchronous: value.isAsynchronous,
errorScript: value.errorScript ?? ''
isEnabled: !formValue.isDisabled,
isInheritable: formValue.isInheritable,
isAsynchronous: formValue.isAsynchronous,
errorScript: formValue.errorScript ?? ''
});
this.onTouch();
});
Expand All @@ -85,19 +86,18 @@ export class RuleOptionsUiComponent implements ControlValueAccessor, OnInit, OnD
errorScriptOptions: ConstraintValue[] = [];

writeValue(options: RuleOptions) {
const isAsynchronousFormControl = this.form.get('isAsynchronous');
const errorScriptFormControl = this.form.get('errorScript');
this.form.get('isDisabled').setValue(!options.isEnabled);
this.form.get('isInheritable').setValue(options.isInheritable);
this.form.get('isAsynchronous').setValue(options.isAsynchronous);
errorScriptFormControl.setValue(options.errorScript ?? '');
if (isAsynchronousFormControl.value) {
this.hideErrorScriptDropdown = false;
errorScriptFormControl.enable();
} else {
this.hideErrorScriptDropdown = true;
errorScriptFormControl.disable();
}
this.form.setValue(
{
isDisabled: !options.isEnabled,
isAsynchronous: options.isAsynchronous,
isInheritable: options.isInheritable,
errorScript: options.errorScript ?? ''
},
{ emitEvent: false }
);
this.isAsynchronousChecked = options.isAsynchronous;
this.isInheritableChecked = options.isInheritable;
this.hideErrorScriptDropdown = !this.isAsynchronousChecked;
}

registerOnChange(fn: () => void) {
Expand All @@ -118,22 +118,17 @@ export class RuleOptionsUiComponent implements ControlValueAccessor, OnInit, OnD
}
}

ngOnInit(): void {
this.errorScriptOptions = this.errorScriptConstraint?.constraints ?? [];
ngOnChanges(changes: SimpleChanges): void {
if (changes['errorScriptConstraint']) {
this.errorScriptOptions = this.errorScriptConstraint?.constraints ?? [];
}
}

ngOnDestroy() {
this.formSubscription.unsubscribe();
}

toggleErrorScriptDropdown(value: MatCheckboxChange) {
const formControl: AbstractControl = this.form.get('errorScript');
if (value.checked) {
this.hideErrorScriptDropdown = false;
formControl.enable();
} else {
this.hideErrorScriptDropdown = true;
formControl.disable();
}
this.hideErrorScriptDropdown = !value.checked;
}
}
Loading