Skip to content
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
35 changes: 35 additions & 0 deletions src/__testing__/InfoTooltip.test.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import { render, screen } from '@testing-library/react';
import React from 'react';
import { InfoTooltip } from '../custom/CustomTooltip';
import { SistentThemeProvider } from '../theme';

// CustomTooltip renders its string titles through the Markdown module, which
// is ESM-only and not transformed by this jest setup. The tooltip's content
// rendering is not what this file exercises.
jest.mock('../custom/Markdown', () => ({
RenderMarkdownTooltip: ({ content }: { content: string }) => <>{content}</>
}));

const renderWithTheme = (ui: React.ReactElement) =>
render(<SistentThemeProvider>{ui}</SistentThemeProvider>);

describe('InfoTooltip', () => {
it('renders a focusable trigger so the tooltip opens on keyboard focus', async () => {
renderWithTheme(<InfoTooltip helpText="Helpful details" />);

const trigger = screen.getByRole('button', { name: 'More information' });

expect(trigger.getAttribute('type')).toBe('button');
expect(trigger.tabIndex).toBeGreaterThanOrEqual(0);
trigger.focus();
expect(await screen.findByRole('tooltip')).not.toBeNull();
});

it('exposes an accessible name so screen readers announce the trigger', () => {
renderWithTheme(<InfoTooltip helpText="Helpful details" />);

expect(
screen.getByRole('button', { name: 'More information' })
).not.toBeNull();
});
});
10 changes: 8 additions & 2 deletions src/custom/CustomTooltip/infoTooltip.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,23 @@ type InfoTooltipProps = {
const InfoTooltip = ({ helpText, style = {}, ...props }: InfoTooltipProps) => {
return (
<CustomTooltip title={helpText} {...props}>
<div
<button
type="button"
aria-label="More information"
style={{
display: 'flex',
flexDirection: 'row',
alignItems: 'center',
justifyContent: 'center',
padding: 0,
border: 'none',
background: 'transparent',
cursor: 'help',
...style
}}
>
<InfoOutlinedIcon {...iconSmall} />
</div>
</button>
</CustomTooltip>
);
};
Expand Down
Loading