import { render, screen } from '@testing-library/react';
import { HelperText } from '../HelperText';
import styles from '@patternfly/react-styles/css/components/HelperText/helper-text';
test('Renders to match snapshot', () => {
const { asFragment } = render();
expect(asFragment()).toMatchSnapshot();
});
test('Renders without children', () => {
render(
);
expect(screen.getByTestId('container').firstChild).toBeVisible();
});
test('Renders default classes', () => {
render(text);
expect(screen.getByText('text')).toHaveClass(styles.helperText);
});
test('Renders id when id is passed', () => {
render(text );
expect(screen.getByText('text')).toHaveAttribute('id', 'helper-id');
});
test('Renders aria-live when isLiveRegion is passed', () => {
render(text );
expect(screen.getByText('text')).toHaveAttribute('aria-live', 'polite');
});
test('Does not render aria-live by default', () => {
render(text );
expect(screen.getByText('text')).not.toHaveAttribute('aria-live');
});
test('Spreads additional props when passed', () => {
render(text );
expect(screen.getByText('text')).toHaveAttribute('dir', 'rtl');
});
test('Renders custom className', () => {
render(text );
expect(screen.getByText('text')).toHaveClass('custom');
});
test('Renders with element passed to component prop', () => {
render(text);
expect(screen.getByText('text').tagName).toBe('UL');
});
test('Renders with div by default when no component prop is passed', () => {
render(text);
expect(screen.getByText('text').tagName).toBe('DIV');
});
test('Renders aria-label and role when component = ul', () => {
render(
text
);
expect(screen.getByText('text')).toHaveAttribute('aria-label', 'helper');
expect(screen.getByText('text')).toHaveAttribute('role', 'list');
});
test('Does not render aria-label and role when component != ul', () => {
render(text);
expect(screen.getByText('text')).not.toHaveAttribute('aria-label', 'helper');
expect(screen.getByText('text')).not.toHaveAttribute('role', 'list');
});