Skip to content

Commit

Permalink
fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
mark-tate committed Dec 20, 2024
1 parent 57c3dff commit 2b97d3d
Show file tree
Hide file tree
Showing 2 changed files with 79 additions and 87 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,46 @@ describe("GIVEN a DatePicker where selectionVariant is single", () => {
// Verify that the calendar is displayed
cy.findAllByRole("application").should("have.length", 2);
});

it("SHOULD be able to enable the overlay to open on click", () => {
cy.mount(<Range openOnClick />);
cy.findByRole("application").should("not.exist");
// Simulate opening the calendar on click
cy.findByLabelText("Start date").realClick();
cy.findAllByRole("application").should("have.length", 2);
cy.document().find("body").realClick();
cy.findByRole("application").should("not.exist");
cy.findByLabelText("End date").realClick();
cy.findAllByRole("application").should("have.length", 2);
});

it("SHOULD be able to enable the overlay to open on keydown", () => {
cy.mount(<Range openOnKeyDown />);
cy.findByRole("application").should("not.exist");
// Simulate opening the calendar on arrow down
cy.findByLabelText("Start date").realClick();
cy.findByRole("application").should("not.exist");
cy.realPress("ArrowDown");
cy.findAllByRole("application").should("have.length", 2);
cy.document().find("body").realClick();
cy.findByRole("application").should("not.exist");
cy.findByLabelText("End date").realClick();
cy.findByRole("application").should("not.exist");
cy.realPress("ArrowDown");
cy.findAllByRole("application").should("have.length", 2);
});

it("SHOULD be able to enable the overlay to open on focus", () => {
cy.mount(<Range openOnFocus />);
cy.findByRole("application").should("not.exist");
// Simulate opening the calendar on focus
cy.findByLabelText("Start date").focus();
cy.findAllByRole("application").should("have.length", 2);
cy.document().find("body").realClick();
cy.findByRole("application").should("not.exist");
cy.findByLabelText("End date").focus();
cy.findAllByRole("application").should("have.length", 2);
});
});

describe("WHEN readOnly", () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ const {
SingleWithMinMaxDate,
SingleWithTodayButton,
SingleCustomFormat,
UncontrolledOpen,
} = datePickerStories as any;

describe("GIVEN a DatePicker where selectionVariant is single", () => {
Expand Down Expand Up @@ -67,6 +66,45 @@ describe("GIVEN a DatePicker where selectionVariant is single", () => {
// Verify that the calendar is displayed
cy.findByRole("application").should("exist");
});

it("SHOULD be able to enable the overlay to open on click", () => {
cy.mount(<Single openOnClick />);
cy.findByRole("application").should("not.exist");
// Simulate opening the calendar on click
cy.document().find("input").realClick();
cy.findByRole("application").should("exist");
});

it("SHOULD be able to enable the overlay to open on keydown", () => {
cy.mount(<Single openOnKeyDown />);
cy.findByRole("application").should("not.exist");
// Simulate opening the calendar on arrow down
cy.document().find("input").realClick();
cy.findByRole("application").should("not.exist");
cy.realPress("ArrowDown");
cy.findByRole("application").should("exist");
});

it("SHOULD be able to enable the overlay to open on focus", () => {
cy.mount(<Single openOnFocus />);
cy.findByRole("application").should("not.exist");
// Simulate opening the calendar on focus
cy.document().find("input").focus();
cy.findByRole("application").should("exist");
});

it("SHOULD be able to control the overlay open state", () => {
cy.mount(<ControlledOpen />);
cy.findByRole("application").should("not.exist");
// Simulate opening the calendar through a controlled state
cy.document().find("input").realClick();
cy.findByRole("application").should("not.exist");
cy.findByRole("button", { name: "Open Calendar" }).realClick();
cy.findByRole("application").should("exist");
cy.findByRole("button", { name: "Cancel" }).realClick();
// Verify that the calendar can be closed by user
cy.findByRole("application").should("not.exist");
});
});

describe("WHEN readOnly", () => {
Expand Down Expand Up @@ -485,68 +523,6 @@ describe("GIVEN a DatePicker where selectionVariant is single", () => {
updatedFormattedDateValue,
);
});

it("SHOULD be able to enable the overlay to open on click", () => {
cy.mount(<Single openOnClick defaultSelectedDate={initialDate} />);
cy.findByRole("application").should("not.exist");
// Simulate opening the calendar on click
cy.document().find("input").realClick();
cy.findByRole("application").should("exist");
// Simulate selecting a new date
cy.findByRole("button", {
name: adapter.format(updatedDate, "DD MMMM YYYY"),
}).should("exist");
cy.findByRole("button", {
name: adapter.format(updatedDate, "DD MMMM YYYY"),
}).realClick();
cy.findByRole("application").should("not.exist");
cy.findByRole("textbox").should(
"have.value",
updatedFormattedDateValue,
);
});

it("SHOULD be able to enable the overlay to open on keydown", () => {
cy.mount(<Single openOnKeyDown defaultSelectedDate={initialDate} />);
cy.findByRole("application").should("not.exist");
// Simulate opening the calendar on arrow down
cy.document().find("input").realClick();
cy.findByRole("application").should("not.exist");
cy.realPress("ArrowDown");
cy.findByRole("application").should("exist");
// Simulate selecting a new date
cy.findByRole("button", {
name: adapter.format(updatedDate, "DD MMMM YYYY"),
}).should("exist");
cy.findByRole("button", {
name: adapter.format(updatedDate, "DD MMMM YYYY"),
}).realClick();
cy.findByRole("application").should("not.exist");
cy.findByRole("textbox").should(
"have.value",
updatedFormattedDateValue,
);
});

it("SHOULD be able to enable the overlay to open on focus", () => {
cy.mount(<Single openOnFocus defaultSelectedDate={initialDate} />);
cy.findByRole("application").should("not.exist");
// Simulate opening the calendar on focus
cy.document().find("input").focus();
cy.findByRole("application").should("exist");
// Simulate selecting a new date
cy.findByRole("button", {
name: adapter.format(updatedDate, "DD MMMM YYYY"),
}).should("exist");
cy.findByRole("button", {
name: adapter.format(updatedDate, "DD MMMM YYYY"),
}).realClick();
cy.findByRole("application").should("not.exist");
cy.findByRole("textbox").should(
"have.value",
updatedFormattedDateValue,
);
});
});

describe("controlled component", () => {
Expand Down Expand Up @@ -631,30 +607,6 @@ describe("GIVEN a DatePicker where selectionVariant is single", () => {
});
});

it("SHOULD be able to control the overlay open state", () => {
cy.mount(<ControlledOpen defaultSelectedDate={initialDate} />);
cy.findByRole("application").should("not.exist");
// Simulate opening the calendar
cy.document().find("input").realClick();
cy.findByRole("application").should("not.exist");
cy.findByRole("button", { name: "Open Calendar" }).realClick();
cy.findByRole("application").should("exist");
// Simulate selecting a new date
cy.findByRole("button", {
name: adapter.format(updatedDate, "DD MMMM YYYY"),
}).should("exist");
cy.findByRole("button", {
name: adapter.format(updatedDate, "DD MMMM YYYY"),
}).realClick();
cy.findByRole("application").should("exist");
cy.findByRole("button", { name: "Apply" }).realClick();
// Verify that the calendar is closed and the new date is applied
cy.findByRole("application").should("not.exist");
cy.document()
.find("input")
.should("have.value", updatedFormattedDateValue);
});

it("SHOULD support format prop on the input", () => {
const format = "YYYY-MM-DD";

Expand Down

0 comments on commit 2b97d3d

Please sign in to comment.