From bad2dabea31fbcab0964d428224fa85a15d4575d Mon Sep 17 00:00:00 2001 From: Nitin Kumar Date: Mon, 22 Jun 2020 11:25:56 +0530 Subject: [PATCH] tests: add tests for convertDateTimeArrayFromServer --- .../app/entities/entity-update.component.ts.ejs | 8 ++------ .../entity-management-update.component.spec.ts.ejs | 14 ++++++++++++++ 2 files changed, 16 insertions(+), 6 deletions(-) diff --git a/generators/entity-client/templates/vue/src/main/webapp/app/entities/entity-update.component.ts.ejs b/generators/entity-client/templates/vue/src/main/webapp/app/entities/entity-update.component.ts.ejs index 52d489b1..8a2c71b5 100644 --- a/generators/entity-client/templates/vue/src/main/webapp/app/entities/entity-update.component.ts.ejs +++ b/generators/entity-client/templates/vue/src/main/webapp/app/entities/entity-update.component.ts.ejs @@ -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; } diff --git a/generators/entity-client/templates/vue/src/test/javascript/spec/app/entities/entity-management-update.component.spec.ts.ejs b/generators/entity-client/templates/vue/src/test/javascript/spec/app/entities/entity-management-update.component.spec.ts.ejs index 9c3b92c1..8015a3fd 100644 --- a/generators/entity-client/templates/vue/src/test/javascript/spec/app/entities/entity-management-update.component.spec.ts.ejs +++ b/generators/entity-client/templates/vue/src/test/javascript/spec/app/entities/entity-management-update.component.spec.ts.ejs @@ -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(); });