Skip to content
Merged
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
Original file line number Diff line number Diff line change
@@ -1,20 +1,34 @@
import React from 'react';
import { render, screen } from '@testing-library/react';
import { BackgroundImage } from '../BackgroundImage';
import styles from '@patternfly/react-styles/css/components/BackgroundImage/background-image';

test('has default className and src URL applied to style', () => {
test(`renders with default className ${styles.backgroundImage}`, () => {
render(<BackgroundImage src="/image/url.png" data-testid="test-id" />);
expect(screen.getByTestId('test-id')).toHaveClass(styles.backgroundImage, { exact: true });
});

test('spreads additional props', () => {
render(<BackgroundImage src="/image/url.png" data-testid="test-id" lang="en-US" />);
expect(screen.getByTestId('test-id')).toHaveProperty('lang');
});

const backgroundImage = screen.getByTestId('test-id');
const backgroundImageStyle = backgroundImage.getAttribute('style');
test('has src URL applied to style', () => {
render(<BackgroundImage src="/image/url.png" data-testid="test-id" />);

expect(backgroundImage).toHaveClass('pf-v5-c-background-image');
expect(backgroundImageStyle).toContain('--pf-v5-c-background-image--BackgroundImage');
expect(backgroundImageStyle).toContain('/image/url.png');
expect(screen.getByTestId('test-id')).toHaveAttribute(
'style',
'--pf-v5-c-background-image--BackgroundImage: url(/image/url.png);'
);
});

test('has additional className when one is provided', () => {
test('renders with custom className when one is provided', () => {
render(<BackgroundImage src="/image/url.png" className="another-class" data-testid="test-id" />);

expect(screen.getByTestId('test-id')).toHaveClass('another-class');
});

test('Matches the snapshot', () => {
const { asFragment } = render(<BackgroundImage src="/image/url.png" data-testid="test-id" />);
expect(asFragment()).toMatchSnapshot();
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`Matches the snapshot 1`] = `
<DocumentFragment>
<div
class="pf-v5-c-background-image"
data-testid="test-id"
style="--pf-v5-c-background-image--BackgroundImage: url(/image/url.png);"
/>
</DocumentFragment>
`;