diff --git a/src/components/BackgroundImage/BackgroundImage.tsx b/src/components/BackgroundImage/BackgroundImage.tsx index 58c7e7fe9..48911d705 100644 --- a/src/components/BackgroundImage/BackgroundImage.tsx +++ b/src/components/BackgroundImage/BackgroundImage.tsx @@ -1,19 +1,24 @@ import React from 'react'; import {BackgroundImageProps, WithChildren} from '../../models'; -import {block} from '../../utils'; +import {block, getQaAttrubutes} from '../../utils'; import Image from '../Image/Image'; import './BackgroundImage.scss'; +export const qaIdByDefault = 'background-image'; + const b = block('storage-background-image'); const BackgroundImage = (props: WithChildren) => { const {children, src, desktop, className, imageClassName, style, hide, qa} = props; + const qaAttributes = getQaAttrubutes(qa || qaIdByDefault); return ( -
- {(src || desktop) && !hide && } +
+ {(src || desktop) && !hide && ( + + )} {children &&
{children}
}
); diff --git a/src/components/BackgroundMedia/BackgroundMedia.tsx b/src/components/BackgroundMedia/BackgroundMedia.tsx index 428a02543..d5a505f15 100644 --- a/src/components/BackgroundMedia/BackgroundMedia.tsx +++ b/src/components/BackgroundMedia/BackgroundMedia.tsx @@ -2,7 +2,7 @@ import React, {useContext} from 'react'; import {MobileContext} from '../../context/mobileContext'; import {BackgroundMediaProps} from '../../models'; -import {block} from '../../utils'; +import {block, getQaAttrubutes} from '../../utils'; import AnimateBlock from '../AnimateBlock/AnimateBlock'; import Media from '../Media/Media'; @@ -18,21 +18,25 @@ const BackgroundMedia = ({ video, mediaClassName, fullWidthMedia, + qa, ...props }: BackgroundMediaProps) => { const isMobile = useContext(MobileContext); + const qaAttributes = getQaAttrubutes(qa, 'media'); return ( { + test('render component by default', async () => { + render(); + const component = screen.getByTestId(qaAttributes.animate); + + expect(component).toBeInTheDocument(); + }); + + test('add className', () => { + testCustomClassName({ + component: BackgroundMedia, + props: {qa: qaId}, + options: {qaId: qaAttributes.animate}, + }); + }); + + test('render with animated', async () => { + testAnimated({ + component: BackgroundMedia, + props: {qa: qaId}, + options: {qaId: qaAttributes.animate}, + }); + }); + + test('render with passed color', () => { + const style = {backgroundColor: 'red'}; + + render(); + const component = screen.getByTestId(qaAttributes.media); + + expect(component).toHaveStyle(style); + }); + + test('add className to media component', () => { + const className = 'my-class'; + + render(); + const component = screen.getByTestId(qaAttributes.media); + + expect(component).toHaveClass(className); + }); + + test('render video', () => { + render(); + const component = screen.getByTestId(qaAttributes.mediaVideoSource); + + expect(component).toBeInTheDocument(); + }); + + test('render video with videoClassName', () => { + render(); + const component = screen.getByTestId(qaAttributes.mediaVideo); + + expect(component).toHaveClass('pc-BackgroundMedia__video'); + }); + + test('render video with default height', () => { + const style = {height: '720px'}; + render(); + const component = screen.getByTestId(qaAttributes.mediaVideo); + + expect(component).toHaveStyle(style); + }); + + test('render video with custom height', () => { + const height = 300; + const style = {height: `${height}px`}; + + render(); + const component = screen.getByTestId(qaAttributes.mediaVideo); + expect(component).toHaveStyle(style); + }); + + test('render with fullWidthMedia prop', () => { + render(); + const component = screen.getByTestId(qaAttributes.media); + + expect(component).toHaveClass('pc-BackgroundMedia__media_full-width-media'); + }); + + test('render image', () => { + const imageQaAttributes = getQaAttrubutes( + qaAttributes.mediaImageBackgroundImage, + 'image-display-source', + ); + render(); + const component = screen.getByTestId(imageQaAttributes.imageDisplaySource); + + expect(component).toBeInTheDocument(); + }); + + test('render image with imageClassName', () => { + render(); + const component = screen.getByTestId(qaAttributes.mediaImageBackgroundImage); + + expect(component).toHaveClass('pc-BackgroundMedia__image'); + }); + + test('render image with default height', () => { + const style = {height: '720px'}; + render(); + const component = screen.getByTestId(qaAttributes.mediaImageBackgroundImage); + + expect(component).toHaveStyle(style); + }); + + test('render image with custom height', () => { + const height = 300; + const style = {height: `${height}px`}; + + render(); + const component = screen.getByTestId(qaAttributes.mediaImageBackgroundImage); + + expect(component).toHaveStyle(style); + }); + + test('do not render image when video is provided', () => { + render(); + const component = screen.getByTestId(qaAttributes.mediaImageBackgroundImage); + + expect(component).toHaveClass('pc-media-component-image__item_withVideo'); + }); + + test('render image with parallax', () => { + const style = {transform: 'translateY(0px)'}; + + render(); + const component = screen.getByTestId(qaAttributes.mediaImageAnimate); + + expect(component).toHaveStyle(style); + }); +}); diff --git a/src/components/Image/Image.tsx b/src/components/Image/Image.tsx index e6217d26f..1861be1e7 100644 --- a/src/components/Image/Image.tsx +++ b/src/components/Image/Image.tsx @@ -3,6 +3,7 @@ import React, {CSSProperties, Fragment, MouseEventHandler, useContext, useState} import {BREAKPOINTS} from '../../constants'; import {ProjectSettingsContext} from '../../context/projectSettingsContext'; import {ImageDeviceProps, ImageObjectProps, QAProps} from '../../models'; +import {getQaAttrubutes} from '../../utils'; import {isCompressible} from '../../utils/imageCompress'; import ImageBase from '../ImageBase/ImageBase'; @@ -42,6 +43,15 @@ const Image = (props: ImageProps) => { return null; } + const qaAttributes = getQaAttrubutes( + qa, + 'mobile-webp-source', + 'mobile-source', + 'tablet-webp-source', + 'tablet-source', + 'display-source', + ); + const disableWebp = projectSettings.disableCompress || disableCompress || @@ -57,9 +67,14 @@ const Image = (props: ImageProps) => { srcSet={checkWebP(mobile)} type="image/webp" media={`(max-width: ${BREAKPOINTS.sm}px)`} + data-qa={qaAttributes.mobileWebpSource} /> )} - + )} {tablet && ( @@ -69,12 +84,23 @@ const Image = (props: ImageProps) => { srcSet={checkWebP(tablet)} type="image/webp" media={`(max-width: ${BREAKPOINTS.md}px)`} + data-qa={qaAttributes.tabletWebpSource} /> )} - + )} - {src && !disableWebp && } + {src && !disableWebp && ( + + )} { const { @@ -38,8 +40,17 @@ const Image = (props: ImageAllProps) => { hasVideoFallback, video, fullscreen, + qa, } = props; + const qaAttributes = getQaAttrubutes( + qa, + 'fullscreen-image', + 'animate', + 'background-image', + 'image-view', + 'slider-block', + ); const [scrollY, setScrollY] = useState(0); const [{springScrollY}, springSetScrollY] = useSpring(() => ({ springScrollY: 0, @@ -79,6 +90,7 @@ const Image = (props: ImageAllProps) => { {...itemData} imageClassName={imageClass} imageStyle={{height}} + qa={qaAttributes.fullscreenImage} /> ); }; @@ -86,15 +98,27 @@ const Image = (props: ImageAllProps) => { const imageBackground = (oneImage: ImageProps) => { const imageData = getMediaImage(oneImage); return ( - - + + ); }; const imageOnly = (oneImage: ImageProps) => { const imageData = getMediaImage(oneImage); - return ; + return ( + + ); }; const imageSlider = (imageArray: ImageProps[]) => { diff --git a/src/components/Media/Media.tsx b/src/components/Media/Media.tsx index 2c519cec9..d065a77d6 100644 --- a/src/components/Media/Media.tsx +++ b/src/components/Media/Media.tsx @@ -1,7 +1,7 @@ import React, {ReactElement, useMemo, useState} from 'react'; -import {MediaProps} from '../../models'; -import {block} from '../../utils'; +import {MediaProps, QAProps} from '../../models'; +import {block, getQaAttrubutes} from '../../utils'; import YoutubeBlock from '../VideoBlock/VideoBlock'; import DataLens from './DataLens/DataLens'; @@ -13,7 +13,7 @@ import './Media.scss'; const b = block('Media'); -export interface MediaAllProps extends MediaProps, VideoAdditionProps, ImageAdditionProps { +export interface MediaAllProps extends MediaProps, VideoAdditionProps, ImageAdditionProps, QAProps { className?: string; youtubeClassName?: string; } @@ -39,10 +39,13 @@ export const Media = (props: MediaAllProps) => { isBackground, playButton, customBarControlsClassName, + qa, } = props; const [hasVideoFallback, setHasVideoFallback] = useState(false); + const qaAttributes = getQaAttrubutes(qa, 'video'); + const content = useMemo(() => { let result: ReactElement | ReactElement[] = []; @@ -58,6 +61,7 @@ export const Media = (props: MediaAllProps) => { video={video} hasVideoFallback={hasVideoFallback} fullscreen={fullscreen} + qa={qaAttributes.image} />, ); } @@ -79,9 +83,9 @@ export const Media = (props: MediaAllProps) => { }; if (fullscreen) { - result.push(); + result.push(); } else { - result.push(