Skip to content

Commit

Permalink
M2-6447: Removed default value for Date Picker Item (#776)
Browse files Browse the repository at this point in the history
  • Loading branch information
BamMironov authored and Artem Mironov committed May 21, 2024
1 parent 03b88aa commit 9e82797
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 13 deletions.
10 changes: 2 additions & 8 deletions src/shared/ui/survey/DatePickerItem.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { FC, useMemo } from 'react';
import { FC } from 'react';

import { format } from 'date-fns';

Expand All @@ -21,13 +21,7 @@ const DatePickerItem: FC<Props> = ({ value, onChange }) => {
onChange(formattedDate);
};

const valueAsDate = useMemo(() => {
if (!value) {
return new Date();
}

return getDateFromString(value);
}, [value]);
const valueAsDate = value ? getDateFromString(value) : null;

return (
<DateTimePicker
Expand Down
9 changes: 4 additions & 5 deletions src/shared/ui/survey/tests/DatePickerItem.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import TamaguiProvider from '@app/app/ui/AppProvider/TamaguiProvider';
import { DatePickerItem } from '@shared/ui';

describe('Test DatePickerItem', () => {
it('Should render now date when value is null', () => {
it('Should render a MM/DD/YYYY placeholder when value is null', () => {
const datePickerComponent = renderer.create(
<TamaguiProvider>
<DatePickerItem value={null} onChange={jest.fn()} />
Expand All @@ -16,11 +16,10 @@ describe('Test DatePickerItem', () => {
accessibilityLabel: 'date-picker',
});

const resultProp = format(datePicker.props.value, 'yyyy-MM-dd');

const expectedDate = format(new Date(), 'yyyy-MM-dd');
const placeholder = datePicker.props.placeholder as string;
const expected = 'MM/DD/YYYY';

expect(resultProp).toBe(expectedDate);
expect(placeholder).toBe(expected);
});

it('Should render new Date(0) when value is 1970-01-01', () => {
Expand Down

0 comments on commit 9e82797

Please sign in to comment.