@gravity-ui/page-constructor 1.26.2-alpha.0 → 1.26.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +17 -30
- package/README.md +8 -7
- package/build/cjs/blocks/Map/schema.d.ts +12 -0
- package/build/cjs/blocks/Share/Share.css +11 -12
- package/build/cjs/components/BlockHeader/BlockHeader.css +2 -2
- package/build/cjs/components/Button/Button.d.ts +0 -1
- package/build/cjs/components/Button/Button.js +1 -1
- package/build/cjs/components/Button/utils.d.ts +0 -1
- package/build/cjs/components/Button/utils.js +1 -2
- package/build/cjs/components/ButtonTabs/ButtonTabs.css +6 -6
- package/build/cjs/components/HTML/HTML.d.ts +1 -1
- package/build/cjs/components/Map/GoogleMap.js +5 -7
- package/build/cjs/components/Map/Map.css +0 -5
- package/build/cjs/components/Map/YMap/YMap.d.ts +2 -4
- package/build/cjs/components/Map/YMap/YMap.js +10 -18
- package/build/cjs/components/Map/YMap/YandexMap.js +9 -18
- package/build/cjs/components/Title/Title.css +5 -20
- package/build/cjs/components/Title/Title.d.ts +1 -1
- package/build/cjs/components/Title/Title.js +2 -4
- package/build/cjs/models/constructor-items/common.d.ts +5 -5
- package/build/cjs/navigation/components/Navigation/Navigation.js +6 -7
- package/build/cjs/schema/validators/common.d.ts +6 -0
- package/build/cjs/schema/validators/common.js +4 -0
- package/build/cjs/sub-blocks/BannerCard/BannerCard.css +1 -2
- package/build/cjs/sub-blocks/Content/Content.css +0 -6
- package/build/cjs/sub-blocks/HubspotForm/HubspotForm.css +0 -1
- package/build/cjs/utils/blocks.d.ts +1 -1
- package/build/cjs/utils/blocks.js +0 -2
- package/build/esm/blocks/Map/schema.d.ts +12 -0
- package/build/esm/blocks/Share/Share.css +11 -12
- package/build/esm/components/BlockHeader/BlockHeader.css +2 -2
- package/build/esm/components/Button/Button.d.ts +0 -1
- package/build/esm/components/Button/Button.js +2 -2
- package/build/esm/components/Button/utils.d.ts +0 -1
- package/build/esm/components/Button/utils.js +0 -1
- package/build/esm/components/ButtonTabs/ButtonTabs.css +6 -6
- package/build/esm/components/HTML/HTML.d.ts +1 -1
- package/build/esm/components/Map/GoogleMap.js +5 -7
- package/build/esm/components/Map/Map.css +0 -5
- package/build/esm/components/Map/YMap/YMap.d.ts +2 -4
- package/build/esm/components/Map/YMap/YMap.js +10 -18
- package/build/esm/components/Map/YMap/YandexMap.js +9 -18
- package/build/esm/components/Title/Title.css +5 -20
- package/build/esm/components/Title/Title.d.ts +1 -1
- package/build/esm/components/Title/Title.js +2 -4
- package/build/esm/models/constructor-items/common.d.ts +5 -5
- package/build/esm/navigation/components/Navigation/Navigation.js +6 -7
- package/build/esm/schema/validators/common.d.ts +6 -0
- package/build/esm/schema/validators/common.js +4 -0
- package/build/esm/sub-blocks/BannerCard/BannerCard.css +1 -2
- package/build/esm/sub-blocks/Content/Content.css +0 -6
- package/build/esm/sub-blocks/HubspotForm/HubspotForm.css +0 -1
- package/build/esm/utils/blocks.d.ts +1 -1
- package/build/esm/utils/blocks.js +0 -2
- package/package.json +6 -7
- package/server/models/constructor-items/common.d.ts +5 -5
- package/server/utils/blocks.d.ts +1 -1
- package/server/utils/blocks.js +0 -2
- package/styles/mixins.scss +7 -9
- package/build/cjs/components/Button/__tests__/Button.test.d.ts +0 -1
- package/build/cjs/components/Button/__tests__/Button.test.js +0 -91
- package/build/esm/components/Button/__tests__/Button.test.d.ts +0 -1
- package/build/esm/components/Button/__tests__/Button.test.js +0 -88
|
@@ -7,7 +7,6 @@ import { ItemColumnName } from '../../constants';
|
|
|
7
7
|
import { NavigationListItem } from '../NavigationListItem/NavigationListItem';
|
|
8
8
|
import './Navigation.css';
|
|
9
9
|
const b = block('navigation');
|
|
10
|
-
const EVENT_HANDLE_DELAY = 100;
|
|
11
10
|
const Navigation = ({ className, onActiveItemChange, links, activeItemId, highlightActiveItem, }) => {
|
|
12
11
|
const { asPath, pathname } = useContext(LocationContext);
|
|
13
12
|
const itemRefs = useRef([]);
|
|
@@ -23,21 +22,21 @@ const Navigation = ({ className, onActiveItemChange, links, activeItemId, highli
|
|
|
23
22
|
}
|
|
24
23
|
}, []);
|
|
25
24
|
useEffect(() => {
|
|
26
|
-
const debouncedCalculateItemPositions = _.debounce(calculateItemPositions,
|
|
27
|
-
const
|
|
25
|
+
const debouncedCalculateItemPositions = _.debounce(calculateItemPositions, 100);
|
|
26
|
+
const calculateOnScroll = _.debounce(() => {
|
|
28
27
|
const curLeftScroll = window.pageXOffset;
|
|
29
28
|
if (curLeftScroll !== lastLeftScroll) {
|
|
30
29
|
setLastLeftScroll(window.pageXOffset);
|
|
31
30
|
calculateItemPositions();
|
|
32
31
|
}
|
|
33
|
-
},
|
|
32
|
+
}, 100);
|
|
34
33
|
calculateItemPositions();
|
|
35
34
|
setLastLeftScroll(window.pageXOffset);
|
|
36
35
|
window.addEventListener('resize', debouncedCalculateItemPositions);
|
|
37
|
-
window.addEventListener('scroll',
|
|
36
|
+
window.addEventListener('scroll', calculateOnScroll);
|
|
38
37
|
return () => {
|
|
39
|
-
window.removeEventListener(`resize`,
|
|
40
|
-
window.removeEventListener('scroll',
|
|
38
|
+
window.removeEventListener(`resize`, calculateItemPositions);
|
|
39
|
+
window.removeEventListener('scroll', calculateOnScroll);
|
|
41
40
|
};
|
|
42
41
|
}, [calculateItemPositions, itemRefs, lastLeftScroll]);
|
|
43
42
|
useEffect(() => {
|
|
@@ -70,10 +70,9 @@ unpredictable css rules order in build */
|
|
|
70
70
|
font-weight: var(--yc-text-accent-font-weight);
|
|
71
71
|
font-weight: normal;
|
|
72
72
|
}
|
|
73
|
-
.pc-banner-card__button
|
|
73
|
+
.pc-banner-card__button {
|
|
74
74
|
margin-top: 28px;
|
|
75
75
|
}
|
|
76
|
-
|
|
77
76
|
.pc-banner-card__image {
|
|
78
77
|
border-top-right-radius: var(--pc-border-radius);
|
|
79
78
|
border-bottom-right-radius: var(--pc-border-radius);
|
|
@@ -31,9 +31,6 @@ unpredictable css rules order in build */
|
|
|
31
31
|
margin-top: 0;
|
|
32
32
|
margin-right: 12px;
|
|
33
33
|
}
|
|
34
|
-
.pc-content__button.pc-content__button:last-child {
|
|
35
|
-
margin-right: 0;
|
|
36
|
-
}
|
|
37
34
|
|
|
38
35
|
.pc-content__links {
|
|
39
36
|
display: flex;
|
|
@@ -44,9 +41,6 @@ unpredictable css rules order in build */
|
|
|
44
41
|
display: block;
|
|
45
42
|
margin-right: 32px;
|
|
46
43
|
}
|
|
47
|
-
.pc-content__link:last-child {
|
|
48
|
-
margin-right: 0;
|
|
49
|
-
}
|
|
50
44
|
.pc-content_centered.pc-content_centered {
|
|
51
45
|
margin: 0 auto;
|
|
52
46
|
text-align: center;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { ConstructorBlock } from '../models/constructor';
|
|
2
2
|
import { TextSize, CustomConfig, PCShareSocialNetwork } from '../models';
|
|
3
|
-
export declare function getHeaderTag(size: TextSize): "h1" | "h2" | "h4"
|
|
3
|
+
export declare function getHeaderTag(size: TextSize): "h1" | "h2" | "h4";
|
|
4
4
|
export declare function getBlockKey(block: ConstructorBlock, index: number): string;
|
|
5
5
|
export declare const getCustomBlockTypes: ({ blocks, headers }?: CustomConfig) => string[];
|
|
6
6
|
export declare const getCustomItems: ({ blocks, headers, subBlocks }?: CustomConfig) => {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@gravity-ui/page-constructor",
|
|
3
|
-
"version": "1.26.2
|
|
3
|
+
"version": "1.26.2",
|
|
4
4
|
"description": "Gravity UI Page Constructor",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": {
|
|
@@ -61,8 +61,8 @@
|
|
|
61
61
|
"uuid": "^9.0.0"
|
|
62
62
|
},
|
|
63
63
|
"peerDependencies": {
|
|
64
|
-
"react": "^16.0.0 || ^17.0.0
|
|
65
|
-
"@gravity-ui/uikit": "^
|
|
64
|
+
"react": "^16.0.0 || ^17.0.0",
|
|
65
|
+
"@gravity-ui/uikit": "^3.11.0",
|
|
66
66
|
"@doc-tools/transform": "^2.6.1"
|
|
67
67
|
},
|
|
68
68
|
"devDependencies": {
|
|
@@ -73,20 +73,19 @@
|
|
|
73
73
|
"@gravity-ui/prettier-config": "^1.0.1",
|
|
74
74
|
"@gravity-ui/stylelint-config": "^1.0.0",
|
|
75
75
|
"@gravity-ui/tsconfig": "^1.0.0",
|
|
76
|
-
"@gravity-ui/uikit": "^
|
|
76
|
+
"@gravity-ui/uikit": "^3.11.0",
|
|
77
77
|
"@storybook/addon-actions": "^6.3.12",
|
|
78
78
|
"@storybook/addon-essentials": "^6.5.10",
|
|
79
79
|
"@storybook/addon-knobs": "^6.3.1",
|
|
80
80
|
"@storybook/addon-viewport": "^6.3.12",
|
|
81
81
|
"@storybook/preset-scss": "^1.0.3",
|
|
82
|
-
"@storybook/react": "^6.5.
|
|
82
|
+
"@storybook/react": "^6.5.10",
|
|
83
83
|
"@testing-library/jest-dom": "^5.16.5",
|
|
84
84
|
"@testing-library/react": "^13.4.0",
|
|
85
85
|
"@testing-library/user-event": "^14.4.3",
|
|
86
86
|
"@types/jest": "^29.2.4",
|
|
87
87
|
"@types/lodash": "^4.14.176",
|
|
88
|
-
"@types/react": "^
|
|
89
|
-
"@types/react-dom": "^18.0.10",
|
|
88
|
+
"@types/react": "^16.14.20",
|
|
90
89
|
"@types/react-slick": "^0.23.7",
|
|
91
90
|
"@types/react-transition-group": "^4.4.4",
|
|
92
91
|
"@types/sanitize-html": "^2.6.0",
|
|
@@ -38,7 +38,7 @@ export declare enum MediaVideoControlsType {
|
|
|
38
38
|
Custom = "custom"
|
|
39
39
|
}
|
|
40
40
|
export type TextTheme = 'light' | 'dark';
|
|
41
|
-
export type TextSize = '
|
|
41
|
+
export type TextSize = 's' | 'm' | 'l';
|
|
42
42
|
export type DividerSize = '0' | 'xxs' | 'xs' | 's' | 'm' | 'l' | 'xl' | 'xxl' | 'xxxl';
|
|
43
43
|
export type HeaderWidth = 's' | 'm' | 'l';
|
|
44
44
|
export type HeaderImageSize = 's' | 'm';
|
|
@@ -130,22 +130,20 @@ export interface FileLinkProps extends ClassNameProps {
|
|
|
130
130
|
theme?: ContentTheme;
|
|
131
131
|
onClick?: () => void;
|
|
132
132
|
}
|
|
133
|
-
export type ButtonTheme = ButtonView | 'github' | 'app-store' | 'google-play' | 'scale' | 'monochrome';
|
|
134
133
|
export interface ButtonProps extends AnalyticsEventsBase {
|
|
135
134
|
text: string;
|
|
136
135
|
url: string;
|
|
137
136
|
primary?: boolean;
|
|
138
137
|
size?: ButtonSize;
|
|
139
|
-
theme?:
|
|
138
|
+
theme?: ButtonView | 'github' | 'app-store' | 'google-play' | 'scale' | 'monochrome';
|
|
140
139
|
img?: ButtonImageProps | string;
|
|
141
140
|
metrikaGoals?: MetrikaGoal;
|
|
142
141
|
pixelEvents?: ButtonPixel;
|
|
143
142
|
target?: string;
|
|
144
143
|
}
|
|
145
|
-
export type ButtonImagePosition = 'left' | 'right';
|
|
146
144
|
export interface ButtonImageProps {
|
|
147
145
|
url: string;
|
|
148
|
-
position?:
|
|
146
|
+
position?: 'left' | 'right';
|
|
149
147
|
alt?: string;
|
|
150
148
|
}
|
|
151
149
|
export interface PlayButtonProps extends ClassNameProps {
|
|
@@ -191,6 +189,7 @@ export interface MediaProps extends Animatable, Partial<MediaComponentDataLensPr
|
|
|
191
189
|
export type Coordinate = number[];
|
|
192
190
|
export interface MapBaseProps {
|
|
193
191
|
zoom?: number;
|
|
192
|
+
center?: Coordinate;
|
|
194
193
|
}
|
|
195
194
|
export interface GMapProps extends MapBaseProps {
|
|
196
195
|
address: string;
|
|
@@ -198,6 +197,7 @@ export interface GMapProps extends MapBaseProps {
|
|
|
198
197
|
export interface YMapProps extends MapBaseProps {
|
|
199
198
|
markers: YMapMarker[];
|
|
200
199
|
id: string;
|
|
200
|
+
center: Coordinate;
|
|
201
201
|
}
|
|
202
202
|
export interface YMapMarker {
|
|
203
203
|
address?: string;
|
package/server/utils/blocks.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { ConstructorBlock } from '../models/constructor';
|
|
2
2
|
import { TextSize, CustomConfig, PCShareSocialNetwork } from '../models';
|
|
3
|
-
export declare function getHeaderTag(size: TextSize): "h1" | "h2" | "h4"
|
|
3
|
+
export declare function getHeaderTag(size: TextSize): "h1" | "h2" | "h4";
|
|
4
4
|
export declare function getBlockKey(block: ConstructorBlock, index: number): string;
|
|
5
5
|
export declare const getCustomBlockTypes: ({ blocks, headers }?: CustomConfig) => string[];
|
|
6
6
|
export declare const getCustomItems: ({ blocks, headers, subBlocks }?: CustomConfig) => {
|
package/server/utils/blocks.js
CHANGED
package/styles/mixins.scss
CHANGED
|
@@ -141,17 +141,15 @@
|
|
|
141
141
|
}
|
|
142
142
|
|
|
143
143
|
@mixin label($size: m) {
|
|
144
|
-
@
|
|
145
|
-
@include text-size(body-1);
|
|
144
|
+
@include text-size(body-1);
|
|
146
145
|
|
|
147
|
-
|
|
146
|
+
$label-height: 20px;
|
|
148
147
|
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
}
|
|
148
|
+
display: inline-block;
|
|
149
|
+
padding: 0 8px;
|
|
150
|
+
border-radius: 2px;
|
|
151
|
+
height: $label-height;
|
|
152
|
+
line-height: $label-height;
|
|
155
153
|
|
|
156
154
|
@if $size == s {
|
|
157
155
|
@include text-size(caption-2);
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1,91 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
const tslib_1 = require("tslib");
|
|
4
|
-
const react_1 = tslib_1.__importDefault(require("react"));
|
|
5
|
-
const react_2 = require("@testing-library/react");
|
|
6
|
-
const user_event_1 = tslib_1.__importDefault(require("@testing-library/user-event"));
|
|
7
|
-
const utils_1 = require("../utils");
|
|
8
|
-
const Button_1 = tslib_1.__importDefault(require("../Button"));
|
|
9
|
-
const qaId = 'button-component';
|
|
10
|
-
const buttonProps = {
|
|
11
|
-
text: 'Button Text',
|
|
12
|
-
url: 'https://github.com/gravity-ui/',
|
|
13
|
-
target: '_blank',
|
|
14
|
-
img: {
|
|
15
|
-
url: 'https://storage.yandexcloud.net/cloud-www-assets/constructor/storybook/images/icon_1_light.svg',
|
|
16
|
-
position: 'left',
|
|
17
|
-
alt: 'alt-text',
|
|
18
|
-
},
|
|
19
|
-
};
|
|
20
|
-
const buttonViews = [
|
|
21
|
-
'normal',
|
|
22
|
-
'action',
|
|
23
|
-
'outlined',
|
|
24
|
-
'outlined-info',
|
|
25
|
-
'outlined-danger',
|
|
26
|
-
'raised',
|
|
27
|
-
'flat',
|
|
28
|
-
'flat-info',
|
|
29
|
-
'flat-danger',
|
|
30
|
-
'flat-secondary',
|
|
31
|
-
'normal-contrast',
|
|
32
|
-
'outlined-contrast',
|
|
33
|
-
'flat-contrast',
|
|
34
|
-
'github',
|
|
35
|
-
'scale',
|
|
36
|
-
'monochrome',
|
|
37
|
-
];
|
|
38
|
-
describe('Button', () => {
|
|
39
|
-
test('render button by default', async () => {
|
|
40
|
-
(0, react_2.render)(react_1.default.createElement(Button_1.default, { text: buttonProps.text }));
|
|
41
|
-
const button = react_2.screen.getByRole('button');
|
|
42
|
-
expect(button).toBeInTheDocument();
|
|
43
|
-
expect(button).toBeVisible();
|
|
44
|
-
expect(button).not.toBeDisabled();
|
|
45
|
-
});
|
|
46
|
-
test('should render <a /> tag', async () => {
|
|
47
|
-
(0, react_2.render)(react_1.default.createElement(Button_1.default, { text: buttonProps.text, url: buttonProps.url, target: buttonProps.target }));
|
|
48
|
-
const button = react_2.screen.getByRole('link');
|
|
49
|
-
expect(button).toBeVisible();
|
|
50
|
-
expect(button).toHaveAttribute('href', buttonProps.url);
|
|
51
|
-
expect(button).toHaveAttribute('target', buttonProps.target);
|
|
52
|
-
});
|
|
53
|
-
test('call onClick', async () => {
|
|
54
|
-
const user = user_event_1.default.setup();
|
|
55
|
-
const handleOnClick = jest.fn();
|
|
56
|
-
(0, react_2.render)(react_1.default.createElement(Button_1.default, { text: buttonProps.text, onClick: handleOnClick }));
|
|
57
|
-
const button = react_2.screen.getByRole('button');
|
|
58
|
-
await user.click(button);
|
|
59
|
-
expect(handleOnClick).toHaveBeenCalledTimes(1);
|
|
60
|
-
});
|
|
61
|
-
test.each(new Array('s', 'm', 'l', 'xl'))('render with given "%s" size', (size) => {
|
|
62
|
-
(0, react_2.render)(react_1.default.createElement(Button_1.default, { text: buttonProps.text, size: size, qa: qaId }));
|
|
63
|
-
const button = react_2.screen.getByTestId(qaId);
|
|
64
|
-
expect(button).toHaveClass(`pc-button-block_size_${size}`);
|
|
65
|
-
});
|
|
66
|
-
test.each(new Array(...buttonViews))('render with given "%s" view', (theme) => {
|
|
67
|
-
(0, react_2.render)(react_1.default.createElement(Button_1.default, { text: buttonProps.text, theme: theme, qa: qaId }));
|
|
68
|
-
const button = react_2.screen.getByTestId(qaId);
|
|
69
|
-
expect(button).toHaveClass(`pc-button-block_theme_${theme}`);
|
|
70
|
-
});
|
|
71
|
-
test('add className', () => {
|
|
72
|
-
const className = 'my-class';
|
|
73
|
-
(0, react_2.render)(react_1.default.createElement(Button_1.default, { text: buttonProps.text, className: className, qa: qaId }));
|
|
74
|
-
const button = react_2.screen.getByTestId(qaId);
|
|
75
|
-
expect(button).toHaveClass(className);
|
|
76
|
-
});
|
|
77
|
-
test('should render icon', () => {
|
|
78
|
-
(0, react_2.render)(react_1.default.createElement(Button_1.default, { text: buttonProps.text, img: buttonProps.img }));
|
|
79
|
-
const button = react_2.screen.getByRole('button');
|
|
80
|
-
const iconComponent = react_2.screen.getByRole('img');
|
|
81
|
-
expect(iconComponent).toBeVisible();
|
|
82
|
-
expect(button).toContainElement(iconComponent);
|
|
83
|
-
});
|
|
84
|
-
test('should render github icon', () => {
|
|
85
|
-
(0, react_2.render)(react_1.default.createElement(Button_1.default, { text: buttonProps.text, img: buttonProps.img, theme: "github" }));
|
|
86
|
-
const button = react_2.screen.getByRole('button');
|
|
87
|
-
const iconComponent = react_2.screen.getByTestId(utils_1.ICON_QA);
|
|
88
|
-
expect(iconComponent).toBeVisible();
|
|
89
|
-
expect(button).toContainElement(iconComponent);
|
|
90
|
-
});
|
|
91
|
-
});
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1,88 +0,0 @@
|
|
|
1
|
-
import React from 'react';
|
|
2
|
-
import { render, screen } from '@testing-library/react';
|
|
3
|
-
import userEvent from '@testing-library/user-event';
|
|
4
|
-
import { ICON_QA } from '../utils';
|
|
5
|
-
import Button from '../Button';
|
|
6
|
-
const qaId = 'button-component';
|
|
7
|
-
const buttonProps = {
|
|
8
|
-
text: 'Button Text',
|
|
9
|
-
url: 'https://github.com/gravity-ui/',
|
|
10
|
-
target: '_blank',
|
|
11
|
-
img: {
|
|
12
|
-
url: 'https://storage.yandexcloud.net/cloud-www-assets/constructor/storybook/images/icon_1_light.svg',
|
|
13
|
-
position: 'left',
|
|
14
|
-
alt: 'alt-text',
|
|
15
|
-
},
|
|
16
|
-
};
|
|
17
|
-
const buttonViews = [
|
|
18
|
-
'normal',
|
|
19
|
-
'action',
|
|
20
|
-
'outlined',
|
|
21
|
-
'outlined-info',
|
|
22
|
-
'outlined-danger',
|
|
23
|
-
'raised',
|
|
24
|
-
'flat',
|
|
25
|
-
'flat-info',
|
|
26
|
-
'flat-danger',
|
|
27
|
-
'flat-secondary',
|
|
28
|
-
'normal-contrast',
|
|
29
|
-
'outlined-contrast',
|
|
30
|
-
'flat-contrast',
|
|
31
|
-
'github',
|
|
32
|
-
'scale',
|
|
33
|
-
'monochrome',
|
|
34
|
-
];
|
|
35
|
-
describe('Button', () => {
|
|
36
|
-
test('render button by default', async () => {
|
|
37
|
-
render(React.createElement(Button, { text: buttonProps.text }));
|
|
38
|
-
const button = screen.getByRole('button');
|
|
39
|
-
expect(button).toBeInTheDocument();
|
|
40
|
-
expect(button).toBeVisible();
|
|
41
|
-
expect(button).not.toBeDisabled();
|
|
42
|
-
});
|
|
43
|
-
test('should render <a /> tag', async () => {
|
|
44
|
-
render(React.createElement(Button, { text: buttonProps.text, url: buttonProps.url, target: buttonProps.target }));
|
|
45
|
-
const button = screen.getByRole('link');
|
|
46
|
-
expect(button).toBeVisible();
|
|
47
|
-
expect(button).toHaveAttribute('href', buttonProps.url);
|
|
48
|
-
expect(button).toHaveAttribute('target', buttonProps.target);
|
|
49
|
-
});
|
|
50
|
-
test('call onClick', async () => {
|
|
51
|
-
const user = userEvent.setup();
|
|
52
|
-
const handleOnClick = jest.fn();
|
|
53
|
-
render(React.createElement(Button, { text: buttonProps.text, onClick: handleOnClick }));
|
|
54
|
-
const button = screen.getByRole('button');
|
|
55
|
-
await user.click(button);
|
|
56
|
-
expect(handleOnClick).toHaveBeenCalledTimes(1);
|
|
57
|
-
});
|
|
58
|
-
test.each(new Array('s', 'm', 'l', 'xl'))('render with given "%s" size', (size) => {
|
|
59
|
-
render(React.createElement(Button, { text: buttonProps.text, size: size, qa: qaId }));
|
|
60
|
-
const button = screen.getByTestId(qaId);
|
|
61
|
-
expect(button).toHaveClass(`pc-button-block_size_${size}`);
|
|
62
|
-
});
|
|
63
|
-
test.each(new Array(...buttonViews))('render with given "%s" view', (theme) => {
|
|
64
|
-
render(React.createElement(Button, { text: buttonProps.text, theme: theme, qa: qaId }));
|
|
65
|
-
const button = screen.getByTestId(qaId);
|
|
66
|
-
expect(button).toHaveClass(`pc-button-block_theme_${theme}`);
|
|
67
|
-
});
|
|
68
|
-
test('add className', () => {
|
|
69
|
-
const className = 'my-class';
|
|
70
|
-
render(React.createElement(Button, { text: buttonProps.text, className: className, qa: qaId }));
|
|
71
|
-
const button = screen.getByTestId(qaId);
|
|
72
|
-
expect(button).toHaveClass(className);
|
|
73
|
-
});
|
|
74
|
-
test('should render icon', () => {
|
|
75
|
-
render(React.createElement(Button, { text: buttonProps.text, img: buttonProps.img }));
|
|
76
|
-
const button = screen.getByRole('button');
|
|
77
|
-
const iconComponent = screen.getByRole('img');
|
|
78
|
-
expect(iconComponent).toBeVisible();
|
|
79
|
-
expect(button).toContainElement(iconComponent);
|
|
80
|
-
});
|
|
81
|
-
test('should render github icon', () => {
|
|
82
|
-
render(React.createElement(Button, { text: buttonProps.text, img: buttonProps.img, theme: "github" }));
|
|
83
|
-
const button = screen.getByRole('button');
|
|
84
|
-
const iconComponent = screen.getByTestId(ICON_QA);
|
|
85
|
-
expect(iconComponent).toBeVisible();
|
|
86
|
-
expect(button).toContainElement(iconComponent);
|
|
87
|
-
});
|
|
88
|
-
});
|