Skip to content

Commit

Permalink
Merge pull request #4827 from yasuaki640/main
Browse files Browse the repository at this point in the history
feat: convert multiple_selected_dates.test.js into tsx
  • Loading branch information
martijnrusschen authored May 28, 2024
2 parents ea6e915 + 053cabb commit 17d3963
Showing 1 changed file with 22 additions and 11 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { render } from "@testing-library/react";
import React from "react";

import DatePicker from "../src";
import { render } from "@testing-library/react";

describe("Multiple Dates Selected", function () {
function getDatePicker(extraProps) {
Expand All @@ -16,36 +17,43 @@ describe("Multiple Dates Selected", function () {
}

it("should handle text format for no selected date", () => {
const datePicker = getDatePicker({
const { container: datePicker } = getDatePicker({
selectsMultiple: true,
selectedDates: [],
});

expect(datePicker.getByRole("textbox").value).toBe("");
const input = datePicker.querySelector("input");

expect(input).not.toBeNull();
expect(input?.value).toBe("");
});

it("should handle text format for one selected date", () => {
const datePicker = getDatePicker({
const { container: datePicker } = getDatePicker({
selectsMultiple: true,
selectedDates: [new Date("2024/01/01")],
});

expect(datePicker.getByRole("textbox").value).toBe("01/01/2024");
const input = datePicker.querySelector("input");

expect(input).not.toBeNull();
expect(input?.value).toBe("01/01/2024");
});

it("should handle text format for two selected dates", () => {
const datePicker = getDatePicker({
const { container: datePicker } = getDatePicker({
selectsMultiple: true,
selectedDates: [new Date("2024/01/01"), new Date("2024/01/15")],
});

expect(datePicker.getByRole("textbox").value).toBe(
"01/01/2024, 01/15/2024",
);
const input = datePicker.querySelector("input");

expect(input).not.toBeNull();
expect(input?.value).toBe("01/01/2024, 01/15/2024");
});

it("should handle text format for more than two selected dates", () => {
const datePicker = getDatePicker({
const { container: datePicker } = getDatePicker({
selectsMultiple: true,
selectedDates: [
new Date("2024/01/01"),
Expand All @@ -54,6 +62,9 @@ describe("Multiple Dates Selected", function () {
],
});

expect(datePicker.getByRole("textbox").value).toBe("01/01/2024 (+2)");
const input = datePicker.querySelector("input");

expect(input).not.toBeNull();
expect(input?.value).toBe("01/01/2024 (+2)");
});
});

0 comments on commit 17d3963

Please sign in to comment.