-
Notifications
You must be signed in to change notification settings - Fork 173
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: tooltip renders when the label is missing
- Loading branch information
1 parent
240c73e
commit 14b295a
Showing
3 changed files
with
53 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
'@strapi/design-system': patch | ||
--- | ||
|
||
Prevent tooltip from rendering when the label property is not passed |
46 changes: 46 additions & 0 deletions
46
packages/design-system/src/components/Tooltip/Tooltip.test.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
import { render as renderHarness } from '@test/utils'; | ||
|
||
import { Button } from '../Button'; | ||
|
||
import { Tooltip, type TooltipProps } from './Tooltip'; | ||
|
||
const render = (props: Partial<TooltipProps> = {}) => | ||
renderHarness( | ||
<Tooltip {...props}> | ||
<Button>My button</Button> | ||
</Tooltip>, | ||
); | ||
|
||
describe('Tooltip', () => { | ||
it('should render and be accessible with a label', async () => { | ||
const { user, getByRole, findByRole } = render({ | ||
label: 'My tooltip', | ||
}); | ||
|
||
await user.hover(getByRole('button')); | ||
|
||
expect(await findByRole('tooltip', { name: 'My tooltip' })).toBeInTheDocument(); | ||
}); | ||
|
||
it('should render the label and not the description if both are provided', async () => { | ||
const { user, getByRole, findByRole, queryByRole } = render({ | ||
label: 'My tooltip label', | ||
description: 'My tooltip description', | ||
}); | ||
|
||
await user.hover(getByRole('button')); | ||
|
||
expect(await findByRole('tooltip', { name: 'My tooltip label' })).toBeInTheDocument(); | ||
expect(queryByRole('tooltip', { name: 'My tooltip description' })).not.toBeInTheDocument(); | ||
}); | ||
|
||
it('should not render when the label is empty', async () => { | ||
const { user, getByRole, queryByRole } = render({ | ||
label: '', | ||
}); | ||
|
||
await user.hover(getByRole('button')); | ||
|
||
expect(queryByRole('tooltip', { name: 'My tooltip' })).not.toBeInTheDocument(); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters