mirror of
https://github.com/Alfresco/alfresco-ng2-components.git
synced 2025-05-26 17:24:56 +00:00
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:
parent
88a2a4c9df
commit
ddf6840511
@ -81,6 +81,7 @@
|
|||||||
[appVersion]="processDefinitionCurrent.appVersion"
|
[appVersion]="processDefinitionCurrent.appVersion"
|
||||||
[data]="resolvedValues"
|
[data]="resolvedValues"
|
||||||
[formId]="processDefinitionCurrent.formKey"
|
[formId]="processDefinitionCurrent.formKey"
|
||||||
|
[fieldValidators]="fieldValidators"
|
||||||
[showSaveButton]="false"
|
[showSaveButton]="false"
|
||||||
[showCompleteButton]="false"
|
[showCompleteButton]="false"
|
||||||
[showRefreshButton]="false"
|
[showRefreshButton]="false"
|
||||||
|
@ -17,7 +17,7 @@
|
|||||||
|
|
||||||
import { SimpleChange } from '@angular/core';
|
import { SimpleChange } from '@angular/core';
|
||||||
import { ComponentFixture, TestBed, fakeAsync, tick } from '@angular/core/testing';
|
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 { of, throwError } from 'rxjs';
|
||||||
import { StartProcessCloudService } from '../services/start-process-cloud.service';
|
import { StartProcessCloudService } from '../services/start-process-cloud.service';
|
||||||
import { FormCloudService } from '../../../form/services/form-cloud.service';
|
import { FormCloudService } from '../../../form/services/form-cloud.service';
|
||||||
@ -38,7 +38,8 @@ import {
|
|||||||
fakeNoNameProcessDefinitions,
|
fakeNoNameProcessDefinitions,
|
||||||
fakeSingleProcessDefinition,
|
fakeSingleProcessDefinition,
|
||||||
fakeSingleProcessDefinitionWithoutForm,
|
fakeSingleProcessDefinitionWithoutForm,
|
||||||
fakeFormModelJson
|
fakeFormModelJson,
|
||||||
|
MockFormFieldValidator
|
||||||
} from '../mock/start-process.component.mock';
|
} from '../mock/start-process.component.mock';
|
||||||
import { By } from '@angular/platform-browser';
|
import { By } from '@angular/platform-browser';
|
||||||
import { ProcessPayloadCloud } from '../models/process-payload-cloud.model';
|
import { ProcessPayloadCloud } from '../models/process-payload-cloud.model';
|
||||||
@ -526,7 +527,6 @@ describe('StartProcessCloudComponent', () => {
|
|||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
component.name = 'My new process';
|
component.name = 'My new process';
|
||||||
component.appName = 'myApp';
|
component.appName = 'myApp';
|
||||||
fixture.detectChanges();
|
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should reload processes when appName input changed', async () => {
|
it('should reload processes when appName input changed', async () => {
|
||||||
@ -588,6 +588,22 @@ describe('StartProcessCloudComponent', () => {
|
|||||||
const processDefinitionInput = fixture.nativeElement.querySelector('#processDefinitionName');
|
const processDefinitionInput = fixture.nativeElement.querySelector('#processDefinitionName');
|
||||||
expect(processDefinitionInput.textContent).toEqual('');
|
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', () => {
|
describe('start process', () => {
|
||||||
|
@ -29,7 +29,7 @@ import {
|
|||||||
ViewEncapsulation
|
ViewEncapsulation
|
||||||
} from '@angular/core';
|
} 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 { AbstractControl, UntypedFormBuilder, UntypedFormControl, UntypedFormGroup, ValidatorFn, Validators } from '@angular/forms';
|
||||||
import { MatAutocompleteTrigger } from '@angular/material/autocomplete';
|
import { MatAutocompleteTrigger } from '@angular/material/autocomplete';
|
||||||
import { debounceTime, takeUntil, tap } from 'rxjs/operators';
|
import { debounceTime, takeUntil, tap } from 'rxjs/operators';
|
||||||
@ -78,6 +78,10 @@ export class StartProcessCloudComponent implements OnChanges, OnInit, OnDestroy
|
|||||||
@Input()
|
@Input()
|
||||||
values: TaskVariableCloud[];
|
values: TaskVariableCloud[];
|
||||||
|
|
||||||
|
/** FormFieldValidator allow to provide additional validators to the form field. */
|
||||||
|
@Input()
|
||||||
|
fieldValidators: FormFieldValidator[];
|
||||||
|
|
||||||
/** Show/hide the process dropdown list. */
|
/** Show/hide the process dropdown list. */
|
||||||
@Input()
|
@Input()
|
||||||
showSelectProcessDropdown: boolean = true;
|
showSelectProcessDropdown: boolean = true;
|
||||||
@ -133,6 +137,8 @@ export class StartProcessCloudComponent implements OnChanges, OnInit, OnDestroy
|
|||||||
) {}
|
) {}
|
||||||
|
|
||||||
ngOnInit() {
|
ngOnInit() {
|
||||||
|
this.initFieldValidators();
|
||||||
|
|
||||||
this.processForm = this.formBuilder.group({
|
this.processForm = this.formBuilder.group({
|
||||||
processInstanceName: new UntypedFormControl('', [
|
processInstanceName: new UntypedFormControl('', [
|
||||||
Validators.required,
|
Validators.required,
|
||||||
@ -178,6 +184,10 @@ export class StartProcessCloudComponent implements OnChanges, OnInit, OnDestroy
|
|||||||
this.formCloud = form;
|
this.formCloud = form;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private initFieldValidators(): void {
|
||||||
|
this.fieldValidators = this.fieldValidators ? [...FORM_FIELD_VALIDATORS, ...this.fieldValidators] : [...FORM_FIELD_VALIDATORS];
|
||||||
|
}
|
||||||
|
|
||||||
private getMaxNameLength(): number {
|
private getMaxNameLength(): number {
|
||||||
return this.maxNameLength > MAX_NAME_LENGTH ? MAX_NAME_LENGTH : this.maxNameLength;
|
return this.maxNameLength > MAX_NAME_LENGTH ? MAX_NAME_LENGTH : this.maxNameLength;
|
||||||
}
|
}
|
||||||
|
@ -15,10 +15,21 @@
|
|||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
import { FormFieldModel, FormFieldValidator } from '@alfresco/adf-core';
|
||||||
import { ProcessDefinitionCloud } from '../../../models/process-definition-cloud.model';
|
import { ProcessDefinitionCloud } from '../../../models/process-definition-cloud.model';
|
||||||
import { ProcessInstanceCloud } from '../models/process-instance-cloud.model';
|
import { ProcessInstanceCloud } from '../models/process-instance-cloud.model';
|
||||||
import { ProcessPayloadCloud } from '../models/process-payload-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 = {
|
export const fakeProcessInstance: ProcessInstanceCloud = {
|
||||||
appName: 'simple-app',
|
appName: 'simple-app',
|
||||||
appVersion: '1',
|
appVersion: '1',
|
||||||
@ -253,14 +264,16 @@ export const fakeFormModelJson = {
|
|||||||
version: 0,
|
version: 0,
|
||||||
standAlone: true,
|
standAlone: true,
|
||||||
tabs: [],
|
tabs: [],
|
||||||
fields: [{
|
fields: [
|
||||||
|
{
|
||||||
id: '60b007f6-f838-458c-b4d4-43c69f355ef9',
|
id: '60b007f6-f838-458c-b4d4-43c69f355ef9',
|
||||||
name: 'Label',
|
name: 'Label',
|
||||||
type: 'container',
|
type: 'container',
|
||||||
ab: null,
|
ab: null,
|
||||||
numberOfColumns: 1,
|
numberOfColumns: 1,
|
||||||
fields: {
|
fields: {
|
||||||
1: [{
|
1: [
|
||||||
|
{
|
||||||
id: 'dropdown',
|
id: 'dropdown',
|
||||||
name: 'Dropdown',
|
name: 'Dropdown',
|
||||||
type: 'dropdown',
|
type: 'dropdown',
|
||||||
@ -291,9 +304,11 @@ export const fakeFormModelJson = {
|
|||||||
maxColspan: 2
|
maxColspan: 2
|
||||||
},
|
},
|
||||||
rule: null
|
rule: null
|
||||||
}]
|
|
||||||
}
|
}
|
||||||
}],
|
]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
],
|
||||||
outcomes: [],
|
outcomes: [],
|
||||||
metadata: {},
|
metadata: {},
|
||||||
variables: []
|
variables: []
|
||||||
|
Loading…
x
Reference in New Issue
Block a user