|
4 | 4 |
|
5 | 5 | import { render, screen, waitFor } from "@testing-library/react"; |
6 | 6 | import userEvent from "@testing-library/user-event"; |
| 7 | +import { createRef } from "react"; |
7 | 8 |
|
8 | 9 | import { afterAll, beforeEach, describe, expect, it, vi } from "@blueprintjs/test-commons/vitest"; |
9 | 10 |
|
@@ -236,6 +237,32 @@ describe("<PopoverNext>", () => { |
236 | 237 | expect(popoverElement).toHaveClass(Classes.DARK); |
237 | 238 | }); |
238 | 239 |
|
| 240 | + it("attaches popoverRef to the popover element", async () => { |
| 241 | + const popoverRef = createRef<HTMLDivElement>(); |
| 242 | + const { container } = render( |
| 243 | + <PopoverNext content="content" isOpen={true} popoverRef={popoverRef} usePortal={false}> |
| 244 | + <Button text="target" /> |
| 245 | + </PopoverNext>, |
| 246 | + ); |
| 247 | + |
| 248 | + await waitFor(() => expect(screen.getByText("content")).toBeInTheDocument()); |
| 249 | + |
| 250 | + const popoverElement = container.querySelector(`.${Classes.POPOVER}`); |
| 251 | + expect(popoverElement).toBeInTheDocument(); |
| 252 | + expect(popoverRef.current).toBe(popoverElement); |
| 253 | + }); |
| 254 | + |
| 255 | + it("popoverRef returns null when closed", () => { |
| 256 | + const ref = createRef<HTMLDivElement>(); |
| 257 | + render( |
| 258 | + <PopoverNext popoverRef={ref} content="content" isOpen={false}> |
| 259 | + <Button text="target" /> |
| 260 | + </PopoverNext>, |
| 261 | + ); |
| 262 | + |
| 263 | + expect(ref.current).toBeNull(); |
| 264 | + }); |
| 265 | + |
239 | 266 | it("renders with aria-haspopup attr", () => { |
240 | 267 | const { container } = render( |
241 | 268 | <PopoverNext content="content" isOpen={true}> |
|
0 commit comments