From d12a01b1c4548f711a121fbfc838fcf7b6158e0a Mon Sep 17 00:00:00 2001 From: Robin Date: Tue, 10 Sep 2024 18:21:19 -0400 Subject: [PATCH] Test StarRating --- src/input/StarRating.test.tsx | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 src/input/StarRating.test.tsx diff --git a/src/input/StarRating.test.tsx b/src/input/StarRating.test.tsx new file mode 100644 index 00000000..f15bb107 --- /dev/null +++ b/src/input/StarRating.test.tsx @@ -0,0 +1,29 @@ +/* +Copyright 2024 New Vector Ltd. + +SPDX-License-Identifier: AGPL-3.0-only +Please see LICENSE in the repository root for full details. +*/ + +import { test, expect, vi } from "vitest"; +import { render, screen } from "@testing-library/react"; +import { axe } from "vitest-axe"; +import userEvent from "@testing-library/user-event"; + +import { StarRatingInput } from "./StarRatingInput"; + +test("StarRatingInput is accessible", async () => { + const user = userEvent.setup(); + const onChange = vi.fn(); + const { container } = render( + , + ); + expect(await axe(container)).toHaveNoViolations(); + // Change the rating to 4 stars + await user.click( + ( + await screen.findAllByRole("radio", { name: "star_rating_input_label" }) + )[3], + ); + expect(onChange).toBeCalledWith(4); +});