Skip to content
This repository has been archived by the owner on May 31, 2021. It is now read-only.

fix: the test parts set value to new Date() when there is no prop #347

Merged
merged 2 commits into from
Sep 16, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions main/DatePicker/Calendar/Calendar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ interface Props {
pastRange?: number; // Number of past months displayed on the calendar
futureRange?: number; // Number of future months displayed on the calendar
calendarWidth: number; // calendar width
locale?: string;
titleContent?: (monthFirst: Date) => React.ReactElement;
weekdayFormat?: 'narrow' | 'short';
}
Expand Down Expand Up @@ -134,6 +135,7 @@ function Calendar(props: Props): React.ReactElement {
width: props.calendarWidth,
height: 22,
}}
locale={props.locale}
weekdayFormat={props.weekdayFormat}
/>
<FlatList
Expand Down
3 changes: 2 additions & 1 deletion main/DatePicker/Calendar/CalendarWeekDays.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ const DayTitle = styled.Text`
interface Props {
style?: ViewStyle;
calendarWidth: number;
locale?: string;
weekdayFormat?: 'narrow' | 'short';
}

Expand All @@ -39,7 +40,7 @@ function CalendarWeekDays(props: Props): React.ReactElement {

for (let idx = 0; idx <= 6; idx++) {
const matchMonth = new Date(2020, 8, 6 + idx);
const weekDay = matchMonth.toLocaleString('default', {
const weekDay = matchMonth.toLocaleString(props.locale, {
JeffGuKang marked this conversation as resolved.
Show resolved Hide resolved
weekday: props.weekdayFormat || 'narrow', // 'narrow',
});

Expand Down
4 changes: 3 additions & 1 deletion main/DatePicker/PickerCalendar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ interface Props {
selectedDate?: Date;
onSelectDate: (date: Date) => void;
containerStyle?: ViewStyle;
locale?: string;
onBackdropPress?: () => void;
calendarWidth?: number;
weekdayFormat?: 'narrow' | 'short';
Expand All @@ -36,7 +37,7 @@ interface Props {
}

const PickerCalendar: FC<Props> = (props) => {
const { calendarWidth = 300 } = props;
const { calendarWidth = 300, locale = 'default' } = props;
JeffGuKang marked this conversation as resolved.
Show resolved Hide resolved

return (
<Modal visible={props.visible} transparent={true} animationType={'fade'}>
Expand Down Expand Up @@ -70,6 +71,7 @@ const PickerCalendar: FC<Props> = (props) => {
containerStyle={{
overflow: 'hidden',
}}
locale={locale}
renderDay={({
date,
isCurrentMonth,
Expand Down
1 change: 1 addition & 0 deletions main/DatePicker/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
| style | | ViewStyle | |
| label | | string | `default arrow image` |
| labelTextStyle | | TextStyle | `` |
| locale | | string | `default` |
| errorText | | string | `Invalid Date` |
| errorTextStyle | | TextStyle | `{ color: '#F00', textAlign: 'left' }` |
| dateTextStyle | | TextStyle |
Expand Down
2 changes: 2 additions & 0 deletions main/DatePicker/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ interface Props {
style?: ViewStyle;
label?: string;
labelTextStyle?: TextStyle;
locale?: string;
errorText?: string;
errorTextStyle?: TextStyle;
dateTextStyle?: TextStyle;
Expand Down Expand Up @@ -59,6 +60,7 @@ const DatePicker = (props: Props): React.ReactElement => {
setCalendarVisible(false);
}}
containerStyle={{ width: 300, height: 350 }}
locale={props.locale}
weekdayFormat={props.weekdayFormat}
titleContent={props.titleContent}
/>
Expand Down
29 changes: 18 additions & 11 deletions main/__tests__/DatePicker.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,11 @@ import { TouchableOpacity } from 'react-native';
import { render } from '@testing-library/react-native';
import renderer from 'react-test-renderer';

const standardDate = new Date('2020-09-01');
const standardDate = new Date('2020-09-13');

describe('[DatePicker] render', () => {
it('should render without crashing', () => {
const rendered = render(<DatePicker />).asJSON();
const rendered = render(<DatePicker selectedDate={standardDate} locale={'en'} />).asJSON();

// expect(rendered).toMatchSnapshot();
expect(rendered).toBeTruthy();
Expand All @@ -29,7 +29,7 @@ describe('[DatePicker] render', () => {
describe('[DateInput] render', () => {
it('should render without crashing', () => {
const rendered = render(
<DateInput onPressCalendar={(): void => {}} />,
<DateInput onPressCalendar={(): void => {}} selectedDate={standardDate} />,
).asJSON();

// expect(rendered).toMatchSnapshot();
Expand All @@ -39,7 +39,7 @@ describe('[DateInput] render', () => {
it('should simulate onPress', () => {
const onPressCalendar = jest.fn();
const rendered = renderer.create(
<DateInput onPressCalendar={onPressCalendar} />,
<DateInput onPressCalendar={onPressCalendar} selectedDate={standardDate} />,
{
createNodeMock: () => {
return {
Expand All @@ -63,7 +63,12 @@ describe('[DateInput] render', () => {
describe('[PickerCalendar] render', () => {
it('should render without crashing', () => {
const rendered = render(
<PickerCalendar visible={false} onSelectDate={(): void => {}} />,
<PickerCalendar
visible={false}
onSelectDate={(): void => {}}
selectedDate={standardDate}
locale={'en'}
weekdayFormat={'narrow'} />,
).asJSON();

// expect(rendered).toMatchSnapshot();
Expand All @@ -75,8 +80,10 @@ describe('[Calendar]', () => {
it('should render without crashing', () => {
const rendered = render(
<Calendar
initDate={standardDate}
renderDay={() => <CalendarDate date={standardDate} isToday={false} />}
calendarWidth={300}
renderDay={() => <CalendarDate date={standardDate}></CalendarDate>}
locale={'en'}
/>,
).asJSON();

Expand All @@ -88,7 +95,7 @@ describe('[Calendar]', () => {
describe('[CalendarDate] render', () => {
it('should render without crashing', () => {
const rendered = render(
<CalendarDate onPress={(): void => {}} date={standardDate} />,
<CalendarDate onPress={(): void => {}} date={standardDate} isToday={false} />,
).asJSON();

// expect(rendered).toMatchSnapshot();
Expand All @@ -99,7 +106,7 @@ describe('[CalendarDate] render', () => {
it('should simulate onPress', () => {
const onSelectDate = jest.fn();
const rendered = renderer.create(
<CalendarDate onPress={onSelectDate} date={standardDate} />,
<CalendarDate onPress={onSelectDate} date={standardDate} isToday={false} />,
{
createNodeMock: () => {
return {
Expand All @@ -126,8 +133,8 @@ describe('[CalendarMonth] render', () => {
<CalendarMonth
monthDate={standardDate}
calendarWidth={300}
renderDay={() => <CalendarDate date={standardDate}></CalendarDate>}
today={new Date(standardDate)}
renderDay={() => <CalendarDate date={standardDate} isToday={false} />}
today={standardDate}
/>,
).asJSON();

Expand All @@ -139,7 +146,7 @@ describe('[CalendarMonth] render', () => {
describe('[CalendarWeekDays] render', () => {
it('should render without crashing', () => {
const rendered = render(
<CalendarWeekDays calendarWidth={300} weekdayFormat={'narrow'} />,
<CalendarWeekDays calendarWidth={300} weekdayFormat={'narrow'} locale={'en'} />,
).asJSON();

// expect(rendered).toMatchSnapshot();
Expand Down