-
Notifications
You must be signed in to change notification settings - Fork 357
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore(BackgroundImage): update tests (#9584)
* chore(BackgroundImage): update tests * add spread prop test, update test * use styles obj * update test name to use styles
- Loading branch information
Showing
2 changed files
with
32 additions
and
7 deletions.
There are no files selected for viewing
28 changes: 21 additions & 7 deletions
28
packages/react-core/src/components/BackgroundImage/__tests__/BackgroundImage.test.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
}); |
11 changes: 11 additions & 0 deletions
11
...core/src/components/BackgroundImage/__tests__/__snapshots__/BackgroundImage.test.tsx.snap
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> | ||
`; |