Skip to content

Commit

Permalink
Merge pull request #3200 from huridocs/1.9.1-datepicker-hotfix
Browse files Browse the repository at this point in the history
1.9.1 datepicker hotfix
  • Loading branch information
RafaPolit authored Sep 22, 2020
2 parents dc37f4c + 399cb52 commit aa08a1d
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 4 deletions.
4 changes: 2 additions & 2 deletions app/react/Forms/components/DatePicker.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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));
}
}

Expand Down
30 changes: 29 additions & 1 deletion app/react/Forms/components/specs/DatePicker.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -45,12 +46,39 @@ 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')));
};

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', () => {
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -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"
Expand Down

0 comments on commit aa08a1d

Please sign in to comment.