diff --git a/packages/lab/src/__tests__/__e2e__/date-picker/DatePicker.range.cy.tsx b/packages/lab/src/__tests__/__e2e__/date-picker/DatePicker.range.cy.tsx index 86d2e0c0d0..637e156d6c 100644 --- a/packages/lab/src/__tests__/__e2e__/date-picker/DatePicker.range.cy.tsx +++ b/packages/lab/src/__tests__/__e2e__/date-picker/DatePicker.range.cy.tsx @@ -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(); + 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(); + 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(); + 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", () => { diff --git a/packages/lab/src/__tests__/__e2e__/date-picker/DatePicker.single.cy.tsx b/packages/lab/src/__tests__/__e2e__/date-picker/DatePicker.single.cy.tsx index 032495cca3..2809282a37 100644 --- a/packages/lab/src/__tests__/__e2e__/date-picker/DatePicker.single.cy.tsx +++ b/packages/lab/src/__tests__/__e2e__/date-picker/DatePicker.single.cy.tsx @@ -36,7 +36,6 @@ const { SingleWithMinMaxDate, SingleWithTodayButton, SingleCustomFormat, - UncontrolledOpen, } = datePickerStories as any; describe("GIVEN a DatePicker where selectionVariant is single", () => { @@ -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(); + 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(); + 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(); + 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(); + 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", () => { @@ -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(); - 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(); - 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(); - 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", () => { @@ -631,30 +607,6 @@ describe("GIVEN a DatePicker where selectionVariant is single", () => { }); }); - it("SHOULD be able to control the overlay open state", () => { - cy.mount(); - 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";