/** * Copyright 2021 Palantir Technologies, Inc. All rights reserved. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ /* eslint-disable @typescript-eslint/no-deprecated */ import { render, screen, waitFor } from "@testing-library/react"; import userEvent from "@testing-library/user-event"; import { afterAll, afterEach, beforeAll, beforeEach, describe, expect, it, type MockInstance, vi, } from "@blueprintjs/test-commons/vitest"; import { Button, PopupKind, Tooltip } from ".."; import { Classes } from "../../common"; import * as Errors from "../../common/errors"; import * as Utils from "../../common/utils"; import { Popover } from "./popover"; import { type PopoverInteractionKind } from "./popoverProps"; describe("", () => { describe("validation", () => { let warnSpy: MockInstance; // use vi.spyOn to prevent warnings from appearing in the test logs beforeAll(() => (warnSpy = vi.spyOn(console, "warn").mockImplementation(vi.fn()))); beforeEach(() => warnSpy.mockClear()); afterAll(() => warnSpy.mockRestore()); it("throws error if given no target", () => { render(); expect(warnSpy).toHaveBeenCalledWith(Errors.POPOVER_REQUIRES_TARGET); }); it("warns if given > 1 target elements", () => { render( , ); expect(warnSpy).not.toHaveBeenCalledWith(Errors.POPOVER_WARN_REACT19); }); it("warns once on React 19", () => { const warnSpy = vi.spyOn(console, "warn").mockImplementation(vi.fn()); vi.spyOn(Utils, "getReactMajorVersion").mockReturnValue(19); render( , ); expect(warnSpy).toHaveBeenCalledWith(Errors.POPOVER_WARN_REACT19); }); }); describe("rendering", () => { it("adds POPOVER_OPEN class to target when the popover is open", async () => { const user = userEvent.setup(); const { container } = render( } shouldReturnFocusOnClose={true} usePortal={false} > } isOpen={true} onClose={onClose} > } isOpen={true} onInteraction={onInteraction} > } defaultIsOpen={true}> } defaultIsOpen={true} usePortal={true} > } defaultIsOpen={true} usePortal={false} > } defaultIsOpen={true}> } defaultIsOpen={true} > } defaultIsOpen={true} >