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