Skip to content

Commit

Permalink
[DateInput] add unit test for timePrecision (palantir#937)
Browse files Browse the repository at this point in the history
* [DateInput] add unit test for timePrecision

* test that TimePicker disappears in absence of prop

* remove only
  • Loading branch information
giladgray authored and cmslewis committed Apr 3, 2017
1 parent 9f9209e commit bed7f98
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 6 deletions.
6 changes: 3 additions & 3 deletions packages/datetime/src/dateInput.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -166,13 +166,13 @@ export class DateInput extends AbstractComponent<IDateInputProps, IDateInputStat
const sharedProps: IDatePickerBaseProps = {
...this.props,
onChange: this.handleDateChange,
value: this.isMomentValidAndInRange(this.state.value) ? fromMomentToDate(this.state.value) : undefined,
value: this.isMomentValidAndInRange(this.state.value) ? fromMomentToDate(this.state.value) : null,
};
const popoverContent = this.props.timePrecision === undefined
? <DatePicker {...sharedProps} />
: <DateTimePicker
{...sharedProps}
timePickerProps={{precision: this.props.timePrecision}}
timePickerProps={{ precision: this.props.timePrecision }}
/>;

const inputClasses = classNames({
Expand All @@ -185,7 +185,7 @@ export class DateInput extends AbstractComponent<IDateInputProps, IDateInputStat
content={popoverContent}
enforceFocus={false}
inline={true}
isOpen={this.state.isOpen}
isOpen={this.state.isOpen && !this.props.disabled}
onClose={this.handleClosePopover}
popoverClassName="pt-dateinput-popover"
position={this.props.popoverPosition}
Expand Down
17 changes: 14 additions & 3 deletions packages/datetime/test/dateInputTests.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import * as React from "react";

import { InputGroup, Popover } from "@blueprintjs/core";
import { Months } from "../src/common/months";
import { Classes, DateInput } from "../src/index";
import { Classes, DateInput, TimePicker, TimePickerPrecision } from "../src/index";
import * as DateTestUtils from "./common/dateTestUtils";

describe("<DateInput>", () => {
Expand All @@ -37,11 +37,22 @@ describe("<DateInput>", () => {
});

it("Popover doesn't open if disabled=true", () => {
const wrapper = mount(<DateInput disabled />);
wrapper.find(InputGroup).simulate("focus");
const wrapper = mount(<DateInput disabled={true} />);
wrapper.find("input").simulate("focus");
assert.isFalse(wrapper.find(Popover).prop("isOpen"));
});

it("setting timePrecision renders a TimePicker", () => {
const wrapper = mount(<DateInput timePrecision={TimePickerPrecision.SECOND} />).setState({ isOpen: true });
// assert TimePicker appears
const timePicker = wrapper.find(TimePicker);
assert.isFalse(timePicker.isEmpty());
assert.strictEqual(timePicker.prop("precision"), TimePickerPrecision.SECOND);
// assert TimePicker disappears in absence of prop
wrapper.setProps({ timePrecision: undefined });
assert.isTrue(wrapper.find(TimePicker).isEmpty());
});

describe("when uncontrolled", () => {
it("Clicking a date puts it in the input box and closes the popover", () => {
const wrapper = mount(<DateInput />).setState({ isOpen: true });
Expand Down

0 comments on commit bed7f98

Please sign in to comment.