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

[Pickers] Add some test regarding the expect value property #4347

Merged
merged 1 commit into from
May 26, 2016
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
18 changes: 12 additions & 6 deletions src/DatePicker/DatePicker.js
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*/
Expand All @@ -147,7 +147,6 @@ class DatePicker extends Component {
style: {},
};


static contextTypes = {
muiTheme: PropTypes.object.isRequired,
};
Expand Down Expand Up @@ -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() {
Expand Down
42 changes: 42 additions & 0 deletions src/DatePicker/DatePicker.spec.js
Original file line number Diff line number Diff line change
@@ -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('<DatePicker />', () => {
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(
<DatePicker value="2016-03-21" />
);
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(
<DatePicker value={new Date()} />
);
assert.strictEqual(consoleStub.callCount, 0);
});
});
});
13 changes: 9 additions & 4 deletions src/TimePicker/TimePicker.js
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,6 @@ class TimePicker extends Component {
* Sets the time for the Time Picker programmatically.
*/
value: PropTypes.object,

};

static defaultProps = {
Expand Down Expand Up @@ -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() {
Expand Down
42 changes: 42 additions & 0 deletions src/TimePicker/TimePicker.test.js
Original file line number Diff line number Diff line change
@@ -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('<TimePicker />', () => {
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(
<TimePicker value="2016-03-21" />
);
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(
<TimePicker value={new Date()} />
);
assert.strictEqual(consoleStub.callCount, 0);
});
});
});