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

Commit bad2dab

Browse files
committed
tests: add tests for convertDateTimeArrayFromServer
1 parent 4ff3aef commit bad2dab

File tree

2 files changed

+16
-6
lines changed

2 files changed

+16
-6
lines changed

generators/entity-client/templates/vue/src/main/webapp/app/entities/entity-update.component.ts.ejs

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -186,13 +186,9 @@ export default class <%= entityAngularName %>Update extends <% if (fieldsContain
186186
return null;
187187
}
188188
189-
public convertDateTimeArrayFromServer(dates: Date[]): string[] {
189+
public mapAllDatesFromServer(dates: Date[]): string[] {
190190
if (dates) {
191-
const convertedDates = [];
192-
dates.forEach(date => {
193-
convertedDates.push(format(date, DATE_TIME_LONG_FORMAT));
194-
});
195-
return convertedDates;
191+
return dates.map(date => format(date, DATE_TIME_LONG_FORMAT));
196192
}
197193
return null;
198194
}

generators/entity-client/templates/vue/src/test/javascript/spec/app/entities/entity-management-update.component.spec.ts.ejs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,20 @@ describe('Component Tests', () => {
130130
expect(convertedDate).toEqual(format(date, DATE_TIME_LONG_FORMAT));
131131
});
132132
133+
it('Should map all dates from server', () => {
134+
// GIVEN
135+
const date1 = new Date('2020-10-15T11:42:02Z');
136+
const date2 = new Date('2020-11-15T11:42:02Z');
137+
const date3 = new Date('2020-12-15T11:42:02Z');
138+
const dates = [date1, date2, date3];
139+
// WHEN
140+
const convertedDates = comp.mapAllDatesFromServer(dates);
141+
142+
// THEN
143+
const exceptedDates = dates.map(date => format(date, DATE_TIME_LONG_FORMAT));
144+
expect(convertedDates).toEqual(exceptedDates);
145+
});
146+
133147
it('Should not convert date if date is not present', () => {
134148
expect(comp.convertDateTimeFromServer(null)).toBeNull();
135149
});

0 commit comments

Comments
 (0)