Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test(Image): test for Image added #361

Merged
merged 5 commits into from
Sep 21, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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-compressed');
const qaAttributes = getQaAttrubutes(qa, 'image-desktop-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.imageDisplaySourceCompressed},
options: {qaId: qaAttributes.imageDesktopSourceCompressed},
});
});

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

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-compressed',
'image-desktop-source-compressed',
);
render(<BackgroundMedia qa={qaId} image={imageUrl} />);
const component = screen.getByTestId(imageQaAttributes.imageDisplaySourceCompressed);
const component = screen.getByTestId(imageQaAttributes.imageDesktopSourceCompressed);

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-compressed',
'desktop-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.displaySourceCompressed}
data-qa={qaAttributes.desktopSourceCompressed}
/>
)}
<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-compressed',
'desktop-source-compressed',
yuberdysheva marked this conversation as resolved.
Show resolved Hide resolved
);

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.displaySourceCompressed);
const sourceWebP = screen.queryByTestId(qaId || qaAttributes.desktopSourceCompressed);
expect(sourceWebP).not.toBeInTheDocument();
} else {
const sourceWebP = screen.getByTestId(qaId || qaAttributes.displaySourceCompressed);
const sourceWebP = screen.getByTestId(qaId || qaAttributes.desktopSourceCompressed);
expect(sourceWebP).toHaveAttribute('srcset', src + '.webp');
}

Expand Down
Loading