({
id = 'test-tooltip',
anchorText = 'Hover Me',
anchorProps = {},
tooltipProps = {},
anchor = <span data-tooltip-id={id}>{anchorText}</span>,
} = {})
| 68 | } |
| 69 | |
| 70 | export function renderTooltip({ |
| 71 | id = 'test-tooltip', |
| 72 | anchorText = 'Hover Me', |
| 73 | anchorProps = {}, |
| 74 | tooltipProps = {}, |
| 75 | anchor = <span data-tooltip-id={id}>{anchorText}</span>, |
| 76 | } = {}) { |
| 77 | const view = render( |
| 78 | <> |
| 79 | {React.isValidElement(anchor) |
| 80 | ? React.cloneElement(anchor, { |
| 81 | 'data-tooltip-id': anchor.props['data-tooltip-id'] ?? id, |
| 82 | ...anchorProps, |
| 83 | }) |
| 84 | : anchor} |
| 85 | <TooltipController id={id} content={`${id} content`} {...tooltipProps} /> |
| 86 | </>, |
| 87 | ) |
| 88 | |
| 89 | const getAnchor = () => |
| 90 | anchorProps['aria-label'] |
| 91 | ? screen.getByLabelText(anchorProps['aria-label']) |
| 92 | : screen.getByText(anchorText) |
| 93 | |
| 94 | return { |
| 95 | ...view, |
| 96 | id, |
| 97 | getAnchor, |
| 98 | } |
| 99 | } |
nothing calls this directly
no outgoing calls
no test coverage detected