From db4759654ced8440f9de8f46be90a017d26c4e2b Mon Sep 17 00:00:00 2001 From: Nik Tverd Date: Wed, 20 Sep 2023 00:42:18 +0600 Subject: [PATCH] fixup! fixup! test(CardBase): test for CardBase added --- src/components/CardBase/CardBase.tsx | 16 +++----- .../CardBase/__tests__/CardBase.test.tsx | 40 +++++++++---------- 2 files changed, 24 insertions(+), 32 deletions(-) diff --git a/src/components/CardBase/CardBase.tsx b/src/components/CardBase/CardBase.tsx index 79d566cff..5af8ae8bc 100644 --- a/src/components/CardBase/CardBase.tsx +++ b/src/components/CardBase/CardBase.tsx @@ -10,7 +10,7 @@ import { WithChildren, } from '../../models'; import {AnalyticsEventsBase, DefaultEventNames} from '../../models/common'; -import {block} from '../../utils'; +import {block, getQaAttrubutes} from '../../utils'; import BackgroundImage from '../BackgroundImage/BackgroundImage'; import RouterLink from '../RouterLink/RouterLink'; @@ -39,11 +39,6 @@ export interface CardFooterBaseProps { const b = block('card-base-block'); -export const defaultHeaderQa = 'card-base-header'; -export const defaultBodyQa = 'card-base-body'; -export const defaultContentQa = 'card-base-content'; -export const defaultFooterQa = 'card-base-footer'; - const Header: React.FC> = () => null; const Content: React.FC> = () => null; const Footer: React.FC> = () => null; @@ -65,6 +60,7 @@ export const Layout = (props: CardBaseProps) => { const handleMetrika = useMetrika(); const handleAnalytics = useAnalytics(DefaultEventNames.CardBase, url); let header, content, footer, image, headerClass, footerClass; + const qaAttributes = getQaAttrubutes(qa, 'header', 'footer', 'body', 'content'); function handleChild(child: ReactElement) { switch (child.type) { @@ -95,17 +91,17 @@ export const Layout = (props: CardBaseProps) => {
{header}
)} -
-
+
+
{content}
{footer && ( -
+
{footer}
)} diff --git a/src/components/CardBase/__tests__/CardBase.test.tsx b/src/components/CardBase/__tests__/CardBase.test.tsx index ebe81f6da..8d004c714 100644 --- a/src/components/CardBase/__tests__/CardBase.test.tsx +++ b/src/components/CardBase/__tests__/CardBase.test.tsx @@ -8,15 +8,11 @@ import {PageConstructorProvider} from '../../../containers/PageConstructor'; import {AnalyticsContextProps} from '../../../context/analyticsContext'; import {MetrikaContextProps} from '../../../context/metrikaContext'; import {CardBorder, PixelEventType} from '../../../models'; -import CardBase, { - CardBaseProps, - defaultBodyQa, - defaultContentQa, - defaultFooterQa, - defaultHeaderQa, -} from '../CardBase'; +import {getQaAttrubutes} from '../../../utils'; +import CardBase, {CardBaseProps} from '../CardBase'; const qaId = 'card-base-component'; +const qaAttributes = getQaAttrubutes(qaId, 'header', 'footer', 'body', 'content'); const url = '#'; @@ -77,11 +73,11 @@ describe('CardBase', () => { test('render CardBase with header', async () => { render( - + Header , ); - const cardBaseHeader = screen.queryByTestId(defaultHeaderQa); + const cardBaseHeader = screen.queryByTestId(qaAttributes.header); expect(cardBaseHeader).toBeInTheDocument(); expect(cardBaseHeader).toBeVisible(); @@ -90,11 +86,11 @@ describe('CardBase', () => { test('render CardBase with content', async () => { render( - + Content , ); - const cardBaseContent = screen.queryByTestId(defaultContentQa); + const cardBaseContent = screen.queryByTestId(qaAttributes.content); expect(cardBaseContent).toBeInTheDocument(); expect(cardBaseContent).toBeVisible(); @@ -103,11 +99,11 @@ describe('CardBase', () => { test('render CardBase with footer', async () => { render( - + Footer , ); - const cardBaseFooter = screen.queryByTestId(defaultFooterQa); + const cardBaseFooter = screen.queryByTestId(qaAttributes.footer); expect(cardBaseFooter).toBeInTheDocument(); expect(cardBaseFooter).toBeVisible(); @@ -118,11 +114,11 @@ describe('CardBase', () => { const bodyClassName = 'body-class-name'; render( - + Content , ); - const cardBaseBody = screen.queryByTestId(defaultBodyQa); + const cardBaseBody = screen.queryByTestId(qaAttributes.body); expect(cardBaseBody).toHaveClass(bodyClassName); }); @@ -131,11 +127,11 @@ describe('CardBase', () => { const contentClassName = 'content-class-name'; render( - + Content , ); - const cardBaseContent = screen.queryByTestId(defaultContentQa); + const cardBaseContent = screen.queryByTestId(qaAttributes.content); expect(cardBaseContent).toHaveClass(contentClassName); }); @@ -144,25 +140,25 @@ describe('CardBase', () => { const className = 'body-class-name'; render( - + Header , ); - const cardBaseHeader = screen.queryByTestId(defaultHeaderQa); + const cardBaseHeader = screen.queryByTestId(qaAttributes.header); expect(cardBaseHeader).toHaveClass(className); }); test('add className to Footer', async () => { - const className = 'body-class-name'; + const className = 'footer-class-name'; render( - + Footer , ); - const cardBaseFooter = screen.queryByTestId(defaultFooterQa); + const cardBaseFooter = screen.getByTestId(qaAttributes.footer); expect(cardBaseFooter).toHaveClass(className); });