AAE-23379 Fix - required attach file allows to start process (#9874)

* AAE-23379 Fix - required attach file allows to start process

* fix unit tests
This commit is contained in:
Tomasz Gnyp 2024-06-26 11:25:46 +02:00 committed by GitHub
parent 88a2a4c9df
commit ddf6840511
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 84 additions and 42 deletions

View File

@ -81,6 +81,7 @@
[appVersion]="processDefinitionCurrent.appVersion"
[data]="resolvedValues"
[formId]="processDefinitionCurrent.formKey"
[fieldValidators]="fieldValidators"
[showSaveButton]="false"
[showCompleteButton]="false"
[showRefreshButton]="false"

View File

@ -17,7 +17,7 @@
import { SimpleChange } from '@angular/core';
import { ComponentFixture, TestBed, fakeAsync, tick } from '@angular/core/testing';
import { FormModel } from '@alfresco/adf-core';
import { FORM_FIELD_VALIDATORS, FormModel } from '@alfresco/adf-core';
import { of, throwError } from 'rxjs';
import { StartProcessCloudService } from '../services/start-process-cloud.service';
import { FormCloudService } from '../../../form/services/form-cloud.service';
@ -38,7 +38,8 @@ import {
fakeNoNameProcessDefinitions,
fakeSingleProcessDefinition,
fakeSingleProcessDefinitionWithoutForm,
fakeFormModelJson
fakeFormModelJson,
MockFormFieldValidator
} from '../mock/start-process.component.mock';
import { By } from '@angular/platform-browser';
import { ProcessPayloadCloud } from '../models/process-payload-cloud.model';
@ -526,7 +527,6 @@ describe('StartProcessCloudComponent', () => {
beforeEach(() => {
component.name = 'My new process';
component.appName = 'myApp';
fixture.detectChanges();
});
it('should reload processes when appName input changed', async () => {
@ -588,6 +588,22 @@ describe('StartProcessCloudComponent', () => {
const processDefinitionInput = fixture.nativeElement.querySelector('#processDefinitionName');
expect(processDefinitionInput.textContent).toEqual('');
});
it('should append additional field validators to the default ones when provided', () => {
const mockFirstCustomFieldValidator = new MockFormFieldValidator();
const mockSecondCustomFieldValidator = new MockFormFieldValidator();
component.fieldValidators = [mockFirstCustomFieldValidator, mockSecondCustomFieldValidator];
fixture.detectChanges();
expect(component.fieldValidators).toEqual([...FORM_FIELD_VALIDATORS, mockFirstCustomFieldValidator, mockSecondCustomFieldValidator]);
});
it('should use default field validators when no additional validators are provided', () => {
fixture.detectChanges();
expect(component.fieldValidators).toEqual([...FORM_FIELD_VALIDATORS]);
});
});
describe('start process', () => {

View File

@ -29,7 +29,7 @@ import {
ViewEncapsulation
} from '@angular/core';
import { ContentLinkModel, FormModel } from '@alfresco/adf-core';
import { ContentLinkModel, FORM_FIELD_VALIDATORS, FormFieldValidator, FormModel } from '@alfresco/adf-core';
import { AbstractControl, UntypedFormBuilder, UntypedFormControl, UntypedFormGroup, ValidatorFn, Validators } from '@angular/forms';
import { MatAutocompleteTrigger } from '@angular/material/autocomplete';
import { debounceTime, takeUntil, tap } from 'rxjs/operators';
@ -78,6 +78,10 @@ export class StartProcessCloudComponent implements OnChanges, OnInit, OnDestroy
@Input()
values: TaskVariableCloud[];
/** FormFieldValidator allow to provide additional validators to the form field. */
@Input()
fieldValidators: FormFieldValidator[];
/** Show/hide the process dropdown list. */
@Input()
showSelectProcessDropdown: boolean = true;
@ -133,6 +137,8 @@ export class StartProcessCloudComponent implements OnChanges, OnInit, OnDestroy
) {}
ngOnInit() {
this.initFieldValidators();
this.processForm = this.formBuilder.group({
processInstanceName: new UntypedFormControl('', [
Validators.required,
@ -178,6 +184,10 @@ export class StartProcessCloudComponent implements OnChanges, OnInit, OnDestroy
this.formCloud = form;
}
private initFieldValidators(): void {
this.fieldValidators = this.fieldValidators ? [...FORM_FIELD_VALIDATORS, ...this.fieldValidators] : [...FORM_FIELD_VALIDATORS];
}
private getMaxNameLength(): number {
return this.maxNameLength > MAX_NAME_LENGTH ? MAX_NAME_LENGTH : this.maxNameLength;
}

View File

@ -15,10 +15,21 @@
* limitations under the License.
*/
import { FormFieldModel, FormFieldValidator } from '@alfresco/adf-core';
import { ProcessDefinitionCloud } from '../../../models/process-definition-cloud.model';
import { ProcessInstanceCloud } from '../models/process-instance-cloud.model';
import { ProcessPayloadCloud } from '../models/process-payload-cloud.model';
export class MockFormFieldValidator implements FormFieldValidator {
isSupported(_field: FormFieldModel): boolean {
return true;
}
validate(_field: FormFieldModel): boolean {
return true;
}
}
export const fakeProcessInstance: ProcessInstanceCloud = {
appName: 'simple-app',
appVersion: '1',
@ -253,47 +264,51 @@ export const fakeFormModelJson = {
version: 0,
standAlone: true,
tabs: [],
fields: [{
id: '60b007f6-f838-458c-b4d4-43c69f355ef9',
name: 'Label',
type: 'container',
ab: null,
numberOfColumns: 1,
fields: {
1: [{
id: 'dropdown',
name: 'Dropdown',
type: 'dropdown',
readOnly: false,
required: false,
colspan: 1,
rowspan: 1,
optionType: 'manual',
options: [
fields: [
{
id: '60b007f6-f838-458c-b4d4-43c69f355ef9',
name: 'Label',
type: 'container',
ab: null,
numberOfColumns: 1,
fields: {
1: [
{
id: '1',
name: 'Label 1'
},
{
id: '2',
name: 'Label 2'
id: 'dropdown',
name: 'Dropdown',
type: 'dropdown',
readOnly: false,
required: false,
colspan: 1,
rowspan: 1,
optionType: 'manual',
options: [
{
id: '1',
name: 'Label 1'
},
{
id: '2',
name: 'Label 2'
}
],
authName: null,
restUrl: null,
restResponsePath: null,
restIdProperty: null,
restLabelProperty: null,
selectionType: 'single',
visibilityCondition: null,
params: {
existingColspan: 1,
maxColspan: 2
},
rule: null
}
],
authName: null,
restUrl: null,
restResponsePath: null,
restIdProperty: null,
restLabelProperty: null,
selectionType: 'single',
visibilityCondition: null,
params: {
existingColspan: 1,
maxColspan: 2
},
rule: null
}]
]
}
}
}],
],
outcomes: [],
metadata: {},
variables: []