From b6752d3a128a2d0e844328dee9c1745d249eda1e Mon Sep 17 00:00:00 2001 From: RafaPolit Date: Tue, 22 Sep 2020 16:30:51 -0500 Subject: [PATCH 1/3] Forced 'en' locale for working with timestamps on datepicker. --- app/react/Forms/components/DatePicker.js | 4 +-- .../Forms/components/specs/DatePicker.spec.js | 34 +++++++++++++++++-- 2 files changed, 34 insertions(+), 4 deletions(-) diff --git a/app/react/Forms/components/DatePicker.js b/app/react/Forms/components/DatePicker.js index ce0baefbe1..d32c114477 100644 --- a/app/react/Forms/components/DatePicker.js +++ b/app/react/Forms/components/DatePicker.js @@ -15,7 +15,7 @@ const removeOffset = (useTimezone, value) => { newValue.subtract(moment().utcOffset(), 'minute'); } - datePickerValue = parseInt(newValue.format('x'), 10); + datePickerValue = parseInt(newValue.locale('en').format('x'), 10); } return datePickerValue; @@ -49,7 +49,7 @@ class DatePicker extends Component { onChange(null); } else { const newValue = addOffset(useTimezone, endOfDay, datePickerValue); - onChange(parseInt(newValue.format('X'), 10)); + onChange(parseInt(newValue.locale('en').format('X'), 10)); } } diff --git a/app/react/Forms/components/specs/DatePicker.spec.js b/app/react/Forms/components/specs/DatePicker.spec.js index 9232d1b91b..b7ebdd0e9a 100644 --- a/app/react/Forms/components/specs/DatePicker.spec.js +++ b/app/react/Forms/components/specs/DatePicker.spec.js @@ -3,6 +3,7 @@ import { shallow } from 'enzyme'; import configureMockStore from 'redux-mock-store'; import thunk from 'redux-thunk'; +import baseMoment from 'moment'; import moment from 'moment-timezone'; import DatePickerComponent from 'react-datepicker'; import DatePicker from '../DatePicker'; @@ -45,12 +46,41 @@ describe('DatePicker', () => { }); describe('onChange', () => { - it('should set the value to timestamp offsetting to UTC', () => { + const expectCorrectOnChange = () => { const newDate = new Date('2020-08-18'); render(); input.simulate('change', newDate); const expectedOnChangeValue = moment.utc(newDate).add(moment().utcOffset(), 'minute'); - expect(props.onChange).toHaveBeenCalledWith(Number(expectedOnChangeValue.format('X'))); + expect(props.onChange).toHaveBeenCalledWith( + Number(expectedOnChangeValue.locale('en').format('X')) + ); + }; + + it('should set the value to timestamp offsetting to UTC', () => { + expectCorrectOnChange(); + }); + + describe('When locale is a non-latin locale', () => { + let originalLocale; + + beforeEach(() => { + originalLocale = baseMoment.locale(); + baseMoment.locale('ar'); + }); + + afterEach(() => { + baseMoment.locale(originalLocale); + }); + + it('should render a latin-based value (until correct locales are implemented)', () => { + render(); + const expectedSelectedValue = date.clone().subtract(moment().utcOffset(), 'minute'); + expect(input.props().selected).toBe(parseInt(expectedSelectedValue.format('x'), 10)); + }); + + it('should not fail on change', () => { + expectCorrectOnChange(); + }); }); describe('when clearing the input', () => { From 17765b6a8c89ba89fd325643ae18af41ac03e79a Mon Sep 17 00:00:00 2001 From: RafaPolit Date: Tue, 22 Sep 2020 16:31:03 -0500 Subject: [PATCH 2/3] Upped hot-fix version --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index f0da39a5e1..2403b1647e 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "uwazi", - "version": "1.9.0", + "version": "1.9.1", "description": "Uwazi is a free, open-source solution for organising, analysing and publishing your documents.", "keywords": [ "react" From 399cb525d0e695f520fa4d304065ecebe804e51e Mon Sep 17 00:00:00 2001 From: RafaPolit Date: Tue, 22 Sep 2020 16:35:32 -0500 Subject: [PATCH 3/3] Removed unnecessary locale. --- app/react/Forms/components/specs/DatePicker.spec.js | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/app/react/Forms/components/specs/DatePicker.spec.js b/app/react/Forms/components/specs/DatePicker.spec.js index b7ebdd0e9a..6b974938b6 100644 --- a/app/react/Forms/components/specs/DatePicker.spec.js +++ b/app/react/Forms/components/specs/DatePicker.spec.js @@ -51,9 +51,7 @@ describe('DatePicker', () => { render(); input.simulate('change', newDate); const expectedOnChangeValue = moment.utc(newDate).add(moment().utcOffset(), 'minute'); - expect(props.onChange).toHaveBeenCalledWith( - Number(expectedOnChangeValue.locale('en').format('X')) - ); + expect(props.onChange).toHaveBeenCalledWith(Number(expectedOnChangeValue.format('X'))); }; it('should set the value to timestamp offsetting to UTC', () => {