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(Companies): test for Companies block added #688

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
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
11 changes: 7 additions & 4 deletions src/blocks/Companies/Companies.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,23 @@ import {Image} from '../../components';
import AnimateBlock from '../../components/AnimateBlock/AnimateBlock';
import {useTheme} from '../../context/theme';
import {CompaniesBlockProps} from '../../models';
import {block, getThemedValue} from '../../utils';
import {block, getQaAttrubutes, getThemedValue} from '../../utils';

import './Companies.scss';

const b = block('companies-block');

export const CompaniesBlock = ({title, images, animated}: CompaniesBlockProps) => {
export const CompaniesBlock = ({title, images, animated, qa}: CompaniesBlockProps) => {
const qaAttributes = getQaAttrubutes(qa, 'title');
const theme = useTheme();
const themedImages = getThemedValue(images, theme) || {};

return (
<AnimateBlock className={b()} offset={150} animate={animated}>
<AnimateBlock className={b()} offset={150} animate={animated} qa={qaAttributes.default}>
<div className={b('content')}>
<h2 className={b('title')}>{title}</h2>
<h2 className={b('title')} data-qa={qaAttributes.title}>
{title}
</h2>
<div className={b('images')}>
<Image {...themedImages} className={b('image')} />
</div>
Expand Down
108 changes: 108 additions & 0 deletions src/blocks/Companies/__tests__/Companies.test.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
import React from 'react';

import {render, screen} from '@testing-library/react';
import userEvent from '@testing-library/user-event';

import {ThemeContext} from '../../../context/theme';
import {CompaniesBlockProps, Theme} from '../../../models';
import {getQaAttrubutes} from '../../../utils';
import Companies from '../Companies';

const companies: CompaniesBlockProps = {
title: 'Companies Title',
animated: true,
images: {
light: {
desktop:
'https://storage.yandexcloud.net/cloud-www-assets/constructor/storybook/images/logo-svg_12-12_desktop_light.svg',
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is maybe not necessary now, but I get task to move all images that constructor depends on inside project. It means we are trying to avoid adding images from storage.yandexcloud.net now

tablet: 'https://storage.yandexcloud.net/cloud-www-assets/constructor/storybook/images/logo-svg_12-12_tablet_light.svg',
mobile: 'https://storage.yandexcloud.net/cloud-www-assets/constructor/storybook/images/logo-svg_12-12_mobile_light.svg',
alt: 'Page constructor',
},
dark: {
desktop:
'https://storage.yandexcloud.net/cloud-www-assets/constructor/storybook/images/logo-svg_12-12_desktop_dark.svg',
tablet: 'https://storage.yandexcloud.net/cloud-www-assets/constructor/storybook/images/logo-svg_12-12_tablet_dark.svg',
mobile: 'https://storage.yandexcloud.net/cloud-www-assets/constructor/storybook/images/logo-svg_12-12_mobile_dark.svg',
alt: 'Page constructor',
},
},
qa: 'companies-block',
};

const qaAttributes = getQaAttrubutes(companies.qa, 'title');

describe('Companies', () => {
test('render Companies by default', async () => {
render(<Companies {...companies} />);

const component = screen.getByTestId(qaAttributes.default);

expect(component).toBeInTheDocument();
expect(component).toBeVisible();
});

test('render Companies with title', async () => {
render(<Companies {...companies} />);

const component = screen.getByTestId(qaAttributes.title);

expect(component).toHaveTextContent(companies.title);
});

test('render Companies with animated', async () => {
const user = userEvent.setup();

render(
<div style={{paddingTop: 100000}}>
<Companies {...companies} />
</div>,
);

const component = screen.getByTestId(qaAttributes.default);
await user.hover(component);

expect(component).toHaveClass('animate');
});

test('render Companies without animated', async () => {
const user = userEvent.setup();

render(
<div style={{paddingTop: 100000}}>
<Companies {...companies} animated={false} />
</div>,
);

const component = screen.getByTestId(qaAttributes.default);
await user.hover(component);

expect(component).not.toHaveClass('animate');
});

test('render Companies pass className to AnimatedBlock', async () => {
render(<Companies {...companies} />);

const component = screen.getByTestId(qaAttributes.default);

expect(component).toHaveClass('pc-companies-block');
});

test.each(new Array<Theme>(Theme.Light, Theme.Dark))(
'render Companies with given %s theme',
async (theme) => {
render(
<ThemeContext.Provider value={{theme}}>
<Companies {...companies} />
</ThemeContext.Provider>,
);

const component = screen.getByRole('img');

expect(component).toHaveAttribute(
'src',
`https://storage.yandexcloud.net/cloud-www-assets/constructor/storybook/images/logo-svg_12-12_desktop_${theme}.svg`,
);
},
);
});
4 changes: 2 additions & 2 deletions src/models/constructor-items/blocks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import {ButtonSize} from '@gravity-ui/uikit';

import {GridColumnSize, GridColumnSizesType} from '../../grid/types';
import {ThemeSupporting} from '../../utils';
import {AnalyticsEventsBase} from '../common';
import {AnalyticsEventsBase, QAProps} from '../common';

import {
AnchorProps,
Expand Down Expand Up @@ -210,7 +210,7 @@ export interface QuestionBlockItemProps extends QuestionItem {

export interface BannerBlockProps extends BannerCardProps, Animatable {}

export interface CompaniesBlockProps extends Animatable {
export interface CompaniesBlockProps extends Animatable, QAProps {
title: string;
images: ThemeSupporting<ImageDeviceProps>;
}
Expand Down
Loading