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', () => {
|
||||
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';
|
||||
|
||||
@@ -729,7 +729,7 @@ describe('FormFieldValidator', () => {
|
||||
|
||||
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 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';
|
||||
|
||||
@@ -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', () => {
|
||||
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';
|
||||
|
||||
@@ -855,7 +855,7 @@ describe('FormFieldValidator', () => {
|
||||
|
||||
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 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';
|
||||
|
||||
@@ -1114,7 +1114,7 @@ describe('FormFieldValidator', () => {
|
||||
const field = new FormFieldModel(new FormModel(), {
|
||||
type: FormFieldTypes.DATETIME,
|
||||
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();
|
||||
|
||||
@@ -212,18 +212,18 @@ export abstract class BoundaryDateFieldValidator implements FormFieldValidator {
|
||||
];
|
||||
|
||||
validate(field: FormFieldModel): boolean {
|
||||
let isValid = true;
|
||||
let isFieldValid = true;
|
||||
if (this.isSupported(field) && field.value && field.isVisible) {
|
||||
const dateFormat = field.dateDisplayFormat;
|
||||
|
||||
if (!DateFieldValidator.isValidDate(field.value, dateFormat)) {
|
||||
field.validationSummary.message = 'FORM.FIELD.VALIDATOR.INVALID_DATE';
|
||||
isValid = false;
|
||||
isFieldValid = false;
|
||||
} else {
|
||||
isValid = this.checkDate(field, dateFormat);
|
||||
isFieldValid = this.checkDate(field, dateFormat);
|
||||
}
|
||||
}
|
||||
return isValid;
|
||||
return isFieldValid;
|
||||
}
|
||||
|
||||
extractDateFormat(date: string): string {
|
||||
@@ -240,7 +240,7 @@ export class MinDateFieldValidator extends BoundaryDateFieldValidator {
|
||||
|
||||
checkDate(field: FormFieldModel, dateFormat: string): boolean {
|
||||
|
||||
let isValid = true;
|
||||
let isFieldValid = true;
|
||||
// remove time and timezone info
|
||||
let fieldValueData;
|
||||
if (typeof field.value === 'string') {
|
||||
@@ -255,9 +255,9 @@ export class MinDateFieldValidator extends BoundaryDateFieldValidator {
|
||||
if (isBefore(fieldValueData, min)) {
|
||||
field.validationSummary.message = `FORM.FIELD.VALIDATOR.NOT_LESS_THAN`;
|
||||
field.validationSummary.attributes.set('minValue', format(min, field.dateDisplayFormat).toLocaleUpperCase());
|
||||
isValid = false;
|
||||
isFieldValid = false;
|
||||
}
|
||||
return isValid;
|
||||
return isFieldValid;
|
||||
}
|
||||
|
||||
isSupported(field: FormFieldModel): boolean {
|
||||
@@ -270,7 +270,7 @@ export class MaxDateFieldValidator extends BoundaryDateFieldValidator {
|
||||
|
||||
checkDate(field: FormFieldModel, dateFormat: string): boolean {
|
||||
|
||||
let isValid = true;
|
||||
let isFieldValid = true;
|
||||
// remove time and timezone info
|
||||
let fieldValueData;
|
||||
if (typeof field.value === 'string') {
|
||||
@@ -285,9 +285,9 @@ export class MaxDateFieldValidator extends BoundaryDateFieldValidator {
|
||||
if (isAfter(fieldValueData, max)) {
|
||||
field.validationSummary.message = `FORM.FIELD.VALIDATOR.NOT_GREATER_THAN`;
|
||||
field.validationSummary.attributes.set('maxValue', format(max, field.dateDisplayFormat).toLocaleUpperCase());
|
||||
isValid = false;
|
||||
isFieldValid = false;
|
||||
}
|
||||
return isValid;
|
||||
return isFieldValid;
|
||||
}
|
||||
|
||||
isSupported(field: FormFieldModel): boolean {
|
||||
@@ -309,22 +309,22 @@ export class MinDateTimeFieldValidator implements FormFieldValidator {
|
||||
}
|
||||
|
||||
validate(field: FormFieldModel): boolean {
|
||||
let isValid = true;
|
||||
let isFieldValid = true;
|
||||
if (this.isSupported(field) && field.value && field.isVisible) {
|
||||
const dateFormat = field.dateDisplayFormat;
|
||||
|
||||
if (!DateFieldValidator.isValidDate(field.value, dateFormat)) {
|
||||
field.validationSummary.message = 'FORM.FIELD.VALIDATOR.INVALID_DATE';
|
||||
isValid = false;
|
||||
isFieldValid = false;
|
||||
} else {
|
||||
isValid = this.checkDateTime(field, dateFormat);
|
||||
isFieldValid = this.checkDateTime(field, dateFormat);
|
||||
}
|
||||
}
|
||||
return isValid;
|
||||
return isFieldValid;
|
||||
}
|
||||
|
||||
private checkDateTime(field: FormFieldModel, dateFormat: string): boolean {
|
||||
let isValid = true;
|
||||
let isFieldValid = true;
|
||||
let fieldValueDate;
|
||||
if (typeof field.value === 'string') {
|
||||
fieldValueDate = parse(field.value, dateFormat, new Date());
|
||||
@@ -336,9 +336,9 @@ export class MinDateTimeFieldValidator implements FormFieldValidator {
|
||||
if (isBefore(fieldValueDate, new Date(min))) {
|
||||
field.validationSummary.message = `FORM.FIELD.VALIDATOR.NOT_LESS_THAN`;
|
||||
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 {
|
||||
let isValid = true;
|
||||
let isFieldValid = true;
|
||||
if (this.isSupported(field) && field.value && field.isVisible) {
|
||||
const dateFormat = field.dateDisplayFormat;
|
||||
|
||||
if (!DateFieldValidator.isValidDate(field.value, dateFormat)) {
|
||||
field.validationSummary.message = 'FORM.FIELD.VALIDATOR.INVALID_DATE';
|
||||
isValid = false;
|
||||
isFieldValid = false;
|
||||
} else {
|
||||
isValid = this.checkDateTime(field, dateFormat);
|
||||
isFieldValid = this.checkDateTime(field, dateFormat);
|
||||
}
|
||||
}
|
||||
return isValid;
|
||||
return isFieldValid;
|
||||
}
|
||||
|
||||
private checkDateTime(field: FormFieldModel, dateFormat: string): boolean {
|
||||
let isValid = true;
|
||||
let isFieldValid = true;
|
||||
let fieldValueDate;
|
||||
|
||||
if (typeof field.value === 'string') {
|
||||
@@ -383,9 +383,9 @@ export class MaxDateTimeFieldValidator implements FormFieldValidator {
|
||||
if (isAfter(fieldValueDate, new Date(max))) {
|
||||
field.validationSummary.message = `FORM.FIELD.VALIDATOR.NOT_GREATER_THAN`;
|
||||
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 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(form.values['datetime']).toEqual(expectedDateTimeFormat);
|
||||
|
||||
@@ -434,7 +434,7 @@ export class FormFieldModel extends FormWidgetModel {
|
||||
}
|
||||
|
||||
const dateTimeValue = parse(this.value, this.dateDisplayFormat, new Date());
|
||||
|
||||
|
||||
if (isValid(dateTimeValue)) {
|
||||
this.form.values[this.id] = `${format(dateTimeValue, 'yyyy-MM-dd\'T\'HH:mm:ss')}.000Z`;
|
||||
} else {
|
||||
|
||||
@@ -102,7 +102,7 @@ describe('DateTimeWidgetComponent', () => {
|
||||
});
|
||||
|
||||
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);
|
||||
|
||||
expect(widget.onFieldChanged).toHaveBeenCalledWith(field);
|
||||
|
||||
@@ -1186,7 +1186,7 @@ describe('Multilingual Form', () => {
|
||||
|
||||
expect(getLabelValue('textField')).toEqual('Champ de texte');
|
||||
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');
|
||||
|
||||
await translateService.use('en').toPromise();
|
||||
@@ -1196,7 +1196,7 @@ describe('Multilingual Form', () => {
|
||||
|
||||
expect(getLabelValue('textField')).toEqual('Text field');
|
||||
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');
|
||||
});
|
||||
|
||||
|
||||
+1
-1
@@ -191,7 +191,7 @@ describe('DateWidgetComponent', () => {
|
||||
readOnly: 'false'
|
||||
});
|
||||
field.isVisible = true;
|
||||
field.dateDisplayFormat = 'MM-DD-YYYY';
|
||||
field.dateDisplayFormat = 'MM-dd-yyyy';
|
||||
widget.field = field;
|
||||
widget.ngOnInit();
|
||||
fixture.detectChanges();
|
||||
|
||||
@@ -372,7 +372,7 @@ export const cloudFormMock = {
|
||||
existingColspan: 1,
|
||||
maxColspan: 2
|
||||
},
|
||||
dateDisplayFormat: 'D-M-YYYY'
|
||||
dateDisplayFormat: 'd-M-yyyy'
|
||||
}
|
||||
],
|
||||
2: [
|
||||
@@ -393,7 +393,7 @@ export const cloudFormMock = {
|
||||
existingColspan: 1,
|
||||
maxColspan: 2
|
||||
},
|
||||
dateDisplayFormat: 'D-M-YYYY'
|
||||
dateDisplayFormat: 'd-M-yyyy'
|
||||
}
|
||||
]
|
||||
}
|
||||
@@ -1037,7 +1037,7 @@ export const multilingualForm: any = {
|
||||
existingColspan: 1,
|
||||
maxColspan: 2
|
||||
},
|
||||
dateDisplayFormat: 'D-M-YYYY'
|
||||
dateDisplayFormat: 'd-M-yyyy'
|
||||
}
|
||||
],
|
||||
2: []
|
||||
|
||||
@@ -271,7 +271,7 @@ describe('StartFormComponent', () => {
|
||||
|
||||
expect(dateWidget).toBeTruthy();
|
||||
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', () => {
|
||||
@@ -312,7 +312,7 @@ describe('StartFormComponent', () => {
|
||||
expect(selectElement).toBeDefined();
|
||||
|
||||
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');
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user