Skip to content

Commit

Permalink
Add nested unit test
Browse files Browse the repository at this point in the history
  • Loading branch information
ciampo committed Jan 4, 2024
1 parent ac7c722 commit 02f9835
Showing 1 changed file with 46 additions and 0 deletions.
46 changes: 46 additions & 0 deletions packages/components/src/tooltip/test/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -436,4 +436,50 @@ describe( 'Tooltip', () => {
await waitForTooltipToHide();
} );
} );

describe( 'nested', () => {
it( 'should render the outer tooltip and ignore inner tooltips', async () => {
render(
<Tooltip text="Outer tooltip">
<Tooltip text="Middle tooltip">
<Tooltip text="Inner tooltip">
<Button>Tooltip anchor</Button>
</Tooltip>
</Tooltip>
</Tooltip>
);

// Hover the anchor. Only the outer tooltip should show.
await hover(
screen.getByRole( 'button', {
name: 'Tooltip anchor',
} )
);

await waitFor( () =>
expect(
screen.getByRole( 'tooltip', { name: 'Outer tooltip' } )
).toBeVisible()
);
expect(
screen.queryByRole( 'tooltip', { name: 'Middle tooltip' } )
).not.toBeInTheDocument();
expect(
screen.queryByRole( 'tooltip', { name: 'Inner tooltip' } )
).not.toBeInTheDocument();
expect(
screen.getByRole( 'button', {
description: 'Outer tooltip',
} )
).toBeInTheDocument();

// Hover outside of the anchor, tooltip should hide
await hoverOutside();
await waitFor( () =>
expect(
screen.queryByRole( 'tooltip', { name: 'Outer tooltip' } )
).not.toBeInTheDocument()
);
} );
} );
} );

0 comments on commit 02f9835

Please sign in to comment.