Debian Codegraph @

install/freeipa-webui/src/components/layouts/PopoverWithIconLayout/PopoverWithIconLayout.test.tsx

raw
1 import React from "react";
2 import {
3 render,
4 screen,
5 fireEvent,
6 cleanup,
7 waitFor,
8 } from "@testing-library/react";
9 import userEvent from "@testing-library/user-event";
10 import { describe, expect, it, vi, afterEach } from "vitest";
11 // Component
12 import PopoverWithIconLayout from "./PopoverWithIconLayout";
13
14 const TestMessage = <div>Popover Content</div>;
15
16 describe("PopoverWithIconLayout", () => {
17 afterEach(() => {
18 vi.clearAllMocks();
19 cleanup();
20 });
21
22 it("renders the question icon", () => {
23 render(<PopoverWithIconLayout message={TestMessage} />);
24 const icon = screen.getByRole("img", { hidden: true });
25 expect(icon).toBeInTheDocument();
26 });
27
28 it("displays popover content on click", async () => {
29 render(<PopoverWithIconLayout message={TestMessage} />);
30 const icon = screen.getByRole("img", { hidden: true });
31 fireEvent.click(icon);
32
33 expect(await screen.findByText("Popover Content")).toBeInTheDocument();
34 });
35
36 it("displays popover content on hover if triggerHover is true", async () => {
37 const user = userEvent.setup();
38 render(<PopoverWithIconLayout message={TestMessage} triggerHover={true} />);
39 const icon = screen.getByRole("img", { hidden: true });
40
41 await user.hover(icon);
42
43 await waitFor(() => {
44 expect(screen.getByText("Popover Content")).toBeInTheDocument();
45 });
46 });
47 });