| 
5 | 5 |  * found at http://www.apache.org/licenses/LICENSE-2.0.  | 
6 | 6 |  */  | 
7 | 7 | 
 
  | 
8 |  | -import React, { createRef, HTMLAttributes } from 'react';  | 
 | 8 | +import React, { act, createRef, HTMLAttributes } from 'react';  | 
9 | 9 | import userEvent from '@testing-library/user-event';  | 
10 | 10 | import { render, fireEvent, waitFor } from '@testing-library/react';  | 
11 |  | -import { act } from 'react-dom/test-utils';  | 
12 | 11 | import { KEYS } from '@zendeskgarden/container-utilities';  | 
13 | 12 | import { TooltipContainer, ITooltipContainerProps } from './';  | 
14 | 13 | 
 
  | 
@@ -194,6 +193,76 @@ describe('TooltipContainer', () => {  | 
194 | 193 |         expect(getByRole('tooltip')).toHaveAttribute('aria-hidden', 'false');  | 
195 | 194 |       });  | 
196 | 195 |     });  | 
 | 196 | + | 
 | 197 | +    describe('tooltip suppression with expanded popup', () => {  | 
 | 198 | +      it('should not show tooltip on focus when trigger has expanded popup', async () => {  | 
 | 199 | +        const { getByText } = render(  | 
 | 200 | +          <BasicExample triggerProps={{ 'aria-haspopup': true, 'aria-expanded': true }} />  | 
 | 201 | +        );  | 
 | 202 | + | 
 | 203 | +        await user.tab();  | 
 | 204 | +        act(() => {  | 
 | 205 | +          jest.runOnlyPendingTimers();  | 
 | 206 | +        });  | 
 | 207 | + | 
 | 208 | +        expect(getByText('tooltip')).toHaveAttribute('aria-hidden', 'true');  | 
 | 209 | +      });  | 
 | 210 | + | 
 | 211 | +      it('should not show tooltip on mouse enter when trigger has expanded popup', async () => {  | 
 | 212 | +        const { getByText } = render(  | 
 | 213 | +          <BasicExample triggerProps={{ 'aria-haspopup': true, 'aria-expanded': true }} />  | 
 | 214 | +        );  | 
 | 215 | + | 
 | 216 | +        await user.hover(getByText('trigger'));  | 
 | 217 | +        act(() => {  | 
 | 218 | +          jest.runOnlyPendingTimers();  | 
 | 219 | +        });  | 
 | 220 | + | 
 | 221 | +        expect(getByText('tooltip')).toHaveAttribute('aria-hidden', 'true');  | 
 | 222 | +      });  | 
 | 223 | + | 
 | 224 | +      it('should allow tooltip to show when popup collapses', async () => {  | 
 | 225 | +        const { getByText, getByRole, rerender } = render(  | 
 | 226 | +          <BasicExample triggerProps={{ 'aria-haspopup': true, 'aria-expanded': true }} />  | 
 | 227 | +        );  | 
 | 228 | +        const trigger = getByText('trigger');  | 
 | 229 | + | 
 | 230 | +        // Initially try to show tooltip with expanded popup - should be suppressed  | 
 | 231 | +        await user.hover(trigger);  | 
 | 232 | +        act(() => {  | 
 | 233 | +          jest.runOnlyPendingTimers();  | 
 | 234 | +        });  | 
 | 235 | + | 
 | 236 | +        expect(getByText('tooltip')).toHaveAttribute('aria-hidden', 'true');  | 
 | 237 | + | 
 | 238 | +        // Collapse popup  | 
 | 239 | +        rerender(<BasicExample triggerProps={{ 'aria-haspopup': true, 'aria-expanded': false }} />);  | 
 | 240 | + | 
 | 241 | +        // Now try to show tooltip again  | 
 | 242 | +        await user.unhover(trigger);  | 
 | 243 | +        await user.hover(trigger);  | 
 | 244 | +        act(() => {  | 
 | 245 | +          jest.runOnlyPendingTimers();  | 
 | 246 | +        });  | 
 | 247 | + | 
 | 248 | +        expect(getByRole('tooltip')).toHaveAttribute('aria-hidden', 'false');  | 
 | 249 | +      });  | 
 | 250 | + | 
 | 251 | +      it('should handle trigger without aria-haspopup normally', async () => {  | 
 | 252 | +        const { getByText, getByRole } = render(  | 
 | 253 | +          <BasicExample triggerProps={{ 'aria-expanded': true }} />  | 
 | 254 | +        );  | 
 | 255 | +        const trigger = getByText('trigger');  | 
 | 256 | + | 
 | 257 | +        await user.hover(trigger);  | 
 | 258 | +        act(() => {  | 
 | 259 | +          jest.runOnlyPendingTimers();  | 
 | 260 | +        });  | 
 | 261 | + | 
 | 262 | +        // Should show tooltip normally since aria-haspopup is not true  | 
 | 263 | +        expect(getByRole('tooltip')).toHaveAttribute('aria-hidden', 'false');  | 
 | 264 | +      });  | 
 | 265 | +    });  | 
197 | 266 |   });  | 
198 | 267 | 
 
  | 
199 | 268 |   describe('getTooltipProps', () => {  | 
@@ -242,23 +311,5 @@ describe('TooltipContainer', () => {  | 
242 | 311 | 
 
  | 
243 | 312 |       expect(getByText('tooltip')).toHaveAttribute('aria-hidden', 'true');  | 
244 | 313 |     });  | 
245 |  | - | 
246 |  | -    it('should close tooltip if the trigger has an expanded popup', async () => {  | 
247 |  | -      const { getByRole, getByText, rerender } = render(<BasicExample />);  | 
248 |  | -      const trigger = getByText('trigger');  | 
249 |  | - | 
250 |  | -      await user.hover(trigger);  | 
251 |  | - | 
252 |  | -      act(() => {  | 
253 |  | -        jest.runOnlyPendingTimers();  | 
254 |  | -      });  | 
255 |  | - | 
256 |  | -      expect(getByRole('tooltip')).toHaveAttribute('aria-hidden', 'false');  | 
257 |  | - | 
258 |  | -      // Simulate triggering a popup  | 
259 |  | -      rerender(<BasicExample triggerProps={{ 'aria-haspopup': true, 'aria-expanded': true }} />);  | 
260 |  | - | 
261 |  | -      expect(getByText('tooltip')).toHaveAttribute('aria-hidden', 'true');  | 
262 |  | -    });  | 
263 | 314 |   });  | 
264 | 315 | });  | 
0 commit comments