diff --git a/src/components/BackgroundImage/BackgroundImage.tsx b/src/components/BackgroundImage/BackgroundImage.tsx index 26e65960d..48911d705 100644 --- a/src/components/BackgroundImage/BackgroundImage.tsx +++ b/src/components/BackgroundImage/BackgroundImage.tsx @@ -1,21 +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 = 'qa-background-image'; +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 5fb2d63f0..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'; @@ -22,19 +22,21 @@ const BackgroundMedia = ({ ...props }: BackgroundMediaProps) => { const isMobile = useContext(MobileContext); + const qaAttributes = getQaAttrubutes(qa, 'media'); return ( { test('render component by default', async () => { render(); - const component = screen.getByTestId(qaId); + const component = screen.getByTestId(qaAttributes.animate); expect(component).toBeInTheDocument(); }); @@ -35,6 +38,7 @@ describe('BackgroundMedia', () => { testCustomClassName({ component: BackgroundMedia, props: {qa: qaId}, + options: {qaId: qaAttributes.animate}, }); }); @@ -42,6 +46,7 @@ describe('BackgroundMedia', () => { testAnimated({ component: BackgroundMedia, props: {qa: qaId}, + options: {qaId: qaAttributes.animate}, }); }); @@ -49,7 +54,7 @@ describe('BackgroundMedia', () => { const style = {backgroundColor: 'red'}; render(); - const component = screen.getByTestId(qaId); + const component = screen.getByTestId(qaAttributes.media); expect(component).toHaveStyle(style); }); @@ -58,21 +63,21 @@ describe('BackgroundMedia', () => { const className = 'my-class'; render(); - const component = screen.getByTestId(qaIdOfMedia); + const component = screen.getByTestId(qaAttributes.media); expect(component).toHaveClass(className); }); test('render video', () => { render(); - const component = screen.getByTestId(defaultMediaVideoSourceQa); + const component = screen.getByTestId(qaAttributes.mediaVideoSource); expect(component).toBeInTheDocument(); }); test('render video with videoClassName', () => { render(); - const component = screen.getByTestId(defaultMediaVideoQa); + const component = screen.getByTestId(qaAttributes.mediaVideo); expect(component).toHaveClass('pc-BackgroundMedia__video'); }); @@ -80,37 +85,41 @@ describe('BackgroundMedia', () => { test('render video with default height', () => { const style = {height: '720px'}; render(); - const component = screen.getByTestId(defaultMediaVideoQa); + const component = screen.getByTestId(qaAttributes.mediaVideo); expect(component).toHaveStyle(style); }); - test('render video with defined height', () => { + test('render video with custom height', () => { const height = 300; const style = {height: `${height}px`}; render(); - const component = screen.getByTestId(defaultMediaVideoQa); + const component = screen.getByTestId(qaAttributes.mediaVideo); expect(component).toHaveStyle(style); }); test('render with fullWidthMedia prop', () => { render(); - const component = screen.getByTestId(qaIdOfMedia); + 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(qaIdOfBackgroundImage); + const component = screen.getByTestId(imageQaAttributes.imageDisplaySource); expect(component).toBeInTheDocument(); }); test('render image with imageClassName', () => { render(); - const component = screen.getByTestId(qaIdOfBackgroundImage); + const component = screen.getByTestId(qaAttributes.mediaImageBackgroundImage); expect(component).toHaveClass('pc-BackgroundMedia__image'); }); @@ -118,24 +127,24 @@ describe('BackgroundMedia', () => { test('render image with default height', () => { const style = {height: '720px'}; render(); - const component = screen.getByTestId(qaIdOfBackgroundImage); + const component = screen.getByTestId(qaAttributes.mediaImageBackgroundImage); expect(component).toHaveStyle(style); }); - test('render image with defined height', () => { + test('render image with custom height', () => { const height = 300; const style = {height: `${height}px`}; render(); - const component = screen.getByTestId(qaIdOfBackgroundImage); + const component = screen.getByTestId(qaAttributes.mediaImageBackgroundImage); expect(component).toHaveStyle(style); }); test('do not render image when video is provided', () => { render(); - const component = screen.getByTestId(qaIdOfBackgroundImage); + const component = screen.getByTestId(qaAttributes.mediaImageBackgroundImage); expect(component).toHaveClass('pc-media-component-image__item_withVideo'); }); @@ -144,7 +153,7 @@ describe('BackgroundMedia', () => { const style = {transform: 'translateY(0px)'}; render(); - const component = screen.getByTestId(defaultAnimatedDivQa); + 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 && ( + + )} { 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, @@ -81,6 +90,7 @@ const Image = (props: ImageAllProps) => { {...itemData} imageClassName={imageClass} imageStyle={{height}} + qa={qaAttributes.fullscreenImage} /> ); }; @@ -88,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 8eb068b3c..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'; @@ -11,14 +11,11 @@ import Video, {VideoAdditionProps} from './Video/Video'; import './Media.scss'; -export const qaIdByDefault = 'qa-media'; - const b = block('Media'); -export interface MediaAllProps extends MediaProps, VideoAdditionProps, ImageAdditionProps { +export interface MediaAllProps extends MediaProps, VideoAdditionProps, ImageAdditionProps, QAProps { className?: string; youtubeClassName?: string; - qa?: string; } export const Media = (props: MediaAllProps) => { @@ -42,11 +39,13 @@ export const Media = (props: MediaAllProps) => { isBackground, playButton, customBarControlsClassName, - qa = qaIdByDefault, + qa, } = props; const [hasVideoFallback, setHasVideoFallback] = useState(false); + const qaAttributes = getQaAttrubutes(qa, 'video'); + const content = useMemo(() => { let result: ReactElement | ReactElement[] = []; @@ -62,6 +61,7 @@ export const Media = (props: MediaAllProps) => { video={video} hasVideoFallback={hasVideoFallback} fullscreen={fullscreen} + qa={qaAttributes.image} />, ); } @@ -83,9 +83,9 @@ export const Media = (props: MediaAllProps) => { }; if (fullscreen) { - result.push(); + result.push(); } else { - result.push(