import { render, screen } from '@testing-library/react'; import { Hero } from '../Hero'; import styles from '@patternfly/react-styles/css/components/Hero/hero'; test('Renders without children', () => { render(
); expect(screen.getByTestId('test-hero').firstChild).toBeVisible(); }); test('Renders with children', () => { render(Test content); expect(screen.getByText('Test content')).toBeVisible(); }); test(`Renders with ${styles.hero} class on wrapper by default`, () => { render(Test); expect(screen.getByText('Test').parentElement).toHaveClass(`${styles.hero}`, { exact: true }); }); test(`Renders with ${styles.modifiers.glass} class when isGlass is true`, () => { render(Test); expect(screen.getByText('Test').parentElement).toHaveClass(`${styles.modifiers.glass}`); }); test(`Renders without ${styles.modifiers.glass} class when isGlass is false`, () => { render(Test); expect(screen.getByText('Test').parentElement).not.toHaveClass(`${styles.modifiers.glass}`); }); test(`Renders without ${styles.modifiers.glass} class by default`, () => { render(Test); expect(screen.getByText('Test').parentElement).not.toHaveClass(`${styles.modifiers.glass}`); }); test('Renders with custom class name on wrapper when className prop is provided', () => { render(Test); expect(screen.getByText('Test').parentElement).toHaveClass('custom-class'); }); test(`Renders with class ${styles.heroBody} on content element`, () => { render(Test); expect(screen.getByText('Test')).toHaveClass(`${styles.heroBody}`, { exact: true }); }); test('Renders with additional props spread to the wrapper component', () => { render(Test); expect(screen.getByText('Test').parentElement).toHaveAttribute('id', 'custom-id'); }); test('Renders with light background image style when backgroundSrcLight is provided', () => { const backgroundSrc = 'light-bg.jpg'; render(Test); expect(screen.getByText('Test').parentElement).toHaveStyle( `--pf-v6-c-hero--BackgroundImage--light: url(${backgroundSrc})` ); }); test('Renders with dark background image style when backgroundSrcDark is provided', () => { const backgroundSrc = 'dark-bg.jpg'; render(Test); expect(screen.getByText('Test').parentElement).toHaveStyle( `--pf-v6-c-hero--BackgroundImage--dark: url(${backgroundSrc})` ); }); test('Renders with both light and dark background image styles when both are provided', () => { const lightSrc = 'light-bg.jpg'; const darkSrc = 'dark-bg.jpg'; render( Test ); const heroElement = screen.getByText('Test').parentElement; expect(heroElement).toHaveStyle(`--pf-v6-c-hero--BackgroundImage--light: url(${lightSrc})`); expect(heroElement).toHaveStyle(`--pf-v6-c-hero--BackgroundImage--dark: url(${darkSrc})`); }); test('Renders with light gradient styles when gradientLight is provided', () => { const gradient = { stop1: '#ff0000', stop2: '#00ff00', stop3: '#0000ff' }; render(Test); const heroElement = screen.getByText('Test').parentElement; expect(heroElement).toHaveStyle(`--pf-v6-c-hero--gradient--stop-1--light: ${gradient.stop1}`); expect(heroElement).toHaveStyle(`--pf-v6-c-hero--gradient--stop-2--light: ${gradient.stop2}`); expect(heroElement).toHaveStyle(`--pf-v6-c-hero--gradient--stop-3--light: ${gradient.stop3}`); }); test('Renders with dark gradient styles when gradientDark is provided', () => { const gradient = { stop1: '#ff0000', stop2: '#00ff00', stop3: '#0000ff' }; render(Test); const heroElement = screen.getByText('Test').parentElement; expect(heroElement).toHaveStyle(`--pf-v6-c-hero--gradient--stop-1--dark: ${gradient.stop1}`); expect(heroElement).toHaveStyle(`--pf-v6-c-hero--gradient--stop-2--dark: ${gradient.stop2}`); expect(heroElement).toHaveStyle(`--pf-v6-c-hero--gradient--stop-3--dark: ${gradient.stop3}`); }); test('Renders with both light and dark gradient styles when both are provided', () => { const lightGradient = { stop1: '#ff0000', stop2: '#00ff00', stop3: '#0000ff' }; const darkGradient = { stop1: '#000000', stop2: '#ffffff', stop3: '#808080' }; render( Test ); const heroElement = screen.getByText('Test').parentElement; expect(heroElement).toHaveStyle(`--pf-v6-c-hero--gradient--stop-1--light: ${lightGradient.stop1}`); expect(heroElement).toHaveStyle(`--pf-v6-c-hero--gradient--stop-1--dark: ${darkGradient.stop1}`); }); test('Renders with both background images and gradient styles when both are provided', () => { const lightSrc = 'light-bg.jpg'; const darkSrc = 'dark-bg.jpg'; const lightGradient = { stop1: '#ff0000' }; const darkGradient = { stop1: '#000000' }; render( Test ); const heroElement = screen.getByText('Test').parentElement; expect(heroElement).toHaveStyle(`--pf-v6-c-hero--BackgroundImage--light: url(${lightSrc})`); expect(heroElement).toHaveStyle(`--pf-v6-c-hero--BackgroundImage--dark: url(${darkSrc})`); expect(heroElement).toHaveStyle(`--pf-v6-c-hero--gradient--stop-1--light: ${lightGradient.stop1}`); expect(heroElement).toHaveStyle(`--pf-v6-c-hero--gradient--stop-1--dark: ${darkGradient.stop1}`); }); test('Renders with inline width style when bodyWidth is passed', () => { const bodyWidth = '100px'; render(Test); const heroElement = screen.getByText('Test').parentElement; expect(heroElement).toHaveStyle(`--pf-v6-c-hero__body--Width: ${bodyWidth}`); }); test('Renders with inline max-width style when bodyMaxWidth is passed', () => { const bodyMaxWidth = '100px'; render(Test); const heroElement = screen.getByText('Test').parentElement; expect(heroElement).toHaveStyle(`--pf-v6-c-hero__body--MaxWidth: ${bodyMaxWidth}`); }); test('Matches the snapshot without backgroundSrc and gradient props', () => { const { asFragment } = render(Hero content); expect(asFragment()).toMatchSnapshot(); }); test('Matches the snapshot with backgroundSrc and gradient props', () => { const { asFragment } = render( Hero content ); expect(asFragment()).toMatchSnapshot(); });