1
1
import * as React from "react"
2
2
import { RiInformationLine } from "react-icons/ri"
3
- import { Box , HStack } from "@chakra-ui/react"
3
+ import { Box } from "@chakra-ui/react"
4
4
import { Meta , StoryObj } from "@storybook/react"
5
+ import { expect , fireEvent , waitFor , within } from "@storybook/test"
5
6
6
7
import InlineLink from "../Link"
7
8
import Translation from "../Translation"
@@ -24,28 +25,49 @@ const meta = {
24
25
args : {
25
26
content : < TooltipContent /> ,
26
27
children : (
27
- < Box as = "span" >
28
+ < Box as = "span" data-testid = "tooltip-icon" >
28
29
< RiInformationLine />
29
30
</ Box >
30
31
) ,
31
32
} ,
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
+ } ,
32
50
} satisfies Meta < TooltipType >
33
51
34
52
export default meta
35
53
36
54
type Story = StoryObj < typeof meta >
37
55
38
- export const Tooltip : Story = {
39
- render : ( args ) => (
40
- < HStack >
41
- < TooltipComponent { ...args } />
42
- </ HStack >
43
- ) ,
44
- }
56
+ export const Basic : Story = { }
45
57
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
+ } )
50
72
} ,
51
73
}
0 commit comments