Skip to content

Commit

Permalink
[TimePicker] Added value prop.
Browse files Browse the repository at this point in the history
- TimePicker#getValue is now deprecated.
- TimePicker#setValue is now deprecated.
- Added value prop.
- defaultTime is only used if value is not defined on props.
- Added tests for TimePicker initialization behavior.
- Adding  utils/DateTime#formatTime

Fixes #3094

Signed-off-by: rscnt <[email protected]>
  • Loading branch information
raul-ascencio-applaudo committed Feb 15, 2016
1 parent 93d19c5 commit b6e0271
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ export default class TimePickerExampleComplex extends React.Component {
render() {
return (
<div>
<TimePicker
format="ampm"
<TimePicker
format="ampm"
hintText="12hr Format"
value={this.state.value12}
onChange={this.handleChangeTimePicker12}
Expand Down
20 changes: 10 additions & 10 deletions test/time-picker/time-picker-spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,45 +7,45 @@ import TestUtils from 'react-addons-test-utils';
describe('TimePicker', () => {

it('has to give value prop precedence over defaultTime', () => {
let initialTime = new Date(1448967059892); // Tue, 01 Dec 2015 10:50:59 GMT
let valueTime = DateTime.addHours(initialTime, 2);
const initialTime = new Date(1448967059892); // Tue, 01 Dec 2015 10:50:59 GMT
const valueTime = DateTime.addHours(initialTime, 2);

let render = TestUtils.renderIntoDocument(
<TimePicker value={valueTime} format="ampm" locale="en-US"
initialTime={initialTime}
/>
);

let timeTextField = TestUtils.findRenderedComponentWithType(render, TextField);
const timeTextField = TestUtils.findRenderedComponentWithType(render, TextField);

expect(timeTextField.props.value, DateTime.formatTime(valueTime));
});

it('takes defaulTime prop to set first value when value prop is missing', () => {
let initialTime = new Date(1448967059892); // Tue, 01 Dec 2015 10:50:59 GMT
const initialTime = new Date(1448967059892); // Tue, 01 Dec 2015 10:50:59 GMT

let render = TestUtils.renderIntoDocument(
const render = TestUtils.renderIntoDocument(
<TimePicker format="ampm" locale="en-US"
defaultTime={initialTime}
/>
);

let timeTextField = TestUtils.findRenderedComponentWithType(render, TextField);
const timeTextField = TestUtils.findRenderedComponentWithType(render, TextField);

expect(timeTextField.props.value, DateTime.formatTime(initialTime));
});

it('shows value prop if defaultTime is missing', () => {
let initialTime = null;
let valueTime = new Date(1448967059892); // Tue, 01 Dec 2015 10:50:59 GM
const initialTime = null;
const valueTime = new Date(1448967059892); // Tue, 01 Dec 2015 10:50:59 GM

let render = TestUtils.renderIntoDocument(
const render = TestUtils.renderIntoDocument(
<TimePicker value={valueTime} format="ampm" locale="en-US"
defaultTime={initialTime}
/>
);

let timeTextField = TestUtils.findRenderedComponentWithType(render, TextField);
const timeTextField = TestUtils.findRenderedComponentWithType(render, TextField);

expect(timeTextField.props.value, DateTime.formatTime(valueTime));
});
Expand Down

0 comments on commit b6e0271

Please sign in to comment.