Skip to content

Commit

Permalink
Merge pull request #1796 from yulric/1738
Browse files Browse the repository at this point in the history
Fixes issue #1738
  • Loading branch information
shaurya947 committed Oct 7, 2015
2 parents 58685dc + c1f4c8f commit e371de6
Show file tree
Hide file tree
Showing 2 changed files with 89 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/date-picker/calendar.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,7 @@ const Calendar = React.createClass({

_getToolbarInteractions() {
return {
prevMonth: DateTime.monthDiff(this.state.selectedDate, this.props.minDate) > 0,
prevMonth: DateTime.monthDiff(this.state.displayDate, this.props.minDate) > 0,
nextMonth: DateTime.monthDiff(this.state.displayDate, this.props.maxDate) < 0,
};
},
Expand Down
90 changes: 88 additions & 2 deletions test/date-picker/calendar-spec.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import injectTapEventPlugin from 'react-tap-event-plugin';
injectTapEventPlugin();

import React from 'react/addons';
import Calendar from 'date-picker/calendar';
import injectTheme from '../fixtures/inject-theme';
import React from 'react';
import CalendarToolbar from 'date-picker/calendar-toolbar';
import IconButton from 'icon-button';
import injectTheme from '../fixtures/inject-theme';

const TestUtils = React.addons.TestUtils;

Expand Down Expand Up @@ -105,4 +105,90 @@ describe(`Calendar`, () => {
expect(renderedCalendarToolbar.props.nextMonth).to.be.false;
});
});

describe('Previous Month Button', () => {
it(`should initially disable the previous month button if the current month is the same as the minDate month prop`, () => {
let initialDate = new Date();
let minDate = new Date(initialDate.toDateString());

let render = TestUtils.renderIntoDocument(
<ThemedCalendar
initialDate={initialDate}
minDate={minDate}
/>
);
let calendarToolbar = TestUtils.findRenderedComponentWithType(render, CalendarToolbar);

expect(calendarToolbar.props.prevMonth).to.be.false;
});

it(`should initially disable the previous month button if the current month is before the minDate month prop`, () => {
let initialDate = new Date();
let minDate = new Date(initialDate.toDateString());
minDate.setMonth(initialDate.getMonth() + 1);

let render = TestUtils.renderIntoDocument(
<ThemedCalendar
initialDate={initialDate}
minDate={minDate}
/>
);
let calendarToolbar = TestUtils.findRenderedComponentWithType(render, CalendarToolbar);

expect(calendarToolbar.props.prevMonth).to.be.false;
});

it(`should initially enable the previous month button if the current month is after the minDate month prop`, () => {
let initialDate = new Date();
let minDate = new Date(initialDate.toDateString());
minDate.setMonth(initialDate.getMonth() - 1);

let render = TestUtils.renderIntoDocument(
<ThemedCalendar
initialDate={initialDate}
minDate={minDate}
/>
);
let calendarToolbar = TestUtils.findRenderedComponentWithType(render, CalendarToolbar);

expect(calendarToolbar.props.prevMonth).to.be.true;
});

it(`should enable the previous month button when the current month is after the minDate month prop`, () => {
let initialDate = new Date();
let minDate = new Date(initialDate.toDateString());

let render = TestUtils.renderIntoDocument(
<ThemedCalendar
initialDate={initialDate}
minDate={minDate}
/>
);

let nextMonthIconButton = React.findDOMNode(TestUtils.scryRenderedComponentsWithType(render, IconButton)[1]);
TestUtils.Simulate.touchTap(nextMonthIconButton);

let calendarToolbar = TestUtils.findRenderedComponentWithType(render, CalendarToolbar);
expect(calendarToolbar.props.prevMonth).to.be.true;
});

it(`should disable the previous month button when the current month is the same as the minDate month prop`, () => {
let initialDate = new Date();
let minDate = new Date(initialDate.toDateString());
minDate.setMonth(minDate.getMonth() - 1);

let render = TestUtils.renderIntoDocument(
<ThemedCalendar
initialDate={initialDate}
minDate={minDate}
/>
);

let prevMonthIconButton = React.findDOMNode(TestUtils.scryRenderedComponentsWithType(render, IconButton)[0]);
TestUtils.Simulate.touchTap(prevMonthIconButton);

let calendarToolbar = TestUtils.findRenderedComponentWithType(render, CalendarToolbar);
expect(calendarToolbar.props.prevMonth).to.be.false;
});
});
});

0 comments on commit e371de6

Please sign in to comment.