@@ -24,11 +24,11 @@ const TooltipAttrs = ({ id, ...anchorParams }) => (
24
24
)
25
25
26
26
describe ( 'tooltip props' , ( ) => {
27
- test ( 'tooltip component - without element reference' , async ( ) => {
27
+ test ( 'tooltip without element reference' , async ( ) => {
28
28
const { container } = render ( < TooltipProps content = "Hello World!" /> )
29
29
const anchorElement = screen . getByText ( 'Lorem Ipsum' )
30
30
31
- userEvent . hover ( anchorElement )
31
+ await userEvent . hover ( anchorElement )
32
32
33
33
await waitFor ( ( ) => {
34
34
expect ( screen . queryByText ( 'Hello World!' ) ) . not . toBeInTheDocument ( )
@@ -38,11 +38,11 @@ describe('tooltip props', () => {
38
38
expect ( container ) . toMatchSnapshot ( )
39
39
} )
40
40
41
- test ( 'basic tooltip component ' , async ( ) => {
41
+ test ( 'basic tooltip' , async ( ) => {
42
42
const { container } = render ( < TooltipProps id = "basic-example" content = "Hello World!" /> )
43
43
const anchorElement = screen . getByText ( 'Lorem Ipsum' )
44
44
45
- userEvent . hover ( anchorElement )
45
+ await userEvent . hover ( anchorElement )
46
46
47
47
let tooltip = null
48
48
@@ -54,13 +54,13 @@ describe('tooltip props', () => {
54
54
expect ( container ) . toMatchSnapshot ( )
55
55
} )
56
56
57
- test ( 'tooltip component with place' , async ( ) => {
57
+ test ( 'tooltip with place' , async ( ) => {
58
58
const { container } = render (
59
59
< TooltipProps id = "example-place" content = "Hello World!" place = "right" /> ,
60
60
)
61
61
const anchorElement = screen . getByText ( 'Lorem Ipsum' )
62
62
63
- userEvent . hover ( anchorElement )
63
+ await userEvent . hover ( anchorElement )
64
64
65
65
let tooltip = null
66
66
@@ -72,11 +72,11 @@ describe('tooltip props', () => {
72
72
expect ( container ) . toMatchSnapshot ( )
73
73
} )
74
74
75
- test ( 'tooltip component with html' , async ( ) => {
75
+ test ( 'tooltip with html' , async ( ) => {
76
76
const { container } = render ( < TooltipProps id = "example-html" html = "<div>Hello World!<div>" /> )
77
77
const anchorElement = screen . getByText ( 'Lorem Ipsum' )
78
78
79
- userEvent . hover ( anchorElement )
79
+ await userEvent . hover ( anchorElement )
80
80
81
81
let tooltip = null
82
82
@@ -87,14 +87,46 @@ describe('tooltip props', () => {
87
87
expect ( tooltip ) . toBeInTheDocument ( )
88
88
expect ( container ) . toMatchSnapshot ( )
89
89
} )
90
+
91
+ test ( 'clickable tooltip' , async ( ) => {
92
+ const id = 'example-clickable'
93
+
94
+ const mockCallBack = jest . fn ( )
95
+ const { container } = render (
96
+ < >
97
+ < span id = { id } > Lorem Ipsum</ span >
98
+ < Tooltip anchorId = { id } clickable >
99
+ < button onClick = { mockCallBack } > button</ button >
100
+ </ Tooltip >
101
+ </ > ,
102
+ )
103
+ const anchorElement = screen . getByText ( 'Lorem Ipsum' )
104
+
105
+ await userEvent . hover ( anchorElement )
106
+
107
+ let tooltip = null
108
+ let button = null
109
+
110
+ await waitFor ( ( ) => {
111
+ tooltip = screen . getByRole ( 'tooltip' )
112
+ button = screen . getByRole ( 'button' )
113
+ } )
114
+
115
+ await userEvent . click ( button )
116
+
117
+ expect ( tooltip ) . toBeInTheDocument ( )
118
+ expect ( button ) . toBeInTheDocument ( )
119
+ expect ( mockCallBack ) . toHaveBeenCalled ( )
120
+ expect ( container ) . toMatchSnapshot ( )
121
+ } )
90
122
} )
91
123
92
124
describe ( 'tooltip attributes' , ( ) => {
93
- test ( 'tooltip component - without element reference' , async ( ) => {
125
+ test ( 'tooltip without element reference' , async ( ) => {
94
126
const { container } = render ( < TooltipAttrs data-tooltip-content = "Hello World!" /> )
95
127
const anchorElement = screen . getByText ( 'Lorem Ipsum' )
96
128
97
- userEvent . hover ( anchorElement )
129
+ await userEvent . hover ( anchorElement )
98
130
99
131
await waitFor ( ( ) => {
100
132
expect ( screen . queryByText ( 'Hello World!' ) ) . not . toBeInTheDocument ( )
@@ -104,13 +136,13 @@ describe('tooltip attributes', () => {
104
136
expect ( container ) . toMatchSnapshot ( )
105
137
} )
106
138
107
- test ( 'basic tooltip component ' , async ( ) => {
139
+ test ( 'basic tooltip' , async ( ) => {
108
140
const { container } = render (
109
141
< TooltipAttrs id = "basic-example-attr" data-tooltip-content = "Hello World!" /> ,
110
142
)
111
143
const anchorElement = screen . getByText ( 'Lorem Ipsum' )
112
144
113
- userEvent . hover ( anchorElement )
145
+ await userEvent . hover ( anchorElement )
114
146
115
147
let tooltip = null
116
148
@@ -123,7 +155,7 @@ describe('tooltip attributes', () => {
123
155
expect ( container ) . toMatchSnapshot ( )
124
156
} )
125
157
126
- test ( 'tooltip component with place' , async ( ) => {
158
+ test ( 'tooltip with place' , async ( ) => {
127
159
const { container } = render (
128
160
< TooltipAttrs
129
161
id = "example-place-attr"
@@ -133,7 +165,7 @@ describe('tooltip attributes', () => {
133
165
)
134
166
const anchorElement = screen . getByText ( 'Lorem Ipsum' )
135
167
136
- userEvent . hover ( anchorElement )
168
+ await userEvent . hover ( anchorElement )
137
169
138
170
let tooltip = null
139
171
0 commit comments