Junior Garcia 6492d36c68
Refactor/rebrand (#4532)
* chore: rebrand in progress

* chore: update docs to use heroui

* chore: components renbranded

* chore: figma moved to the docs files

* fix: posthog config

* fix(docs): extra classname in form example (#4465)

* chore: clean git

* chore: make heroui private

* chore: new logo

* chore: node env var renamed

* chore: public robots txt deleted

* chore: wrangler installed

* chore: wrangler renamed

* chore: cloudlfare workers removed

* chore: force vercel deploy

* refactor: first migration and provider

* refactor: rename nextui plugin

* refactor: rename github site

* refactor: rename CONTRIBUTING

* refactor: rename package name

* refactor: nextjs image hostname

* refactor: mdx repo nextui-org rename frontio-ai

* refactor: nextui.org rename heroui.com

* refactor: add heroui to missing places

* fix: heroui plugin name

* fix: update docs

* docs: nextui to heroui add npmrc pnpm migratation

* chore: rename all packages with new org name

* chore: replace frontio-ai by frontioai

* chore: revert previous changes

* chore: small adjustment

* chore: doc updated

* feat: blog

* chore: avatar updated

* fix: url

* chore: add new ogimage

* fix: ogimage command

* fix: heroui name and storybook welcome page

* fix: og image url

* feat: favicon and icon changed

---------

Co-authored-by: աӄա <wingkwong.code@gmail.com>
Co-authored-by: winches <329487092@qq.com>
2025-01-16 15:03:45 -03:00

85 lines
2.2 KiB
TypeScript

import * as React from "react";
import {render, fireEvent, act} from "@testing-library/react";
import {Button} from "@heroui/button";
import {Tooltip} from "../src";
// e.g. console.error Warning: Function components cannot be given refs.
// Attempts to access this ref will fail. Did you mean to use React.forwardRef()?
const spy = jest.spyOn(console, "error").mockImplementation(() => {});
describe("Tooltip", () => {
afterEach(() => {
jest.clearAllMocks();
});
it("should throw error if no children is passed", () => {
const spy = jest.spyOn(console, "warn").mockImplementation(() => {});
render(<Tooltip content="tooltip" />);
expect(spy).toHaveBeenCalled();
});
it("should render correctly", () => {
const wrapper = render(
<Tooltip content="tooltip">
<Button>Trigger</Button>
</Tooltip>,
);
expect(() => wrapper.unmount()).not.toThrow();
expect(spy).toHaveBeenCalledTimes(0);
});
it("ref should be forwarded", () => {
const ref = React.createRef<HTMLDivElement>();
render(
<Tooltip ref={ref} defaultOpen content="tooltip">
<Button>Trigger</Button>
</Tooltip>,
);
expect(ref.current).not.toBeNull();
});
it("should hide the tooltip when pressing the escape key", async () => {
const onClose = jest.fn();
const wrapper = render(
<Tooltip defaultOpen content={<p data-testid="content-test">tooltip</p>} onClose={onClose}>
<Button>Trigger</Button>
</Tooltip>,
);
const content = wrapper.getByTestId("content-test");
await act(async () => {
await fireEvent.keyDown(content, {key: "Escape"});
expect(onClose).toHaveBeenCalledTimes(1);
});
});
it("should still hide the tooltip when pressing the escape key if isDismissable is false", () => {
const onClose = jest.fn();
const wrapper = render(
<Tooltip
defaultOpen
content={<p data-testid="content-test">tooltip</p>}
isDismissable={false}
onClose={onClose}
>
<Button>Trigger</Button>
</Tooltip>,
);
const content = wrapper.getByTestId("content-test");
fireEvent.keyDown(content, {key: "Escape"});
expect(onClose).toHaveBeenCalledTimes(1);
});
});