diff --git a/packages/datetime/test/dateRangeInputTests.tsx b/packages/datetime/test/dateRangeInputTests.tsx index bb87953f2a..6ea37cff3c 100644 --- a/packages/datetime/test/dateRangeInputTests.tsx +++ b/packages/datetime/test/dateRangeInputTests.tsx @@ -28,12 +28,16 @@ type WrappedComponentRoot = ReactWrapper; type WrappedComponentInput = ReactWrapper, any>; type WrappedComponentDayElement = ReactWrapper, any>; -type OutOfRangeTestFunction = (input: WrappedComponentInput, inputString: string, boundary?: DateRangeBoundary) => void; +type OutOfRangeTestFunction = ( + inputGetterFn: (root: WrappedComponentRoot) => WrappedComponentInput, + inputString: string, + boundary?: DateRangeBoundary, +) => void; type InvalidDateTestFunction = ( - input: WrappedComponentInput, + inputGetterFn: (root: WrappedComponentRoot) => WrappedComponentInput, boundary: DateRangeBoundary, - otherInput: WrappedComponentInput, + otherInputGetterFn: (root: WrappedComponentRoot) => WrappedComponentInput, ) => void; describe("", () => { @@ -126,12 +130,12 @@ describe("", () => { mountFn: (inputGroupProps: HTMLInputProps & IInputGroupProps) => any, ) { it("allows custom placeholder text", () => { - const { root } = mountFn({ placeholder: "Hello" }); + const root = mountFn({ placeholder: "Hello" }); expect(getInputPlaceholderText(inputGetterFn(root))).to.equal("Hello"); }); it("supports custom style", () => { - const { root } = mountFn({ style: { background: "yellow" } }); + const root = mountFn({ style: { background: "yellow" } }); const inputElement = inputGetterFn(root).getDOMNode() as HTMLElement; expect(inputElement.style.background).to.equal("yellow"); }); @@ -408,24 +412,25 @@ describe("", () => { const { root } = wrap(); root.setState({ isOpen: true }); - const startInput = getStartInput(root); - startInput.simulate("focus"); - startInput.simulate("change", { target: { value: START_STR } }); - startInput.simulate("keydown", { which: Keys.ENTER }); + // Don't save the input elements into variables; they can become + // stale across React updates. + + getStartInput(root).simulate("focus"); + getStartInput(root).simulate("change", { target: { value: START_STR } }); + getStartInput(root).simulate("keydown", { which: Keys.ENTER }); expect(startInputProps.onKeyDown.calledOnce, "startInputProps.onKeyDown called once"); expect(isStartInputFocused(root), "start input still focused").to.be.false; expect(root.state("isOpen"), "popover still open").to.be.true; - const endInput = getEndInput(root); - endInput.simulate("focus"); - endInput.simulate("change", { target: { value: END_STR } }); - endInput.simulate("keydown", { which: Keys.ENTER }); + getEndInput(root).simulate("focus"); + getEndInput(root).simulate("change", { target: { value: END_STR } }); + getEndInput(root).simulate("keydown", { which: Keys.ENTER }); expect(endInputProps.onKeyDown.calledOnce, "endInputProps.onKeyDown called once"); expect(isEndInputFocused(root), "end input still focused").to.be.true; - expect(startInput.prop("value")).to.equal(START_STR); - expect(endInput.prop("value")).to.equal(END_STR); + expect(getStartInput(root).prop("value"), "startInput value is correct").to.equal(START_STR); + expect(getEndInput(root).prop("value"), "endInput value is correct").to.equal(END_STR); expect(root.state("isOpen"), "popover closed at end").to.be.false; }); @@ -518,64 +523,64 @@ describe("", () => { }); describe("shows the error message on blur", () => { - runTestForEachScenario((input, inputString) => { - changeInputText(input, inputString); - input.simulate("blur"); - assertInputTextEquals(input, OUT_OF_RANGE_MESSAGE); + runTestForEachScenario((inputGetterFn, inputString) => { + changeInputText(inputGetterFn(root), inputString); + inputGetterFn(root).simulate("blur"); + assertInputTextEquals(inputGetterFn(root), OUT_OF_RANGE_MESSAGE); }); }); describe("shows the offending date in the field on focus", () => { - runTestForEachScenario((input, inputString) => { - changeInputText(input, inputString); - input.simulate("blur"); - input.simulate("focus"); - assertInputTextEquals(input, inputString); + runTestForEachScenario((inputGetterFn, inputString) => { + changeInputText(inputGetterFn(root), inputString); + inputGetterFn(root).simulate("blur"); + inputGetterFn(root).simulate("focus"); + assertInputTextEquals(inputGetterFn(root), inputString); }); }); describe("calls onError with invalid date on blur", () => { - runTestForEachScenario((input, inputString, boundary) => { + runTestForEachScenario((inputGetterFn, inputString, boundary) => { const expectedRange = boundary === DateRangeBoundary.START ? [inputString, null] : [null, inputString]; - input.simulate("focus"); - changeInputText(input, inputString); + inputGetterFn(root).simulate("focus"); + changeInputText(inputGetterFn(root), inputString); expect(onError.called).to.be.false; - input.simulate("blur"); + inputGetterFn(root).simulate("blur"); expect(onError.calledOnce).to.be.true; assertDateRangesEqual(onError.getCall(0).args[0], expectedRange); }); }); describe("does NOT call onChange before OR after blur", () => { - runTestForEachScenario((input, inputString) => { - input.simulate("focus"); - changeInputText(input, inputString); + runTestForEachScenario((inputGetterFn, inputString) => { + inputGetterFn(root).simulate("focus"); + changeInputText(inputGetterFn(root), inputString); expect(onChange.called).to.be.false; - input.simulate("blur"); + inputGetterFn(root).simulate("blur"); expect(onChange.called).to.be.false; }); }); describe("removes error message if input is changed to an in-range date again", () => { - runTestForEachScenario((input, inputString) => { - changeInputText(input, inputString); - input.simulate("blur"); + runTestForEachScenario((inputGetterFn, inputString) => { + changeInputText(inputGetterFn(root), inputString); + inputGetterFn(root).simulate("blur"); const IN_RANGE_DATE_STR = START_STR; - input.simulate("focus"); - changeInputText(input, IN_RANGE_DATE_STR); - input.simulate("blur"); - assertInputTextEquals(input, IN_RANGE_DATE_STR); + inputGetterFn(root).simulate("focus"); + changeInputText(inputGetterFn(root), IN_RANGE_DATE_STR); + inputGetterFn(root).simulate("blur"); + assertInputTextEquals(inputGetterFn(root), IN_RANGE_DATE_STR); }); }); function runTestForEachScenario(runTestFn: OutOfRangeTestFunction) { const { START, END } = DateRangeBoundary; // deconstruct to keep line lengths under threshold - it("if start < minDate", () => runTestFn(getStartInput(root), OUT_OF_RANGE_START_STR, START)); - it("if start > maxDate", () => runTestFn(getStartInput(root), OUT_OF_RANGE_END_STR, START)); - it("if end < minDate", () => runTestFn(getEndInput(root), OUT_OF_RANGE_START_STR, END)); - it("if end > maxDate", () => runTestFn(getEndInput(root), OUT_OF_RANGE_END_STR, END)); + it("if start < minDate", () => runTestFn(getStartInput, OUT_OF_RANGE_START_STR, START)); + it("if start > maxDate", () => runTestFn(getStartInput, OUT_OF_RANGE_END_STR, START)); + it("if end < minDate", () => runTestFn(getEndInput, OUT_OF_RANGE_START_STR, END)); + it("if end > maxDate", () => runTestFn(getEndInput, OUT_OF_RANGE_END_STR, END)); } }); @@ -601,30 +606,30 @@ describe("", () => { }); describe("shows the error message on blur", () => { - runTestForEachScenario(input => { - input.simulate("focus"); - changeInputText(input, INVALID_STR); - input.simulate("blur"); - assertInputTextEquals(input, INVALID_MESSAGE); + runTestForEachScenario(inputGetterFn => { + inputGetterFn(root).simulate("focus"); + changeInputText(inputGetterFn(root), INVALID_STR); + inputGetterFn(root).simulate("blur"); + assertInputTextEquals(inputGetterFn(root), INVALID_MESSAGE); }); }); describe("keeps showing the error message on next focus", () => { - runTestForEachScenario(input => { - input.simulate("focus"); - changeInputText(input, INVALID_STR); - input.simulate("blur"); - input.simulate("focus"); - assertInputTextEquals(input, INVALID_MESSAGE); + runTestForEachScenario(inputGetterFn => { + inputGetterFn(root).simulate("focus"); + changeInputText(inputGetterFn(root), INVALID_STR); + inputGetterFn(root).simulate("blur"); + inputGetterFn(root).simulate("focus"); + assertInputTextEquals(inputGetterFn(root), INVALID_MESSAGE); }); }); describe("calls onError on blur with Date(undefined) in place of the invalid date", () => { - runTestForEachScenario((input, boundary) => { - input.simulate("focus"); - changeInputText(input, INVALID_STR); + runTestForEachScenario((inputGetterFn, boundary) => { + inputGetterFn(root).simulate("focus"); + changeInputText(inputGetterFn(root), INVALID_STR); expect(onError.called).to.be.false; - input.simulate("blur"); + inputGetterFn(root).simulate("blur"); expect(onError.calledOnce).to.be.true; const dateRange = onError.getCall(0).args[0]; @@ -634,42 +639,42 @@ describe("", () => { }); describe("does NOT call onChange before OR after blur", () => { - runTestForEachScenario(input => { - input.simulate("focus"); - changeInputText(input, INVALID_STR); + runTestForEachScenario(inputGetterFn => { + inputGetterFn(root).simulate("focus"); + changeInputText(inputGetterFn(root), INVALID_STR); expect(onChange.called).to.be.false; - input.simulate("blur"); + inputGetterFn(root).simulate("blur"); expect(onChange.called).to.be.false; }); }); describe("removes error message if input is changed to an in-range date again", () => { - runTestForEachScenario(input => { - input.simulate("focus"); - changeInputText(input, INVALID_STR); - input.simulate("blur"); + runTestForEachScenario(inputGetterFn => { + inputGetterFn(root).simulate("focus"); + changeInputText(inputGetterFn(root), INVALID_STR); + inputGetterFn(root).simulate("blur"); // just use START_STR for this test, because it will be // valid in either field. const VALID_STR = START_STR; - input.simulate("focus"); - changeInputText(input, VALID_STR); - input.simulate("blur"); - assertInputTextEquals(input, VALID_STR); + inputGetterFn(root).simulate("focus"); + changeInputText(inputGetterFn(root), VALID_STR); + inputGetterFn(root).simulate("blur"); + assertInputTextEquals(inputGetterFn(root), VALID_STR); }); }); // tslint:disable-next-line:max-line-length describe("calls onChange if last-edited boundary is in range and the other boundary is out of range", () => { - runTestForEachScenario((input, boundary, otherInput) => { - otherInput.simulate("focus"); - changeInputText(otherInput, INVALID_STR); - otherInput.simulate("blur"); + runTestForEachScenario((inputGetterFn, boundary, otherInputGetterFn) => { + otherInputGetterFn(root).simulate("focus"); + changeInputText(otherInputGetterFn(root), INVALID_STR); + otherInputGetterFn(root).simulate("blur"); expect(onChange.called).to.be.false; const VALID_STR = START_STR; - input.simulate("focus"); - changeInputText(input, VALID_STR); + inputGetterFn(root).simulate("focus"); + changeInputText(inputGetterFn(root), VALID_STR); expect(onChange.calledOnce).to.be.true; // because latest date is valid const actualRange = onChange.getCall(0).args[0]; @@ -683,8 +688,8 @@ describe("", () => { }); function runTestForEachScenario(runTestFn: InvalidDateTestFunction) { - it("in start field", () => runTestFn(getStartInput(root), DateRangeBoundary.START, getEndInput(root))); - it("in end field", () => runTestFn(getEndInput(root), DateRangeBoundary.END, getStartInput(root))); + it("in start field", () => runTestFn(getStartInput, DateRangeBoundary.START, getEndInput)); + it("in end field", () => runTestFn(getEndInput, DateRangeBoundary.END, getStartInput)); } }); @@ -694,8 +699,6 @@ describe("", () => { let onChange: sinon.SinonSpy; let onError: sinon.SinonSpy; let root: WrappedComponentRoot; - let startInput: WrappedComponentInput; - let endInput: WrappedComponentInput; beforeEach(() => { onChange = sinon.spy(); @@ -710,93 +713,90 @@ describe("", () => { />, ); root = result.root; - - startInput = getStartInput(root); - endInput = getEndInput(root); }); describe("in the start field", () => { it("shows an error message in the end field right away", () => { - startInput.simulate("focus"); - changeInputText(startInput, OVERLAPPING_START_STR); - assertInputTextEquals(endInput, OVERLAPPING_DATES_MESSAGE); + getStartInput(root).simulate("focus"); + changeInputText(getStartInput(root), OVERLAPPING_START_STR); + assertInputTextEquals(getEndInput(root), OVERLAPPING_DATES_MESSAGE); }); it("shows the offending date in the end field on focus in the end field", () => { - startInput.simulate("focus"); - changeInputText(startInput, OVERLAPPING_START_STR); - startInput.simulate("blur"); - endInput.simulate("focus"); - assertInputTextEquals(endInput, END_STR); + getStartInput(root).simulate("focus"); + changeInputText(getStartInput(root), OVERLAPPING_START_STR); + getStartInput(root).simulate("blur"); + getEndInput(root).simulate("focus"); + assertInputTextEquals(getEndInput(root), END_STR); }); it("calls onError with [, { - startInput.simulate("focus"); - changeInputText(startInput, OVERLAPPING_START_STR); + getStartInput(root).simulate("focus"); + changeInputText(getStartInput(root), OVERLAPPING_START_STR); expect(onError.called).to.be.false; - startInput.simulate("blur"); + getStartInput(root).simulate("blur"); expect(onError.calledOnce).to.be.true; assertDateRangesEqual(onError.getCall(0).args[0], [OVERLAPPING_START_STR, END_STR]); }); it("does NOT call onChange before OR after blur", () => { - startInput.simulate("focus"); - changeInputText(startInput, OVERLAPPING_START_STR); + getStartInput(root).simulate("focus"); + changeInputText(getStartInput(root), OVERLAPPING_START_STR); expect(onChange.called).to.be.false; - startInput.simulate("blur"); + getStartInput(root).simulate("blur"); expect(onChange.called).to.be.false; }); it("removes error message if input is changed to an in-range date again", () => { - startInput.simulate("focus"); - changeInputText(startInput, OVERLAPPING_START_STR); - changeInputText(startInput, START_STR); - assertInputTextEquals(endInput, END_STR); + getStartInput(root).simulate("focus"); + changeInputText(getStartInput(root), OVERLAPPING_START_STR); + changeInputText(getStartInput(root), START_STR); + assertInputTextEquals(getEndInput(root), END_STR); }); }); describe("in the end field", () => { it("shows an error message in the end field on blur", () => { - endInput.simulate("focus"); - changeInputText(endInput, OVERLAPPING_END_STR); - assertInputTextEquals(endInput, OVERLAPPING_END_STR); - endInput.simulate("blur"); - assertInputTextEquals(endInput, OVERLAPPING_DATES_MESSAGE); + getEndInput(root).simulate("focus"); + changeInputText(getEndInput(root), OVERLAPPING_END_STR); + assertInputTextEquals(getEndInput(root), OVERLAPPING_END_STR); + getEndInput(root).simulate("blur"); + assertInputTextEquals(getEndInput(root), OVERLAPPING_DATES_MESSAGE); }); it("shows the offending date in the end field on re-focus", () => { - endInput.simulate("focus"); - changeInputText(endInput, OVERLAPPING_END_STR); - endInput.simulate("blur"); - endInput.simulate("focus"); - assertInputTextEquals(endInput, OVERLAPPING_END_STR); + getEndInput(root).simulate("focus"); + changeInputText(getEndInput(root), OVERLAPPING_END_STR); + getEndInput(root).simulate("blur"); + getEndInput(root).simulate("focus"); + assertInputTextEquals(getEndInput(root), OVERLAPPING_END_STR); }); it("calls onError with [, ] on blur", () => { - endInput.simulate("focus"); - changeInputText(endInput, OVERLAPPING_END_STR); + getEndInput(root).simulate("focus"); + changeInputText(getEndInput(root), OVERLAPPING_END_STR); expect(onError.called).to.be.false; - endInput.simulate("blur"); + getEndInput(root).simulate("blur"); expect(onError.calledOnce).to.be.true; assertDateRangesEqual(onError.getCall(0).args[0], [START_STR, OVERLAPPING_END_STR]); }); it("does NOT call onChange before OR after blur", () => { - endInput.simulate("focus"); - changeInputText(endInput, OVERLAPPING_END_STR); + getEndInput(root).simulate("focus"); + changeInputText(getEndInput(root), OVERLAPPING_END_STR); expect(onChange.called).to.be.false; - endInput.simulate("blur"); + getEndInput(root).simulate("blur"); expect(onChange.called).to.be.false; }); it("removes error message if input is changed to an in-range date again", () => { - endInput.simulate("focus"); - changeInputText(endInput, OVERLAPPING_END_STR); - endInput.simulate("blur"); - endInput.simulate("focus"); - changeInputText(endInput, END_STR); - endInput.simulate("blur"); - assertInputTextEquals(endInput, END_STR); + getEndInput(root).simulate("focus"); + changeInputText(getEndInput(root), OVERLAPPING_END_STR); + getEndInput(root).simulate("blur"); + getEndInput(root).simulate("focus"); + changeInputText(getEndInput(root), END_STR); + getEndInput(root).simulate("blur"); + assertInputTextEquals(getEndInput(root), END_STR); }); }); }); @@ -837,41 +837,33 @@ describe("", () => { } let root: WrappedComponentRoot; - let rootInstance: DateRangeInput; - let startInput: WrappedComponentInput; - let endInput: WrappedComponentInput; let getDayElement: (dayNumber?: number, fromLeftMonth?: boolean) => WrappedComponentDayElement; - let dayElement: WrappedComponentDayElement; before(() => { + // reuse the same mounted component for every test to speed + // things up (mounting is costly). const result = wrap( , ); root = result.root; - rootInstance = root.instance() as DateRangeInput; getDayElement = result.getDayElement; - startInput = getStartInput(root); - endInput = getEndInput(root); }); beforeEach(() => { + // need to set wasLastFocusChangeDueToHover=false to fully reset state between tests. + root.setState({ isOpen: true, wasLastFocusChangeDueToHover: false }); // clear the inputs to start from a fresh state, but do so // *after* opening the popover so that the calendar doesn't // move away from the view we expect for these tests. - root.setState({ isOpen: true }); - changeInputText(startInput, ""); - changeInputText(endInput, ""); - }); - - afterEach(() => { - rootInstance.reset(); + changeInputText(getStartInput(root), ""); + changeInputText(getEndInput(root), ""); }); function setSelectedRangeForHoverTest(selectedDateConfigs: IHoverTextDateConfig[]) { const [startConfig, endConfig] = selectedDateConfigs; - changeInputText(startInput, startConfig == null ? "" : startConfig.str); - changeInputText(endInput, endConfig == null ? "" : endConfig.str); + changeInputText(getStartInput(root), startConfig == null ? "" : startConfig.str); + changeInputText(getEndInput(root), endConfig == null ? "" : endConfig.str); } describe("when selected date range is [null, null]", () => { @@ -880,13 +872,12 @@ describe("", () => { beforeEach(() => { setSelectedRangeForHoverTest(SELECTED_RANGE); - dayElement = getDayElement(HOVER_TEST_DATE_CONFIG.day); }); describe("if start field is focused", () => { beforeEach(() => { - startInput.simulate("focus"); - dayElement.simulate("mouseenter"); + getStartInput(root).simulate("focus"); + getDayElement(HOVER_TEST_DATE_CONFIG.day).simulate("mouseenter"); }); it("shows [, null] in input fields", () => { @@ -899,7 +890,7 @@ describe("", () => { describe("on click", () => { beforeEach(() => { - dayElement.simulate("click"); + getDayElement(HOVER_TEST_DATE_CONFIG.day).simulate("click"); }); it("sets selection to [, null]", () => { @@ -913,7 +904,7 @@ describe("", () => { describe("if mouse moves to no longer be over a calendar day", () => { beforeEach(() => { - dayElement.simulate("mouseleave"); + getDayElement(HOVER_TEST_DATE_CONFIG.day).simulate("mouseleave"); }); it("shows [null, null] in input fields", () => { @@ -928,8 +919,8 @@ describe("", () => { describe("if end field is focused", () => { beforeEach(() => { - endInput.simulate("focus"); - dayElement.simulate("mouseenter"); + getEndInput(root).simulate("focus"); + getDayElement(HOVER_TEST_DATE_CONFIG.day).simulate("mouseenter"); }); it("shows [null, ] in input fields", () => { @@ -941,13 +932,13 @@ describe("", () => { }); it("sets selection to [null, ] on click", () => { - dayElement.simulate("click"); + getDayElement(HOVER_TEST_DATE_CONFIG.day).simulate("click"); assertInputTextsEqual(root, "", HOVER_TEST_DATE_CONFIG.str); }); describe("on click", () => { beforeEach(() => { - dayElement.simulate("click"); + getDayElement(HOVER_TEST_DATE_CONFIG.day).simulate("click"); }); it("sets selection to [null, ]", () => { @@ -961,7 +952,7 @@ describe("", () => { describe("if mouse moves to no longer be over a calendar day", () => { beforeEach(() => { - dayElement.simulate("mouseleave"); + getDayElement(HOVER_TEST_DATE_CONFIG.day).simulate("mouseleave"); }); it("shows [null, null] in input fields", () => { @@ -984,15 +975,14 @@ describe("", () => { describe("if start field is focused", () => { beforeEach(() => { - startInput.simulate("focus"); + getStartInput(root).simulate("focus"); }); describe("if < ", () => { const DATE_CONFIG = HOVER_TEST_DATE_CONFIG_3; beforeEach(() => { - dayElement = getDayElement(DATE_CONFIG.day); - dayElement.simulate("mouseenter"); + getDayElement(DATE_CONFIG.day).simulate("mouseenter"); }); it("shows [, null] in input fields", () => { @@ -1005,7 +995,7 @@ describe("", () => { describe("on click", () => { beforeEach(() => { - dayElement.simulate("click"); + getDayElement(DATE_CONFIG.day).simulate("click"); }); it("sets selection to [, null]", () => { @@ -1019,7 +1009,7 @@ describe("", () => { describe("if mouse moves to no longer be over a calendar day", () => { beforeEach(() => { - dayElement.simulate("mouseleave"); + getDayElement(DATE_CONFIG.day).simulate("mouseleave"); }); it("shows [, null] in input fields", () => { @@ -1036,8 +1026,7 @@ describe("", () => { const DATE_CONFIG = HOVER_TEST_DATE_CONFIG_1; beforeEach(() => { - dayElement = getDayElement(DATE_CONFIG.day); - dayElement.simulate("mouseenter"); + getDayElement(DATE_CONFIG.day).simulate("mouseenter"); }); it("shows [, null] in input fields", () => { @@ -1050,7 +1039,7 @@ describe("", () => { describe("on click", () => { beforeEach(() => { - dayElement.simulate("click"); + getDayElement(DATE_CONFIG.day).simulate("click"); }); it("sets selection to [, null]", () => { @@ -1064,7 +1053,7 @@ describe("", () => { describe("if mouse moves to no longer be over a calendar day", () => { beforeEach(() => { - dayElement.simulate("mouseleave"); + getDayElement(DATE_CONFIG.day).simulate("mouseleave"); }); it("shows [, null] in input fields", () => { @@ -1081,8 +1070,7 @@ describe("", () => { const DATE_CONFIG = HOVER_TEST_DATE_CONFIG_2; beforeEach(() => { - dayElement = getDayElement(DATE_CONFIG.day); - dayElement.simulate("mouseenter"); + getDayElement(DATE_CONFIG.day).simulate("mouseenter"); }); it("shows [null, null] in input fields", () => { @@ -1095,7 +1083,7 @@ describe("", () => { describe("on click", () => { beforeEach(() => { - dayElement.simulate("click"); + getDayElement(DATE_CONFIG.day).simulate("click"); }); it("sets selection to [null, null]", () => { @@ -1109,7 +1097,7 @@ describe("", () => { describe("if mouse moves to no longer be over a calendar day", () => { beforeEach(() => { - dayElement.simulate("mouseleave"); + getDayElement(DATE_CONFIG.day).simulate("mouseleave"); }); it("shows [, null] in input fields", () => { @@ -1125,15 +1113,14 @@ describe("", () => { describe("if end field is focused", () => { beforeEach(() => { - endInput.simulate("focus"); + getEndInput(root).simulate("focus"); }); describe("if < ", () => { const DATE_CONFIG = HOVER_TEST_DATE_CONFIG_3; beforeEach(() => { - dayElement = getDayElement(DATE_CONFIG.day); - dayElement.simulate("mouseenter"); + getDayElement(DATE_CONFIG.day).simulate("mouseenter"); }); it("shows [, ] in input fields", () => { @@ -1146,7 +1133,7 @@ describe("", () => { describe("on click", () => { beforeEach(() => { - dayElement.simulate("click"); + getDayElement(DATE_CONFIG.day).simulate("click"); }); it("sets selection to [, ]", () => { @@ -1160,7 +1147,7 @@ describe("", () => { describe("if mouse moves to no longer be over a calendar day", () => { beforeEach(() => { - dayElement.simulate("mouseleave"); + getDayElement(DATE_CONFIG.day).simulate("mouseleave"); }); it("shows [, null] in input fields", () => { @@ -1177,8 +1164,7 @@ describe("", () => { const DATE_CONFIG = HOVER_TEST_DATE_CONFIG_1; beforeEach(() => { - dayElement = getDayElement(DATE_CONFIG.day); - dayElement.simulate("mouseenter"); + getDayElement(DATE_CONFIG.day).simulate("mouseenter"); }); it("shows [, ] in input fields", () => { @@ -1191,7 +1177,7 @@ describe("", () => { describe("on click", () => { beforeEach(() => { - dayElement.simulate("click"); + getDayElement(DATE_CONFIG.day).simulate("click"); }); it("sets selection to [, ]", () => { @@ -1205,7 +1191,7 @@ describe("", () => { describe("if mouse moves to no longer be over a calendar day", () => { beforeEach(() => { - dayElement.simulate("mouseleave"); + getDayElement(DATE_CONFIG.day).simulate("mouseleave"); }); it("shows [, null] in input fields", () => { @@ -1222,8 +1208,7 @@ describe("", () => { const DATE_CONFIG = HOVER_TEST_DATE_CONFIG_2; beforeEach(() => { - dayElement = getDayElement(DATE_CONFIG.day); - dayElement.simulate("mouseenter"); + getDayElement(DATE_CONFIG.day).simulate("mouseenter"); }); it("shows [null, null] in input fields", () => { @@ -1236,7 +1221,7 @@ describe("", () => { describe("on click", () => { beforeEach(() => { - dayElement.simulate("click"); + getDayElement(DATE_CONFIG.day).simulate("click"); }); it("sets selection to [null, null] on click", () => { @@ -1250,7 +1235,7 @@ describe("", () => { describe("if mouse moves to no longer be over a calendar day", () => { beforeEach(() => { - dayElement.simulate("mouseleave"); + getDayElement(DATE_CONFIG.day).simulate("mouseleave"); }); it("shows [, null] in input fields", () => { @@ -1274,15 +1259,14 @@ describe("", () => { describe("if start field is focused", () => { beforeEach(() => { - startInput.simulate("focus"); + getStartInput(root).simulate("focus"); }); describe("if < ", () => { const DATE_CONFIG = HOVER_TEST_DATE_CONFIG_3; beforeEach(() => { - dayElement = getDayElement(DATE_CONFIG.day); - dayElement.simulate("mouseenter"); + getDayElement(DATE_CONFIG.day).simulate("mouseenter"); }); it("shows [, ] in input fields", () => { @@ -1295,7 +1279,7 @@ describe("", () => { describe("on click", () => { beforeEach(() => { - dayElement.simulate("click"); + getDayElement(DATE_CONFIG.day).simulate("click"); }); it("sets selection to [, ]", () => { @@ -1309,7 +1293,7 @@ describe("", () => { describe("if mouse moves to no longer be over a calendar day", () => { beforeEach(() => { - dayElement.simulate("mouseleave"); + getDayElement(DATE_CONFIG.day).simulate("mouseleave"); }); it("shows [null, ] in input fields", () => { @@ -1326,8 +1310,7 @@ describe("", () => { const DATE_CONFIG = HOVER_TEST_DATE_CONFIG_5; beforeEach(() => { - dayElement = getDayElement(DATE_CONFIG.day); - dayElement.simulate("mouseenter"); + getDayElement(DATE_CONFIG.day).simulate("mouseenter"); }); it("shows [, ] in input fields", () => { @@ -1340,7 +1323,7 @@ describe("", () => { describe("on click", () => { beforeEach(() => { - dayElement.simulate("click"); + getDayElement(DATE_CONFIG.day).simulate("click"); }); it("sets selection to [, ] on click", () => { @@ -1354,7 +1337,7 @@ describe("", () => { describe("if mouse moves to no longer be over a calendar day", () => { beforeEach(() => { - dayElement.simulate("mouseleave"); + getDayElement(DATE_CONFIG.day).simulate("mouseleave"); }); it("shows [null, ] in input fields", () => { @@ -1371,8 +1354,7 @@ describe("", () => { const DATE_CONFIG = HOVER_TEST_DATE_CONFIG_4; beforeEach(() => { - dayElement = getDayElement(DATE_CONFIG.day); - dayElement.simulate("mouseenter"); + getDayElement(DATE_CONFIG.day).simulate("mouseenter"); }); it("shows [null, null] in input fields", () => { @@ -1385,7 +1367,7 @@ describe("", () => { describe("on click", () => { beforeEach(() => { - dayElement.simulate("click"); + getDayElement(DATE_CONFIG.day).simulate("click"); }); it("sets selection to [null, null] on click", () => { @@ -1399,7 +1381,7 @@ describe("", () => { describe("if mouse moves to no longer be over a calendar day", () => { beforeEach(() => { - dayElement.simulate("mouseleave"); + getDayElement(DATE_CONFIG.day).simulate("mouseleave"); }); it("shows [null, ] in input fields", () => { @@ -1415,15 +1397,14 @@ describe("", () => { describe("if end field is focused", () => { beforeEach(() => { - endInput.simulate("focus"); + getEndInput(root).simulate("focus"); }); describe("if < ", () => { const DATE_CONFIG = HOVER_TEST_DATE_CONFIG_3; beforeEach(() => { - dayElement = getDayElement(DATE_CONFIG.day); - dayElement.simulate("mouseenter"); + getDayElement(DATE_CONFIG.day).simulate("mouseenter"); }); it("shows [null, ] in input fields", () => { @@ -1436,7 +1417,7 @@ describe("", () => { describe("on click", () => { beforeEach(() => { - dayElement.simulate("click"); + getDayElement(DATE_CONFIG.day).simulate("click"); }); it("sets selection to [null, ]", () => { @@ -1450,7 +1431,7 @@ describe("", () => { describe("if mouse moves to no longer be over a calendar day", () => { beforeEach(() => { - dayElement.simulate("mouseleave"); + getDayElement(DATE_CONFIG.day).simulate("mouseleave"); }); it("shows [null, ] in input fields", () => { @@ -1467,8 +1448,7 @@ describe("", () => { const DATE_CONFIG = HOVER_TEST_DATE_CONFIG_5; beforeEach(() => { - dayElement = getDayElement(DATE_CONFIG.day); - dayElement.simulate("mouseenter"); + getDayElement(DATE_CONFIG.day).simulate("mouseenter"); }); it("shows [null, ] in input fields", () => { @@ -1481,7 +1461,7 @@ describe("", () => { describe("on click", () => { beforeEach(() => { - dayElement.simulate("click"); + getDayElement(DATE_CONFIG.day).simulate("click"); }); it("sets selection to [null, ] on click", () => { @@ -1495,7 +1475,7 @@ describe("", () => { describe("if mouse moves to no longer be over a calendar day", () => { beforeEach(() => { - dayElement.simulate("mouseleave"); + getDayElement(DATE_CONFIG.day).simulate("mouseleave"); }); it("shows [null, ] in input fields", () => { @@ -1512,8 +1492,7 @@ describe("", () => { const DATE_CONFIG = HOVER_TEST_DATE_CONFIG_4; beforeEach(() => { - dayElement = getDayElement(DATE_CONFIG.day); - dayElement.simulate("mouseenter"); + getDayElement(DATE_CONFIG.day).simulate("mouseenter"); }); it("shows [null, null] in input fields", () => { @@ -1526,7 +1505,7 @@ describe("", () => { describe("on click", () => { beforeEach(() => { - dayElement.simulate("click"); + getDayElement(DATE_CONFIG.day).simulate("click"); }); it("sets selection to [null, null] on click", () => { @@ -1540,7 +1519,7 @@ describe("", () => { describe("if mouse moves to no longer be over a calendar day", () => { beforeEach(() => { - dayElement.simulate("mouseleave"); + getDayElement(DATE_CONFIG.day).simulate("mouseleave"); }); it("shows [null, ] in input fields", () => { @@ -1564,15 +1543,14 @@ describe("", () => { describe("if start field is focused", () => { beforeEach(() => { - startInput.simulate("focus"); + getStartInput(root).simulate("focus"); }); describe("if < ", () => { const DATE_CONFIG = HOVER_TEST_DATE_CONFIG_1; beforeEach(() => { - dayElement = getDayElement(DATE_CONFIG.day); - dayElement.simulate("mouseenter"); + getDayElement(DATE_CONFIG.day).simulate("mouseenter"); }); it("shows [, ] in input fields", () => { @@ -1585,7 +1563,7 @@ describe("", () => { describe("on click", () => { beforeEach(() => { - dayElement.simulate("click"); + getDayElement(DATE_CONFIG.day).simulate("click"); }); it("sets selection to [, ]", () => { @@ -1599,7 +1577,7 @@ describe("", () => { describe("if mouse moves to no longer be over a calendar day", () => { beforeEach(() => { - dayElement.simulate("mouseleave"); + getDayElement(DATE_CONFIG.day).simulate("mouseleave"); }); it("shows [, ] in input fields", () => { @@ -1616,8 +1594,7 @@ describe("", () => { const DATE_CONFIG = HOVER_TEST_DATE_CONFIG_3; beforeEach(() => { - dayElement = getDayElement(DATE_CONFIG.day); - dayElement.simulate("mouseenter"); + getDayElement(DATE_CONFIG.day).simulate("mouseenter"); }); it("shows [, ] in input fields", () => { @@ -1630,7 +1607,7 @@ describe("", () => { describe("on click", () => { beforeEach(() => { - dayElement.simulate("click"); + getDayElement(DATE_CONFIG.day).simulate("click"); }); it("sets selection to [, ]", () => { @@ -1644,7 +1621,7 @@ describe("", () => { describe("if mouse moves to no longer be over a calendar day", () => { beforeEach(() => { - dayElement.simulate("mouseleave"); + getDayElement(DATE_CONFIG.day).simulate("mouseleave"); }); it("shows [, ] in input fields", () => { @@ -1661,8 +1638,7 @@ describe("", () => { const DATE_CONFIG = HOVER_TEST_DATE_CONFIG_5; beforeEach(() => { - dayElement = getDayElement(DATE_CONFIG.day); - dayElement.simulate("mouseenter"); + getDayElement(DATE_CONFIG.day).simulate("mouseenter"); }); it("shows [, null] in input fields", () => { @@ -1675,7 +1651,7 @@ describe("", () => { describe("on click", () => { beforeEach(() => { - dayElement.simulate("click"); + getDayElement(DATE_CONFIG.day).simulate("click"); }); it("sets selection to [, null]", () => { @@ -1689,7 +1665,7 @@ describe("", () => { describe("if mouse moves to no longer be over a calendar day", () => { beforeEach(() => { - dayElement.simulate("mouseleave"); + getDayElement(DATE_CONFIG.day).simulate("mouseleave"); }); it("shows [, ] in input fields", () => { @@ -1706,8 +1682,7 @@ describe("", () => { const DATE_CONFIG = HOVER_TEST_DATE_CONFIG_2; beforeEach(() => { - dayElement = getDayElement(DATE_CONFIG.day); - dayElement.simulate("mouseenter"); + getDayElement(DATE_CONFIG.day).simulate("mouseenter"); }); it("shows [null, ] in input fields", () => { @@ -1720,7 +1695,7 @@ describe("", () => { describe("on click", () => { beforeEach(() => { - dayElement.simulate("click"); + getDayElement(DATE_CONFIG.day).simulate("click"); }); it("sets selection to [null, ]", () => { @@ -1734,7 +1709,7 @@ describe("", () => { describe("if mouse moves to no longer be over a calendar day", () => { beforeEach(() => { - dayElement.simulate("mouseleave"); + getDayElement(DATE_CONFIG.day).simulate("mouseleave"); }); it("shows [, ] in input fields", () => { @@ -1751,8 +1726,7 @@ describe("", () => { const DATE_CONFIG = HOVER_TEST_DATE_CONFIG_4; beforeEach(() => { - dayElement = getDayElement(DATE_CONFIG.day); - dayElement.simulate("mouseenter"); + getDayElement(DATE_CONFIG.day).simulate("mouseenter"); }); it("shows [, null] in input fields", () => { @@ -1765,7 +1739,7 @@ describe("", () => { describe("on click", () => { beforeEach(() => { - dayElement.simulate("click"); + getDayElement(DATE_CONFIG.day).simulate("click"); }); it("sets selection to [, null]", () => { @@ -1779,7 +1753,7 @@ describe("", () => { describe("if mouse moves to no longer be over a calendar day", () => { beforeEach(() => { - dayElement.simulate("mouseleave"); + getDayElement(DATE_CONFIG.day).simulate("mouseleave"); }); it("shows [, ] in input fields", () => { @@ -1795,15 +1769,14 @@ describe("", () => { describe("if end field is focused", () => { beforeEach(() => { - endInput.simulate("focus"); + getEndInput(root).simulate("focus"); }); describe("if < ", () => { const DATE_CONFIG = HOVER_TEST_DATE_CONFIG_1; beforeEach(() => { - dayElement = getDayElement(DATE_CONFIG.day); - dayElement.simulate("mouseenter"); + getDayElement(DATE_CONFIG.day).simulate("mouseenter"); }); it("shows [null, ] in input fields", () => { @@ -1816,7 +1789,7 @@ describe("", () => { describe("on click", () => { beforeEach(() => { - dayElement.simulate("click"); + getDayElement(DATE_CONFIG.day).simulate("click"); }); it("sets selection to [null, ]", () => { @@ -1830,7 +1803,7 @@ describe("", () => { describe("if mouse moves to no longer be over a calendar day", () => { beforeEach(() => { - dayElement.simulate("mouseleave"); + getDayElement(DATE_CONFIG.day).simulate("mouseleave"); }); it("shows [, ] in input fields", () => { @@ -1847,8 +1820,7 @@ describe("", () => { const DATE_CONFIG = HOVER_TEST_DATE_CONFIG_3; beforeEach(() => { - dayElement = getDayElement(DATE_CONFIG.day); - dayElement.simulate("mouseenter"); + getDayElement(DATE_CONFIG.day).simulate("mouseenter"); }); it("shows [, ] in input fields", () => { @@ -1861,7 +1833,7 @@ describe("", () => { describe("on click", () => { beforeEach(() => { - dayElement.simulate("click"); + getDayElement(DATE_CONFIG.day).simulate("click"); }); it("sets selection to [, ]", () => { @@ -1875,7 +1847,7 @@ describe("", () => { describe("if mouse moves to no longer be over a calendar day", () => { beforeEach(() => { - dayElement.simulate("mouseleave"); + getDayElement(DATE_CONFIG.day).simulate("mouseleave"); }); it("shows [, ] in input fields", () => { @@ -1892,8 +1864,7 @@ describe("", () => { const DATE_CONFIG = HOVER_TEST_DATE_CONFIG_5; beforeEach(() => { - dayElement = getDayElement(DATE_CONFIG.day); - dayElement.simulate("mouseenter"); + getDayElement(DATE_CONFIG.day).simulate("mouseenter"); }); it("shows [, ] in input fields", () => { @@ -1906,7 +1877,7 @@ describe("", () => { describe("on click", () => { beforeEach(() => { - dayElement.simulate("click"); + getDayElement(DATE_CONFIG.day).simulate("click"); }); it("sets selection to [, ]", () => { @@ -1920,7 +1891,7 @@ describe("", () => { describe("if mouse moves to no longer be over a calendar day", () => { beforeEach(() => { - dayElement.simulate("mouseleave"); + getDayElement(DATE_CONFIG.day).simulate("mouseleave"); }); it("shows [, ] in input fields", () => { @@ -1937,8 +1908,7 @@ describe("", () => { const DATE_CONFIG = HOVER_TEST_DATE_CONFIG_2; beforeEach(() => { - dayElement = getDayElement(DATE_CONFIG.day); - dayElement.simulate("mouseenter"); + getDayElement(DATE_CONFIG.day).simulate("mouseenter"); }); it("shows [null, ] in input fields", () => { @@ -1951,7 +1921,7 @@ describe("", () => { describe("on click", () => { beforeEach(() => { - dayElement.simulate("click"); + getDayElement(DATE_CONFIG.day).simulate("click"); }); it("sets selection to [null, ]", () => { @@ -1965,7 +1935,7 @@ describe("", () => { describe("if mouse moves to no longer be over a calendar day", () => { beforeEach(() => { - dayElement.simulate("mouseleave"); + getDayElement(DATE_CONFIG.day).simulate("mouseleave"); }); it("shows [, ] in input fields", () => { @@ -1982,8 +1952,7 @@ describe("", () => { const DATE_CONFIG = HOVER_TEST_DATE_CONFIG_4; beforeEach(() => { - dayElement = getDayElement(DATE_CONFIG.day); - dayElement.simulate("mouseenter"); + getDayElement(DATE_CONFIG.day).simulate("mouseenter"); }); it("shows [, null] in input fields", () => { @@ -1996,7 +1965,7 @@ describe("", () => { describe("on click", () => { beforeEach(() => { - dayElement.simulate("click"); + getDayElement(DATE_CONFIG.day).simulate("click"); }); it("sets selection to [, null]", () => { @@ -2010,7 +1979,7 @@ describe("", () => { describe("if mouse moves to no longer be over a calendar day", () => { beforeEach(() => { - dayElement.simulate("mouseleave"); + getDayElement(DATE_CONFIG.day).simulate("mouseleave"); }); it("shows [, ] in input fields", () => { @@ -2201,34 +2170,34 @@ describe("", () => { }); describe("calls onError with invalid date on blur", () => { - runTestForEachScenario((input, inputString, boundary) => { + runTestForEachScenario((inputGetterFn, inputString, boundary) => { const expectedRange = boundary === DateRangeBoundary.START ? [inputString, null] : [null, inputString]; - input.simulate("focus"); - changeInputText(input, inputString); + inputGetterFn(root).simulate("focus"); + changeInputText(inputGetterFn(root), inputString); expect(onError.called).to.be.false; - input.simulate("blur"); + inputGetterFn(root).simulate("blur"); expect(onError.calledOnce).to.be.true; assertDateRangesEqual(onError.getCall(0).args[0], expectedRange); }); }); describe("does NOT call onChange before OR after blur", () => { - runTestForEachScenario((input, inputString) => { - input.simulate("focus"); - changeInputText(input, inputString); + runTestForEachScenario((inputGetterFn, inputString) => { + inputGetterFn(root).simulate("focus"); + changeInputText(inputGetterFn(root), inputString); expect(onChange.called).to.be.false; - input.simulate("blur"); + inputGetterFn(root).simulate("blur"); expect(onChange.called).to.be.false; }); }); function runTestForEachScenario(runTestFn: OutOfRangeTestFunction) { const { START, END } = DateRangeBoundary; - it("if start < minDate", () => runTestFn(getStartInput(root), OUT_OF_RANGE_START_STR, START)); - it("if start > maxDate", () => runTestFn(getStartInput(root), OUT_OF_RANGE_END_STR, START)); - it("if end < minDate", () => runTestFn(getEndInput(root), OUT_OF_RANGE_START_STR, END)); - it("if end > maxDate", () => runTestFn(getEndInput(root), OUT_OF_RANGE_END_STR, END)); + it("if start < minDate", () => runTestFn(getStartInput, OUT_OF_RANGE_START_STR, START)); + it("if start > maxDate", () => runTestFn(getStartInput, OUT_OF_RANGE_END_STR, START)); + it("if end < minDate", () => runTestFn(getEndInput, OUT_OF_RANGE_START_STR, END)); + it("if end > maxDate", () => runTestFn(getEndInput, OUT_OF_RANGE_END_STR, END)); } }); @@ -2252,11 +2221,11 @@ describe("", () => { }); describe("calls onError on blur with Date(undefined) in place of the invalid date", () => { - runTestForEachScenario((input, boundary) => { - input.simulate("focus"); - changeInputText(input, INVALID_STR); + runTestForEachScenario((inputGetterFn, boundary) => { + inputGetterFn(root).simulate("focus"); + changeInputText(inputGetterFn(root), INVALID_STR); expect(onError.called).to.be.false; - input.simulate("blur"); + inputGetterFn(root).simulate("blur"); expect(onError.calledOnce).to.be.true; const dateRange = onError.getCall(0).args[0]; @@ -2266,18 +2235,18 @@ describe("", () => { }); describe("does NOT call onChange before OR after blur", () => { - runTestForEachScenario(input => { - input.simulate("focus"); - changeInputText(input, INVALID_STR); + runTestForEachScenario(inputGetterFn => { + inputGetterFn(root).simulate("focus"); + changeInputText(inputGetterFn(root), INVALID_STR); expect(onChange.called).to.be.false; - input.simulate("blur"); + inputGetterFn(root).simulate("blur"); expect(onChange.called).to.be.false; }); }); function runTestForEachScenario(runTestFn: InvalidDateTestFunction) { - it("in start field", () => runTestFn(getStartInput(root), DateRangeBoundary.START, getEndInput(root))); - it("in end field", () => runTestFn(getEndInput(root), DateRangeBoundary.END, getStartInput(root))); + it("in start field", () => runTestFn(getStartInput, DateRangeBoundary.START, getEndInput)); + it("in end field", () => runTestFn(getEndInput, DateRangeBoundary.END, getStartInput)); } }); diff --git a/packages/datetime/test/dateRangePickerTests.tsx b/packages/datetime/test/dateRangePickerTests.tsx index 46c9425892..a03f40cb33 100644 --- a/packages/datetime/test/dateRangePickerTests.tsx +++ b/packages/datetime/test/dateRangePickerTests.tsx @@ -6,7 +6,7 @@ import { Classes } from "@blueprintjs/core"; import { assert } from "chai"; -import { mount } from "enzyme"; +import { mount, ReactWrapper } from "enzyme"; import * as React from "react"; import * as ReactDayPicker from "react-day-picker"; import * as ReactDOM from "react-dom"; @@ -18,7 +18,7 @@ import { expectPropValidationError } from "@blueprintjs/test-commons"; import * as DateUtils from "../src/common/dateUtils"; import * as Errors from "../src/common/errors"; import { Months } from "../src/common/months"; -import { IDateRangeShortcut } from "../src/dateRangePicker"; +import { IDateRangePickerState, IDateRangeShortcut } from "../src/dateRangePicker"; import { Classes as DateClasses, DateRange, @@ -1216,32 +1216,44 @@ describe("", () => { function wrap(datepicker: JSX.Element) { const wrapper = mount(datepicker); - const dayPickers = wrapper.find(ReactDayPicker).find("Month"); - const leftDayPicker = dayPickers.at(0); - const rightDayPicker = dayPickers.length > 1 ? dayPickers.at(1) : dayPickers.at(0); + // Don't cache the left/right day pickers into variables in this scope, + // because as of Enzyme 3.0 they can get stale if the views change. return { getDayLeftView: (dayNumber = 1) => { - return leftDayPicker + return getLeftDayPicker(wrapper) .find(`.${DateClasses.DATEPICKER_DAY}`) .filterWhere( day => day.text() === "" + dayNumber && !day.hasClass(DateClasses.DATEPICKER_DAY_OUTSIDE), ); }, getDayRightView: (dayNumber = 1) => { - return rightDayPicker + return getRightDayPicker(wrapper) .find(`.${DateClasses.DATEPICKER_DAY}`) .filterWhere( day => day.text() === "" + dayNumber && !day.hasClass(DateClasses.DATEPICKER_DAY_OUTSIDE), ); }, leftDayPickerNavbar: wrapper.find("Navbar").at(0), - leftView: leftDayPicker, + leftView: getLeftDayPicker(wrapper), rightDayPickerNavbar: wrapper.find("Navbar").at(1) || wrapper.find("Navbar").at(0), - rightView: rightDayPicker, + rightView: getRightDayPicker(wrapper), root: wrapper, }; } + function getLeftDayPicker(wrapper: ReactWrapper) { + return getDayPickers(wrapper).at(0); + } + + function getRightDayPicker(wrapper: ReactWrapper) { + const dayPickers = getDayPickers(wrapper); + return dayPickers.length > 1 ? dayPickers.at(1) : dayPickers.at(0); + } + + function getDayPickers(wrapper: ReactWrapper) { + return wrapper.find(ReactDayPicker).find("Month"); + } + function clickDay(dayNumber = 1, fromLeftMonth = true) { TestUtils.Simulate.click(getDayElement(dayNumber, fromLeftMonth)); }