import { render, screen } from '@testing-library/react';
import { Banner } from '../Banner';
import styles from '@patternfly/react-styles/css/components/Banner/banner';
test('Renders without children', () => {
render(
);
expect(screen.getByTestId('banner').firstChild).toBeVisible();
});
test('Renders children', () => {
render(Test);
expect(screen.getByText('Test')).toBeVisible();
});
test(`Renders with class name ${styles.banner}`, () => {
render(Test);
expect(screen.getByText('Test')).toHaveClass(styles.banner);
});
test('Renders with custom class name when className prop is provided', () => {
render(Test);
expect(screen.getByText('Test')).toHaveClass('custom-class');
});
test('Renders without any modifier class when color and status props are not passed', () => {
render(Test);
expect(screen.getByText('Test')).toHaveClass(styles.banner, { exact: true });
});
test('Renders with class name pf-m-red when "red" is passed to color prop', () => {
render(Test);
expect(screen.getByText('Test')).toHaveClass('pf-m-red');
});
test('Renders with class name pf-m-orangered when "orangered" is passed to color prop', () => {
render(Test);
expect(screen.getByText('Test')).toHaveClass('pf-m-orangered');
});
test('Renders with class name pf-m-orange when "orange" is passed to color prop', () => {
render(Test);
expect(screen.getByText('Test')).toHaveClass('pf-m-orange');
});
test('Renders with class name pf-m-yellow when "yellow" is passed to color prop', () => {
render(Test);
expect(screen.getByText('Test')).toHaveClass('pf-m-yellow');
});
test('Renders with class name pf-m-green when "green" is passed to color prop', () => {
render(Test);
expect(screen.getByText('Test')).toHaveClass('pf-m-green');
});
test('Renders with class name pf-m-teal when "teal" is passed to color prop', () => {
render(Test);
expect(screen.getByText('Test')).toHaveClass('pf-m-teal');
});
test('Renders with class name pf-m-blue when "blue" is passed to color prop', () => {
render(Test);
expect(screen.getByText('Test')).toHaveClass('pf-m-blue');
});
test('Renders with class name pf-m-purple when "purple" is passed to color prop', () => {
render(Test);
expect(screen.getByText('Test')).toHaveClass('pf-m-purple');
});
test('Renders with class name pf-m-success when "success" is passed to status prop', () => {
render(Test);
expect(screen.getByText('Test')).toHaveClass('pf-m-success');
});
test('Renders with class name pf-m-warning when "warning" is passed to status prop', () => {
render(Test);
expect(screen.getByText('Test')).toHaveClass('pf-m-warning');
});
test('Renders with class name pf-m-danger when "danger" is passed to status prop', () => {
render(Test);
expect(screen.getByText('Test')).toHaveClass('pf-m-danger');
});
test('Renders with class name pf-m-info when "info" is passed to status prop', () => {
render(Test);
expect(screen.getByText('Test')).toHaveClass('pf-m-info');
});
test('Renders with class name pf-m-custom when "custom" is passed to status prop', () => {
render(Test);
expect(screen.getByText('Test')).toHaveClass('pf-m-custom');
});
test('Does not render pf-v6-screen-reader class by default', () => {
render(Test);
expect(screen.getByText('Test')).not.toContainHTML('');
});
test('Renders screenReaderText passed via prop', () => {
render(Test);
expect(screen.getByText('Custom screen reader text')).toBeInTheDocument();
});
test('Renders without pf-m-sticky by default', () => {
render(Test);
expect(screen.getByText('Test')).not.toHaveClass('pf-m-sticky');
});
test('Renders with class name pf-m-sticky when isSticky prop is passed', () => {
render(Test);
expect(screen.getByText('Test')).toHaveClass('pf-m-sticky');
});
test('Renders with inherited element props spread to the component', () => {
render(Test);
expect(screen.getByText('Test')).toHaveAccessibleName('Test label');
});
test(`Renders with class name ${styles.modifiers.pill} when isPill prop is true`, () => {
render(Test);
expect(screen.getByText('Test')).toHaveClass(styles.modifiers.pill);
});
test(`Does not render with class name ${styles.modifiers.pill} when isPill is false`, () => {
render(Test);
expect(screen.getByText('Test')).not.toHaveClass(styles.modifiers.pill);
});
test(`Does not render with class name ${styles.modifiers.pill} when isPill is undefined`, () => {
render(Test);
expect(screen.getByText('Test')).not.toHaveClass(styles.modifiers.pill);
});
test('Matches the snapshot', () => {
const { asFragment } = render(Test);
expect(asFragment()).toMatchSnapshot();
});