Skip to content

Commit

Permalink
Add tests for dismissing popover with ESC and blurring last tabbable …
Browse files Browse the repository at this point in the history
…element
  • Loading branch information
mud committed Feb 6, 2018
1 parent 85bb3d5 commit 031cfdf
Showing 1 changed file with 25 additions and 0 deletions.
25 changes: 25 additions & 0 deletions packages/datetime/test/dateInputTests.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,31 @@ describe("<DateInput>", () => {
assert.isFalse(wrapper.find(Popover).prop("isOpen"));
});

it("Popover closes when ESC key pressed", () => {
const wrapper = mount(<DateInput openOnFocus={true} />);
const input = wrapper.find("input");
input.simulate("focus");
const popover = wrapper.find(Popover);
assert.isTrue(popover.prop("isOpen"));
input.simulate("keydown", { which: Keys.ESCAPE });
assert.isFalse(popover.prop("isOpen"));
});

it("Popover closes when last tabbable component is blurred", () => {
const wrapper = mount(<DateInput openOnFocus={true} />);
const input = wrapper.find("input");
input.simulate("focus");
const popover = wrapper.find(Popover);
assert.isTrue(popover.prop("isOpen"));
input.simulate("blur");
const lastTabbable = popover
.find(".DayPicker-Day--outside")
.last()
.getDOMNode() as HTMLElement;
lastTabbable.dispatchEvent(new Event("blur"));
assert.isFalse(popover.prop("isOpen"));
});

it("setting timePrecision renders a TimePicker", () => {
const wrapper = mount(<DateInput timePrecision={TimePickerPrecision.SECOND} />).setState({ isOpen: true });
// assert TimePicker appears
Expand Down

0 comments on commit 031cfdf

Please sign in to comment.