Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(Tooltip): update default delay #2965

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 9 additions & 3 deletions packages/components/avatar/src/Avatar/Avatar.test.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React from 'react';
import { render, screen } from '@testing-library/react';
import { render, screen, waitFor } from '@testing-library/react';
import { CheckCircleIcon } from '@contentful/f36-icons';
import userEvent from '@testing-library/user-event';
import { Avatar } from './Avatar';
Expand All @@ -26,21 +26,27 @@ describe('Avatar', () => {
it('renders an icon when it is provided', () => {
const src = 'https://example.com/image.jpg';
render(<Avatar src={src} icon={<CheckCircleIcon variant="positive" />} />);

expect(screen.queryByTestId('cf-ui-avatar-icon')).toBeInTheDocument();
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This test had no assertion so I added the data-test-id attribute to the icon in the Avatar component.

});

it('renders no tooltip when no props are provided', async () => {
const user = userEvent.setup();
render(<Avatar />);
await user.hover(screen.getByTestId('cf-ui-avatar-fallback'));

expect(screen.queryByTestId('tooltip')).not.toBeInTheDocument();
await waitFor(() =>
expect(screen.queryByTestId('tooltip')).not.toBeInTheDocument(),
);
});

it('renders with tooltip when props are provided', async () => {
const user = userEvent.setup();
render(<Avatar tooltipProps={{ content: 'some content' }} />);
await user.hover(screen.getByTestId('cf-ui-avatar-fallback'));

expect(screen.getByRole('tooltip').textContent).toBe('some content');
await waitFor(() =>
expect(screen.getByRole('tooltip').textContent).toBe('some content'),
);
});
});
6 changes: 5 additions & 1 deletion packages/components/avatar/src/Avatar/Avatar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,11 @@ function _Avatar(
width="100%"
/>
)}
{!!icon && <span className={styles.overlayIcon}>{icon}</span>}
{!!icon && (
<span className={styles.overlayIcon} data-test-id={`${testId}-icon`}>
{icon}
</span>
)}
</div>
);

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React from 'react';
import { render, screen } from '@testing-library/react';
import { render, screen, waitFor } from '@testing-library/react';
import UserEvent from '@testing-library/user-event/';
import { Avatar } from '../Avatar';
import { AvatarGroup } from './AvatarGroup';
Expand Down Expand Up @@ -87,7 +87,10 @@ describe('AvatarGroup', () => {

// Renders the tooltip for the presented avatars
await user.hover(screen.getAllByTestId('cf-ui-avatar')[0]);
expect(screen.getByRole('tooltip').textContent).toBe('Marge Simpson');

await waitFor(() =>
expect(screen.getByRole('tooltip').textContent).toBe('Marge Simpson'),
);
});

it('renders the avatars with tooltip in dropdown', async () => {
Expand Down
40 changes: 26 additions & 14 deletions packages/components/tooltip/src/Tooltip.test.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React from 'react';
import { render, screen } from '@testing-library/react';
import { render, screen, waitFor } from '@testing-library/react';
import userEvent from '@testing-library/user-event';
import { axe } from '@/scripts/test/axeHelper';

Expand Down Expand Up @@ -36,7 +36,9 @@ describe('Tooltip', () => {

await user.hover(screen.getByText('Hover me'));

expect(screen.getByRole('tooltip').textContent).toBe('Tooltip content');
await waitFor(() =>
expect(screen.getByRole('tooltip').textContent).toBe('Tooltip content'),
);
});

it('renders the component with an additional class name', async () => {
Expand All @@ -49,7 +51,9 @@ describe('Tooltip', () => {

await user.hover(screen.getByText('Hover me'));

expect(screen.getByRole('tooltip')).toHaveClass('extra-class-name');
await waitFor(() =>
expect(screen.getByRole('tooltip')).toHaveClass('extra-class-name'),
);
});

it('renders the component with a target wrapper classname', async () => {
Expand Down Expand Up @@ -80,9 +84,11 @@ describe('Tooltip', () => {

await user.hover(screen.getByText('Hover me'));

expect(
screen.getByRole('tooltip').getAttribute('data-popper-placement'),
).toBe('left');
await waitFor(() =>
expect(
screen.getByRole('tooltip').getAttribute('data-popper-placement'),
).toBe('left'),
);
});

it('renders the component with a id attribute', async () => {
Expand All @@ -95,7 +101,9 @@ describe('Tooltip', () => {

await user.hover(screen.getByText('Hover me'));

expect(screen.getByRole('tooltip').getAttribute('id')).toBe('Tooltip');
await waitFor(() =>
expect(screen.getByRole('tooltip').getAttribute('id')).toBe('Tooltip'),
);
});

it('renders the component as span with a id attribute', async () => {
Expand All @@ -108,9 +116,11 @@ describe('Tooltip', () => {

await user.hover(screen.getByText('Hover me'));

const tooltip = screen.getByRole('tooltip');
expect(tooltip.getAttribute('id')).toBe('Tooltip');
expect(tooltip.nodeName).toMatch(/span/i);
await waitFor(() => {
const tooltip = screen.getByRole('tooltip');
expect(tooltip.getAttribute('id')).toBe('Tooltip');
expect(tooltip.nodeName).toMatch(/span/i);
});
});

it('has no a11y issues', async () => {
Expand Down Expand Up @@ -144,9 +154,11 @@ describe('Tooltip', () => {

const results = await axe(container);

expect(results).toHaveNoViolations();
expect(screen.getByRole('tooltip').textContent).toBe(
'Ich bin ein Paragraph',
);
await waitFor(() => {
expect(results).toHaveNoViolations();
expect(screen.getByRole('tooltip').textContent).toBe(
'Ich bin ein Paragraph',
);
});
});
});
4 changes: 2 additions & 2 deletions packages/components/tooltip/src/Tooltip.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ export type WithEnhancedContent = {
*/
content?: ReactElement | string;
/**
* Accesible label property, only required when using ReactElement as content
* Accessible label property, only required when using ReactElement as content
*/
label?: string;
};
Expand Down Expand Up @@ -123,7 +123,7 @@ export const Tooltip = ({
onMouseLeave,
onMouseOver,
onKeyDown,
showDelay = 0,
showDelay = 375,
targetWrapperClassName,
maxWidth = 360,
testId = 'cf-ui-tooltip',
Expand Down
Loading