Skip to content

Commit

Permalink
test: assert live announcer tests in range calendar
Browse files Browse the repository at this point in the history
  • Loading branch information
anuraghazra committed Oct 22, 2020
1 parent 5eda94c commit d24ad27
Showing 1 changed file with 32 additions and 0 deletions.
32 changes: 32 additions & 0 deletions src/calendar/__tests__/RangeCalendar.test.tsx
Original file line number Diff line number Diff line change
@@ -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 {
Expand All @@ -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<RangeCalendarInitialState> = props => {
const state = useRangeCalendarState(props);
Expand Down Expand Up @@ -105,6 +114,29 @@ describe("RangeCalendar", () => {
expect(end).toHaveTextContent("30");
});

it("should announce selected range after finishing selection", async () => {
const { getByLabelText: label } = render(
<RangeCalendarComp
defaultValue={{ start: "2019-10-07", end: "2019-10-30" }}
/>,
);

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(
<RangeCalendarComp
Expand Down

0 comments on commit d24ad27

Please sign in to comment.