Bert Leunis pushed to branch feature/CHANNELMGR-1391 at cms-community / hippo-addon-channel-manager
Commits: 592d03f6 by Bert Leunis at 2018-03-22T11:57:44+01:00 CHANNELMGR-1391 unit tests for all display values that differ when a timezone or the dateline is crossed - - - - - 9622b745 by Bert Leunis at 2018-03-22T12:46:22+01:00 CHANNELMGR-1391 unit test to cover hours validation - - - - - 1 changed file: - frontend-ng/src/app/channel/sidePanels/rightSidePanel/contentEditor/fields/dateField/dateField.spec.js Changes: ===================================== frontend-ng/src/app/channel/sidePanels/rightSidePanel/contentEditor/fields/dateField/dateField.spec.js ===================================== --- a/frontend-ng/src/app/channel/sidePanels/rightSidePanel/contentEditor/fields/dateField/dateField.spec.js +++ b/frontend-ng/src/app/channel/sidePanels/rightSidePanel/contentEditor/fields/dateField/dateField.spec.js @@ -99,6 +99,11 @@ describe('DateValue', () => { expect(dateValue.minutes).toBe('01'); }); + it('it keeps hours to a maximum of 23 when a higher number is set', () => { + dateValue.hours = 24; + expect(dateValue.hours).toBe(23); + }); + it('when a new date is set, existing hours and minutes are maintained', () => { const newDate = new Date(2017, 2, 2, 0, 0, 0, 0); // date with hours and minutes = 0 dateValue.date = newDate; @@ -107,6 +112,71 @@ describe('DateValue', () => { }); }); + describe('when populated with time zone', () => { + // Note that the day, month year part of the date are shown in the md-datepicker which uses the get/set date + // methods. The fields for the hours and minutes part of the date are using their own getter/setters. + + it('shows the day of the month correctly across the dateline', () => { + // in Amsterdam this is january 1 in 2019 at 0:30 (am) + // in Londen this is december 31 in 2018 at 23:30 + const dateString = '2019-01-01T00:30:00.000+01:00'; + + dateValue = new DateValue(dateString, 'Europe/London'); + expect(dateValue.date.getDate()).toBe(31); + + dateValue = new DateValue(dateString, 'Europe/Amsterdam'); + expect(dateValue.date.getDate()).toBe(1); + }); + + it('shows the month correctly across the dateline', () => { + // in Amsterdam this is january 1 in 2019 at 0:30 (am) + // in Londen this is december 31 in 2018 at 23:30 + const dateString = '2019-01-01T00:30:00.000+01:00'; + + dateValue = new DateValue(dateString, 'Europe/London'); + expect(dateValue.date.getMonth()).toBe(11); + + dateValue = new DateValue(dateString, 'Europe/Amsterdam'); + expect(dateValue.date.getMonth()).toBe(0); + }); + + it('shows the year correctly across the dateline', () => { + // in Amsterdam this is january 1 in 2019 at 0:30 (am) + // in Londen this is december 31 in 2018 at 23:30 + const dateString = '2019-01-01T00:30:00.000+01:00'; + + dateValue = new DateValue(dateString, 'Europe/London'); + expect(dateValue.date.getFullYear()).toBe(2018); + + dateValue = new DateValue(dateString, 'Europe/Amsterdam'); + expect(dateValue.date.getFullYear()).toBe(2019); + }); + + it('shows the hours correctly across the timezone', () => { + // in Amsterdam this is january 1 in 2019 at 0:30 (am) + // in Londen this is december 31 in 2018 at 23:30 + const dateString = '2019-01-01T00:30:00.000+01:00'; + + dateValue = new DateValue(dateString, 'Europe/London'); + expect(dateValue.hours).toBe(23); + + dateValue = new DateValue(dateString, 'Europe/Amsterdam'); + expect(dateValue.hours).toBe(0); + }); + + it('shows the minutes correctly across the timezone', () => { + // in Amsterdam this is january 1 in 2019 at 0:30 (am) + // in Calcutta this is january 1 in 2019 at 5:00 (India timezone differs 5.5 hours with CET). + const dateString = '2019-01-01T00:30:00.000+01:00'; + + dateValue = new DateValue(dateString, 'Asia/Calcutta'); + expect(dateValue.minutes).toBe('00'); // string due to zero padding + + dateValue = new DateValue(dateString, 'Europe/Amsterdam'); + expect(dateValue.minutes).toBe(30); + }); + }); + describe('when empty', () => { beforeEach(() => { dateValue = new DateValue(''); View it on GitLab: https://code.onehippo.org/cms-community/hippo-addon-channel-manager/compare/3a94763afe9c1514ec09e1fc714e28b962d2a679...9622b745d674df200f74fd1e6580001a27e46ae3 --- View it on GitLab: https://code.onehippo.org/cms-community/hippo-addon-channel-manager/compare/3a94763afe9c1514ec09e1fc714e28b962d2a679...9622b745d674df200f74fd1e6580001a27e46ae3 You're receiving this email because of your account on code.onehippo.org.
_______________________________________________ Hippocms-svn mailing list Hippocms-svn@lists.onehippo.org https://lists.onehippo.org/mailman/listinfo/hippocms-svn