Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,11 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/) and this p

## [Unreleased]

### Added

- `<Tooltip />`
- prove useage of `usePlaceholder` by jest test coverage

## [24.4.1] - 2025-08-25

### Fixed
Expand Down
2 changes: 2 additions & 0 deletions src/components/Tooltip/Tooltip.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import React from "react";
import { loremIpsum } from "react-lorem-ipsum";
import { OverlaysProvider } from "@blueprintjs/core";
import { Meta, StoryFn } from "@storybook/react";
import { fn } from "@storybook/test";

import { Tooltip } from "../../index";

Expand Down Expand Up @@ -34,6 +35,7 @@ Default.args = {
children: "hover me",
content: testContent,
addIndicator: true,
onOpening: fn(),
};

export const MarkdownSupport = Template.bind({});
Expand Down
63 changes: 63 additions & 0 deletions src/components/Tooltip/Tooltip.test.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
import React from "react";
import { fireEvent, render, screen, waitFor } from "@testing-library/react";

import "@testing-library/jest-dom";

import { CLASSPREFIX as eccgui } from "../../configuration/constants";

import Tooltip from "./Tooltip";
import { Default as TooltipStory } from "./Tooltip.stories";

const checkForPlaceholderClass = (container: HTMLElement, tobe: number) => {
expect(container.getElementsByClassName(`${eccgui}-tooltip__wrapper--placeholder`).length).toBe(tobe);
};

describe("Tooltip", () => {
it("should render placeholder automatically for text tooltip", () => {
const { container } = render(<Tooltip {...TooltipStory.args} content="this is a simple text tooltip" />);
checkForPlaceholderClass(container, 1);
});
it("should render no placeholder automatically for html tooltip", () => {
const { container } = render(
<Tooltip {...TooltipStory.args} content={<div>this is a simple text tooltip</div>} />
);
checkForPlaceholderClass(container, 0);
});
it("should render placeholder when `usePlaceholder===true`", () => {
const { container } = render(
<Tooltip {...TooltipStory.args} content={<div>this is a simple text tooltip</div>} usePlaceholder={true} />
);
checkForPlaceholderClass(container, 1);
});
it("should render no placeholder when `usePlaceholder===false`", () => {
const { container } = render(
<Tooltip {...TooltipStory.args} content="this is a simple text tooltip" usePlaceholder={false} />
);
checkForPlaceholderClass(container, 0);
});
it("should be displayed on first mouse hover when no placeholder is used", async () => {
const { container } = render(<Tooltip {...TooltipStory.args} usePlaceholder={false} />);
fireEvent.mouseEnter(container.getElementsByClassName(`${eccgui}-tooltip__wrapper`)[0]);
expect(await screen.findByText(TooltipStory.args.content)).toBeVisible();
});
it("should not be displayed on first mouse hover when placeholder is used but placeholder markup is swapped", async () => {
const { container } = render(<Tooltip {...TooltipStory.args} usePlaceholder={true} />);
fireEvent.mouseEnter(container.getElementsByClassName(`${eccgui}-tooltip__wrapper--placeholder`)[0]);
checkForPlaceholderClass(container, 1);
await waitFor(() => {
expect(screen.queryAllByText(TooltipStory.args.content)).toHaveLength(0);
checkForPlaceholderClass(container, 0);
});
});
it("should be displayed on two continues mouse hover when placeholder is used", async () => {
const { container } = render(<Tooltip {...TooltipStory.args} usePlaceholder={true} />);
fireEvent.mouseEnter(container.getElementsByClassName(`${eccgui}-tooltip__wrapper`)[0]);
checkForPlaceholderClass(container, 1);
await waitFor(async () => {
expect(screen.queryAllByText(TooltipStory.args.content)).toHaveLength(0);
checkForPlaceholderClass(container, 0);
fireEvent.mouseOver(container.getElementsByClassName(`${eccgui}-tooltip__wrapper`)[0]);
expect(await screen.findByText(TooltipStory.args.content)).toBeVisible();
});
});
});
4 changes: 3 additions & 1 deletion src/components/Tooltip/Tooltip.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,9 @@ export const Tooltip = ({
targetProps={
{
...otherTooltipProps.targetProps,
"data-postplaceholder": `id${eventMemory.current}${searchId.current}`,
"data-postplaceholder": eventMemory.current
? `id${eventMemory.current}${searchId.current}`
: undefined,
} as React.HTMLProps<HTMLElement>
}
>
Expand Down