From 4ff3aefa0033715d81f036174e55a0eb7c2749b7 Mon Sep 17 00:00:00 2001 From: Nitin Kumar Date: Tue, 16 Jun 2020 18:46:20 +0530 Subject: [PATCH 1/3] feat: map all dates from server in HTTP services --- .../app/entities/entity-update.component.ts.ejs | 11 +++++++++++ 1 file changed, 11 insertions(+) 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 d11b8c69..52d489b1 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,6 +186,17 @@ export default class <%= entityAngularName %>Update extends <% if (fieldsContain return null; } + public convertDateTimeArrayFromServer(dates: Date[]): string[] { + if (dates) { + const convertedDates = []; + dates.forEach(date => { + convertedDates.push(format(date, DATE_TIME_LONG_FORMAT)); + }); + return convertedDates; + } + return null; + } + public updateInstantField(field, event) { if (event.target.value) { this.<%= entityInstance %>[field] = parse(event.target.value, DATE_TIME_LONG_FORMAT, new Date()); From bad2dabea31fbcab0964d428224fa85a15d4575d Mon Sep 17 00:00:00 2001 From: Nitin Kumar Date: Mon, 22 Jun 2020 11:25:56 +0530 Subject: [PATCH 2/3] 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(); }); From bb3784771fbe75e88f4d0ceaa4bcea6397c77305 Mon Sep 17 00:00:00 2001 From: Nitin Kumar Date: Mon, 22 Jun 2020 13:50:04 +0530 Subject: [PATCH 3/3] tests: add more test cases for mapAllDatesFromServer --- .../entities/entity-management-update.component.spec.ts.ejs | 4 ++++ 1 file changed, 4 insertions(+) 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 8015a3fd..1504de01 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 @@ -144,6 +144,10 @@ describe('Component Tests', () => { expect(convertedDates).toEqual(exceptedDates); }); + it('Should not map dates if dates are not present', () => { + expect(comp.mapAllDatesFromServer(null)).toBeNull(); + }); + it('Should not convert date if date is not present', () => { expect(comp.convertDateTimeFromServer(null)).toBeNull(); });