mirror of
https://github.com/Alfresco/alfresco-ng2-components.git
synced 2026-09-09 18:03:21 +00:00
[ACS-5857] resolved unit tests and linting issues
This commit is contained in:
@@ -714,7 +714,7 @@ describe('FormFieldValidator', () => {
|
|||||||
|
|
||||||
it('should take into account that max value is in UTC and NOT fail validating value checking the time', () => {
|
it('should take into account that max value is in UTC and NOT fail validating value checking the time', () => {
|
||||||
const maxValueFromActivitiInput = '31-3-2018 12:00 AM';
|
const maxValueFromActivitiInput = '31-3-2018 12:00 AM';
|
||||||
const maxValueSavedInForm = format(parse(maxValueFromActivitiInput, 'dd-MM-yyyy hh:mm a', new Date()), "yyyy-MM-dd'T'HH:mm:ssXXX");
|
const maxValueSavedInForm = format(parse(maxValueFromActivitiInput, 'dd-MM-yyyy hh:mm a', new Date()), `yyyy-MM-dd'T'HH:mm:ssXXX`);
|
||||||
|
|
||||||
const localValidValue = '2018-3-30 11:59 PM';
|
const localValidValue = '2018-3-30 11:59 PM';
|
||||||
|
|
||||||
@@ -729,7 +729,7 @@ describe('FormFieldValidator', () => {
|
|||||||
|
|
||||||
it('should take into account that max value is in UTC and fail validating value checking the time', () => {
|
it('should take into account that max value is in UTC and fail validating value checking the time', () => {
|
||||||
const maxValueFromActivitiInput = '31-3-2018 12:00 AM';
|
const maxValueFromActivitiInput = '31-3-2018 12:00 AM';
|
||||||
const maxValueSavedInForm = format(parse(maxValueFromActivitiInput, 'd-M-yyyy hh:mm a', new Date()), "yyyy-MM-dd'T'HH:mm:ssxxx");
|
const maxValueSavedInForm = format(parse(maxValueFromActivitiInput, 'd-M-yyyy hh:mm a', new Date()), `yyyy-MM-dd'T'HH:mm:ssxxx`);
|
||||||
|
|
||||||
const localInvalidValue = '2018-3-31 12:01 AM';
|
const localInvalidValue = '2018-3-31 12:01 AM';
|
||||||
|
|
||||||
@@ -840,7 +840,7 @@ describe('FormFieldValidator', () => {
|
|||||||
|
|
||||||
it('should take into account that min value is in UTC and NOT fail validating value checking the time', () => {
|
it('should take into account that min value is in UTC and NOT fail validating value checking the time', () => {
|
||||||
const minValueFromActivitiInput = '02-3-2018 06:00 AM';
|
const minValueFromActivitiInput = '02-3-2018 06:00 AM';
|
||||||
const minValueSavedInForm = format(parse(minValueFromActivitiInput, 'dd-MM-yyyy hh:mm a', new Date()), "yyyy-MM-dd'T'HH:mm:ssXXX");
|
const minValueSavedInForm = format(parse(minValueFromActivitiInput, 'dd-MM-yyyy hh:mm a', new Date()), `yyyy-MM-dd'T'HH:mm:ssXXX`);
|
||||||
|
|
||||||
const localValidValue = '2018-3-02 06:01 AM';
|
const localValidValue = '2018-3-02 06:01 AM';
|
||||||
|
|
||||||
@@ -855,7 +855,7 @@ describe('FormFieldValidator', () => {
|
|||||||
|
|
||||||
it('should take into account that min value is in UTC and fail validating value checking the time', () => {
|
it('should take into account that min value is in UTC and fail validating value checking the time', () => {
|
||||||
const minValueFromActivitiInput = '02-3-2018 06:00 AM';
|
const minValueFromActivitiInput = '02-3-2018 06:00 AM';
|
||||||
const minValueSavedInForm = format(parse(minValueFromActivitiInput, 'dd-MM-yyyy hh:mm a', new Date()), "yyyy-MM-dd'T'HH:mm:ssXXX");
|
const minValueSavedInForm = format(parse(minValueFromActivitiInput, 'dd-MM-yyyy hh:mm a', new Date()), `yyyy-MM-dd'T'HH:mm:ssXXX`);
|
||||||
|
|
||||||
const localInvalidValue = '2018-3-02 05:59 AM';
|
const localInvalidValue = '2018-3-02 05:59 AM';
|
||||||
|
|
||||||
@@ -1114,7 +1114,7 @@ describe('FormFieldValidator', () => {
|
|||||||
const field = new FormFieldModel(new FormModel(), {
|
const field = new FormFieldModel(new FormModel(), {
|
||||||
type: FormFieldTypes.DATETIME,
|
type: FormFieldTypes.DATETIME,
|
||||||
value: '2021-06-09 02:10 PM',
|
value: '2021-06-09 02:10 PM',
|
||||||
dateDisplayFormat: 'yyyy-MM-dd hh:mm a',
|
dateDisplayFormat: 'yyyy-MM-dd hh:mm a'
|
||||||
});
|
});
|
||||||
|
|
||||||
expect(validator.validate(field)).toBeTruthy();
|
expect(validator.validate(field)).toBeTruthy();
|
||||||
|
|||||||
@@ -212,18 +212,18 @@ export abstract class BoundaryDateFieldValidator implements FormFieldValidator {
|
|||||||
];
|
];
|
||||||
|
|
||||||
validate(field: FormFieldModel): boolean {
|
validate(field: FormFieldModel): boolean {
|
||||||
let isValid = true;
|
let isFieldValid = true;
|
||||||
if (this.isSupported(field) && field.value && field.isVisible) {
|
if (this.isSupported(field) && field.value && field.isVisible) {
|
||||||
const dateFormat = field.dateDisplayFormat;
|
const dateFormat = field.dateDisplayFormat;
|
||||||
|
|
||||||
if (!DateFieldValidator.isValidDate(field.value, dateFormat)) {
|
if (!DateFieldValidator.isValidDate(field.value, dateFormat)) {
|
||||||
field.validationSummary.message = 'FORM.FIELD.VALIDATOR.INVALID_DATE';
|
field.validationSummary.message = 'FORM.FIELD.VALIDATOR.INVALID_DATE';
|
||||||
isValid = false;
|
isFieldValid = false;
|
||||||
} else {
|
} else {
|
||||||
isValid = this.checkDate(field, dateFormat);
|
isFieldValid = this.checkDate(field, dateFormat);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return isValid;
|
return isFieldValid;
|
||||||
}
|
}
|
||||||
|
|
||||||
extractDateFormat(date: string): string {
|
extractDateFormat(date: string): string {
|
||||||
@@ -240,7 +240,7 @@ export class MinDateFieldValidator extends BoundaryDateFieldValidator {
|
|||||||
|
|
||||||
checkDate(field: FormFieldModel, dateFormat: string): boolean {
|
checkDate(field: FormFieldModel, dateFormat: string): boolean {
|
||||||
|
|
||||||
let isValid = true;
|
let isFieldValid = true;
|
||||||
// remove time and timezone info
|
// remove time and timezone info
|
||||||
let fieldValueData;
|
let fieldValueData;
|
||||||
if (typeof field.value === 'string') {
|
if (typeof field.value === 'string') {
|
||||||
@@ -255,9 +255,9 @@ export class MinDateFieldValidator extends BoundaryDateFieldValidator {
|
|||||||
if (isBefore(fieldValueData, min)) {
|
if (isBefore(fieldValueData, min)) {
|
||||||
field.validationSummary.message = `FORM.FIELD.VALIDATOR.NOT_LESS_THAN`;
|
field.validationSummary.message = `FORM.FIELD.VALIDATOR.NOT_LESS_THAN`;
|
||||||
field.validationSummary.attributes.set('minValue', format(min, field.dateDisplayFormat).toLocaleUpperCase());
|
field.validationSummary.attributes.set('minValue', format(min, field.dateDisplayFormat).toLocaleUpperCase());
|
||||||
isValid = false;
|
isFieldValid = false;
|
||||||
}
|
}
|
||||||
return isValid;
|
return isFieldValid;
|
||||||
}
|
}
|
||||||
|
|
||||||
isSupported(field: FormFieldModel): boolean {
|
isSupported(field: FormFieldModel): boolean {
|
||||||
@@ -270,7 +270,7 @@ export class MaxDateFieldValidator extends BoundaryDateFieldValidator {
|
|||||||
|
|
||||||
checkDate(field: FormFieldModel, dateFormat: string): boolean {
|
checkDate(field: FormFieldModel, dateFormat: string): boolean {
|
||||||
|
|
||||||
let isValid = true;
|
let isFieldValid = true;
|
||||||
// remove time and timezone info
|
// remove time and timezone info
|
||||||
let fieldValueData;
|
let fieldValueData;
|
||||||
if (typeof field.value === 'string') {
|
if (typeof field.value === 'string') {
|
||||||
@@ -285,9 +285,9 @@ export class MaxDateFieldValidator extends BoundaryDateFieldValidator {
|
|||||||
if (isAfter(fieldValueData, max)) {
|
if (isAfter(fieldValueData, max)) {
|
||||||
field.validationSummary.message = `FORM.FIELD.VALIDATOR.NOT_GREATER_THAN`;
|
field.validationSummary.message = `FORM.FIELD.VALIDATOR.NOT_GREATER_THAN`;
|
||||||
field.validationSummary.attributes.set('maxValue', format(max, field.dateDisplayFormat).toLocaleUpperCase());
|
field.validationSummary.attributes.set('maxValue', format(max, field.dateDisplayFormat).toLocaleUpperCase());
|
||||||
isValid = false;
|
isFieldValid = false;
|
||||||
}
|
}
|
||||||
return isValid;
|
return isFieldValid;
|
||||||
}
|
}
|
||||||
|
|
||||||
isSupported(field: FormFieldModel): boolean {
|
isSupported(field: FormFieldModel): boolean {
|
||||||
@@ -309,22 +309,22 @@ export class MinDateTimeFieldValidator implements FormFieldValidator {
|
|||||||
}
|
}
|
||||||
|
|
||||||
validate(field: FormFieldModel): boolean {
|
validate(field: FormFieldModel): boolean {
|
||||||
let isValid = true;
|
let isFieldValid = true;
|
||||||
if (this.isSupported(field) && field.value && field.isVisible) {
|
if (this.isSupported(field) && field.value && field.isVisible) {
|
||||||
const dateFormat = field.dateDisplayFormat;
|
const dateFormat = field.dateDisplayFormat;
|
||||||
|
|
||||||
if (!DateFieldValidator.isValidDate(field.value, dateFormat)) {
|
if (!DateFieldValidator.isValidDate(field.value, dateFormat)) {
|
||||||
field.validationSummary.message = 'FORM.FIELD.VALIDATOR.INVALID_DATE';
|
field.validationSummary.message = 'FORM.FIELD.VALIDATOR.INVALID_DATE';
|
||||||
isValid = false;
|
isFieldValid = false;
|
||||||
} else {
|
} else {
|
||||||
isValid = this.checkDateTime(field, dateFormat);
|
isFieldValid = this.checkDateTime(field, dateFormat);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return isValid;
|
return isFieldValid;
|
||||||
}
|
}
|
||||||
|
|
||||||
private checkDateTime(field: FormFieldModel, dateFormat: string): boolean {
|
private checkDateTime(field: FormFieldModel, dateFormat: string): boolean {
|
||||||
let isValid = true;
|
let isFieldValid = true;
|
||||||
let fieldValueDate;
|
let fieldValueDate;
|
||||||
if (typeof field.value === 'string') {
|
if (typeof field.value === 'string') {
|
||||||
fieldValueDate = parse(field.value, dateFormat, new Date());
|
fieldValueDate = parse(field.value, dateFormat, new Date());
|
||||||
@@ -336,9 +336,9 @@ export class MinDateTimeFieldValidator implements FormFieldValidator {
|
|||||||
if (isBefore(fieldValueDate, new Date(min))) {
|
if (isBefore(fieldValueDate, new Date(min))) {
|
||||||
field.validationSummary.message = `FORM.FIELD.VALIDATOR.NOT_LESS_THAN`;
|
field.validationSummary.message = `FORM.FIELD.VALIDATOR.NOT_LESS_THAN`;
|
||||||
field.validationSummary.attributes.set('minValue', format(new Date(min), field.dateDisplayFormat).replace(':', '-'));
|
field.validationSummary.attributes.set('minValue', format(new Date(min), field.dateDisplayFormat).replace(':', '-'));
|
||||||
isValid = false;
|
isFieldValid = false;
|
||||||
}
|
}
|
||||||
return isValid;
|
return isFieldValid;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -355,22 +355,22 @@ export class MaxDateTimeFieldValidator implements FormFieldValidator {
|
|||||||
}
|
}
|
||||||
|
|
||||||
validate(field: FormFieldModel): boolean {
|
validate(field: FormFieldModel): boolean {
|
||||||
let isValid = true;
|
let isFieldValid = true;
|
||||||
if (this.isSupported(field) && field.value && field.isVisible) {
|
if (this.isSupported(field) && field.value && field.isVisible) {
|
||||||
const dateFormat = field.dateDisplayFormat;
|
const dateFormat = field.dateDisplayFormat;
|
||||||
|
|
||||||
if (!DateFieldValidator.isValidDate(field.value, dateFormat)) {
|
if (!DateFieldValidator.isValidDate(field.value, dateFormat)) {
|
||||||
field.validationSummary.message = 'FORM.FIELD.VALIDATOR.INVALID_DATE';
|
field.validationSummary.message = 'FORM.FIELD.VALIDATOR.INVALID_DATE';
|
||||||
isValid = false;
|
isFieldValid = false;
|
||||||
} else {
|
} else {
|
||||||
isValid = this.checkDateTime(field, dateFormat);
|
isFieldValid = this.checkDateTime(field, dateFormat);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return isValid;
|
return isFieldValid;
|
||||||
}
|
}
|
||||||
|
|
||||||
private checkDateTime(field: FormFieldModel, dateFormat: string): boolean {
|
private checkDateTime(field: FormFieldModel, dateFormat: string): boolean {
|
||||||
let isValid = true;
|
let isFieldValid = true;
|
||||||
let fieldValueDate;
|
let fieldValueDate;
|
||||||
|
|
||||||
if (typeof field.value === 'string') {
|
if (typeof field.value === 'string') {
|
||||||
@@ -383,9 +383,9 @@ export class MaxDateTimeFieldValidator implements FormFieldValidator {
|
|||||||
if (isAfter(fieldValueDate, new Date(max))) {
|
if (isAfter(fieldValueDate, new Date(max))) {
|
||||||
field.validationSummary.message = `FORM.FIELD.VALIDATOR.NOT_GREATER_THAN`;
|
field.validationSummary.message = `FORM.FIELD.VALIDATOR.NOT_GREATER_THAN`;
|
||||||
field.validationSummary.attributes.set('maxValue', format(new Date(max), field.dateDisplayFormat).replace(':', '-'));
|
field.validationSummary.attributes.set('maxValue', format(new Date(max), field.dateDisplayFormat).replace(':', '-'));
|
||||||
isValid = false;
|
isFieldValid = false;
|
||||||
}
|
}
|
||||||
return isValid;
|
return isFieldValid;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -306,7 +306,7 @@ describe('FormFieldModel', () => {
|
|||||||
|
|
||||||
const currentDateTime = new Date();
|
const currentDateTime = new Date();
|
||||||
const expectedDateTime = format(currentDateTime, 'yyyy-MM-dd hh:mm');
|
const expectedDateTime = format(currentDateTime, 'yyyy-MM-dd hh:mm');
|
||||||
const expectedDateTimeFormat = `${format(currentDateTime, "yyyy-MM-dd'T'hh:mm")}:00.000Z`;
|
const expectedDateTimeFormat = `${format(currentDateTime, `yyyy-MM-dd'T'hh:mm`)}:00.000Z`;
|
||||||
|
|
||||||
expect(field.value).toBe(expectedDateTime);
|
expect(field.value).toBe(expectedDateTime);
|
||||||
expect(form.values['datetime']).toEqual(expectedDateTimeFormat);
|
expect(form.values['datetime']).toEqual(expectedDateTimeFormat);
|
||||||
|
|||||||
@@ -102,7 +102,7 @@ describe('DateTimeWidgetComponent', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
widget.field = field;
|
widget.field = field;
|
||||||
const mockDate = format(new Date('1982-03-13 10:00 AM'), "yyyy-MM-dd'T'hh:mm:ssxxx");
|
const mockDate = format(new Date('1982-03-13 10:00 AM'), `yyyy-MM-dd'T'hh:mm:ssxxx`);
|
||||||
widget.onDateChanged(mockDate);
|
widget.onDateChanged(mockDate);
|
||||||
|
|
||||||
expect(widget.onFieldChanged).toHaveBeenCalledWith(field);
|
expect(widget.onFieldChanged).toHaveBeenCalledWith(field);
|
||||||
|
|||||||
@@ -1186,7 +1186,7 @@ describe('Multilingual Form', () => {
|
|||||||
|
|
||||||
expect(getLabelValue('textField')).toEqual('Champ de texte');
|
expect(getLabelValue('textField')).toEqual('Champ de texte');
|
||||||
expect(getLabelValue('fildUploadField')).toEqual('Téléchargement de fichiers');
|
expect(getLabelValue('fildUploadField')).toEqual('Téléchargement de fichiers');
|
||||||
expect(getLabelValue('dateField')).toEqual('Champ de date (D-M-YYYY)');
|
expect(getLabelValue('dateField')).toEqual('Champ de date (d-M-yyyy)');
|
||||||
expect(getLabelValue('amountField')).toEqual('Champ Montant');
|
expect(getLabelValue('amountField')).toEqual('Champ Montant');
|
||||||
|
|
||||||
await translateService.use('en').toPromise();
|
await translateService.use('en').toPromise();
|
||||||
@@ -1196,7 +1196,7 @@ describe('Multilingual Form', () => {
|
|||||||
|
|
||||||
expect(getLabelValue('textField')).toEqual('Text field');
|
expect(getLabelValue('textField')).toEqual('Text field');
|
||||||
expect(getLabelValue('fildUploadField')).toEqual('File Upload');
|
expect(getLabelValue('fildUploadField')).toEqual('File Upload');
|
||||||
expect(getLabelValue('dateField')).toEqual('Date field (D-M-YYYY)');
|
expect(getLabelValue('dateField')).toEqual('Date field (d-M-yyyy)');
|
||||||
expect(getLabelValue('amountField')).toEqual('Amount field');
|
expect(getLabelValue('amountField')).toEqual('Amount field');
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
+1
-1
@@ -191,7 +191,7 @@ describe('DateWidgetComponent', () => {
|
|||||||
readOnly: 'false'
|
readOnly: 'false'
|
||||||
});
|
});
|
||||||
field.isVisible = true;
|
field.isVisible = true;
|
||||||
field.dateDisplayFormat = 'MM-DD-YYYY';
|
field.dateDisplayFormat = 'MM-dd-yyyy';
|
||||||
widget.field = field;
|
widget.field = field;
|
||||||
widget.ngOnInit();
|
widget.ngOnInit();
|
||||||
fixture.detectChanges();
|
fixture.detectChanges();
|
||||||
|
|||||||
@@ -372,7 +372,7 @@ export const cloudFormMock = {
|
|||||||
existingColspan: 1,
|
existingColspan: 1,
|
||||||
maxColspan: 2
|
maxColspan: 2
|
||||||
},
|
},
|
||||||
dateDisplayFormat: 'D-M-YYYY'
|
dateDisplayFormat: 'd-M-yyyy'
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
2: [
|
2: [
|
||||||
@@ -393,7 +393,7 @@ export const cloudFormMock = {
|
|||||||
existingColspan: 1,
|
existingColspan: 1,
|
||||||
maxColspan: 2
|
maxColspan: 2
|
||||||
},
|
},
|
||||||
dateDisplayFormat: 'D-M-YYYY'
|
dateDisplayFormat: 'd-M-yyyy'
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
@@ -1037,7 +1037,7 @@ export const multilingualForm: any = {
|
|||||||
existingColspan: 1,
|
existingColspan: 1,
|
||||||
maxColspan: 2
|
maxColspan: 2
|
||||||
},
|
},
|
||||||
dateDisplayFormat: 'D-M-YYYY'
|
dateDisplayFormat: 'd-M-yyyy'
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
2: []
|
2: []
|
||||||
|
|||||||
@@ -271,7 +271,7 @@ describe('StartFormComponent', () => {
|
|||||||
|
|
||||||
expect(dateWidget).toBeTruthy();
|
expect(dateWidget).toBeTruthy();
|
||||||
expect(labelField.type).toBe('date');
|
expect(labelField.type).toBe('date');
|
||||||
expect(dateLabelElement.innerText).toBe('date (D-M-YYYY)');
|
expect(dateLabelElement.innerText).toBe('date (d-M-yyyy)');
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should fetch and define form fields with proper type', () => {
|
it('should fetch and define form fields with proper type', () => {
|
||||||
@@ -312,7 +312,7 @@ describe('StartFormComponent', () => {
|
|||||||
expect(selectElement).toBeDefined();
|
expect(selectElement).toBeDefined();
|
||||||
|
|
||||||
expect(translate.instant(inputLabelElement.textContent)).toBe('ClientName*');
|
expect(translate.instant(inputLabelElement.textContent)).toBe('ClientName*');
|
||||||
expect(translate.instant(dateLabelElement.innerText)).toBe('BillDate (D-M-YYYY)');
|
expect(translate.instant(dateLabelElement.innerText)).toBe('BillDate (d-M-yyyy)');
|
||||||
expect(translate.instant(selectLabelElement.innerText)).toBe('ClaimType');
|
expect(translate.instant(selectLabelElement.innerText)).toBe('ClaimType');
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user