Skip to content

Commit

Permalink
Add unit tests for derived calendarType value
Browse files Browse the repository at this point in the history
  • Loading branch information
wojtekmaj committed Dec 8, 2019
1 parent 0922d37 commit 31a0e56
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 3 deletions.
4 changes: 1 addition & 3 deletions src/MonthView.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -72,15 +72,13 @@ export default function MonthView(props) {
showFixedNumberOfWeeks,
} = props;
const {
calendarType: calendarTypeProps,
calendarType = getCalendarTypeFromLocale(locale),
formatShortWeekday,
onClickWeekNumber,
showWeekNumbers,
...childProps
} = props;

const calendarType = calendarTypeProps || getCalendarTypeFromLocale(locale);

function renderWeekdays() {
return (
<Weekdays
Expand Down
60 changes: 60 additions & 0 deletions src/MonthView.spec.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,36 @@ describe('MonthView', () => {
expect(component.find('WeekNumbers')).toHaveLength(1);
});

it('passes calendarType to Weekdays component', () => {
const calendarType = 'ISO 8601';

const component = shallow(
<MonthView
{...defaultProps}
calendarType={calendarType}
/>,
);

const weekdays = component.find('Weekdays');

expect(weekdays.prop('calendarType')).toBe(calendarType);
});

it('passes derived calendarType to Weekdays component if calendarType is not given', () => {
const locale = 'en-US';

const component = shallow(
<MonthView
{...defaultProps}
locale={locale}
/>,
);

const weekdays = component.find('Weekdays');

expect(weekdays.prop('calendarType')).toBe('US');
});

it('passes formatShortWeekday flag to Weekdays component', () => {
const formatShortWeekday = () => 'Weekday';

Expand All @@ -161,6 +191,36 @@ describe('MonthView', () => {
expect(weekdays.prop('formatShortWeekday')).toBe(formatShortWeekday);
});

it('passes calendarType to Days component', () => {
const calendarType = 'ISO 8601';

const component = shallow(
<MonthView
{...defaultProps}
calendarType={calendarType}
/>,
);

const days = component.find('Days');

expect(days.prop('calendarType')).toBe(calendarType);
});

it('passes derived calendarType to Days component if calendarType is not given', () => {
const locale = 'en-US';

const component = shallow(
<MonthView
{...defaultProps}
locale={locale}
/>,
);

const days = component.find('Days');

expect(days.prop('calendarType')).toBe('US');
});

it('passes formatLongDate flag to Days component', () => {
const formatLongDate = () => 'Long date';

Expand Down

0 comments on commit 31a0e56

Please sign in to comment.