@@ -5,12 +5,16 @@ SPDX-License-Identifier: AGPL-3.0-only OR LicenseRef-Element-Commercial
55Please see LICENSE files in the repository root for full details.
66*/
77
8- import { describe , it , expect } from "vitest" ;
9- import { render } from "@testing-library/react" ;
8+ import { describe , it , expect , vi } from "vitest" ;
9+ import { render , screen } from "@testing-library/react" ;
1010import React from "react" ;
1111import { composeStories } from "@storybook/react" ;
12+ import userEvent from "@testing-library/user-event" ;
1213
1314import * as stories from "./IconButton.stories" ;
15+ import { IconButton } from "./IconButton" ;
16+ import { TooltipProvider } from "../../Tooltip/TooltipProvider" ;
17+ import { UserIcon } from "@vector-im/compound-design-tokens/assets/web/icons" ;
1418
1519const {
1620 Default,
@@ -56,4 +60,30 @@ describe("IconButton", () => {
5660 const { container } = render ( < WithSecondaryKindAndNoBackground /> ) ;
5761 expect ( container ) . toMatchSnapshot ( ) ;
5862 } ) ;
63+ it ( "calls onTooltipOpenChange when the tooltip opens and closes" , async ( ) => {
64+ const user = userEvent . setup ( ) ;
65+ const onTooltipOpenChange = vi . fn ( ) ;
66+ render (
67+ < TooltipProvider >
68+ < IconButton tooltip = "Profile" onTooltipOpenChange = { onTooltipOpenChange } >
69+ < UserIcon />
70+ </ IconButton >
71+ </ TooltipProvider > ,
72+ ) ;
73+
74+ await user . tab ( ) ;
75+ expect ( screen . getByRole ( "button" ) ) . toHaveFocus ( ) ;
76+ expect ( onTooltipOpenChange ) . toHaveBeenLastCalledWith (
77+ true ,
78+ expect . anything ( ) ,
79+ expect . anything ( ) ,
80+ ) ;
81+
82+ await user . tab ( ) ;
83+ expect ( onTooltipOpenChange ) . toHaveBeenLastCalledWith (
84+ false ,
85+ expect . anything ( ) ,
86+ expect . anything ( ) ,
87+ ) ;
88+ } ) ;
5989} ) ;
0 commit comments