diff --git a/src/DatePicker/DatePicker.js b/src/DatePicker/DatePicker.js index 46fc0a202458dc..25e659757fc548 100644 --- a/src/DatePicker/DatePicker.js +++ b/src/DatePicker/DatePicker.js @@ -131,7 +131,7 @@ class DatePicker extends Component { /** * Sets the date for the Date Picker programmatically. */ - value: PropTypes.any, + value: PropTypes.object, /** * Wordings used inside the button of the dialog. */ @@ -147,7 +147,6 @@ class DatePicker extends Component { style: {}, }; - static contextTypes = { muiTheme: PropTypes.object.isRequired, }; @@ -210,21 +209,28 @@ class DatePicker extends Component { date: date, }); } - if (this.props.onChange) this.props.onChange(null, date); + if (this.props.onChange) { + this.props.onChange(null, date); + } }; handleFocus = (event) => { event.target.blur(); - if (this.props.onFocus) this.props.onFocus(event); + if (this.props.onFocus) { + this.props.onFocus(event); + } }; handleTouchTap = (event) => { - if (this.props.onTouchTap) this.props.onTouchTap(event); + if (this.props.onTouchTap) { + this.props.onTouchTap(event); + } - if (!this.props.disabled) + if (!this.props.disabled) { setTimeout(() => { this.openDialog(); }, 0); + } }; isControlled() { diff --git a/src/DatePicker/DatePicker.spec.js b/src/DatePicker/DatePicker.spec.js new file mode 100644 index 00000000000000..96a5a38ff53109 --- /dev/null +++ b/src/DatePicker/DatePicker.spec.js @@ -0,0 +1,42 @@ +/* eslint-env mocha */ +import React from 'react'; +import {shallow} from 'enzyme'; +import {assert} from 'chai'; +import {stub} from 'sinon'; +import DatePicker from './DatePicker'; +import getMuiTheme from '../styles/getMuiTheme'; + +describe('', () => { + const muiTheme = getMuiTheme(); + const shallowWithContext = (node) => shallow(node, {context: {muiTheme}}); + + describe('propTypes', () => { + let consoleStub; + + beforeEach(() => { + consoleStub = stub(console, 'error'); + }); + + afterEach(() => { + console.error.restore(); // eslint-disable-line no-console + }); + + it('should throw when using wrong properties', () => { + shallowWithContext( + + ); + assert.strictEqual(consoleStub.callCount, 1); + assert.strictEqual( + consoleStub.args[0][0], + 'Warning: Failed propType: Invalid prop `value` of type `string` supplied to `DatePicker`, expected `object`.' + ); + }); + + it('should not throw when using a valid properties', () => { + shallowWithContext( + + ); + assert.strictEqual(consoleStub.callCount, 0); + }); + }); +}); diff --git a/src/TimePicker/TimePicker.js b/src/TimePicker/TimePicker.js index a4899cf5e0aa04..ad63081318320e 100644 --- a/src/TimePicker/TimePicker.js +++ b/src/TimePicker/TimePicker.js @@ -78,7 +78,6 @@ class TimePicker extends Component { * Sets the time for the Time Picker programmatically. */ value: PropTypes.object, - }; static defaultProps = { @@ -155,15 +154,21 @@ class TimePicker extends Component { handleFocusInput = (event) => { event.target.blur(); - if (this.props.onFocus) this.props.onFocus(event); + if (this.props.onFocus) { + this.props.onFocus(event); + } }; handleTouchTapInput = (event) => { event.preventDefault(); - if (!this.props.disabled) this.openDialog(); + if (!this.props.disabled) { + this.openDialog(); + } - if (this.props.onTouchTap) this.props.onTouchTap(event); + if (this.props.onTouchTap) { + this.props.onTouchTap(event); + } }; isControlled() { diff --git a/src/TimePicker/TimePicker.test.js b/src/TimePicker/TimePicker.test.js new file mode 100644 index 00000000000000..2dcf6ea4ad2589 --- /dev/null +++ b/src/TimePicker/TimePicker.test.js @@ -0,0 +1,42 @@ +/* eslint-env mocha */ +import React from 'react'; +import {shallow} from 'enzyme'; +import {assert} from 'chai'; +import {stub} from 'sinon'; +import TimePicker from './TimePicker'; +import getMuiTheme from '../styles/getMuiTheme'; + +describe('', () => { + const muiTheme = getMuiTheme(); + const shallowWithContext = (node) => shallow(node, {context: {muiTheme}}); + + describe('propTypes', () => { + let consoleStub; + + beforeEach(() => { + consoleStub = stub(console, 'error'); + }); + + afterEach(() => { + console.error.restore(); // eslint-disable-line no-console + }); + + it('should throw when using wrong properties', () => { + shallowWithContext( + + ); + assert.strictEqual(consoleStub.callCount, 1); + assert.strictEqual( + consoleStub.args[0][0], + 'Warning: Failed propType: Invalid prop `value` of type `string` supplied to `TimePicker`, expected `object`.' + ); + }); + + it('should not throw when using a valid properties', () => { + shallowWithContext( + + ); + assert.strictEqual(consoleStub.callCount, 0); + }); + }); +});