|
| 1 | +import React from 'react'; |
| 2 | + |
| 3 | +import {render, screen} from '@testing-library/react'; |
| 4 | +import {BackgroundImageProps} from 'src/models'; |
| 5 | + |
| 6 | +import {testCustomClassName, testCustomStyle} from '../../../../test-utils/shared/common'; |
| 7 | +import BackgroundImage from '../BackgroundImage'; |
| 8 | + |
| 9 | +const qaId = 'background-image-component'; |
| 10 | + |
| 11 | +const imageSrc = |
| 12 | + 'https://storage.yandexcloud.net/cloud-www-assets/constructor/storybook/images/img-gray.png'; |
| 13 | + |
| 14 | +describe('BackgroundImage', () => { |
| 15 | + test('Render BackgroundImage by default', async () => { |
| 16 | + render(<BackgroundImage qa={qaId} />); |
| 17 | + |
| 18 | + const component = screen.getByTestId(qaId); |
| 19 | + expect(component).toBeInTheDocument(); |
| 20 | + expect(component).toBeVisible(); |
| 21 | + }); |
| 22 | + |
| 23 | + test('add image as src prop', () => { |
| 24 | + render(<BackgroundImage src={imageSrc} />); |
| 25 | + const component = screen.getByRole('img'); |
| 26 | + |
| 27 | + expect(component).toHaveAttribute('src', imageSrc); |
| 28 | + }); |
| 29 | + |
| 30 | + test('add image as desktop prop', () => { |
| 31 | + render(<BackgroundImage desktop={imageSrc} />); |
| 32 | + const component = screen.getByRole('img'); |
| 33 | + |
| 34 | + expect(component).toHaveAttribute('src', imageSrc); |
| 35 | + }); |
| 36 | + |
| 37 | + test('should hide image', () => { |
| 38 | + render(<BackgroundImage src={imageSrc} hide qa={qaId} />); |
| 39 | + const component = screen.getByTestId(qaId); |
| 40 | + const imageComponent = screen.queryByRole('img'); |
| 41 | + |
| 42 | + expect(component).toBeInTheDocument(); |
| 43 | + expect(component).toBeVisible(); |
| 44 | + expect(imageComponent).not.toBeInTheDocument(); |
| 45 | + }); |
| 46 | + |
| 47 | + test('should render children', () => { |
| 48 | + const childText = 'child-component'; |
| 49 | + render( |
| 50 | + <BackgroundImage src={imageSrc} hide qa={qaId}> |
| 51 | + <p>{childText}</p> |
| 52 | + </BackgroundImage>, |
| 53 | + ); |
| 54 | + const component = screen.getByText(childText); |
| 55 | + |
| 56 | + expect(component).toBeInTheDocument(); |
| 57 | + expect(component).toBeVisible(); |
| 58 | + }); |
| 59 | + |
| 60 | + test('add className', () => { |
| 61 | + testCustomClassName<BackgroundImageProps>({ |
| 62 | + component: BackgroundImage, |
| 63 | + props: {qa: qaId}, |
| 64 | + }); |
| 65 | + }); |
| 66 | + |
| 67 | + test('add style', () => { |
| 68 | + testCustomStyle<BackgroundImageProps>({ |
| 69 | + component: BackgroundImage, |
| 70 | + props: {qa: qaId}, |
| 71 | + }); |
| 72 | + }); |
| 73 | + |
| 74 | + test('add className to image', () => { |
| 75 | + const className = 'my-class'; |
| 76 | + |
| 77 | + render(<BackgroundImage src={imageSrc} imageClassName={className} />); |
| 78 | + const component = screen.getByRole('img'); |
| 79 | + |
| 80 | + expect(component).toHaveClass(className); |
| 81 | + }); |
| 82 | +}); |
0 commit comments