Skip to content

Commit

Permalink
feature: add tests for aria-disabled Month component
Browse files Browse the repository at this point in the history
  • Loading branch information
MatteoPieroni committed Apr 17, 2024
1 parent f22a885 commit 356f0d2
Showing 1 changed file with 10 additions and 5 deletions.
15 changes: 10 additions & 5 deletions test/month_test.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -430,7 +430,7 @@ describe("Month", () => {
expect(utils.getMonth(monthClicked)).toBe(6);
});

it("should return disabled class if current date is out of bound of minDate and maxDate", () => {
it("should return disabled month if current date is out of bound of minDate and maxDate", () => {
const onDayClickSpy = jest.fn();
const onDayMouseEnterSpy = jest.fn();
const { container } = render(
Expand All @@ -449,13 +449,14 @@ describe("Month", () => {
expect(
month.classList.contains("react-datepicker__month-text--disabled"),
).toBe(true);
expect(month.getAttribute("aria-disabled")).toBe("true");
fireEvent.click(month);
expect(onDayClickSpy).not.toHaveBeenCalled();
fireEvent.mouseEnter(month);
expect(onDayMouseEnterSpy).not.toHaveBeenCalled();
});

it("should not return disabled class if current date is before minDate but same month", () => {
it("should not return disabled month if current date is before minDate but same month", () => {
const onDayClickSpy = jest.fn();
const onDayMouseEnterSpy = jest.fn();
const { container } = render(
Expand All @@ -473,13 +474,14 @@ describe("Month", () => {
expect(
month.classList.contains("react-datepicker__month-text--disabled"),
).not.toBe(true);
expect(month.getAttribute("aria-disabled")).not.toBe("true");
fireEvent.click(month);
expect(onDayClickSpy).toHaveBeenCalled();
fireEvent.mouseEnter(month);
expect(onDayMouseEnterSpy).toHaveBeenCalled();
});

it("should not return disabled class if current date is after maxDate but same month", () => {
it("should not return disabled month if current date is after maxDate but same month", () => {
const onDayClickSpy = jest.fn();
const onDayMouseEnterSpy = jest.fn();
const { container } = render(
Expand All @@ -497,13 +499,14 @@ describe("Month", () => {
expect(
month.classList.contains("react-datepicker__month-text--disabled"),
).not.toBe(true);
expect(month.getAttribute("aria-disabled")).not.toBe("true");
fireEvent.click(month);
expect(onDayClickSpy).toHaveBeenCalled();
fireEvent.mouseEnter(month);
expect(onDayMouseEnterSpy).toHaveBeenCalled();
});

it("should return disabled class if specified excludeDate", () => {
it("should return disabled month if specified excludeDate", () => {
const onDayClickSpy = jest.fn();
const onDayMouseEnterSpy = jest.fn();
const { container } = render(
Expand All @@ -530,14 +533,15 @@ describe("Month", () => {
expect(
month.classList.contains("react-datepicker__month-text--disabled"),
).toBe(true);
expect(month.getAttribute("aria-disabled")).toBe("true");
fireEvent.click(month);
expect(onDayClickSpy).not.toHaveBeenCalled();
fireEvent.mouseEnter(month);
expect(onDayMouseEnterSpy).not.toHaveBeenCalled();
});
});

it("should return disabled class if specified includeDate", () => {
it("should return disabled month if specified includeDate", () => {
const { container } = render(
<Month
day={utils.newDate("2015-01-01")}
Expand Down Expand Up @@ -566,6 +570,7 @@ describe("Month", () => {
expect(
month.classList.contains("react-datepicker__month-text--disabled"),
).toBe(true);
expect(month.getAttribute("aria-disabled")).toBe("true");
}
});

Expand Down

0 comments on commit 356f0d2

Please sign in to comment.