Skip to content

Commit

Permalink
#3723 Add test to ensure the preselection Date is set in the state wh…
Browse files Browse the repository at this point in the history
…en Today button is clicked after clicking any other date
  • Loading branch information
AthiraKadampatta committed Sep 5, 2022
1 parent f0ec267 commit c7443e4
Showing 1 changed file with 26 additions and 0 deletions.
26 changes: 26 additions & 0 deletions test/datepicker_test.js
Expand Up @@ -319,6 +319,32 @@ describe("DatePicker", () => {
).to.equal(utils.formatDate(data.copyM, data.testFormat));
});

it("should update the preSelection state when Today button is clicked after selecting a different day for inline mode", () => {
var datePicker = TestUtils.renderIntoDocument(
<DatePicker
todayButton="Today"
selected={utils.newDate()}
inline
onChange={(d) => {
var date = d;
}}
/>
);

var today = getSelectedDayNode(datePicker);
var anyOtherDay = today.nextElementSibling || today.previousElementSibling;
TestUtils.Simulate.click(anyOtherDay); // will update the preSelection to next or previous day

var todayBtn = datePicker.calendar.componentNode.querySelector(
".react-datepicker__today-button"
);
TestUtils.Simulate.click(todayBtn); // will update the preSelection

expect(
utils.formatDate(datePicker.state.preSelection, "yyyy-MM-dd")
).to.equal(utils.formatDate(utils.newDate(), "yyyy-MM-dd"));
});

it("should hide the calendar when pressing enter in the date input", () => {
var datePicker = TestUtils.renderIntoDocument(<DatePicker />);
var dateInput = datePicker.input;
Expand Down

0 comments on commit c7443e4

Please sign in to comment.