Skip to content

Commit 1c0049d

Browse files
authored
test(BlockBase): test for BlockBase added (#168)
* test(BlockBase): test for BlockBase added
1 parent 4395f8a commit 1c0049d

File tree

4 files changed

+64
-2
lines changed

4 files changed

+64
-2
lines changed

src/components/Anchor/Anchor.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,15 @@ import './Anchor.scss';
88

99
const b = block('Anchor');
1010

11+
export const qaIdByDefault = 'qa-anchor';
12+
1113
export interface AnchorProps extends ClassNameProps {
1214
id: string;
1315
dataQa?: string;
1416
}
1517

1618
const Anchor = ({id, className, dataQa}: AnchorProps) => (
17-
<div id={id} className={b(null, className)} data-qa={dataQa}></div>
19+
<div id={id} className={b(null, className)} data-qa={dataQa || qaIdByDefault}></div>
1820
);
1921

2022
export default Anchor;

src/components/BlockBase/BlockBase.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,14 @@ import './BlockBase.scss';
1010
const b = block('block-base');
1111

1212
const BlockBase = (props: WithChildren<BlockBaseProps & ClassNameProps>) => {
13-
const {anchor, visible, children, className, resetPaddings} = props;
13+
const {anchor, visible, children, className, resetPaddings, qa} = props;
1414

1515
return (
1616
<Col
1717
className={b({['reset-paddings']: resetPaddings}, className)}
1818
visible={visible}
1919
reset={true}
20+
dataQa={qa}
2021
>
2122
{anchor && <Anchor id={anchor.url} className={b('anchor')} />}
2223
{children}
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
import React from 'react';
2+
3+
import {render, screen} from '@testing-library/react';
4+
5+
import {qaIdByDefault} from '../../../components/Anchor/Anchor';
6+
import {GridColumnSize} from '../../../grid';
7+
import BlockBase from '../BlockBase';
8+
9+
const qaId = 'block-base-component';
10+
11+
describe('BlockBase', () => {
12+
test('render component by default', async () => {
13+
render(<BlockBase qa={qaId} />);
14+
const component = screen.getByTestId(qaId);
15+
16+
expect(component).toBeInTheDocument();
17+
expect(component).toBeVisible();
18+
expect(component).not.toBeDisabled();
19+
});
20+
21+
test('add className', () => {
22+
const className = 'my-class';
23+
24+
render(<BlockBase qa={qaId} className={className} />);
25+
const component = screen.getByTestId(qaId);
26+
27+
expect(component).toHaveClass(className);
28+
});
29+
30+
test('should reset paddings', () => {
31+
render(<BlockBase qa={qaId} resetPaddings={true} />);
32+
const component = screen.getByTestId(qaId);
33+
34+
expect(component).toHaveClass('pc-block-base_reset-paddings');
35+
});
36+
37+
test.each(new Array<GridColumnSize>(...Object.values(GridColumnSize)))(
38+
'render with given "%s" size',
39+
(size) => {
40+
render(<BlockBase qa={qaId} visible={size} />);
41+
const component = screen.getByTestId(qaId);
42+
43+
expect(component).toHaveClass(`d-${size}-block`);
44+
},
45+
);
46+
47+
test('should have anchor', () => {
48+
const anchor = {
49+
text: 'anchor',
50+
url: 'https://github.com/gravity-ui/',
51+
};
52+
render(<BlockBase anchor={anchor} />);
53+
const component = screen.getByTestId(qaIdByDefault);
54+
55+
expect(component).toBeInTheDocument();
56+
expect(component).toHaveAttribute('id', anchor.url);
57+
});
58+
});

src/models/constructor-items/blocks.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@ export interface BlockBaseProps {
7575
anchor?: AnchorProps;
7676
visible?: GridColumnSize;
7777
resetPaddings?: boolean;
78+
qa?: string;
7879
}
7980

8081
export interface LoadableProps {

0 commit comments

Comments
 (0)