mirror of
https://github.com/Alfresco/alfresco-ng2-components.git
synced 2025-05-26 17:24:56 +00:00
[ADF-2698] Date and time Widget - UTC vs local time issue (#3393)
* [ADF-2698] Date and time Widget - UTC vs local time issue * [ADF-2698] add unit test to check that the format for min and max values is correct * [ADF-2698] test behavior
This commit is contained in:
parent
54e80e7863
commit
fd90fe69c9
@ -32,6 +32,7 @@ import {
|
||||
} from './form-field-validator';
|
||||
import { FormFieldModel } from './form-field.model';
|
||||
import { FormModel } from './form.model';
|
||||
declare let moment: any;
|
||||
|
||||
describe('FormFieldValidator', () => {
|
||||
|
||||
@ -662,6 +663,39 @@ describe('FormFieldValidator', () => {
|
||||
expect(validator.validate(field)).toBeTruthy();
|
||||
});
|
||||
|
||||
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 = moment(maxValueFromActivitiInput, 'DD-M-YYYY hh:mm A').utc().format();
|
||||
|
||||
const localValidValue = '2018-3-30 11:59 PM';
|
||||
|
||||
let field = new FormFieldModel(new FormModel(), {
|
||||
type: FormFieldTypes.DATETIME,
|
||||
value: localValidValue,
|
||||
maxValue: maxValueSavedInForm
|
||||
});
|
||||
|
||||
expect(validator.validate(field)).toBeTruthy();
|
||||
});
|
||||
|
||||
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 = moment(maxValueFromActivitiInput, 'DD-M-YYYY hh:mm A').utc().format();
|
||||
|
||||
let localInvalidValue = '2018-3-31 12:01 AM';
|
||||
|
||||
let field = new FormFieldModel(new FormModel(), {
|
||||
type: FormFieldTypes.DATETIME,
|
||||
value: localInvalidValue,
|
||||
maxValue: maxValueSavedInForm
|
||||
});
|
||||
|
||||
field.validationSummary = new ErrorMessageModel();
|
||||
expect(validator.validate(field)).toBeFalsy();
|
||||
expect(field.validationSummary).not.toBeNull();
|
||||
expect(field.validationSummary.message).toBe('FORM.FIELD.VALIDATOR.NOT_GREATER_THAN');
|
||||
});
|
||||
|
||||
it('should succeed validating value checking the time', () => {
|
||||
let field = new FormFieldModel(new FormModel(), {
|
||||
type: FormFieldTypes.DATETIME,
|
||||
@ -756,6 +790,39 @@ describe('FormFieldValidator', () => {
|
||||
expect(validator.validate(field)).toBeTruthy();
|
||||
});
|
||||
|
||||
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 = moment(minValueFromActivitiInput, 'DD-M-YYYY hh:mm A').utc().format();
|
||||
|
||||
const localValidValue = '2018-3-02 06:01 AM';
|
||||
|
||||
let field = new FormFieldModel(new FormModel(), {
|
||||
type: FormFieldTypes.DATETIME,
|
||||
value: localValidValue,
|
||||
minValue: minValueSavedInForm
|
||||
});
|
||||
|
||||
expect(validator.validate(field)).toBeTruthy();
|
||||
});
|
||||
|
||||
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 = moment(minValueFromActivitiInput, 'DD-M-YYYY hh:mm A').utc().format();
|
||||
|
||||
let localInvalidValue = '2018-3-02 05:59 AM';
|
||||
|
||||
let field = new FormFieldModel(new FormModel(), {
|
||||
type: FormFieldTypes.DATETIME,
|
||||
value: localInvalidValue,
|
||||
minValue: minValueSavedInForm
|
||||
});
|
||||
|
||||
field.validationSummary = new ErrorMessageModel();
|
||||
expect(validator.validate(field)).toBeFalsy();
|
||||
expect(field.validationSummary).not.toBeNull();
|
||||
expect(field.validationSummary.message).toBe('FORM.FIELD.VALIDATOR.NOT_LESS_THAN');
|
||||
});
|
||||
|
||||
it('should succeed validating value by time', () => {
|
||||
let field = new FormFieldModel(new FormModel(), {
|
||||
type: FormFieldTypes.DATETIME,
|
||||
|
@ -256,6 +256,7 @@ export class MinDateTimeFieldValidator implements FormFieldValidator {
|
||||
private supportedTypes = [
|
||||
FormFieldTypes.DATETIME
|
||||
];
|
||||
MIN_DATETIME_FORMAT = 'YYYY-MM-DD hh:mm AZ';
|
||||
|
||||
isSupported(field: FormFieldModel): boolean {
|
||||
return field &&
|
||||
@ -278,8 +279,6 @@ export class MinDateTimeFieldValidator implements FormFieldValidator {
|
||||
}
|
||||
|
||||
private checkDateTime(field: FormFieldModel, dateFormat: string): boolean {
|
||||
const MIN_DATE_FORMAT = 'YYYY-MM-DD hh:mm A';
|
||||
|
||||
let isValid = true;
|
||||
let fieldValueDate;
|
||||
if (typeof field.value === 'string') {
|
||||
@ -287,7 +286,7 @@ export class MinDateTimeFieldValidator implements FormFieldValidator {
|
||||
} else {
|
||||
fieldValueDate = field.value;
|
||||
}
|
||||
let min = moment(field.minValue, MIN_DATE_FORMAT);
|
||||
let min = moment(field.minValue, this.MIN_DATETIME_FORMAT);
|
||||
|
||||
if (fieldValueDate.isBefore(min)) {
|
||||
field.validationSummary.message = `FORM.FIELD.VALIDATOR.NOT_LESS_THAN`;
|
||||
@ -303,6 +302,7 @@ export class MaxDateTimeFieldValidator implements FormFieldValidator {
|
||||
private supportedTypes = [
|
||||
FormFieldTypes.DATETIME
|
||||
];
|
||||
MAX_DATETIME_FORMAT = 'YYYY-MM-DD hh:mm AZ';
|
||||
|
||||
isSupported(field: FormFieldModel): boolean {
|
||||
return field &&
|
||||
@ -325,7 +325,6 @@ export class MaxDateTimeFieldValidator implements FormFieldValidator {
|
||||
}
|
||||
|
||||
private checkDateTime(field: FormFieldModel, dateFormat: string): boolean {
|
||||
const MAX_DATE_FORMAT = 'YYYY-MM-DD hh:mm A';
|
||||
let isValid = true;
|
||||
let fieldValueDate;
|
||||
|
||||
@ -334,7 +333,7 @@ export class MaxDateTimeFieldValidator implements FormFieldValidator {
|
||||
} else {
|
||||
fieldValueDate = field.value;
|
||||
}
|
||||
let max = moment(field.maxValue, MAX_DATE_FORMAT);
|
||||
let max = moment(field.maxValue, this.MAX_DATETIME_FORMAT);
|
||||
|
||||
if (fieldValueDate.isAfter(max)) {
|
||||
field.validationSummary.message = `FORM.FIELD.VALIDATOR.NOT_GREATER_THAN`;
|
||||
|
Loading…
x
Reference in New Issue
Block a user