Skip to content

Commit

Permalink
Merge pull request #274 from gpbl/update-dependencies
Browse files Browse the repository at this point in the history
Update dependencies
  • Loading branch information
gpbl authored Mar 6, 2017
2 parents 6942d6b + ee05837 commit 9d592bf
Show file tree
Hide file tree
Showing 14 changed files with 265 additions and 174 deletions.
24 changes: 12 additions & 12 deletions examples/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,30 +23,30 @@
"homepage": "http://react-day-picker.js.org/",
"dependencies": {
"autoprefixer-loader": "^3.1.0",
"babel-cli": "^6.22.2",
"babel-core": "^6.22.1",
"babel-cli": "^6.23.0",
"babel-core": "^6.23.1",
"babel-eslint": "^7.1.1",
"babel-preset-es2015": "^6.22.0",
"babel-preset-react": "^6.22.0",
"babel-preset-react": "^6.23.0",
"babel-preset-stage-1": "^6.22.0",
"babel-register": "^6.22.0",
"babel-runtime": "^6.22.0",
"css-loader": "^0.26.1",
"eslint": "^3.15.0",
"babel-register": "^6.23.0",
"babel-runtime": "^6.23.0",
"css-loader": "^0.26.2",
"eslint": "^3.17.0",
"eslint-config-airbnb": "^14.1.0",
"eslint-plugin-import": "^2.2.0",
"eslint-plugin-jsx-a11y": "^4.0.0",
"eslint-plugin-react": "^6.9.0",
"file-loader": "^0.10.0",
"eslint-plugin-react": "^6.10.0",
"file-loader": "^0.10.1",
"history": "^4.5.1",
"moment": "^2.17.1",
"raw-loader": "^0.5.1",
"react": "^15.4.2",
"react-dom": "^15.4.2",
"react-hot-loader": "^3.0.0-beta.6",
"style-loader": "0.13.1",
"url-loader": "^0.5.6",
"style-loader": "^0.13.2",
"url-loader": "^0.5.8",
"webpack": "^2.2.1",
"webpack-dev-server": "^2.3.0"
"webpack-dev-server": "^2.4.1"
}
}
6 changes: 1 addition & 5 deletions examples/src/Examples.js
Original file line number Diff line number Diff line change
Expand Up @@ -146,11 +146,6 @@ const EXAMPLES = {
description: 'Use <code>numberOfMonths</code> to display a custom number of calendars.',
Component: YearCalendar,
},
cssModules: {
title: 'CSS Modules',
description: 'Use the <code>classNames</code> prop to pass to the component the styles imported with <a href="https://github.com/css-modules/css-modules">CSS Modules</a>.',
Component: CSSModules,
},
};

