Skip to content
This repository has been archived by the owner on Mar 21, 2021. It is now read-only.

Commit

Permalink
tests: add tests for convertDateTimeArrayFromServer
Browse files Browse the repository at this point in the history
  • Loading branch information
snitin315 committed Jun 22, 2020
1 parent 4ff3aef commit bad2dab
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -186,13 +186,9 @@ export default class <%= entityAngularName %>Update extends <% if (fieldsContain
return null;
}

public convertDateTimeArrayFromServer(dates: Date[]): string[] {
public mapAllDatesFromServer(dates: Date[]): string[] {
if (dates) {
const convertedDates = [];
dates.forEach(date => {
convertedDates.push(format(date, DATE_TIME_LONG_FORMAT));
});
return convertedDates;
return dates.map(date => format(date, DATE_TIME_LONG_FORMAT));
}
return null;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,20 @@ describe('Component Tests', () => {
expect(convertedDate).toEqual(format(date, DATE_TIME_LONG_FORMAT));
});

it('Should map all dates from server', () => {
// GIVEN
const date1 = new Date('2020-10-15T11:42:02Z');
const date2 = new Date('2020-11-15T11:42:02Z');
const date3 = new Date('2020-12-15T11:42:02Z');
const dates = [date1, date2, date3];
// WHEN
const convertedDates = comp.mapAllDatesFromServer(dates);

// THEN
const exceptedDates = dates.map(date => format(date, DATE_TIME_LONG_FORMAT));
expect(convertedDates).toEqual(exceptedDates);
});

it('Should not convert date if date is not present', () => {
expect(comp.convertDateTimeFromServer(null)).toBeNull();
});
Expand Down

0 comments on commit bad2dab

Please sign in to comment.