mirror of
https://github.com/Alfresco/alfresco-ng2-components.git
synced 2025-07-24 17:32:15 +00:00
[APPS-2108] migrate unit tests to date-fns (#8991)
* migrate unit tests * [ci:force] cleanup
This commit is contained in:
@@ -35,7 +35,6 @@ import {
|
||||
} from './form-field-validator';
|
||||
import { FormFieldModel } from './form-field.model';
|
||||
import { FormModel } from './form.model';
|
||||
declare let moment: any;
|
||||
|
||||
describe('FormFieldValidator', () => {
|
||||
describe('RequiredFieldValidator', () => {
|
||||
@@ -707,30 +706,24 @@ 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 = moment(maxValueFromActivitiInput, 'DD-M-YYYY hh:mm A').utc().format();
|
||||
|
||||
const localValidValue = '2018-3-30 11:59 PM';
|
||||
|
||||
const field = new FormFieldModel(new FormModel(), {
|
||||
type: FormFieldTypes.DATETIME,
|
||||
value: localValidValue,
|
||||
maxValue: maxValueSavedInForm
|
||||
maxValue: '2018-03-31T23:00:00.000Z'
|
||||
});
|
||||
|
||||
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();
|
||||
|
||||
const localInvalidValue = '2018-3-31 12:01 AM';
|
||||
|
||||
const field = new FormFieldModel(new FormModel(), {
|
||||
type: FormFieldTypes.DATETIME,
|
||||
value: localInvalidValue,
|
||||
maxValue: maxValueSavedInForm
|
||||
maxValue: `2018-03-30T23:00:00.000Z`
|
||||
});
|
||||
|
||||
field.validationSummary = new ErrorMessageModel();
|
||||
@@ -832,30 +825,24 @@ 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 = moment(minValueFromActivitiInput, 'DD-M-YYYY hh:mm A').utc().format();
|
||||
|
||||
const localValidValue = '2018-3-02 06:01 AM';
|
||||
|
||||
const field = new FormFieldModel(new FormModel(), {
|
||||
type: FormFieldTypes.DATETIME,
|
||||
value: localValidValue,
|
||||
minValue: minValueSavedInForm
|
||||
minValue: '2018-03-02T06:00:00+00:00'
|
||||
});
|
||||
|
||||
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();
|
||||
|
||||
const localInvalidValue = '2018-3-02 05:59 AM';
|
||||
|
||||
const field = new FormFieldModel(new FormModel(), {
|
||||
type: FormFieldTypes.DATETIME,
|
||||
value: localInvalidValue,
|
||||
minValue: minValueSavedInForm
|
||||
minValue: '2018-03-02T06:00:00+00:00'
|
||||
});
|
||||
|
||||
field.validationSummary = new ErrorMessageModel();
|
||||
|
@@ -15,7 +15,7 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import moment from 'moment';
|
||||
import { DateFnsUtils } from '../../../../common';
|
||||
import { FormFieldTypes } from './form-field-types';
|
||||
import { FormFieldModel } from './form-field.model';
|
||||
import { FormModel } from './form.model';
|
||||
@@ -273,9 +273,9 @@ describe('FormFieldModel', () => {
|
||||
dateDisplayFormat: 'DD-MM-YYYY'
|
||||
});
|
||||
|
||||
const currentDate = moment(new Date());
|
||||
const expectedDate = moment(currentDate).format('DD-MM-YYYY');
|
||||
const expectedDateFormat = `${currentDate.format('YYYY-MM-DD')}T00:00:00.000Z`;
|
||||
const currentDate = new Date();
|
||||
const expectedDate = DateFnsUtils.formatDate(currentDate, 'dd-MM-yyyy');
|
||||
const expectedDateFormat = `${DateFnsUtils.formatDate(currentDate, 'yyyy-MM-dd')}T00:00:00.000Z`;
|
||||
|
||||
expect(field.value).toBe(expectedDate);
|
||||
expect(form.values['ddmmyyy']).toEqual(expectedDateFormat);
|
||||
@@ -304,9 +304,9 @@ describe('FormFieldModel', () => {
|
||||
dateDisplayFormat: 'YYYY-MM-DD HH:mm'
|
||||
});
|
||||
|
||||
const currentDateTime = moment(new Date());
|
||||
const expectedDateTime = moment.utc(currentDateTime).format('YYYY-MM-DD HH:mm');
|
||||
const expectedDateTimeFormat = `${currentDateTime.utc().format('YYYY-MM-DDTHH:mm:00')}.000Z`;
|
||||
const currentDateTime = new Date();
|
||||
const expectedDateTime = DateFnsUtils.formatDate(currentDateTime, 'YYYY-MM-DD HH:mm');
|
||||
const expectedDateTimeFormat = `${DateFnsUtils.formatDate(currentDateTime, 'YYYY-MM-DDTHH:mm:00')}.000Z`;
|
||||
|
||||
expect(field.value).toBe(expectedDateTime);
|
||||
expect(form.values['datetime']).toEqual(expectedDateTimeFormat);
|
||||
|
Reference in New Issue
Block a user