From 27a6c1905a67e8bb084472de14241105dedda03d Mon Sep 17 00:00:00 2001 From: Anurag Date: Wed, 28 Oct 2020 17:15:14 +0530 Subject: [PATCH 1/2] test: added more test cases for calendar --- src/calendar/__tests__/Calendar.test.tsx | 53 +++++++++++++++++++++++ src/calendar/stories/Calendar.stories.tsx | 14 +++--- 2 files changed, 60 insertions(+), 7 deletions(-) diff --git a/src/calendar/__tests__/Calendar.test.tsx b/src/calendar/__tests__/Calendar.test.tsx index 0e9538d5b..dabe426a1 100644 --- a/src/calendar/__tests__/Calendar.test.tsx +++ b/src/calendar/__tests__/Calendar.test.tsx @@ -152,6 +152,59 @@ describe("Calendar", () => { expect(label("Saturday, November 14, 2020")).toHaveFocus(); }); + test("should be able to go to prev/next month when min/max values are set", async () => { + const { getByLabelText: label } = render( + , + ); + + repeat(press.Tab, 5); + expect(label("Saturday, November 7, 2020 selected")).toHaveFocus(); + + press.PageUp(); + expect(label("Saturday, October 31, 2020")).toHaveFocus(); + + press.PageDown(); + expect(label("Saturday, November 14, 2020")).toHaveFocus(); + + // Should not be able to go to next/prev year + press.PageDown(null, { shiftKey: true }); + expect(label("Saturday, November 14, 2020")).toHaveFocus(); + press.PageUp(null, { shiftKey: true }); + expect(label("Saturday, November 14, 2020")).toHaveFocus(); + }); + + test("should be able to go to prev/next year when min/max values are set", async () => { + const { getByLabelText: label } = render( + , + ); + + repeat(press.Tab, 5); + expect(label("Saturday, November 7, 2020 selected")).toHaveFocus(); + + press.PageUp(); + expect(label("Saturday, October 31, 2020")).toHaveFocus(); + + press.PageDown(null, { shiftKey: true }); + expect(label("Sunday, October 31, 2021")).toHaveFocus(); + + press.PageDown(); + expect(label("Sunday, November 14, 2021")).toHaveFocus(); + + press.PageUp(); + expect(label("Thursday, October 14, 2021")).toHaveFocus(); + + press.PageUp(null, { shiftKey: true }); + expect(label("Saturday, October 31, 2020")).toHaveFocus(); + }); + test("Calendar renders with no a11y violations", async () => { const { container } = render(); const results = await axe(container); diff --git a/src/calendar/stories/Calendar.stories.tsx b/src/calendar/stories/Calendar.stories.tsx index 2f01ed03d..3cc7cfe89 100644 --- a/src/calendar/stories/Calendar.stories.tsx +++ b/src/calendar/stories/Calendar.stories.tsx @@ -43,21 +43,21 @@ DefaultValue.args = { value: "2001-01-01", defaultValue: "2001-01-01" }; export const MinMaxDate = Base.bind({}); MinMaxDate.args = { - defaultValue: format(new Date(2020, 10, 1), "yyyy-MM-dd"), - minValue: format(new Date(), "yyyy-MM-dd"), - maxValue: format(addWeeks(new Date(), 1), "yyyy-MM-dd"), + defaultValue: new Date(2020, 10, 1), + minValue: new Date(), + maxValue: addWeeks(new Date(), 1), }; export const MinMaxDefaultDate = Base.bind({}); MinMaxDefaultDate.args = { - defaultValue: format(new Date(2020, 10, 7), "yyyy-MM-dd"), - minValue: format(subWeeks(new Date(2020, 10, 7), 1), "yyyy-MM-dd"), - maxValue: format(addWeeks(new Date(2020, 10, 7), 1), "yyyy-MM-dd"), + defaultValue: new Date(2020, 10, 7), + minValue: subWeeks(new Date(2020, 10, 7), 1), + maxValue: addWeeks(new Date(2020, 10, 7), 1), }; export const Options = Base.bind({}); Options.args = { - value: format(new Date(), "yyyy-MM-dd"), + value: new Date(), isDisabled: false, isReadOnly: false, autoFocus: false, From 07c547e531e45d7312fe172153207c78f18c4b66 Mon Sep 17 00:00:00 2001 From: Anurag Date: Wed, 28 Oct 2020 17:19:48 +0530 Subject: [PATCH 2/2] chore: removed unneeded async --- src/calendar/__tests__/Calendar.test.tsx | 6 +++--- src/calendar/__tests__/RangeCalendar.test.tsx | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/calendar/__tests__/Calendar.test.tsx b/src/calendar/__tests__/Calendar.test.tsx index dabe426a1..ac3042e93 100644 --- a/src/calendar/__tests__/Calendar.test.tsx +++ b/src/calendar/__tests__/Calendar.test.tsx @@ -132,7 +132,7 @@ describe("Calendar", () => { expect(testId("current-year")).toHaveTextContent("October 2019"); }); - test("should have min/max values", async () => { + test("should have min/max values", () => { const { getByLabelText: label } = render( { expect(label("Saturday, November 14, 2020")).toHaveFocus(); }); - test("should be able to go to prev/next month when min/max values are set", async () => { + test("should be able to go to prev/next month when min/max values are set", () => { const { getByLabelText: label } = render( { expect(label("Saturday, November 14, 2020")).toHaveFocus(); }); - test("should be able to go to prev/next year when min/max values are set", async () => { + test("should be able to go to prev/next year when min/max values are set", () => { const { getByLabelText: label } = render( { expect(end).toHaveTextContent("30"); }); - it("should announce selected range after finishing selection", async () => { + it("should announce selected range after finishing selection", () => { const { getByLabelText: label } = render(