@patternfly/react-core 5.0.0-alpha.4 → 5.0.0-alpha.6
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 +8 -0
- package/package.json +2 -3
- package/src/components/Menu/__mocks__/Menu.tsx +12 -0
- package/src/components/Menu/__mocks__/MenuContent.tsx +3 -0
- package/src/components/Menu/__mocks__/MenuGroup.tsx +12 -0
- package/src/components/Menu/__mocks__/MenuItem.tsx +12 -0
- package/src/components/Menu/__mocks__/MenuList.tsx +10 -0
- package/src/components/Menu/__mocks__/index.ts +5 -0
- package/src/helpers/Popper/__mocks__/Popper.tsx +11 -0
- package/src/helpers/Popper/__mocks__/index.ts +1 -0
- package/src/next/components/Dropdown/__tests__/Dropdown.test.tsx +236 -0
- package/src/next/components/Dropdown/__tests__/DropdownGroup.test.tsx +69 -0
- package/src/next/components/Dropdown/__tests__/DropdownItem.test.tsx +73 -0
- package/src/next/components/Dropdown/__tests__/DropdownList.test.tsx +41 -0
- package/src/next/components/Dropdown/__tests__/__snapshots__/Dropdown.test.tsx.snap +47 -0
- package/src/next/components/Dropdown/__tests__/__snapshots__/DropdownGroup.test.tsx.snap +20 -0
- package/src/next/components/Dropdown/__tests__/__snapshots__/DropdownItem.test.tsx.snap +20 -0
- package/src/next/components/Dropdown/__tests__/__snapshots__/DropdownList.test.tsx.snap +14 -0
- package/dist/esm/helpers/Popper/DeprecatedPopperTypes.d.ts +0 -137
- package/dist/esm/helpers/Popper/DeprecatedPopperTypes.d.ts.map +0 -1
- package/dist/esm/helpers/Popper/DeprecatedPopperTypes.js +0 -8
- package/dist/esm/helpers/Popper/DeprecatedPopperTypes.js.map +0 -1
- package/dist/esm/helpers/Popper/DeprecatedTippyTypes.d.ts +0 -211
- package/dist/esm/helpers/Popper/DeprecatedTippyTypes.d.ts.map +0 -1
- package/dist/esm/helpers/Popper/DeprecatedTippyTypes.js +0 -8
- package/dist/esm/helpers/Popper/DeprecatedTippyTypes.js.map +0 -1
- package/dist/js/helpers/Popper/DeprecatedPopperTypes.d.ts +0 -137
- package/dist/js/helpers/Popper/DeprecatedPopperTypes.d.ts.map +0 -1
- package/dist/js/helpers/Popper/DeprecatedPopperTypes.js +0 -10
- package/dist/js/helpers/Popper/DeprecatedPopperTypes.js.map +0 -1
- package/dist/js/helpers/Popper/DeprecatedTippyTypes.d.ts +0 -211
- package/dist/js/helpers/Popper/DeprecatedTippyTypes.d.ts.map +0 -1
- package/dist/js/helpers/Popper/DeprecatedTippyTypes.js +0 -10
- package/dist/js/helpers/Popper/DeprecatedTippyTypes.js.map +0 -1
- package/src/helpers/Popper/DeprecatedPopperTypes.ts +0 -180
- package/src/helpers/Popper/DeprecatedTippyTypes.ts +0 -284
package/CHANGELOG.md
CHANGED
|
@@ -3,6 +3,14 @@
|
|
|
3
3
|
All notable changes to this project will be documented in this file.
|
|
4
4
|
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
|
|
5
5
|
|
|
6
|
+
# [5.0.0-alpha.6](https://github.com/patternfly/patternfly-react/compare/@patternfly/react-core@5.0.0-alpha.5...@patternfly/react-core@5.0.0-alpha.6) (2023-02-02)
|
|
7
|
+
|
|
8
|
+
**Note:** Version bump only for package @patternfly/react-core
|
|
9
|
+
|
|
10
|
+
# [5.0.0-alpha.5](https://github.com/patternfly/patternfly-react/compare/@patternfly/react-core@5.0.0-alpha.4...@patternfly/react-core@5.0.0-alpha.5) (2023-02-02)
|
|
11
|
+
|
|
12
|
+
**Note:** Version bump only for package @patternfly/react-core
|
|
13
|
+
|
|
6
14
|
# 5.0.0-alpha.4 (2023-01-18)
|
|
7
15
|
|
|
8
16
|
**Note:** Version bump only for package @patternfly/react-core
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@patternfly/react-core",
|
|
3
|
-
"version": "5.0.0-alpha.
|
|
3
|
+
"version": "5.0.0-alpha.6",
|
|
4
4
|
"description": "This library provides a set of common React components for use with the PatternFly reference implementation.",
|
|
5
5
|
"main": "dist/js/index.js",
|
|
6
6
|
"module": "dist/esm/index.js",
|
|
@@ -50,7 +50,6 @@
|
|
|
50
50
|
"@patternfly/react-tokens": "^5.0.0-alpha.1",
|
|
51
51
|
"focus-trap": "6.9.2",
|
|
52
52
|
"react-dropzone": "^14.2.3",
|
|
53
|
-
"tippy.js": "5.1.2",
|
|
54
53
|
"tslib": "^2.0.0"
|
|
55
54
|
},
|
|
56
55
|
"devDependencies": {
|
|
@@ -71,5 +70,5 @@
|
|
|
71
70
|
"react": "^16.8 || ^17 || ^18",
|
|
72
71
|
"react-dom": "^16.8 || ^17 || ^18"
|
|
73
72
|
},
|
|
74
|
-
"gitHead": "
|
|
73
|
+
"gitHead": "7597ae3651b5d51db280629c663950dd7fa40feb"
|
|
75
74
|
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { MenuProps } from '../Menu';
|
|
3
|
+
|
|
4
|
+
export const Menu = ({ className, isPlain, isScrollable, style, onSelect, ...props }: MenuProps) => (
|
|
5
|
+
<>
|
|
6
|
+
<div className={className} data-testid="menu-mock" {...props}></div>
|
|
7
|
+
<div onClick={onSelect}>{'Mock item'}</div>
|
|
8
|
+
<p>{`isPlain: ${isPlain}`}</p>
|
|
9
|
+
<p>{`isScrollable: ${isScrollable}`}</p>
|
|
10
|
+
<p>{`minWidth: ${style?.['--pf-c-menu--MinWidth']}`}</p>
|
|
11
|
+
</>
|
|
12
|
+
);
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { MenuGroupProps } from '../MenuGroup';
|
|
3
|
+
|
|
4
|
+
export const MenuGroup = ({ className, children, label, labelHeadingLevel }: MenuGroupProps) => (
|
|
5
|
+
<>
|
|
6
|
+
<div className={className} data-testid="menu-group-mock">
|
|
7
|
+
{children}
|
|
8
|
+
</div>
|
|
9
|
+
<p>{`label: ${label}`}</p>
|
|
10
|
+
<p>{`labelHeadingLevel: ${labelHeadingLevel}`}</p>
|
|
11
|
+
</>
|
|
12
|
+
);
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { MenuItemProps } from '../MenuItem';
|
|
3
|
+
|
|
4
|
+
export const MenuItem = ({ className, children, description, itemId }: MenuItemProps) => (
|
|
5
|
+
<>
|
|
6
|
+
<div className={className} data-testid="menu-item-mock">
|
|
7
|
+
{children}
|
|
8
|
+
</div>
|
|
9
|
+
<p>{`description: ${description}`}</p>
|
|
10
|
+
<p>{`itemId: ${itemId}`}</p>
|
|
11
|
+
</>
|
|
12
|
+
);
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { PopperProps } from '../Popper';
|
|
3
|
+
|
|
4
|
+
export const Popper = ({ popper, zIndex, isVisible, trigger }: PopperProps) => (
|
|
5
|
+
<>
|
|
6
|
+
<div>{popper}</div>
|
|
7
|
+
<p>{`zIndex: ${zIndex}`}</p>
|
|
8
|
+
<p>{`isOpen: ${isVisible}`}</p>
|
|
9
|
+
<div>{trigger}</div>
|
|
10
|
+
</>
|
|
11
|
+
);
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './Popper';
|
|
@@ -0,0 +1,236 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { Dropdown } from '../../Dropdown';
|
|
3
|
+
import { render, screen, waitFor } from '@testing-library/react';
|
|
4
|
+
import userEvent from '@testing-library/user-event';
|
|
5
|
+
|
|
6
|
+
jest.mock('../../../../components/Menu');
|
|
7
|
+
|
|
8
|
+
jest.mock('../../../../helpers/Popper/Popper');
|
|
9
|
+
|
|
10
|
+
const toggle = (ref: React.RefObject<any>) => <button ref={ref}>Dropdown</button>;
|
|
11
|
+
|
|
12
|
+
const dropdownChildren = <div>Dropdown children</div>;
|
|
13
|
+
|
|
14
|
+
test('renders dropdown', () => {
|
|
15
|
+
render(
|
|
16
|
+
<div data-testid="dropdown">
|
|
17
|
+
<Dropdown toggle={toggleRef => toggle(toggleRef)}>{dropdownChildren}</Dropdown>
|
|
18
|
+
</div>
|
|
19
|
+
);
|
|
20
|
+
|
|
21
|
+
expect(screen.getByTestId('dropdown').children[0]).toBeVisible();
|
|
22
|
+
});
|
|
23
|
+
|
|
24
|
+
test('passes children', () => {
|
|
25
|
+
render(<Dropdown toggle={toggleRef => toggle(toggleRef)}>{dropdownChildren}</Dropdown>);
|
|
26
|
+
|
|
27
|
+
expect(screen.getByText('Dropdown children')).toBeVisible();
|
|
28
|
+
});
|
|
29
|
+
|
|
30
|
+
test('renders passed toggle element', () => {
|
|
31
|
+
render(<Dropdown toggle={toggleRef => toggle(toggleRef)}>{dropdownChildren}</Dropdown>);
|
|
32
|
+
|
|
33
|
+
expect(screen.getByRole('button', { name: 'Dropdown' })).toBeVisible();
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
test('passes no class name by default', () => {
|
|
37
|
+
render(
|
|
38
|
+
<Dropdown isOpen={true} toggle={toggleRef => toggle(toggleRef)}>
|
|
39
|
+
{dropdownChildren}
|
|
40
|
+
</Dropdown>
|
|
41
|
+
);
|
|
42
|
+
|
|
43
|
+
expect(screen.getByTestId('menu-mock')).not.toHaveClass();
|
|
44
|
+
});
|
|
45
|
+
|
|
46
|
+
test('passes custom class name', () => {
|
|
47
|
+
render(
|
|
48
|
+
<Dropdown className="custom-class" isOpen={true} toggle={toggleRef => toggle(toggleRef)}>
|
|
49
|
+
{dropdownChildren}
|
|
50
|
+
</Dropdown>
|
|
51
|
+
);
|
|
52
|
+
|
|
53
|
+
expect(screen.getByTestId('menu-mock')).toHaveClass('custom-class');
|
|
54
|
+
});
|
|
55
|
+
|
|
56
|
+
test('does not pass isPlain to Menu by default', () => {
|
|
57
|
+
render(
|
|
58
|
+
<Dropdown isOpen={true} toggle={toggleRef => toggle(toggleRef)}>
|
|
59
|
+
{dropdownChildren}
|
|
60
|
+
</Dropdown>
|
|
61
|
+
);
|
|
62
|
+
|
|
63
|
+
expect(screen.getByText('isPlain: undefined')).toBeVisible();
|
|
64
|
+
});
|
|
65
|
+
|
|
66
|
+
test('passes isPlain to Menu', () => {
|
|
67
|
+
render(
|
|
68
|
+
<Dropdown isPlain isOpen={true} toggle={toggleRef => toggle(toggleRef)}>
|
|
69
|
+
{dropdownChildren}
|
|
70
|
+
</Dropdown>
|
|
71
|
+
);
|
|
72
|
+
|
|
73
|
+
expect(screen.getByText('isPlain: true')).toBeVisible();
|
|
74
|
+
});
|
|
75
|
+
|
|
76
|
+
test('does not pass isScrollable to Menu by default', () => {
|
|
77
|
+
render(
|
|
78
|
+
<Dropdown isOpen={true} toggle={toggleRef => toggle(toggleRef)}>
|
|
79
|
+
{dropdownChildren}
|
|
80
|
+
</Dropdown>
|
|
81
|
+
);
|
|
82
|
+
|
|
83
|
+
expect(screen.getByText('isScrollable: undefined')).toBeVisible();
|
|
84
|
+
});
|
|
85
|
+
|
|
86
|
+
test('passes isScrollable to Menu', () => {
|
|
87
|
+
render(
|
|
88
|
+
<Dropdown isScrollable isOpen={true} toggle={toggleRef => toggle(toggleRef)}>
|
|
89
|
+
{dropdownChildren}
|
|
90
|
+
</Dropdown>
|
|
91
|
+
);
|
|
92
|
+
|
|
93
|
+
expect(screen.getByText('isScrollable: true')).toBeVisible();
|
|
94
|
+
});
|
|
95
|
+
|
|
96
|
+
test('does not pass minWidth to Menu by default', () => {
|
|
97
|
+
render(
|
|
98
|
+
<Dropdown isOpen={true} toggle={toggleRef => toggle(toggleRef)}>
|
|
99
|
+
{dropdownChildren}
|
|
100
|
+
</Dropdown>
|
|
101
|
+
);
|
|
102
|
+
|
|
103
|
+
expect(screen.getByText('minWidth: undefined')).toBeVisible();
|
|
104
|
+
});
|
|
105
|
+
|
|
106
|
+
test('passes minWidth to Menu', () => {
|
|
107
|
+
render(
|
|
108
|
+
<Dropdown minWidth="100px" isOpen={true} toggle={toggleRef => toggle(toggleRef)}>
|
|
109
|
+
{dropdownChildren}
|
|
110
|
+
</Dropdown>
|
|
111
|
+
);
|
|
112
|
+
|
|
113
|
+
expect(screen.getByText('minWidth: 100px')).toBeVisible();
|
|
114
|
+
});
|
|
115
|
+
|
|
116
|
+
test('passes default zIndex to popper', () => {
|
|
117
|
+
render(<Dropdown toggle={toggleRef => toggle(toggleRef)}>{dropdownChildren}</Dropdown>);
|
|
118
|
+
|
|
119
|
+
expect(screen.getByText('zIndex: 9999')).toBeVisible();
|
|
120
|
+
});
|
|
121
|
+
|
|
122
|
+
test('passes zIndex to popper', () => {
|
|
123
|
+
render(
|
|
124
|
+
<Dropdown zIndex={100} toggle={toggleRef => toggle(toggleRef)}>
|
|
125
|
+
{dropdownChildren}
|
|
126
|
+
</Dropdown>
|
|
127
|
+
);
|
|
128
|
+
|
|
129
|
+
expect(screen.getByText('zIndex: 100')).toBeVisible();
|
|
130
|
+
});
|
|
131
|
+
|
|
132
|
+
test('does not pass isOpen to popper by default', () => {
|
|
133
|
+
render(<Dropdown toggle={toggleRef => toggle(toggleRef)}>{dropdownChildren}</Dropdown>);
|
|
134
|
+
|
|
135
|
+
expect(screen.getByText('isOpen: undefined')).toBeVisible();
|
|
136
|
+
});
|
|
137
|
+
|
|
138
|
+
test('passes isOpen to popper', () => {
|
|
139
|
+
render(
|
|
140
|
+
<Dropdown isOpen toggle={toggleRef => toggle(toggleRef)}>
|
|
141
|
+
{dropdownChildren}
|
|
142
|
+
</Dropdown>
|
|
143
|
+
);
|
|
144
|
+
|
|
145
|
+
expect(screen.getByText('isOpen: true')).toBeVisible();
|
|
146
|
+
});
|
|
147
|
+
|
|
148
|
+
/* no default tests for callback props
|
|
149
|
+
since there is no way to test that the
|
|
150
|
+
function doesn`t get passed */
|
|
151
|
+
|
|
152
|
+
test('passes onSelect callback', async () => {
|
|
153
|
+
const user = userEvent.setup();
|
|
154
|
+
|
|
155
|
+
const onSelect = jest.fn();
|
|
156
|
+
render(
|
|
157
|
+
<Dropdown onSelect={onSelect} toggle={toggleRef => toggle(toggleRef)}>
|
|
158
|
+
{dropdownChildren}
|
|
159
|
+
</Dropdown>
|
|
160
|
+
);
|
|
161
|
+
|
|
162
|
+
const trigger = await screen.findByText('Mock item');
|
|
163
|
+
await user.click(trigger);
|
|
164
|
+
|
|
165
|
+
expect(onSelect).toBeCalledTimes(1);
|
|
166
|
+
});
|
|
167
|
+
|
|
168
|
+
test('onOpenChange is called when passed and user clicks outside of dropdown', async () => {
|
|
169
|
+
const user = userEvent.setup();
|
|
170
|
+
const onOpenChange = jest.fn();
|
|
171
|
+
|
|
172
|
+
render(
|
|
173
|
+
<Dropdown isOpen={true} onOpenChange={onOpenChange} toggle={toggleRef => toggle(toggleRef)}>
|
|
174
|
+
{dropdownChildren}
|
|
175
|
+
</Dropdown>
|
|
176
|
+
);
|
|
177
|
+
|
|
178
|
+
const dropdown = screen.getByRole('button', { name: 'Dropdown' });
|
|
179
|
+
await user.click(dropdown);
|
|
180
|
+
await user.click(document.body);
|
|
181
|
+
|
|
182
|
+
expect(onOpenChange).toBeCalledTimes(1);
|
|
183
|
+
});
|
|
184
|
+
|
|
185
|
+
test('onOpenChange is called when passed and user presses tab key', async () => {
|
|
186
|
+
const user = userEvent.setup();
|
|
187
|
+
const onOpenChange = jest.fn();
|
|
188
|
+
|
|
189
|
+
render(
|
|
190
|
+
<Dropdown isOpen={true} onOpenChange={onOpenChange} toggle={toggleRef => toggle(toggleRef)}>
|
|
191
|
+
{dropdownChildren}
|
|
192
|
+
</Dropdown>
|
|
193
|
+
);
|
|
194
|
+
|
|
195
|
+
//focus dropdown
|
|
196
|
+
const dropdown = screen.getByRole('button', { name: 'Dropdown' });
|
|
197
|
+
await user.click(dropdown);
|
|
198
|
+
await user.keyboard('{Tab}');
|
|
199
|
+
|
|
200
|
+
expect(onOpenChange).toBeCalledTimes(1);
|
|
201
|
+
});
|
|
202
|
+
|
|
203
|
+
test('onOpenChange is called when passed and user presses esc key', async () => {
|
|
204
|
+
const user = userEvent.setup();
|
|
205
|
+
const onOpenChange = jest.fn();
|
|
206
|
+
|
|
207
|
+
render(
|
|
208
|
+
<Dropdown isOpen={true} onOpenChange={onOpenChange} toggle={toggleRef => toggle(toggleRef)}>
|
|
209
|
+
{dropdownChildren}
|
|
210
|
+
</Dropdown>
|
|
211
|
+
);
|
|
212
|
+
|
|
213
|
+
//focus dropdown
|
|
214
|
+
const dropdown = screen.getByRole('button', { name: 'Dropdown' });
|
|
215
|
+
await user.click(dropdown);
|
|
216
|
+
await user.keyboard('{Escape}');
|
|
217
|
+
|
|
218
|
+
expect(onOpenChange).toBeCalledTimes(1);
|
|
219
|
+
});
|
|
220
|
+
|
|
221
|
+
test('match snapshot', () => {
|
|
222
|
+
const { asFragment } = render(
|
|
223
|
+
<Dropdown
|
|
224
|
+
ouiaId={'dropdown'}
|
|
225
|
+
isOpen
|
|
226
|
+
isScrollable
|
|
227
|
+
isPlain
|
|
228
|
+
className={'customClass'}
|
|
229
|
+
toggle={toggleRef => toggle(toggleRef)}
|
|
230
|
+
>
|
|
231
|
+
{dropdownChildren}
|
|
232
|
+
</Dropdown>
|
|
233
|
+
);
|
|
234
|
+
|
|
235
|
+
expect(asFragment()).toMatchSnapshot();
|
|
236
|
+
});
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
import { DropdownGroup } from '../../Dropdown';
|
|
2
|
+
import { render, screen } from '@testing-library/react';
|
|
3
|
+
import React from 'react';
|
|
4
|
+
|
|
5
|
+
jest.mock('../../../../components/Menu');
|
|
6
|
+
|
|
7
|
+
const dropdownGroupChildren = <div>Dropdown Group children</div>;
|
|
8
|
+
|
|
9
|
+
test('renders dropdown group', () => {
|
|
10
|
+
render(
|
|
11
|
+
<div data-testid="dropdown-group">
|
|
12
|
+
<DropdownGroup>{dropdownGroupChildren}</DropdownGroup>
|
|
13
|
+
</div>
|
|
14
|
+
);
|
|
15
|
+
|
|
16
|
+
expect(screen.getByTestId('dropdown-group').children[0]).toBeVisible();
|
|
17
|
+
});
|
|
18
|
+
|
|
19
|
+
test('passes children', () => {
|
|
20
|
+
render(<DropdownGroup>{dropdownGroupChildren}</DropdownGroup>);
|
|
21
|
+
|
|
22
|
+
expect(screen.getByText('Dropdown Group children')).toBeVisible();
|
|
23
|
+
});
|
|
24
|
+
|
|
25
|
+
test('passes no class name by default', () => {
|
|
26
|
+
render(<DropdownGroup>{dropdownGroupChildren}</DropdownGroup>);
|
|
27
|
+
|
|
28
|
+
expect(screen.getByTestId('menu-group-mock')).not.toHaveClass();
|
|
29
|
+
});
|
|
30
|
+
|
|
31
|
+
test('passes custom class name to MenuGroup', () => {
|
|
32
|
+
render(<DropdownGroup className="custom-class">{dropdownGroupChildren}</DropdownGroup>);
|
|
33
|
+
|
|
34
|
+
expect(screen.getByTestId('menu-group-mock')).toHaveClass('custom-class');
|
|
35
|
+
});
|
|
36
|
+
|
|
37
|
+
test('passes no label by default', () => {
|
|
38
|
+
render(<DropdownGroup>{dropdownGroupChildren}</DropdownGroup>);
|
|
39
|
+
|
|
40
|
+
expect(screen.getByText('label: undefined')).toBeVisible();
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
test('passes custom label to MenuGroup', () => {
|
|
44
|
+
render(<DropdownGroup label="Test label">{dropdownGroupChildren}</DropdownGroup>);
|
|
45
|
+
|
|
46
|
+
expect(screen.getByText('label: Test label')).toBeVisible();
|
|
47
|
+
});
|
|
48
|
+
|
|
49
|
+
test('passes h1 as labelHeadingLevel to MenuGroup by default', () => {
|
|
50
|
+
render(<DropdownGroup>{dropdownGroupChildren}</DropdownGroup>);
|
|
51
|
+
|
|
52
|
+
expect(screen.getByText('labelHeadingLevel: h1')).toBeVisible();
|
|
53
|
+
});
|
|
54
|
+
|
|
55
|
+
test('passes custom labelHeadingLevel to MenuGroup', () => {
|
|
56
|
+
render(<DropdownGroup labelHeadingLevel="h2">{dropdownGroupChildren}</DropdownGroup>);
|
|
57
|
+
|
|
58
|
+
expect(screen.getByText('labelHeadingLevel: h2')).toBeVisible();
|
|
59
|
+
});
|
|
60
|
+
|
|
61
|
+
test('matches snapshot', () => {
|
|
62
|
+
const { asFragment } = render(
|
|
63
|
+
<DropdownGroup className="custom-class" label="Test label" labelHeadingLevel="h2">
|
|
64
|
+
{dropdownGroupChildren}
|
|
65
|
+
</DropdownGroup>
|
|
66
|
+
);
|
|
67
|
+
|
|
68
|
+
expect(asFragment()).toMatchSnapshot();
|
|
69
|
+
});
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
import { DropdownItem } from '../../Dropdown';
|
|
2
|
+
import { render, screen } from '@testing-library/react';
|
|
3
|
+
import React from 'react';
|
|
4
|
+
|
|
5
|
+
jest.mock('../../../../components/Menu');
|
|
6
|
+
|
|
7
|
+
const dropdownItemChildren = <div>Dropdown Item children</div>;
|
|
8
|
+
|
|
9
|
+
test('renders dropdown item', () => {
|
|
10
|
+
render(
|
|
11
|
+
<div data-testid="dropdown-item">
|
|
12
|
+
<DropdownItem>{dropdownItemChildren}</DropdownItem>
|
|
13
|
+
</div>
|
|
14
|
+
);
|
|
15
|
+
|
|
16
|
+
expect(screen.getByTestId('dropdown-item').children[0]).toBeVisible();
|
|
17
|
+
});
|
|
18
|
+
|
|
19
|
+
test('passes children', () => {
|
|
20
|
+
render(<DropdownItem>{dropdownItemChildren}</DropdownItem>);
|
|
21
|
+
|
|
22
|
+
expect(screen.getByText('Dropdown Item children')).toBeVisible();
|
|
23
|
+
});
|
|
24
|
+
|
|
25
|
+
test('passes no class name by default', () => {
|
|
26
|
+
render(<DropdownItem>{dropdownItemChildren}</DropdownItem>);
|
|
27
|
+
|
|
28
|
+
expect(screen.getByTestId('menu-item-mock')).not.toHaveClass();
|
|
29
|
+
});
|
|
30
|
+
|
|
31
|
+
test('passes custom class name to MenuItem', () => {
|
|
32
|
+
render(<DropdownItem className="custom-class">{dropdownItemChildren}</DropdownItem>);
|
|
33
|
+
|
|
34
|
+
expect(screen.getByTestId('menu-item-mock')).toHaveClass('custom-class');
|
|
35
|
+
});
|
|
36
|
+
|
|
37
|
+
test('passes no description by default', () => {
|
|
38
|
+
render(<DropdownItem>{dropdownItemChildren}</DropdownItem>);
|
|
39
|
+
|
|
40
|
+
expect(screen.getByText('description: undefined')).toBeVisible();
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
test('passes custom description to MenuItem', () => {
|
|
44
|
+
render(<DropdownItem description="Test description">{dropdownItemChildren}</DropdownItem>);
|
|
45
|
+
|
|
46
|
+
expect(screen.getByText('description: Test description')).toBeVisible();
|
|
47
|
+
});
|
|
48
|
+
|
|
49
|
+
test('passes no itemId by default', () => {
|
|
50
|
+
render(<DropdownItem description="Test description">{dropdownItemChildren}</DropdownItem>);
|
|
51
|
+
|
|
52
|
+
expect(screen.getByText('itemId: undefined'));
|
|
53
|
+
});
|
|
54
|
+
|
|
55
|
+
test('passes itemId to MenuItem', () => {
|
|
56
|
+
render(
|
|
57
|
+
<DropdownItem itemId="dropdown item" description="Test description">
|
|
58
|
+
{dropdownItemChildren}
|
|
59
|
+
</DropdownItem>
|
|
60
|
+
);
|
|
61
|
+
|
|
62
|
+
expect(screen.getByText('itemId: dropdown item'));
|
|
63
|
+
});
|
|
64
|
+
|
|
65
|
+
test('matches snapshot', () => {
|
|
66
|
+
const { asFragment } = render(
|
|
67
|
+
<DropdownItem ouiaId="dropdown item" className="custom-class" description="Test description">
|
|
68
|
+
{dropdownItemChildren}
|
|
69
|
+
</DropdownItem>
|
|
70
|
+
);
|
|
71
|
+
|
|
72
|
+
expect(asFragment()).toMatchSnapshot();
|
|
73
|
+
});
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { DropdownList } from '../../Dropdown';
|
|
2
|
+
import { render, screen } from '@testing-library/react';
|
|
3
|
+
import React from 'react';
|
|
4
|
+
|
|
5
|
+
jest.mock('../../../../components/Menu');
|
|
6
|
+
|
|
7
|
+
const dropdownListChildren = <div>Dropdown List children</div>;
|
|
8
|
+
|
|
9
|
+
test('renders dropdown list', () => {
|
|
10
|
+
render(
|
|
11
|
+
<div data-testid="dropdown-list">
|
|
12
|
+
<DropdownList>{dropdownListChildren}</DropdownList>
|
|
13
|
+
</div>
|
|
14
|
+
);
|
|
15
|
+
|
|
16
|
+
expect(screen.getByTestId('dropdown-list').children[0]).toBeVisible();
|
|
17
|
+
});
|
|
18
|
+
|
|
19
|
+
test('passes children', () => {
|
|
20
|
+
render(<DropdownList>{dropdownListChildren}</DropdownList>);
|
|
21
|
+
|
|
22
|
+
expect(screen.getByText('Dropdown List children')).toBeVisible();
|
|
23
|
+
});
|
|
24
|
+
|
|
25
|
+
test('passes no class name by default', () => {
|
|
26
|
+
render(<DropdownList>{dropdownListChildren}</DropdownList>);
|
|
27
|
+
|
|
28
|
+
expect(screen.getByTestId('menu-list-mock')).not.toHaveClass();
|
|
29
|
+
});
|
|
30
|
+
|
|
31
|
+
test('passes custom class name to MenuList', () => {
|
|
32
|
+
render(<DropdownList className="custom-class">{dropdownListChildren}</DropdownList>);
|
|
33
|
+
|
|
34
|
+
expect(screen.getByTestId('menu-list-mock')).toHaveClass('custom-class');
|
|
35
|
+
});
|
|
36
|
+
|
|
37
|
+
test('matches snapshot', () => {
|
|
38
|
+
const { asFragment } = render(<DropdownList className="custom-class">{dropdownListChildren}</DropdownList>);
|
|
39
|
+
|
|
40
|
+
expect(asFragment()).toMatchSnapshot();
|
|
41
|
+
});
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
// Jest Snapshot v1, https://goo.gl/fbAQLP
|
|
2
|
+
|
|
3
|
+
exports[`match snapshot 1`] = `
|
|
4
|
+
<DocumentFragment>
|
|
5
|
+
<div
|
|
6
|
+
data-ouia-component-id="dropdown"
|
|
7
|
+
data-ouia-component-type="PF4/Dropdown"
|
|
8
|
+
data-ouia-safe="true"
|
|
9
|
+
>
|
|
10
|
+
<div>
|
|
11
|
+
<div
|
|
12
|
+
class="customClass"
|
|
13
|
+
data-testid="menu-mock"
|
|
14
|
+
>
|
|
15
|
+
<div>
|
|
16
|
+
<div>
|
|
17
|
+
Dropdown children
|
|
18
|
+
</div>
|
|
19
|
+
</div>
|
|
20
|
+
</div>
|
|
21
|
+
<div>
|
|
22
|
+
Mock item
|
|
23
|
+
</div>
|
|
24
|
+
<p>
|
|
25
|
+
isPlain: true
|
|
26
|
+
</p>
|
|
27
|
+
<p>
|
|
28
|
+
isScrollable: true
|
|
29
|
+
</p>
|
|
30
|
+
<p>
|
|
31
|
+
minWidth: undefined
|
|
32
|
+
</p>
|
|
33
|
+
</div>
|
|
34
|
+
<p>
|
|
35
|
+
zIndex: 9999
|
|
36
|
+
</p>
|
|
37
|
+
<p>
|
|
38
|
+
isOpen: true
|
|
39
|
+
</p>
|
|
40
|
+
<div>
|
|
41
|
+
<button>
|
|
42
|
+
Dropdown
|
|
43
|
+
</button>
|
|
44
|
+
</div>
|
|
45
|
+
</div>
|
|
46
|
+
</DocumentFragment>
|
|
47
|
+
`;
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
// Jest Snapshot v1, https://goo.gl/fbAQLP
|
|
2
|
+
|
|
3
|
+
exports[`matches snapshot 1`] = `
|
|
4
|
+
<DocumentFragment>
|
|
5
|
+
<div
|
|
6
|
+
class="custom-class"
|
|
7
|
+
data-testid="menu-group-mock"
|
|
8
|
+
>
|
|
9
|
+
<div>
|
|
10
|
+
Dropdown Group children
|
|
11
|
+
</div>
|
|
12
|
+
</div>
|
|
13
|
+
<p>
|
|
14
|
+
label: Test label
|
|
15
|
+
</p>
|
|
16
|
+
<p>
|
|
17
|
+
labelHeadingLevel: h2
|
|
18
|
+
</p>
|
|
19
|
+
</DocumentFragment>
|
|
20
|
+
`;
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
// Jest Snapshot v1, https://goo.gl/fbAQLP
|
|
2
|
+
|
|
3
|
+
exports[`matches snapshot 1`] = `
|
|
4
|
+
<DocumentFragment>
|
|
5
|
+
<div
|
|
6
|
+
class="custom-class"
|
|
7
|
+
data-testid="menu-item-mock"
|
|
8
|
+
>
|
|
9
|
+
<div>
|
|
10
|
+
Dropdown Item children
|
|
11
|
+
</div>
|
|
12
|
+
</div>
|
|
13
|
+
<p>
|
|
14
|
+
description: Test description
|
|
15
|
+
</p>
|
|
16
|
+
<p>
|
|
17
|
+
itemId: undefined
|
|
18
|
+
</p>
|
|
19
|
+
</DocumentFragment>
|
|
20
|
+
`;
|