From bae7392fe18582dd885e56e303b9ab65be2a4e03 Mon Sep 17 00:00:00 2001 From: Lebaud Antoine Date: Wed, 2 Aug 2023 00:33:08 +0200 Subject: [PATCH] =?UTF-8?q?=E2=9C=85(react)=20strip=20"Today,=20"=20from?= =?UTF-8?q?=20selected=20date=20range=20literal?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit DateRangePicker aria-labels mention when a selected date range contains today's date, which breaks the tests while ran on the first day of the month. Avoid these tests to be flaky. --- .changeset/rare-emus-wait.md | 5 +++++ .../Forms/DatePicker/DateRangePicker.spec.tsx | 18 +++++++++++++----- 2 files changed, 18 insertions(+), 5 deletions(-) create mode 100644 .changeset/rare-emus-wait.md diff --git a/.changeset/rare-emus-wait.md b/.changeset/rare-emus-wait.md new file mode 100644 index 0000000..082342c --- /dev/null +++ b/.changeset/rare-emus-wait.md @@ -0,0 +1,5 @@ +--- +"@openfun/cunningham-react": patch +--- + +Fix flaky tests on DateRangePicker diff --git a/packages/react/src/components/Forms/DatePicker/DateRangePicker.spec.tsx b/packages/react/src/components/Forms/DatePicker/DateRangePicker.spec.tsx index 797b5f9..9020993 100644 --- a/packages/react/src/components/Forms/DatePicker/DateRangePicker.spec.tsx +++ b/packages/react/src/components/Forms/DatePicker/DateRangePicker.spec.tsx @@ -241,7 +241,9 @@ describe("", () => { ).getByRole("button")!; // Pick a start date. - const gridCellStartDate = startGridCellButton.getAttribute("aria-label"); + const gridCellStartDate = startGridCellButton + .getAttribute("aria-label") + ?.replace("Today, ", ""); await user.click(startGridCellButton); expectCalendarToBeOpen(); @@ -254,7 +256,9 @@ describe("", () => { ).getByRole("button")!; // Pick an end date. - const gridCellEndDate = endGridCellButton.getAttribute("aria-label"); + const gridCellEndDate = endGridCellButton + .getAttribute("aria-label") + ?.replace("Today, ", ""); await user.click(endGridCellButton); // Calendar should close on range's selection. @@ -273,7 +277,8 @@ describe("", () => { const selectedRange = within(selectedCells[0]) .getByRole("button")! .getAttribute("aria-label") - ?.replace("selected", ""); + ?.replace("selected", "") + ?.replace("Today, ", ""); // Make sure start and end dates are in the selected range, // that describes the range with its start and end date. @@ -311,7 +316,9 @@ describe("", () => { ).getByRole("button")!; // Pick a start date. - const gridCellDate = gridCellButton.getAttribute("aria-label"); + const gridCellDate = gridCellButton + .getAttribute("aria-label") + ?.replace("Today, ", ""); await user.click(gridCellButton); expectCalendarToBeOpen(); @@ -335,7 +342,8 @@ describe("", () => { const selectedRange = within(selectedCells[0]) .getByRole("button")! .getAttribute("aria-label") - ?.replace("selected", ""); + ?.replace("selected", "") + ?.replace("Today, ", ""); // Make sure start and end dates are in the selected range, // that describes the range with its start and end date.