From d24ad2705819b2eb20a250a616b506abb4e26ae2 Mon Sep 17 00:00:00 2001 From: Anurag Date: Thu, 22 Oct 2020 19:12:58 +0530 Subject: [PATCH] test: assert live announcer tests in range calendar --- src/calendar/__tests__/RangeCalendar.test.tsx | 32 +++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/src/calendar/__tests__/RangeCalendar.test.tsx b/src/calendar/__tests__/RangeCalendar.test.tsx index 9947b1b16..57f2538d3 100644 --- a/src/calendar/__tests__/RangeCalendar.test.tsx +++ b/src/calendar/__tests__/RangeCalendar.test.tsx @@ -1,4 +1,6 @@ +jest.mock("../../utils/LiveAnnouncer"); import * as React from "react"; +import { cleanup } from "@testing-library/react"; import { axe, render, press } from "reakit-test-utils"; import { @@ -13,6 +15,13 @@ import { RangeCalendarInitialState, } from "../index"; import { isEndSelection, isStartSelection } from "../../utils/test-utils"; +import { announce, destroyAnnouncer } from "../../utils/LiveAnnouncer"; + +afterEach(cleanup); + +beforeEach(() => { + destroyAnnouncer(); +}); const RangeCalendarComp: React.FC = props => { const state = useRangeCalendarState(props); @@ -105,6 +114,29 @@ describe("RangeCalendar", () => { expect(end).toHaveTextContent("30"); }); + it("should announce selected range after finishing selection", async () => { + const { getByLabelText: label } = render( + , + ); + + press.Tab(); + press.Tab(); + press.Tab(); + press.Tab(); + press.Tab(); + press.Enter(label(/Monday, October 7, 2019 selected/)); + press.ArrowDown(); + press.ArrowRight(); + press.Enter(label(/Tuesday, October 15, 2019/)); + + expect(announce).toHaveBeenCalledTimes(2); + expect(announce).toHaveBeenLastCalledWith( + "Selected range, from 7th Oct 2019 to 15th Oct 2019", + ); + }); + it("should be able to select ranges with keyboard navigation", () => { const { getByLabelText: label, getByTestId: testId, baseElement } = render(