mirror of
https://github.com/Alfresco/alfresco-ng2-components.git
synced 2026-09-09 18:03:21 +00:00
[ACS-5640] refactored unit tests post migration
This commit is contained in:
@@ -24,7 +24,7 @@ import { TranslateModule } from '@ngx-translate/core';
|
||||
import { MatTooltipModule } from '@angular/material/tooltip';
|
||||
import { FormFieldTypes } from '../core/form-field-types';
|
||||
import { By } from '@angular/platform-browser';
|
||||
import { isSameDay, parse } from 'date-fns';
|
||||
import { format, parse, parseISO } from 'date-fns';
|
||||
|
||||
describe('DateTimeWidgetComponent', () => {
|
||||
|
||||
@@ -52,7 +52,8 @@ describe('DateTimeWidgetComponent', () => {
|
||||
});
|
||||
|
||||
it('should setup min value for date picker', () => {
|
||||
const minValue = '7-8-2023 02:45 PM';
|
||||
const minValue = '1982-03-13T00:00:00.000Z';
|
||||
|
||||
widget.field = new FormFieldModel(null, {
|
||||
id: 'date-id',
|
||||
name: 'date-name',
|
||||
@@ -62,8 +63,8 @@ describe('DateTimeWidgetComponent', () => {
|
||||
|
||||
fixture.detectChanges();
|
||||
|
||||
const expected = parse(minValue, widget.DATE_TIME_FORMAT, new Date());
|
||||
expect(isSameDay(widget.minDate, expected)).toBeTruthy();
|
||||
const expected = format(parseISO(minValue), `yyyy-MM-dd'T'HH:mm:ssXXX`);
|
||||
expect(widget.minDate).toBe(expected);
|
||||
});
|
||||
|
||||
it('should date field be present', () => {
|
||||
@@ -79,14 +80,14 @@ describe('DateTimeWidgetComponent', () => {
|
||||
});
|
||||
|
||||
it('should setup max value for date picker', () => {
|
||||
const maxValue = '20-9-2023 02:45 PM';
|
||||
const maxValue = '1982-03-13T00:00:00.000Z';
|
||||
widget.field = new FormFieldModel(null, {
|
||||
maxValue
|
||||
});
|
||||
fixture.detectChanges();
|
||||
|
||||
const expected = parse(maxValue, widget.DATE_TIME_FORMAT, new Date());
|
||||
expect(isSameDay(widget.maxDate, expected)).toBeTruthy();
|
||||
const expected = format(parseISO(maxValue), `yyyy-MM-dd'T'HH:mm:ssXXX`);
|
||||
expect(widget.maxDate).toBe(expected);
|
||||
});
|
||||
|
||||
it('should eval visibility on date changed', () => {
|
||||
|
||||
@@ -29,7 +29,7 @@ import { WidgetComponent } from '../widget.component';
|
||||
import { Subject } from 'rxjs';
|
||||
import { takeUntil } from 'rxjs/operators';
|
||||
import { DateFnsAdapter } from '@angular/material-date-fns-adapter';
|
||||
import { format, isValid, parse } from 'date-fns';
|
||||
import { format, isValid, parseISO } from 'date-fns';
|
||||
|
||||
@Component({
|
||||
providers: [
|
||||
@@ -47,8 +47,8 @@ export class DateTimeWidgetComponent extends WidgetComponent implements OnInit,
|
||||
|
||||
DATE_TIME_FORMAT = 'd-M-yyyy hh:mm a';
|
||||
|
||||
minDate: Date;
|
||||
maxDate: Date;
|
||||
minDate: string;
|
||||
maxDate: string;
|
||||
|
||||
private onDestroy$ = new Subject<boolean>();
|
||||
|
||||
@@ -66,11 +66,11 @@ export class DateTimeWidgetComponent extends WidgetComponent implements OnInit,
|
||||
|
||||
if (this.field) {
|
||||
if (this.field.minValue) {
|
||||
this.minDate = parse(this.field.minValue, this.DATE_TIME_FORMAT, new Date());
|
||||
this.minDate = format(parseISO(this.field.minValue), `yyyy-MM-dd'T'HH:mm:ssXXX`);
|
||||
}
|
||||
|
||||
if (this.field.maxValue) {
|
||||
this.maxDate = parse(this.field.maxValue, this.DATE_TIME_FORMAT, new Date());
|
||||
this.maxDate = format(parseISO(this.field.maxValue), `yyyy-MM-dd'T'HH:mm:ssXXX`);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+5
-5
@@ -21,7 +21,7 @@ import { FormFieldModel, FormModel, FormFieldTypes } from '@alfresco/adf-core';
|
||||
import { ProcessServiceCloudTestingModule } from '../../../../testing/process-service-cloud.testing.module';
|
||||
import { TranslateModule } from '@ngx-translate/core';
|
||||
import { By } from '@angular/platform-browser';
|
||||
import { addDays, format, isSameDay, subDays } from 'date-fns';
|
||||
import { addDays, format, subDays } from 'date-fns';
|
||||
|
||||
describe('DateWidgetComponent', () => {
|
||||
|
||||
@@ -42,7 +42,7 @@ describe('DateWidgetComponent', () => {
|
||||
});
|
||||
|
||||
it('should setup min value for date picker', () => {
|
||||
const minValue = '3-3-1982';
|
||||
const minValue = '1982-03-13';
|
||||
widget.field = new FormFieldModel(null, {
|
||||
id: 'date-id',
|
||||
name: 'date-name',
|
||||
@@ -52,7 +52,7 @@ describe('DateWidgetComponent', () => {
|
||||
widget.ngOnInit();
|
||||
|
||||
const expected = format(new Date(minValue), widget.DATE_FORMAT);
|
||||
expect(isSameDay(new Date(widget.minDate), new Date(expected))).toBeTruthy();
|
||||
expect(widget.minDate).toEqual(expected);
|
||||
});
|
||||
|
||||
it('should date field be present', () => {
|
||||
@@ -68,14 +68,14 @@ describe('DateWidgetComponent', () => {
|
||||
});
|
||||
|
||||
it('should setup max value for date picker', () => {
|
||||
const maxValue = '3-3-1982';
|
||||
const maxValue = '1982-03-13';
|
||||
widget.field = new FormFieldModel(null, {
|
||||
maxValue
|
||||
});
|
||||
widget.ngOnInit();
|
||||
|
||||
const expected = format(new Date(maxValue), widget.DATE_FORMAT);
|
||||
expect(isSameDay(new Date(widget.maxDate), new Date(expected))).toBeTruthy();
|
||||
expect(widget.maxDate).toEqual(expected);
|
||||
});
|
||||
|
||||
it('should eval visibility on date changed', () => {
|
||||
|
||||
Reference in New Issue
Block a user