Skip to content

Commit

Permalink
AAE-4241 Add coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
pmartinezga committed Jan 9, 2021
1 parent 7ab42e7 commit 8bbbd4a
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 59 deletions.
106 changes: 53 additions & 53 deletions lib/core/form/components/widgets/date-time/date-time.widget.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -185,60 +185,61 @@ describe('DateTimeWidgetComponent', () => {

expect(tooltip).toEqual(widget.field.tooltip);
}));
});

it('should display always the json value', () => {
const field = new FormFieldModel(new FormModel(), {
id: 'date-field-id',
name: 'datetime-field-name',
value: '12-30-9999 10:30 AM',
type: 'datetime',
readOnly: 'false',
dateDisplayFormat: 'MM-DD-YYYY HH:mm A',
isVisible: true
});
widget.field = field;
widget.ngOnInit();
fixture.detectChanges();
fixture.whenStable()
.then(() => {
expect(element.querySelector('#date-field-id')).toBeDefined();
expect(element.querySelector('#date-field-id')).not.toBeNull();
const dateElement: any = element.querySelector('#date-field-id');
expect(dateElement.value).toContain('12-30-9999 10:30 AM');

const newField = { ...field, value: '03-02-2020 12:00 AM' };

const changes: SimpleChanges = {
'field': {
previousValue: field,
currentValue: newField,
firstChange: false,
isFirstChange(): boolean { return this.firstChange; }
}
};
widget.ngOnChanges(changes);
fixture.detectChanges();
fixture.whenStable()
.then(() => {
expect(dateElement.value).toContain('03-02-2020 12:00 AM');
});
});
it('should display always the json value', () => {
const field = new FormFieldModel(new FormModel(), {
id: 'date-field-id',
name: 'datetime-field-name',
value: '12-30-9999 10:30 AM',
type: 'datetime',
readOnly: 'false'
});
field.isVisible = true;
field.dateDisplayFormat = 'MM-DD-YYYY HH:mm A';
widget.field = field;
widget.ngOnInit();
fixture.detectChanges();
fixture.whenStable()
.then(() => {
expect(element.querySelector('#date-field-id')).toBeDefined();
expect(element.querySelector('#date-field-id')).not.toBeNull();
const dateElement: any = element.querySelector('#date-field-id');
expect(dateElement.value).toContain('12-30-9999 10:30 AM');

it('should not call on change when is first change or field is not set or the field value does not change', () => {
const field = new FormFieldModel(new FormModel(), {
id: 'datetime-field-id',
name: 'datetime-field-name',
value: '12-30-9999 10:30 AM',
type: 'datetime',
readOnly: 'false',
dateDisplayFormat: 'MM-DD-YYYY HH:mm A',
isVisible: true
const newField = { ...field, value: '03-02-2020 12:00 AM' };

const changes: SimpleChanges = {
'field': {
previousValue: field,
currentValue: newField,
firstChange: false,
isFirstChange(): boolean { return this.firstChange; }
}
};
widget.ngOnChanges(changes);
fixture.detectChanges();
fixture.whenStable()
.then(() => {
expect(dateElement.value).toContain('03-02-2020 12:00 AM');
});
});
widget.field = field;
widget.ngOnInit();
fixture.detectChanges();
fixture.whenStable()
});

it('should not call on change when is first change or field is not set or the field value does not change', () => {
const field = new FormFieldModel(new FormModel(), {
id: 'datetime-field-id',
name: 'datetime-field-name',
value: '12-30-9999 10:30 AM',
type: 'datetime',
readOnly: 'false'
});
field.isVisible = true;
field.dateDisplayFormat = 'MM-DD-YYYY HH:mm A',
widget.field = field;
widget.ngOnInit();
fixture.detectChanges();
fixture.whenStable()
.then(() => {
expect(element.querySelector('#datetime-field-id')).toBeDefined();
expect(element.querySelector('#datetime-field-id')).not.toBeNull();
Expand All @@ -259,7 +260,7 @@ describe('DateTimeWidgetComponent', () => {
fixture.detectChanges();
fixture.whenStable()
.then(() => {
expect(dateTimeElement.value).toContain('12-30-9999');
expect(dateTimeElement.value).toContain('12-30-9999 10:30 AM');
changes = {};
widget.ngOnChanges(changes);
fixture.detectChanges();
Expand All @@ -270,7 +271,7 @@ describe('DateTimeWidgetComponent', () => {
'field': {
previousValue: field,
currentValue: field,
firstChange: true,
firstChange: false,
isFirstChange(): boolean { return this.firstChange; }
}
};
Expand All @@ -290,6 +291,5 @@ describe('DateTimeWidgetComponent', () => {
});
});
});
});
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,6 @@ export class DateTimeWidgetComponent extends WidgetComponent implements OnInit,
this.maxDate = moment(this.field.maxValue, 'YYYY-MM-DDTHH:mm:ssZ');
}
}

this.displayDate = moment(this.field.value, this.field.dateDisplayFormat)
.add(
moment(this.field.value, this.field.dateDisplayFormat).utcOffset(),
Expand All @@ -85,9 +84,7 @@ export class DateTimeWidgetComponent extends WidgetComponent implements OnInit,
ngOnChanges(changes: SimpleChanges): void {
if (changes && changes.field && !changes.field.firstChange && changes.field.currentValue.value !== changes.field.previousValue.value) {
this.displayDate = moment(changes.field.currentValue.value, this.field.dateDisplayFormat)
.add(
moment(changes.field.currentValue.value, this.field.dateDisplayFormat).utcOffset(),
'minutes');
.add(moment(changes.field.currentValue.value, this.field.dateDisplayFormat).utcOffset(), 'minutes');
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -282,7 +282,7 @@ describe('DateWidgetComponent', () => {
'field': {
previousValue: field,
currentValue: field,
firstChange: true,
firstChange: false,
isFirstChange(): boolean { return this.firstChange; }
}
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,6 @@ export class DateCloudWidgetComponent extends WidgetComponent implements OnInit,
this.maxDate = moment(this.field.maxValue, this.DATE_FORMAT_CLOUD);
}
}

this.displayDate = moment(this.field.value, this.field.dateDisplayFormat);
}

Expand Down

0 comments on commit 8bbbd4a

Please sign in to comment.