export default class Examples extends Component {
Expand Down Expand Up @@ -208,6 +203,7 @@ export default class Examples extends Component {
const componentName = ExampleComponent.name || getFunctionName(ExampleComponent);
let source = require(`!raw-loader!./examples/${componentName}.js`);
source = source.replace('../../../src', 'react-day-picker');
source = source.replace('../../../src/addons/MomentLocaleUtils', 'react-day-picker/moment');
source = source.replace('../../../src/style.css', 'react-day-picker/lib/style.css');
return (
<div>
Expand Down
2 changes: 1 addition & 1 deletion examples/src/examples/InputField.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import React from 'react';
import moment from 'moment';

import DayPicker, { DateUtils } from '../../../src';
import DayPicker from '../../../src';

import '../../../src/style.css';

Expand Down
6 changes: 4 additions & 2 deletions examples/src/examples/LocalizedMoment.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
import React from 'react';

// Make sure moment.js has the required locale data
import 'moment/locale/ja';
import 'moment/locale/ar';
import 'moment/locale/it';

import DayPicker from '../../../src';

// Use a custom util to format the calendar values according to the
// selected locale. This one is based on moment.js
import MomentLocaleUtils from 'react-day-picker/moment';
import DayPicker from '../../../src';
import MomentLocaleUtils from '../../../src/addons/MomentLocaleUtils';

import '../../../src/style.css';

Expand Down
35 changes: 14 additions & 21 deletions examples/src/examples/Modifiers.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,25 +3,18 @@ import DayPicker from '../../../src';

import '../../../src/style.css';

export default class Modifiers extends React.Component {
constructor(props) {
super(props);
this.handleDayClick = this.handleDayClick.bind(this);
}
handleDayClick(day, modifiers) {
console.log('Day\'s CSS classes', e.target.classList.toString());
console.log('Day\'s modifiers', modifiers);
}
render() {
return (
<div>
<DayPicker
initialMonth={ new Date(2017, 3) }
selectedDays={ new Date(2017, 3, 12) }
disabledDays={ new Date(2017, 3, 15) }
onDayClick={ this.handleDayClick }
/>
</div>
);
}
function handleDayClick(day, modifiers, e) {
console.log('Day\'s modifiers', modifiers);
console.log('Day\'s CSS classes', e.target.classList.toString());
}

export default function Modifiers() {
return (
<DayPicker
initialMonth={ new Date(2017, 3) }
selectedDays={ new Date(2017, 3, 12) }
disabledDays={ new Date(2017, 3, 15) }
onDayClick={ handleDayClick }
/>
);
}
18 changes: 9 additions & 9 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -60,24 +60,24 @@
"react": "~0.13.x || ~0.14.x || ^15.0.0"
},
"devDependencies": {
"autoprefixer": "^6.7.2",
"babel-cli": "^6.22.2",
"babel-core": "^6.22.1",
"autoprefixer": "^6.7.6",
"babel-cli": "^6.23.0",
"babel-core": "^6.23.1",
"babel-eslint": "^7.1.1",
"babel-loader": "^6.2.10",
"babel-loader": "^6.4.0",
"babel-preset-es2015": "^6.22.0",
"babel-preset-react": "^6.22.0",
"babel-preset-react": "^6.23.0",
"babel-preset-stage-1": "^6.22.0",
"chai": "3.5.0",
"chai-enzyme": "^0.6.1",
"cheerio": "0.22.0",
"coveralls": "^2.11.16",
"coveralls": "^2.12.0",
"enzyme": "^2.7.1",
"eslint": "^3.15.0",
"eslint": "^3.17.0",
"eslint-config-airbnb": "^14.1.0",
"eslint-plugin-import": "^2.2.0",
"eslint-plugin-jsx-a11y": "^4.0.0",
"eslint-plugin-react": "^6.9.0",
"eslint-plugin-react": "^6.10.0",
"gitbook-cli": "2.3.0",
"istanbul": "1.1.0-alpha.1",
"jsdom": "9.0.0",
Expand All @@ -88,7 +88,7 @@
"react-addons-test-utils": "^15.4.2",
"react-dom": "^15.4.2",
"react-hot-loader": "^3.0.0-beta.6",
"rimraf": "2.5.4",
"rimraf": "^2.6.1",
"sinon": "^1.17.7",
"sinon-chai": "2.8.0",
"webpack": "^2.2.1"
Expand Down
2 changes: 2 additions & 0 deletions src/DayPicker.js
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,8 @@ export default class DayPicker extends Component {

constructor(props) {
super(props);
/* istanbul ignore next */
// for the ignore above see: https://github.com/gotwarlost/istanbul/issues/690

this.renderDayInMonth = this.renderDayInMonth.bind(this);
this.showNextMonth = this.showNextMonth.bind(this);
Expand Down
10 changes: 5 additions & 5 deletions src/Helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ export function getFirstDayOfWeekFromProps(props) {
}

export function isRangeOfDates(value) {
return value && typeof value === 'object' && value.from && value.to;
return !!(value && value.from && value.to);
}

export function getModifiersForDay(d, modifiersObj = {}) {
Expand All @@ -70,10 +70,10 @@ export function getModifiersForDay(d, modifiersObj = {}) {
const range = day;
return isDayInRange(d, range);
}
if (typeof day === 'object' && day.after) {
if (day.after) {
return d > day.after;
}
if (typeof day === 'object' && day.before) {
if (day.before) {
return d < day.before;
}
return false;
Expand All @@ -83,10 +83,10 @@ export function getModifiersForDay(d, modifiersObj = {}) {
} else if (isRangeOfDates(value) && isDayInRange(d, value)) {
// modifier's value is a range
modifiers.push(modifier);
} else if (typeof value === 'object' && value.after && d > value.after) {
} else if (value.after && d > value.after) {
// modifier's value has an after date
modifiers.push(modifier);
} else if (typeof value === 'object' && value.before && d < value.before) {
} else if (value.before && d < value.before) {
// modifier's value has an after date
modifiers.push(modifier);
} else if (typeof value === 'function' && value(d)) {
Expand Down
2 changes: 1 addition & 1 deletion src/Navbar.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ export default function Navbar({
onPreviousClick,
onNextClick,
labels,
dir = 'ltr',
dir,
}) {
const previousClickHandler = dir === 'rtl' ? onNextClick : onPreviousClick;
const nextClickHandler = dir === 'rtl' ? onPreviousClick : onNextClick;
Expand Down
19 changes: 19 additions & 0 deletions test/Helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -301,6 +301,25 @@ describe('Helpers', () => {
});
});

describe('isRangeOfDates', () => {
it('should detect a properly shaped object', () => {
expect(Helpers.isRangeOfDates(
{ from: new Date(), to: new Date() },
)).to.be.true;
});
it('should detect not properly shaped objects', () => {
expect(Helpers.isRangeOfDates(
{ from: null, to: new Date() },
)).to.be.false;
expect(Helpers.isRangeOfDates(
{ to: new Date() },
)).to.be.false;
expect(Helpers.isRangeOfDates(
{ from: new Date() },
)).to.be.false;
});
});

describe('startOfMonth', () => {
it('should set a date as start of its month', () => {
const date = new Date(1979, 8, 19);
Expand Down
9 changes: 9 additions & 0 deletions test/daypicker/events.js
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,15 @@ describe('DayPicker’s events handlers', () => {
wrapper.find('.DayPicker-Day--foo').simulate('keyDown', { keyCode: keys.ENTER });
expect(handleDayClick).to.have.been.calledWith(...eventArgs);
});
it('should not call an undefined `onDayClick` event handler when pressing the ENTER key', () => {
const handleDayClick = spy();
const modifiers = { foo: d => d.getDate() === 15, bar: () => false };
const wrapper = mount(
<DayPicker modifiers={ modifiers } />,
);
wrapper.find('.DayPicker-Day--foo').simulate('keyDown', { keyCode: keys.ENTER });
expect(handleDayClick).to.not.have.been.called;
});
it('should call `onDayClick` event handler when pressing the SPACE key', () => {
const handleDayClick = spy();
const modifiers = { foo: d => d.getDate() === 15 };
Expand Down
14 changes: 14 additions & 0 deletions test/daypicker/navigation.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,20 @@ describe('DayPicker’s navigation', () => {
expect(instance.state.currentMonth.getFullYear()).to.equal(2015);
expect(instance.state.currentMonth.getMonth()).to.equal(6);
});
it('should not show the previous month when clicking outside days from the first month out of 2', () => {
const wrapper = mount(
<DayPicker
initialMonth={ new Date(2015, 3) }
numberOfMonths={ 2 }
enableOutsideDays
onDayClick={ () => {} }
/>,
);
wrapper.find('.DayPicker-Day--outside').at(6).simulate('click');
const instance = wrapper.instance();
expect(instance.state.currentMonth.getFullYear()).to.equal(2015);
expect(instance.state.currentMonth.getMonth()).to.equal(3);
});
it('should not allow changing to the year when cannot change months', () => {
const wrapper = shallow(<DayPicker canChangeMonth={ false } />);
expect(wrapper.instance().allowYearChange()).to.be.false;
Expand Down
8 changes: 8 additions & 0 deletions test/daypicker/rendering.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,14 @@ describe('DayPicker’s rendering', () => {
expect(instance.state.currentMonth.getMonth()).to.equal(1);
expect(instance.state.currentMonth.getDate()).to.equal(1);
});
it('should not do anything when other props are updated', () => {
const wrapper = mount(<DayPicker month={ new Date(2018, 10, 11) } />);
wrapper.setProps({ initialMonth: new Date(2014, 10, 11) });
const instance = wrapper.instance();
expect(instance.state.currentMonth.getFullYear()).to.equal(2018);
expect(instance.state.currentMonth.getMonth()).to.equal(10);
expect(instance.state.currentMonth.getDate()).to.equal(1);
});
it('should render multiple months', () => {
const wrapper = mount(<DayPicker numberOfMonths={ 12 } />);
expect(wrapper.find('.DayPicker-Month')).to.have.length(12);
Expand Down
Loading

0 comments on commit 9d592bf

Please sign in to comment.