mirror of
https://github.com/Alfresco/alfresco-content-app.git
synced 2025-05-19 17:14:45 +00:00
[ACS-4103] clear empty parameters for folder rules actions (#3641)
This commit is contained in:
parent
ade5c67256
commit
7024bfc926
@ -47,6 +47,13 @@ describe('RuleActionUiComponent', () => {
|
|||||||
|
|
||||||
const getPropertiesCardView = (): CardViewComponent => fixture.debugElement.query(By.directive(CardViewComponent)).componentInstance;
|
const getPropertiesCardView = (): CardViewComponent => fixture.debugElement.query(By.directive(CardViewComponent)).componentInstance;
|
||||||
|
|
||||||
|
function setInputValue(value: string) {
|
||||||
|
const input = fixture.debugElement.query(By.css('input')).nativeElement;
|
||||||
|
input.value = value;
|
||||||
|
input.dispatchEvent(new Event('input'));
|
||||||
|
fixture.detectChanges();
|
||||||
|
}
|
||||||
|
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
TestBed.configureTestingModule({
|
TestBed.configureTestingModule({
|
||||||
imports: [CoreTestingModule, RuleActionUiComponent]
|
imports: [CoreTestingModule, RuleActionUiComponent]
|
||||||
@ -56,6 +63,24 @@ describe('RuleActionUiComponent', () => {
|
|||||||
component = fixture.componentInstance;
|
component = fixture.componentInstance;
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('should clear empty parameters', async () => {
|
||||||
|
component.actionDefinitions = actionsTransformedListMock;
|
||||||
|
component.parameterConstraints = dummyConstraints;
|
||||||
|
fixture.detectChanges();
|
||||||
|
|
||||||
|
changeMatSelectValue('mock-action-1-definition');
|
||||||
|
|
||||||
|
setInputValue('test');
|
||||||
|
await fixture.whenStable();
|
||||||
|
|
||||||
|
expect(component.parameters).toEqual({ 'mock-action-parameter-boolean': false, 'mock-action-parameter-text': 'test' });
|
||||||
|
|
||||||
|
setInputValue('');
|
||||||
|
await fixture.whenStable();
|
||||||
|
|
||||||
|
expect(component.parameters).toEqual({ 'mock-action-parameter-boolean': false });
|
||||||
|
});
|
||||||
|
|
||||||
it('should populate the dropdown selector with the action definitions', () => {
|
it('should populate the dropdown selector with the action definitions', () => {
|
||||||
component.actionDefinitions = actionsTransformedListMock;
|
component.actionDefinitions = actionsTransformedListMock;
|
||||||
fixture.detectChanges();
|
fixture.detectChanges();
|
||||||
|
@ -159,10 +159,10 @@ export class RuleActionUiComponent implements ControlValueAccessor, OnInit, OnCh
|
|||||||
});
|
});
|
||||||
|
|
||||||
this.cardViewUpdateService.itemUpdated$.pipe(takeUntil(this.onDestroy$)).subscribe((updateNotification: UpdateNotification) => {
|
this.cardViewUpdateService.itemUpdated$.pipe(takeUntil(this.onDestroy$)).subscribe((updateNotification: UpdateNotification) => {
|
||||||
this.parameters = {
|
this.parameters = this.clearEmptyParameters({
|
||||||
...this.parameters,
|
...this.parameters,
|
||||||
...updateNotification.changed
|
...updateNotification.changed
|
||||||
};
|
});
|
||||||
this.onChange({
|
this.onChange({
|
||||||
actionDefinitionId: this.selectedActionDefinitionId,
|
actionDefinitionId: this.selectedActionDefinitionId,
|
||||||
params: this.parameters
|
params: this.parameters
|
||||||
@ -291,7 +291,9 @@ export class RuleActionUiComponent implements ControlValueAccessor, OnInit, OnCh
|
|||||||
setDefaultParameters() {
|
setDefaultParameters() {
|
||||||
this.parameters = {};
|
this.parameters = {};
|
||||||
(this.selectedActionDefinition?.parameterDefinitions ?? []).forEach((paramDef: ActionParameterDefinition) => {
|
(this.selectedActionDefinition?.parameterDefinitions ?? []).forEach((paramDef: ActionParameterDefinition) => {
|
||||||
this.parameters[paramDef.name] = paramDef.type === 'd:boolean' ? false : '';
|
if (paramDef.type === 'd:boolean') {
|
||||||
|
this.parameters[paramDef.name] = false;
|
||||||
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -321,4 +323,9 @@ export class RuleActionUiComponent implements ControlValueAccessor, OnInit, OnCh
|
|||||||
label: constraint.label ? `${constraint.label} [${constraint.value}]` : constraint.value
|
label: constraint.label ? `${constraint.label} [${constraint.value}]` : constraint.value
|
||||||
}));
|
}));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private clearEmptyParameters(params: { [key: string]: unknown }): { [key: string]: unknown } {
|
||||||
|
Object.keys(params).forEach((key) => (params[key] === null || params[key] === undefined || params[key] === '') && delete params[key]);
|
||||||
|
return params;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user