From ece8b8fa1578da16baca88524b58d52e8b3f910f Mon Sep 17 00:00:00 2001 From: Nik Tverd Date: Wed, 14 Jun 2023 15:26:32 +0600 Subject: [PATCH] test(Image): test for Image added --- .../__tests__/BackgroundImage.test.tsx | 17 +-- .../Button/__tests__/Button.test.tsx | 15 +- src/components/Image/Image.tsx | 61 ++++---- src/components/Image/__tests__/Image.test.tsx | 131 ++++++++++++++++++ test-utils/shared/common.tsx | 30 +++- test-utils/shared/image.tsx | 64 +++++++++ 6 files changed, 266 insertions(+), 52 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..c162825d8 100644 --- a/src/components/BackgroundImage/__tests__/BackgroundImage.test.tsx +++ b/src/components/BackgroundImage/__tests__/BackgroundImage.test.tsx @@ -3,6 +3,7 @@ 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 BackgroundImage from '../BackgroundImage'; @@ -21,17 +22,17 @@ 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: qaId}, + }); }); test('add image as desktop prop', () => { - render(); - const component = screen.getByRole('img'); - - expect(component).toHaveAttribute('src', imageSrc); + testSourceProps({ + component: BackgroundImage, + props: {desktop: imageSrc, qa: qaId}, + }); }); test('should hide image', () => { diff --git a/src/components/Button/__tests__/Button.test.tsx b/src/components/Button/__tests__/Button.test.tsx index a3064bece..42b0b9862 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(