[ADF-4473] TaskCloud - add priority numeric validation (#4684)

* [ADF-4473] TaskCloud - add priority numeric validation

* [ADF-4473] - change validation conditiion

* [ADF-4473] - add return type

* [ADF-4473] - fix unit test
This commit is contained in:
Silviu Popa 2019-05-09 19:48:23 +03:00 committed by Eugenio Romano
parent 028e2eb981
commit ead22d9e3c
6 changed files with 63 additions and 33 deletions

View File

@ -507,7 +507,7 @@ describe('EditProcessFilterCloudComponent', () => {
fixture.detectChanges();
const lastModifiedToControl: AbstractControl = component.editProcessFilterForm.get('lastModifiedTo');
lastModifiedToControl.setValue('Tue Apr 09 2019 00:00:00 GMT+0300 (Eastern European Summer Time)');
lastModifiedToControl.setValue(new Date().toISOString());
const lastModifiedToFilter = moment(lastModifiedToControl.value);
lastModifiedToFilter.set({
hour: 23,

View File

@ -76,11 +76,6 @@ describe('PeopleCloudComponent', () => {
element = fixture.nativeElement;
}));
afterEach(() => {
fixture.destroy();
TestBed.resetTestingModule();
});
it('should list the users if the typed result match', async(() => {
const inputHTMLElement: HTMLInputElement = <HTMLInputElement> element.querySelector('input');
inputHTMLElement.focus();
@ -173,11 +168,6 @@ describe('PeopleCloudComponent', () => {
element = fixture.nativeElement;
}));
afterEach(() => {
fixture.destroy();
TestBed.resetTestingModule();
});
it('should list users who have access to the app when appName is specified', async(() => {
const inputHTMLElement: HTMLInputElement = <HTMLInputElement> element.querySelector('input');
inputHTMLElement.focus();
@ -314,11 +304,6 @@ describe('PeopleCloudComponent', () => {
element = fixture.nativeElement;
}));
afterEach(() => {
fixture.destroy();
TestBed.resetTestingModule();
});
it('should filter users if users has any specified role', async(() => {
fixture.detectChanges();
const inputHTMLElement: HTMLInputElement = <HTMLInputElement> element.querySelector('input');
@ -378,11 +363,6 @@ describe('PeopleCloudComponent', () => {
element = fixture.nativeElement;
}));
afterEach(() => {
fixture.destroy();
TestBed.resetTestingModule();
});
it('should not show chip list when mode=single', async(() => {
fixture.detectChanges();
fixture.whenStable().then(() => {
@ -413,11 +393,6 @@ describe('PeopleCloudComponent', () => {
element = fixture.nativeElement;
}));
afterEach(() => {
fixture.destroy();
TestBed.resetTestingModule();
});
it('should not show chip list when mode=single', async(() => {
fixture.detectChanges();
fixture.whenStable().then(() => {
@ -450,11 +425,6 @@ describe('PeopleCloudComponent', () => {
alfrescoApiService = TestBed.get(AlfrescoApiService);
}));
afterEach(() => {
fixture.destroy();
TestBed.resetTestingModule();
});
it('should show chip list when mode=multiple', async(() => {
fixture.detectChanges();
fixture.whenStable().then(() => {

View File

@ -403,7 +403,7 @@ describe('EditTaskFilterCloudComponent', () => {
fixture.detectChanges();
const lastModifiedToControl: AbstractControl = component.editTaskFilterForm.get('lastModifiedTo');
lastModifiedToControl.setValue('Tue Apr 09 2019 00:00:00 GMT+0300 (Eastern European Summer Time)');
lastModifiedToControl.setValue(new Date().toISOString());
const lastModifiedToFilter = moment(lastModifiedToControl.value);
lastModifiedToFilter.set({
hour: 23,

View File

@ -89,6 +89,29 @@ describe('TaskHeaderCloudComponent', () => {
});
}));
it('should display error if priority is not a number', async(() => {
component.ngOnInit();
fixture.detectChanges();
fixture.whenStable().then(() => {
const edit = fixture.debugElement.query(By.css('[data-automation-id="card-textitem-edit-icon-priority"]'));
edit.nativeElement.click();
fixture.detectChanges();
const formPriorityEl = fixture.debugElement.query(By.css('[data-automation-id="card-textitem-editinput-priority"]'));
formPriorityEl.nativeElement.value = 'stringValue';
formPriorityEl.nativeElement.dispatchEvent(new Event('input'));
fixture.detectChanges();
const submitEl = fixture.debugElement.query(By.css('[data-automation-id="card-textitem-update-priority"]'));
submitEl.nativeElement.click();
fixture.detectChanges();
const errorMessageEl = fixture.debugElement.query(By.css('[data-automation-id="card-textitem-error-priority"]'));
expect(errorMessageEl).not.toBeNull();
});
}));
it('should display due date', async(() => {
component.ngOnInit();
fixture.detectChanges();

View File

@ -30,6 +30,7 @@ import { TaskDetailsCloudModel, TaskStatusEnum } from '../../start-task/models/t
import { Router } from '@angular/router';
import { TaskCloudService } from '../../services/task-cloud.service';
import { Subscription } from 'rxjs';
import { NumericFieldValidator } from '../../../validators/numeric-field.validator';
@Component({
selector: 'adf-cloud-task-header',
@ -112,7 +113,8 @@ export class TaskHeaderCloudComponent implements OnInit, OnDestroy {
label: 'ADF_CLOUD_TASK_HEADER.PROPERTIES.PRIORITY',
value: this.taskDetails.priority,
key: 'priority',
editable: true
editable: true,
validators: [new NumericFieldValidator()]
}
),
new CardViewDateItemModel(

View File

@ -0,0 +1,35 @@
/*!
* @license
* Copyright 2019 Alfresco Software, Ltd.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import { CardViewItemValidator } from '@alfresco/adf-core';
export class NumericFieldValidator implements CardViewItemValidator {
message: string = 'ADF_CLOUD_TASK_HEADER.FORM_VALIDATION.INVALID_FIELD';
isValid(value: any): boolean {
if (!value) {
return false;
}
return !isNaN(+value) && !this.whitespaces(value);
}
whitespaces(value: any): boolean {
const isWhitespace = (value || '').trim().length === 0;
return !(value.length === 0 || !isWhitespace);
}
}