Skip to content

Commit c7443e4

Browse files
author
AthiraKadampatta
committed
#3723 Add test to ensure the preselection Date is set in the state when Today button is clicked after clicking any other date
1 parent f0ec267 commit c7443e4

File tree

1 file changed

+26
-0
lines changed

1 file changed

+26
-0
lines changed

test/datepicker_test.js

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -319,6 +319,32 @@ describe("DatePicker", () => {
319319
).to.equal(utils.formatDate(data.copyM, data.testFormat));
320320
});
321321

322+
it("should update the preSelection state when Today button is clicked after selecting a different day for inline mode", () => {
323+
var datePicker = TestUtils.renderIntoDocument(
324+
<DatePicker
325+
todayButton="Today"
326+
selected={utils.newDate()}
327+
inline
328+
onChange={(d) => {
329+
var date = d;
330+
}}
331+
/>
332+
);
333+
334+
var today = getSelectedDayNode(datePicker);
335+
var anyOtherDay = today.nextElementSibling || today.previousElementSibling;
336+
TestUtils.Simulate.click(anyOtherDay); // will update the preSelection to next or previous day
337+
338+
var todayBtn = datePicker.calendar.componentNode.querySelector(
339+
".react-datepicker__today-button"
340+
);
341+
TestUtils.Simulate.click(todayBtn); // will update the preSelection
342+
343+
expect(
344+
utils.formatDate(datePicker.state.preSelection, "yyyy-MM-dd")
345+
).to.equal(utils.formatDate(utils.newDate(), "yyyy-MM-dd"));
346+
});
347+
322348
it("should hide the calendar when pressing enter in the date input", () => {
323349
var datePicker = TestUtils.renderIntoDocument(<DatePicker />);
324350
var dateInput = datePicker.input;

0 commit comments

Comments
 (0)