Skip to content

Commit b207969

Browse files
feat(tooltip): add play function to open popover story
1 parent f0afd56 commit b207969

File tree

2 files changed

+36
-14
lines changed

2 files changed

+36
-14
lines changed

src/components/Tooltip/Tooltip.stories.tsx

Lines changed: 35 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
import * as React from "react"
22
import { RiInformationLine } from "react-icons/ri"
3-
import { Box, HStack } from "@chakra-ui/react"
3+
import { Box } from "@chakra-ui/react"
44
import { Meta, StoryObj } from "@storybook/react"
5+
import { expect, fireEvent, waitFor, within } from "@storybook/test"
56

67
import InlineLink from "../Link"
78
import Translation from "../Translation"
@@ -24,28 +25,49 @@ const meta = {
2425
args: {
2526
content: <TooltipContent />,
2627
children: (
27-
<Box as="span">
28+
<Box as="span" data-testid="tooltip-icon">
2829
<RiInformationLine />
2930
</Box>
3031
),
3132
},
33+
argTypes: {
34+
children: {
35+
table: {
36+
disable: true,
37+
},
38+
},
39+
content: {
40+
table: {
41+
disable: true,
42+
},
43+
},
44+
onBeforeOpen: {
45+
table: {
46+
disable: true,
47+
},
48+
},
49+
},
3250
} satisfies Meta<TooltipType>
3351

3452
export default meta
3553

3654
type Story = StoryObj<typeof meta>
3755

38-
export const Tooltip: Story = {
39-
render: (args) => (
40-
<HStack>
41-
<TooltipComponent {...args} />
42-
</HStack>
43-
),
44-
}
56+
export const Basic: Story = {}
4557

46-
// for chromatic visual testing
47-
export const AlwaysOpen: Story = {
48-
args: {
49-
isOpen: true,
58+
// for chromatic story snapshot showing the rendered popover
59+
export const OnOpen: Story = {
60+
play: async ({ canvasElement }) => {
61+
// Add delay for snapshot capture of the popover
62+
const canvas = within(canvasElement)
63+
const canvasParent = within(canvasElement.parentElement!)
64+
65+
const tooltipIcon = canvas.getByTestId("tooltip-icon")
66+
67+
fireEvent.mouseOver(tooltipIcon)
68+
69+
await waitFor(async () => {
70+
await expect(canvasParent.getByTestId("tooltip-popover")).toBeVisible()
71+
})
5072
},
5173
}

src/components/Tooltip/index.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ const Tooltip: React.FC<IProps> = ({
6969
>
7070
<PopoverTrigger>{children}</PopoverTrigger>
7171
<Portal>
72-
<PopoverContent>
72+
<PopoverContent data-testid="tooltip-popover">
7373
<PopoverArrow />
7474
<PopoverBody>{content}</PopoverBody>
7575
</PopoverContent>

0 commit comments

Comments
 (0)