-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test(BackgroundMedia): test for BackgroundMedia added
- Loading branch information
Showing
9 changed files
with
178 additions
and
5 deletions.
There are no files selected for viewing
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
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
146 changes: 146 additions & 0 deletions
146
src/components/BackgroundMedia/__tests__/BackgroundMedia.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 |
---|---|---|
@@ -0,0 +1,146 @@ | ||
import React from 'react'; | ||
|
||
import {render, screen} from '@testing-library/react'; | ||
|
||
import {testAnimated, testCustomClassName} from '../../../../test-utils/shared/common'; | ||
import {qaIdByDefault as qaIdOfBackgroundImage} from '../../../components/BackgroundImage/BackgroundImage'; | ||
import {qaIdByDefault as qaIdOfMedia} from '../../../components/Media/Media'; | ||
import {BackgroundMediaProps} from '../../../models'; | ||
import BackgroundMedia from '../BackgroundMedia'; | ||
|
||
const qaId = 'background-media-component'; | ||
|
||
const imageUrl = | ||
'https://storage.yandexcloud.net/cloud-www-assets/constructor/storybook/images/img-gray.png'; | ||
const videoProps = { | ||
src: [ | ||
'https://storage.yandexcloud.net/cloud-www-assets/constructor/storybook/images/header-bg-video_light.mp4', | ||
], | ||
}; | ||
|
||
describe('BackgroundMedia', () => { | ||
test('render component by default', async () => { | ||
render(<BackgroundMedia qa={qaId} />); | ||
const component = screen.getByTestId(qaId); | ||
|
||
expect(component).toBeInTheDocument(); | ||
}); | ||
|
||
test('add className', () => { | ||
testCustomClassName<BackgroundMediaProps>({ | ||
component: BackgroundMedia, | ||
props: {qa: qaId}, | ||
}); | ||
}); | ||
|
||
test('render with animated', async () => { | ||
testAnimated<BackgroundMediaProps>({ | ||
component: BackgroundMedia, | ||
props: {qa: qaId}, | ||
}); | ||
}); | ||
|
||
test('render with passed color', () => { | ||
const style = {backgroundColor: 'red'}; | ||
|
||
render(<BackgroundMedia color={style.backgroundColor} qa={qaId} />); | ||
const component = screen.getByTestId(qaId); | ||
|
||
expect(component).toHaveStyle(style); | ||
}); | ||
|
||
test('add className to media component', () => { | ||
const className = 'my-class'; | ||
|
||
render(<BackgroundMedia qa={qaId} mediaClassName={className} />); | ||
const component = screen.getByTestId(qaIdOfMedia); | ||
|
||
expect(component).toHaveClass(className); | ||
}); | ||
|
||
test('render video', () => { | ||
render(<BackgroundMedia qa={qaId} video={videoProps} />); | ||
const component = screen.getByRole('media-video-source'); | ||
|
||
expect(component).toBeInTheDocument(); | ||
}); | ||
|
||
test('render video with videoClassName', () => { | ||
render(<BackgroundMedia qa={qaId} video={videoProps} />); | ||
const component = screen.getByRole('media-video'); | ||
|
||
expect(component).toHaveClass('pc-BackgroundMedia__video'); | ||
}); | ||
|
||
test('render video with default height', () => { | ||
const style = {height: '720px'}; | ||
render(<BackgroundMedia qa={qaId} video={videoProps} />); | ||
const component = screen.getByRole('media-video'); | ||
|
||
expect(component).toHaveStyle(style); | ||
}); | ||
|
||
test('render video with defined height', () => { | ||
const height = 300; | ||
const style = {height: `${height}px`}; | ||
|
||
render(<BackgroundMedia qa={qaId} video={videoProps} height={height} />); | ||
const component = screen.getByRole('media-video'); | ||
expect(component).toHaveStyle(style); | ||
}); | ||
|
||
test('render with fullWidthMedia prop', () => { | ||
render(<BackgroundMedia qa={qaId} fullWidthMedia />); | ||
const component = screen.getByTestId(qaIdOfMedia); | ||
|
||
expect(component).toHaveClass('pc-BackgroundMedia__media_full-width-media'); | ||
}); | ||
|
||
test('render image', () => { | ||
render(<BackgroundMedia qa={qaId} image={imageUrl} />); | ||
const component = screen.getByTestId(qaIdOfBackgroundImage); | ||
|
||
expect(component).toBeInTheDocument(); | ||
}); | ||
|
||
test('render image with imageClassName', () => { | ||
render(<BackgroundMedia qa={qaId} image={imageUrl} />); | ||
const component = screen.getByTestId(qaIdOfBackgroundImage); | ||
|
||
expect(component).toHaveClass('pc-BackgroundMedia__image'); | ||
}); | ||
|
||
test('render image with default height', () => { | ||
const style = {height: '720px'}; | ||
render(<BackgroundMedia qa={qaId} image={imageUrl} />); | ||
const component = screen.getByTestId(qaIdOfBackgroundImage); | ||
|
||
expect(component).toHaveStyle(style); | ||
}); | ||
|
||
test('render image with defined height', () => { | ||
const height = 300; | ||
const style = {height: `${height}px`}; | ||
|
||
render(<BackgroundMedia qa={qaId} image={imageUrl} height={height} />); | ||
const component = screen.getByTestId(qaIdOfBackgroundImage); | ||
|
||
expect(component).toHaveStyle(style); | ||
}); | ||
|
||
test('do not render image when video is provided', () => { | ||
render(<BackgroundMedia qa={qaId} image={imageUrl} video={videoProps} />); | ||
const component = screen.getByTestId(qaIdOfBackgroundImage); | ||
|
||
expect(component).toHaveClass('pc-media-component-image__item_withVideo'); | ||
}); | ||
|
||
test('render image with parallax', () => { | ||
const style = {transform: 'translateY(0px)'}; | ||
|
||
render(<BackgroundMedia qa={qaId} parallax image={imageUrl} />); | ||
const component = screen.getByRole('animated-div'); | ||
|
||
expect(component).toHaveStyle(style); | ||
}); | ||
}); |
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
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
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
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
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
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