Skip to content

Commit e131f26

Browse files
authored
Merge pull request #330 from eccenca/feature/addTooltipTests-CMEM-6871
Add tooltip tests to prove usePlaceholder functionality (CMEM-6871)
2 parents f7d2e9c + 2e73515 commit e131f26

4 files changed

Lines changed: 73 additions & 1 deletion

File tree

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,11 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/) and this p
66

77
## [Unreleased]
88

9+
### Added
10+
11+
- `<Tooltip />`
12+
- prove useage of `usePlaceholder` by jest test coverage
13+
914
## [24.4.1] - 2025-08-25
1015

1116
### Fixed

src/components/Tooltip/Tooltip.stories.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import React from "react";
22
import { loremIpsum } from "react-lorem-ipsum";
33
import { OverlaysProvider } from "@blueprintjs/core";
44
import { Meta, StoryFn } from "@storybook/react";
5+
import { fn } from "@storybook/test";
56

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

@@ -34,6 +35,7 @@ Default.args = {
3435
children: "hover me",
3536
content: testContent,
3637
addIndicator: true,
38+
onOpening: fn(),
3739
};
3840

3941
export const MarkdownSupport = Template.bind({});
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
import React from "react";
2+
import { fireEvent, render, screen, waitFor } from "@testing-library/react";
3+
4+
import "@testing-library/jest-dom";
5+
6+
import { CLASSPREFIX as eccgui } from "../../configuration/constants";
7+
8+
import Tooltip from "./Tooltip";
9+
import { Default as TooltipStory } from "./Tooltip.stories";
10+
11+
const checkForPlaceholderClass = (container: HTMLElement, tobe: number) => {
12+
expect(container.getElementsByClassName(`${eccgui}-tooltip__wrapper--placeholder`).length).toBe(tobe);
13+
};
14+
15+
describe("Tooltip", () => {
16+
it("should render placeholder automatically for text tooltip", () => {
17+
const { container } = render(<Tooltip {...TooltipStory.args} content="this is a simple text tooltip" />);
18+
checkForPlaceholderClass(container, 1);
19+
});
20+
it("should render no placeholder automatically for html tooltip", () => {
21+
const { container } = render(
22+
<Tooltip {...TooltipStory.args} content={<div>this is a simple text tooltip</div>} />
23+
);
24+
checkForPlaceholderClass(container, 0);
25+
});
26+
it("should render placeholder when `usePlaceholder===true`", () => {
27+
const { container } = render(
28+
<Tooltip {...TooltipStory.args} content={<div>this is a simple text tooltip</div>} usePlaceholder={true} />
29+
);
30+
checkForPlaceholderClass(container, 1);
31+
});
32+
it("should render no placeholder when `usePlaceholder===false`", () => {
33+
const { container } = render(
34+
<Tooltip {...TooltipStory.args} content="this is a simple text tooltip" usePlaceholder={false} />
35+
);
36+
checkForPlaceholderClass(container, 0);
37+
});
38+
it("should be displayed on first mouse hover when no placeholder is used", async () => {
39+
const { container } = render(<Tooltip {...TooltipStory.args} usePlaceholder={false} />);
40+
fireEvent.mouseEnter(container.getElementsByClassName(`${eccgui}-tooltip__wrapper`)[0]);
41+
expect(await screen.findByText(TooltipStory.args.content)).toBeVisible();
42+
});
43+
it("should not be displayed on first mouse hover when placeholder is used but placeholder markup is swapped", async () => {
44+
const { container } = render(<Tooltip {...TooltipStory.args} usePlaceholder={true} />);
45+
fireEvent.mouseEnter(container.getElementsByClassName(`${eccgui}-tooltip__wrapper--placeholder`)[0]);
46+
checkForPlaceholderClass(container, 1);
47+
await waitFor(() => {
48+
expect(screen.queryAllByText(TooltipStory.args.content)).toHaveLength(0);
49+
checkForPlaceholderClass(container, 0);
50+
});
51+
});
52+
it("should be displayed on two continues mouse hover when placeholder is used", async () => {
53+
const { container } = render(<Tooltip {...TooltipStory.args} usePlaceholder={true} />);
54+
fireEvent.mouseEnter(container.getElementsByClassName(`${eccgui}-tooltip__wrapper`)[0]);
55+
checkForPlaceholderClass(container, 1);
56+
await waitFor(async () => {
57+
expect(screen.queryAllByText(TooltipStory.args.content)).toHaveLength(0);
58+
checkForPlaceholderClass(container, 0);
59+
fireEvent.mouseOver(container.getElementsByClassName(`${eccgui}-tooltip__wrapper`)[0]);
60+
expect(await screen.findByText(TooltipStory.args.content)).toBeVisible();
61+
});
62+
});
63+
});

src/components/Tooltip/Tooltip.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,9 @@ export const Tooltip = ({
199199
targetProps={
200200
{
201201
...otherTooltipProps.targetProps,
202-
"data-postplaceholder": `id${eventMemory.current}${searchId.current}`,
202+
"data-postplaceholder": eventMemory.current
203+
? `id${eventMemory.current}${searchId.current}`
204+
: undefined,
203205
} as React.HTMLProps<HTMLElement>
204206
}
205207
>

0 commit comments

Comments
 (0)