mirror of
https://github.com/Alfresco/alfresco-ng2-components.git
synced 2026-09-09 18:03:21 +00:00
[MNT-24175]: fixes non node values handling (#11641)
This commit is contained in:
+1
-1
@@ -85,7 +85,7 @@
|
|||||||
<ng-container *ngIf="hasStartForm(); else noStartFormTemplate">
|
<ng-container *ngIf="hasStartForm(); else noStartFormTemplate">
|
||||||
<adf-start-form
|
<adf-start-form
|
||||||
#startForm
|
#startForm
|
||||||
[data]="movedNodeToPS"
|
[data]="populatedFormData"
|
||||||
[disableStartProcessButton]="processNameInput.invalid"
|
[disableStartProcessButton]="processNameInput.invalid"
|
||||||
[processDefinitionId]="selectedProcessDef.id"
|
[processDefinitionId]="selectedProcessDef.id"
|
||||||
(outcomeClick)="onOutcomeClick($event)"
|
(outcomeClick)="onOutcomeClick($event)"
|
||||||
|
|||||||
+38
-21
@@ -246,23 +246,7 @@ describe('StartProcessComponent', () => {
|
|||||||
expect(component.alfrescoRepositoryName).toBe('alfresco-1-fake-repo-name');
|
expect(component.alfrescoRepositoryName).toBe('alfresco-1-fake-repo-name');
|
||||||
});
|
});
|
||||||
|
|
||||||
it('if values in input is a node should be linked in the process service', async () => {
|
it('should handle a collection of nodes as input and link to the process service', async () => {
|
||||||
component.values = {};
|
|
||||||
component.values['file'] = {
|
|
||||||
isFile: true,
|
|
||||||
name: 'example-file'
|
|
||||||
};
|
|
||||||
|
|
||||||
component.moveNodeFromCStoPS();
|
|
||||||
|
|
||||||
fixture.detectChanges();
|
|
||||||
await fixture.whenStable();
|
|
||||||
|
|
||||||
expect(component.movedNodeToPS.file[0].id).toBe(1234);
|
|
||||||
expect(applyAlfrescoNodeSpy).toHaveBeenCalled();
|
|
||||||
});
|
|
||||||
|
|
||||||
it('if values in input is a collection of nodes should be linked in the process service', async () => {
|
|
||||||
component.values = {};
|
component.values = {};
|
||||||
component.values['file'] = [
|
component.values['file'] = [
|
||||||
{
|
{
|
||||||
@@ -279,16 +263,49 @@ describe('StartProcessComponent', () => {
|
|||||||
}
|
}
|
||||||
];
|
];
|
||||||
|
|
||||||
component.moveNodeFromCStoPS();
|
component.populateFormData();
|
||||||
|
|
||||||
fixture.detectChanges();
|
fixture.detectChanges();
|
||||||
await fixture.whenStable();
|
await fixture.whenStable();
|
||||||
|
|
||||||
expect(component.movedNodeToPS.file.length).toBe(3);
|
expect(component.populatedFormData.file.length).toBe(3);
|
||||||
expect(component.movedNodeToPS.file[0].id).toBe(1234);
|
expect(component.populatedFormData.file[0].id).toBe(1234);
|
||||||
expect(component.movedNodeToPS.file[1].id).toBe(1234);
|
expect(component.populatedFormData.file[1].id).toBe(1234);
|
||||||
expect(applyAlfrescoNodeSpy).toHaveBeenCalledTimes(3);
|
expect(applyAlfrescoNodeSpy).toHaveBeenCalledTimes(3);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('should handle not Node values in the input without call the process service', async () => {
|
||||||
|
component.values = {};
|
||||||
|
component.values['form-field-id'] = 'form-field-value';
|
||||||
|
component.values['another-form-field-id'] = 'another-form-field-value';
|
||||||
|
|
||||||
|
component.populateFormData();
|
||||||
|
|
||||||
|
fixture.detectChanges();
|
||||||
|
await fixture.whenStable();
|
||||||
|
|
||||||
|
expect(applyAlfrescoNodeSpy).not.toHaveBeenCalled();
|
||||||
|
expect(component.populatedFormData['form-field-id']).toEqual(['form-field-value']);
|
||||||
|
expect(component.populatedFormData['another-form-field-id']).toEqual(['another-form-field-value']);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should handle mixed values in the input making required amount of calls to process service', async () => {
|
||||||
|
component.values = {};
|
||||||
|
component.values['form-field-id'] = 'form-field-value';
|
||||||
|
component.values['file'] = {
|
||||||
|
isFile: true,
|
||||||
|
name: 'example-file'
|
||||||
|
};
|
||||||
|
|
||||||
|
component.populateFormData();
|
||||||
|
|
||||||
|
fixture.detectChanges();
|
||||||
|
await fixture.whenStable();
|
||||||
|
|
||||||
|
expect(applyAlfrescoNodeSpy).toHaveBeenCalledTimes(1);
|
||||||
|
expect(component.populatedFormData['form-field-id']).toEqual(['form-field-value']);
|
||||||
|
expect(component.populatedFormData.file[0].id).toBe(1234);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
+8
-8
@@ -32,7 +32,7 @@ import { AppConfigService, AppConfigValues, EmptyContentComponent, FormValues, L
|
|||||||
import { AppsProcessService } from '../../../services/apps-process.service';
|
import { AppsProcessService } from '../../../services/apps-process.service';
|
||||||
import { ProcessService } from '../../services/process.service';
|
import { ProcessService } from '../../services/process.service';
|
||||||
import { AbstractControl, FormsModule, ReactiveFormsModule, UntypedFormControl, Validators } from '@angular/forms';
|
import { AbstractControl, FormsModule, ReactiveFormsModule, UntypedFormControl, Validators } from '@angular/forms';
|
||||||
import { forkJoin, Observable } from 'rxjs';
|
import { forkJoin, Observable, of } from 'rxjs';
|
||||||
import { map } from 'rxjs/operators';
|
import { map } from 'rxjs/operators';
|
||||||
import { MatAutocompleteModule, MatAutocompleteTrigger } from '@angular/material/autocomplete';
|
import { MatAutocompleteModule, MatAutocompleteTrigger } from '@angular/material/autocomplete';
|
||||||
import { MatSelectChange, MatSelectModule } from '@angular/material/select';
|
import { MatSelectChange, MatSelectModule } from '@angular/material/select';
|
||||||
@@ -162,7 +162,7 @@ export class StartProcessInstanceComponent implements OnChanges, OnInit {
|
|||||||
|
|
||||||
isProcessDefinitionsLoading = true;
|
isProcessDefinitionsLoading = true;
|
||||||
isAppsLoading = true;
|
isAppsLoading = true;
|
||||||
movedNodeToPS: FormValues;
|
populatedFormData: FormValues;
|
||||||
|
|
||||||
private readonly destroyRef = inject(DestroyRef);
|
private readonly destroyRef = inject(DestroyRef);
|
||||||
|
|
||||||
@@ -199,7 +199,7 @@ export class StartProcessInstanceComponent implements OnChanges, OnInit {
|
|||||||
|
|
||||||
ngOnChanges(changes: SimpleChanges) {
|
ngOnChanges(changes: SimpleChanges) {
|
||||||
if (changes['values']?.currentValue) {
|
if (changes['values']?.currentValue) {
|
||||||
this.moveNodeFromCStoPS();
|
this.populateFormData();
|
||||||
}
|
}
|
||||||
|
|
||||||
const appId = changes['appId'];
|
const appId = changes['appId'];
|
||||||
@@ -356,17 +356,17 @@ export class StartProcessInstanceComponent implements OnChanges, OnInit {
|
|||||||
return alfrescoRepositoryName + 'Alfresco';
|
return alfrescoRepositoryName + 'Alfresco';
|
||||||
}
|
}
|
||||||
|
|
||||||
moveNodeFromCStoPS(): void {
|
populateFormData(): void {
|
||||||
const accountIdentifier = this.getAlfrescoRepositoryName();
|
const accountIdentifier = this.getAlfrescoRepositoryName();
|
||||||
|
|
||||||
for (const key in this.values) {
|
for (const key in this.values) {
|
||||||
if (Object.prototype.hasOwnProperty.call(this.values, key)) {
|
if (Object.prototype.hasOwnProperty.call(this.values, key)) {
|
||||||
const currentValue = Array.isArray(this.values[key]) ? this.values[key] : [this.values[key]];
|
const currentValue = Array.isArray(this.values[key]) ? this.values[key] : [this.values[key]];
|
||||||
const contents = currentValue
|
const contents = currentValue.map((content: Node) =>
|
||||||
.filter((value: any) => !!value?.isFile)
|
content.isFile ? this.contentService.applyAlfrescoNode(content, null, accountIdentifier) : of(content)
|
||||||
.map((content: Node) => this.contentService.applyAlfrescoNode(content, null, accountIdentifier));
|
);
|
||||||
forkJoin(contents).subscribe((res: RelatedContentRepresentation[]) => {
|
forkJoin(contents).subscribe((res: RelatedContentRepresentation[]) => {
|
||||||
this.movedNodeToPS = { [key]: [...res] };
|
this.populatedFormData = { ...(this.populatedFormData || {}), [key]: [...res] };
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user