Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes issue #1738 #1796

Merged
merged 12 commits into from
Oct 7, 2015
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: 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;
});
});
});