Skip to content

Commit

Permalink
fixup! test(Image): test for Image added
Browse files Browse the repository at this point in the history
  • Loading branch information
niktverd committed Sep 19, 2023
1 parent 8839516 commit d520fba
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ const qa = 'background-image-component';
const imageSrc =
'https://storage.yandexcloud.net/cloud-www-assets/constructor/storybook/images/img-gray.png';

const qaAttributes = getQaAttrubutes(qa, 'image-display-source');
const qaAttributes = getQaAttrubutes(qa, 'image-display-source-compressed');

describe('BackgroundImage', () => {
test('Render BackgroundImage by default', async () => {
Expand All @@ -28,15 +28,15 @@ describe('BackgroundImage', () => {
testSourceProps<BackgroundImageProps>({
component: BackgroundImage,
props: {src: imageSrc, qa},
options: {qaId: qaAttributes.imageDisplaySource},
options: {qaId: qaAttributes.imageDisplaySourceCompressed},
});
});

test('add image as desktop prop', () => {
testSourceProps<BackgroundImageProps>({
component: BackgroundImage,
props: {desktop: imageSrc, qa},
options: {qaId: qaAttributes.imageDisplaySource},
options: {qaId: qaAttributes.imageDisplaySourceCompressed},
});
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,10 +109,10 @@ describe('BackgroundMedia', () => {
test('render image', () => {
const imageQaAttributes = getQaAttrubutes(
qaAttributes.mediaImageBackgroundImage,
'image-display-source',
'image-display-source-compressed',
);
render(<BackgroundMedia qa={qaId} image={imageUrl} />);
const component = screen.getByTestId(imageQaAttributes.imageDisplaySource);
const component = screen.getByTestId(imageQaAttributes.imageDisplaySourceCompressed);

expect(component).toBeInTheDocument();
});
Expand Down
4 changes: 2 additions & 2 deletions src/components/Image/Image.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ const Image = (props: ImageProps) => {
'mobile-source',
'tablet-webp-source',
'tablet-source',
'display-source',
'display-source-compressed',
);

const disableWebp =
Expand Down Expand Up @@ -105,7 +105,7 @@ const Image = (props: ImageProps) => {
<source
srcSet={checkWebP(src)}
type="image/webp"
data-qa={qaAttributes.displaySource}
data-qa={qaAttributes.displaySourceCompressed}
/>
)}
<ImageBase
Expand Down
6 changes: 3 additions & 3 deletions test-utils/shared/image.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ export const testSourceProps = <T,>({
'mobile-source',
'tablet-source-compressed',
'tablet-source',
'display-source',
'display-source-compressed',
);

const disableWebp = src && (props.disableCompress || !isCompressible(src));
Expand All @@ -47,10 +47,10 @@ export const testSourceProps = <T,>({
expect(component).toHaveAttribute('src', src);

if (disableWebp) {
const sourceWebP = screen.queryByTestId(qaId || qaAttributes.displaySource);
const sourceWebP = screen.queryByTestId(qaId || qaAttributes.displaySourceCompressed);
expect(sourceWebP).not.toBeInTheDocument();
} else {
const sourceWebP = screen.getByTestId(qaId || qaAttributes.displaySource);
const sourceWebP = screen.getByTestId(qaId || qaAttributes.displaySourceCompressed);
expect(sourceWebP).toHaveAttribute('srcset', src + '.webp');
}

Expand Down

0 comments on commit d520fba

Please sign in to comment.