From 591aeed14906c29477a88edc61cd2727cc10c687 Mon Sep 17 00:00:00 2001 From: Nik Tverd Date: Wed, 14 Jun 2023 15:26:32 +0600 Subject: [PATCH 1/5] test(Image): test for Image added --- .../__tests__/BackgroundImage.test.tsx | 22 +-- .../__tests__/BackgroundMedia.test.tsx | 4 +- .../Button/__tests__/Button.test.tsx | 15 +- src/components/Image/Image.tsx | 71 +++++----- src/components/Image/__tests__/Image.test.tsx | 131 ++++++++++++++++++ test-utils/shared/common.tsx | 64 ++++++--- test-utils/shared/image.tsx | 88 ++++++++++++ 7 files changed, 327 insertions(+), 68 deletions(-) create mode 100644 src/components/Image/__tests__/Image.test.tsx create mode 100644 test-utils/shared/image.tsx diff --git a/src/components/BackgroundImage/__tests__/BackgroundImage.test.tsx b/src/components/BackgroundImage/__tests__/BackgroundImage.test.tsx index 4326a66d3..a562ca7dc 100644 --- a/src/components/BackgroundImage/__tests__/BackgroundImage.test.tsx +++ b/src/components/BackgroundImage/__tests__/BackgroundImage.test.tsx @@ -3,7 +3,9 @@ import React from 'react'; import {render, screen} from '@testing-library/react'; import {testCustomClassName, testCustomStyle} from '../../../../test-utils/shared/common'; +import {testSourceProps} from '../../../../test-utils/shared/image'; import {BackgroundImageProps} from '../../../models'; +import {getQaAttrubutes} from '../../../utils'; import BackgroundImage from '../BackgroundImage'; const qa = 'background-image-component'; @@ -11,6 +13,8 @@ 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'); + describe('BackgroundImage', () => { test('Render BackgroundImage by default', async () => { render(); @@ -21,17 +25,19 @@ describe('BackgroundImage', () => { }); test('add image as src prop', () => { - render(); - const component = screen.getByRole('img'); - - expect(component).toHaveAttribute('src', imageSrc); + testSourceProps({ + component: BackgroundImage, + props: {src: imageSrc, qa}, + options: {qaId: qaAttributes.imageDisplaySourceCompressed}, + }); }); test('add image as desktop prop', () => { - render(); - const component = screen.getByRole('img'); - - expect(component).toHaveAttribute('src', imageSrc); + testSourceProps({ + component: BackgroundImage, + props: {desktop: imageSrc, qa}, + options: {qaId: qaAttributes.imageDisplaySourceCompressed}, + }); }); test('should hide image', () => { diff --git a/src/components/BackgroundMedia/__tests__/BackgroundMedia.test.tsx b/src/components/BackgroundMedia/__tests__/BackgroundMedia.test.tsx index 5fe0a0423..a3bf4bcf2 100644 --- a/src/components/BackgroundMedia/__tests__/BackgroundMedia.test.tsx +++ b/src/components/BackgroundMedia/__tests__/BackgroundMedia.test.tsx @@ -109,10 +109,10 @@ describe('BackgroundMedia', () => { test('render image', () => { const imageQaAttributes = getQaAttrubutes( qaAttributes.mediaImageBackgroundImage, - 'image-display-source', + 'image-display-source-compressed', ); render(); - const component = screen.getByTestId(imageQaAttributes.imageDisplaySource); + const component = screen.getByTestId(imageQaAttributes.imageDisplaySourceCompressed); expect(component).toBeInTheDocument(); }); diff --git a/src/components/Button/__tests__/Button.test.tsx b/src/components/Button/__tests__/Button.test.tsx index a3064bece..a7afd6ec7 100644 --- a/src/components/Button/__tests__/Button.test.tsx +++ b/src/components/Button/__tests__/Button.test.tsx @@ -2,9 +2,8 @@ import React from 'react'; import {ButtonSize} from '@gravity-ui/uikit'; import {render, screen} from '@testing-library/react'; -import userEvent from '@testing-library/user-event'; -import {testCustomClassName} from '../../../../test-utils/shared/common'; +import {testCustomClassName, testOnClick} from '../../../../test-utils/shared/common'; import {ButtonImagePosition, ButtonTheme} from '../../../models'; import Button, {ButtonProps} from '../Button'; import {ICON_QA} from '../utils'; @@ -63,14 +62,10 @@ describe('Button', () => { }); test('call onClick', async () => { - const user = userEvent.setup(); - const handleOnClick = jest.fn(); - render(