@patternfly/react-core 5.2.0-prerelease.15 → 5.2.0-prerelease.17
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 +11 -0
- package/components/package.json +1 -1
- package/deprecated/package.json +1 -1
- package/dist/dynamic/components/AboutModal/package.json +1 -1
- package/dist/dynamic/components/Accordion/package.json +1 -1
- package/dist/dynamic/components/ActionList/package.json +1 -1
- package/dist/dynamic/components/Alert/package.json +1 -1
- package/dist/dynamic/components/Avatar/package.json +1 -1
- package/dist/dynamic/components/BackToTop/package.json +1 -1
- package/dist/dynamic/components/Backdrop/package.json +1 -1
- package/dist/dynamic/components/BackgroundImage/package.json +1 -1
- package/dist/dynamic/components/Badge/package.json +1 -1
- package/dist/dynamic/components/Banner/package.json +1 -1
- package/dist/dynamic/components/Brand/package.json +1 -1
- package/dist/dynamic/components/Breadcrumb/package.json +1 -1
- package/dist/dynamic/components/Button/package.json +1 -1
- package/dist/dynamic/components/CalendarMonth/package.json +1 -1
- package/dist/dynamic/components/Card/package.json +1 -1
- package/dist/dynamic/components/Checkbox/package.json +1 -1
- package/dist/dynamic/components/Chip/package.json +1 -1
- package/dist/dynamic/components/ClipboardCopy/package.json +1 -1
- package/dist/dynamic/components/CodeBlock/package.json +1 -1
- package/dist/dynamic/components/DataList/package.json +1 -1
- package/dist/dynamic/components/DatePicker/package.json +1 -1
- package/dist/dynamic/components/DescriptionList/package.json +1 -1
- package/dist/dynamic/components/Divider/package.json +1 -1
- package/dist/dynamic/components/DragDrop/package.json +1 -1
- package/dist/dynamic/components/Drawer/package.json +1 -1
- package/dist/dynamic/components/Dropdown/package.json +1 -1
- package/dist/dynamic/components/DualListSelector/package.json +1 -1
- package/dist/dynamic/components/EmptyState/package.json +1 -1
- package/dist/dynamic/components/ExpandableSection/package.json +1 -1
- package/dist/dynamic/components/FileUpload/package.json +1 -1
- package/dist/dynamic/components/Form/package.json +1 -1
- package/dist/dynamic/components/FormSelect/package.json +1 -1
- package/dist/dynamic/components/HelperText/package.json +1 -1
- package/dist/dynamic/components/Hint/package.json +1 -1
- package/dist/dynamic/components/Icon/package.json +1 -1
- package/dist/dynamic/components/InputGroup/package.json +1 -1
- package/dist/dynamic/components/JumpLinks/package.json +1 -1
- package/dist/dynamic/components/Label/package.json +1 -1
- package/dist/dynamic/components/List/package.json +1 -1
- package/dist/dynamic/components/LoginPage/package.json +1 -1
- package/dist/dynamic/components/Masthead/package.json +1 -1
- package/dist/dynamic/components/Menu/package.json +1 -1
- package/dist/dynamic/components/MenuToggle/package.json +1 -1
- package/dist/dynamic/components/Modal/package.json +1 -1
- package/dist/dynamic/components/MultipleFileUpload/package.json +1 -1
- package/dist/dynamic/components/Nav/package.json +1 -1
- package/dist/dynamic/components/NotificationBadge/package.json +1 -1
- package/dist/dynamic/components/NotificationDrawer/package.json +1 -1
- package/dist/dynamic/components/NumberInput/package.json +1 -1
- package/dist/dynamic/components/OverflowMenu/package.json +1 -1
- package/dist/dynamic/components/Page/package.json +1 -1
- package/dist/dynamic/components/Pagination/package.json +1 -1
- package/dist/dynamic/components/Panel/package.json +1 -1
- package/dist/dynamic/components/Popover/package.json +1 -1
- package/dist/dynamic/components/Progress/package.json +1 -1
- package/dist/dynamic/components/ProgressStepper/package.json +1 -1
- package/dist/dynamic/components/Radio/package.json +1 -1
- package/dist/dynamic/components/SearchInput/package.json +1 -1
- package/dist/dynamic/components/Select/package.json +1 -1
- package/dist/dynamic/components/Sidebar/package.json +1 -1
- package/dist/dynamic/components/SimpleList/package.json +1 -1
- package/dist/dynamic/components/Skeleton/package.json +1 -1
- package/dist/dynamic/components/SkipToContent/package.json +1 -1
- package/dist/dynamic/components/Slider/package.json +1 -1
- package/dist/dynamic/components/Spinner/package.json +1 -1
- package/dist/dynamic/components/Switch/package.json +1 -1
- package/dist/dynamic/components/Tabs/package.json +1 -1
- package/dist/dynamic/components/Text/package.json +1 -1
- package/dist/dynamic/components/TextArea/package.json +1 -1
- package/dist/dynamic/components/TextInput/package.json +1 -1
- package/dist/dynamic/components/TextInputGroup/package.json +1 -1
- package/dist/dynamic/components/Tile/package.json +1 -1
- package/dist/dynamic/components/TimePicker/package.json +1 -1
- package/dist/dynamic/components/Timestamp/package.json +1 -1
- package/dist/dynamic/components/Title/package.json +1 -1
- package/dist/dynamic/components/ToggleGroup/package.json +1 -1
- package/dist/dynamic/components/Toolbar/package.json +1 -1
- package/dist/dynamic/components/Tooltip/package.json +1 -1
- package/dist/dynamic/components/TreeView/package.json +1 -1
- package/dist/dynamic/components/Truncate/package.json +1 -1
- package/dist/dynamic/components/Wizard/hooks/package.json +1 -1
- package/dist/dynamic/components/Wizard/package.json +1 -1
- package/dist/dynamic/deprecated/components/ApplicationLauncher/package.json +1 -1
- package/dist/dynamic/deprecated/components/ContextSelector/package.json +1 -1
- package/dist/dynamic/deprecated/components/Dropdown/package.json +1 -1
- package/dist/dynamic/deprecated/components/OptionsMenu/package.json +1 -1
- package/dist/dynamic/deprecated/components/PageHeader/package.json +1 -1
- package/dist/dynamic/deprecated/components/Select/package.json +1 -1
- package/dist/dynamic/deprecated/components/Wizard/package.json +1 -1
- package/dist/dynamic/deprecated/components/package.json +1 -1
- package/dist/dynamic/helpers/FocusTrap/FocusTrap/package.json +1 -1
- package/dist/dynamic/helpers/GenerateId/GenerateId/package.json +1 -1
- package/dist/dynamic/helpers/KeyboardHandler/package.json +1 -1
- package/dist/dynamic/helpers/OUIA/ouia/package.json +1 -1
- package/dist/dynamic/helpers/Popper/Popper/package.json +1 -1
- package/dist/dynamic/helpers/constants/package.json +1 -1
- package/dist/dynamic/helpers/datetimeUtils/package.json +1 -1
- package/dist/dynamic/helpers/favorites/package.json +1 -1
- package/dist/dynamic/helpers/fileUtils/package.json +1 -1
- package/dist/dynamic/helpers/htmlConstants/package.json +1 -1
- package/dist/dynamic/helpers/package.json +1 -1
- package/dist/dynamic/helpers/resizeObserver/package.json +1 -1
- package/dist/dynamic/helpers/typeUtils/package.json +1 -1
- package/dist/dynamic/helpers/useInterval/package.json +1 -1
- package/dist/dynamic/helpers/useIsomorphicLayout/package.json +1 -1
- package/dist/dynamic/helpers/useUnmountEffect/package.json +1 -1
- package/dist/dynamic/helpers/util/package.json +1 -1
- package/dist/dynamic/layouts/Bullseye/package.json +1 -1
- package/dist/dynamic/layouts/Flex/package.json +1 -1
- package/dist/dynamic/layouts/Gallery/package.json +1 -1
- package/dist/dynamic/layouts/Grid/package.json +1 -1
- package/dist/dynamic/layouts/Level/package.json +1 -1
- package/dist/dynamic/layouts/Split/package.json +1 -1
- package/dist/dynamic/layouts/Stack/package.json +1 -1
- package/dist/dynamic/next/components/package.json +1 -1
- package/dist/esm/components/Chip/Chip.d.ts.map +1 -1
- package/dist/esm/components/Chip/Chip.js +2 -2
- package/dist/esm/components/Chip/Chip.js.map +1 -1
- package/dist/esm/components/Drawer/DrawerPanelContent.js +4 -4
- package/dist/esm/components/Drawer/DrawerPanelContent.js.map +1 -1
- package/dist/esm/components/Dropdown/Dropdown.d.ts +2 -0
- package/dist/esm/components/Dropdown/Dropdown.d.ts.map +1 -1
- package/dist/esm/components/Dropdown/Dropdown.js.map +1 -1
- package/dist/esm/components/Menu/Menu.d.ts.map +1 -1
- package/dist/esm/components/Menu/Menu.js +2 -1
- package/dist/esm/components/Menu/Menu.js.map +1 -1
- package/dist/esm/components/Menu/MenuContainer.d.ts +2 -0
- package/dist/esm/components/Menu/MenuContainer.d.ts.map +1 -1
- package/dist/esm/components/Menu/MenuContainer.js.map +1 -1
- package/dist/esm/components/Nav/NavList.js +3 -3
- package/dist/esm/components/Nav/NavList.js.map +1 -1
- package/dist/esm/components/Select/Select.d.ts +2 -0
- package/dist/esm/components/Select/Select.d.ts.map +1 -1
- package/dist/esm/components/Select/Select.js.map +1 -1
- package/dist/esm/components/Slider/Slider.d.ts.map +1 -1
- package/dist/esm/components/Slider/Slider.js +2 -1
- package/dist/esm/components/Slider/Slider.js.map +1 -1
- package/dist/esm/components/Tabs/Tabs.js +3 -3
- package/dist/esm/components/Tabs/Tabs.js.map +1 -1
- package/dist/esm/helpers/Popper/Popper.d.ts +2 -1
- package/dist/esm/helpers/Popper/Popper.d.ts.map +1 -1
- package/dist/esm/helpers/Popper/Popper.js +3 -13
- package/dist/esm/helpers/Popper/Popper.js.map +1 -1
- package/dist/esm/helpers/util.d.ts +9 -0
- package/dist/esm/helpers/util.d.ts.map +1 -1
- package/dist/esm/helpers/util.js +18 -0
- package/dist/esm/helpers/util.js.map +1 -1
- package/dist/js/components/Chip/Chip.d.ts.map +1 -1
- package/dist/js/components/Chip/Chip.js +2 -2
- package/dist/js/components/Chip/Chip.js.map +1 -1
- package/dist/js/components/Drawer/DrawerPanelContent.js +3 -3
- package/dist/js/components/Drawer/DrawerPanelContent.js.map +1 -1
- package/dist/js/components/Dropdown/Dropdown.d.ts +2 -0
- package/dist/js/components/Dropdown/Dropdown.d.ts.map +1 -1
- package/dist/js/components/Dropdown/Dropdown.js.map +1 -1
- package/dist/js/components/Menu/Menu.d.ts.map +1 -1
- package/dist/js/components/Menu/Menu.js +2 -1
- package/dist/js/components/Menu/Menu.js.map +1 -1
- package/dist/js/components/Menu/MenuContainer.d.ts +2 -0
- package/dist/js/components/Menu/MenuContainer.d.ts.map +1 -1
- package/dist/js/components/Menu/MenuContainer.js.map +1 -1
- package/dist/js/components/Nav/NavList.js +2 -2
- package/dist/js/components/Nav/NavList.js.map +1 -1
- package/dist/js/components/Select/Select.d.ts +2 -0
- package/dist/js/components/Select/Select.d.ts.map +1 -1
- package/dist/js/components/Select/Select.js.map +1 -1
- package/dist/js/components/Slider/Slider.d.ts.map +1 -1
- package/dist/js/components/Slider/Slider.js +2 -1
- package/dist/js/components/Slider/Slider.js.map +1 -1
- package/dist/js/components/Tabs/Tabs.js +2 -2
- package/dist/js/components/Tabs/Tabs.js.map +1 -1
- package/dist/js/helpers/Popper/Popper.d.ts +2 -1
- package/dist/js/helpers/Popper/Popper.d.ts.map +1 -1
- package/dist/js/helpers/Popper/Popper.js +5 -16
- package/dist/js/helpers/Popper/Popper.js.map +1 -1
- package/dist/js/helpers/util.d.ts +9 -0
- package/dist/js/helpers/util.d.ts.map +1 -1
- package/dist/js/helpers/util.js +20 -1
- package/dist/js/helpers/util.js.map +1 -1
- package/dist/umd/react-core.min.js +1 -1
- package/helpers/package.json +1 -1
- package/layouts/package.json +1 -1
- package/next/package.json +1 -1
- package/package.json +3 -3
- package/src/components/Chip/Chip.tsx +2 -1
- package/src/components/Chip/__tests__/Chip.test.tsx +249 -32
- package/src/components/Chip/__tests__/ChipGroup.test.tsx +288 -61
- package/src/components/Chip/__tests__/__snapshots__/Chip.test.tsx.snap +9 -209
- package/src/components/Chip/__tests__/__snapshots__/ChipGroup.test.tsx.snap +2 -313
- package/src/components/Drawer/DrawerPanelContent.tsx +4 -4
- package/src/components/Dropdown/Dropdown.tsx +2 -0
- package/src/components/Menu/Menu.tsx +2 -1
- package/src/components/Menu/MenuContainer.tsx +2 -0
- package/src/components/Nav/NavList.tsx +3 -3
- package/src/components/Select/Select.tsx +2 -0
- package/src/components/Slider/Slider.tsx +2 -1
- package/src/components/Tabs/Tabs.tsx +3 -3
- package/src/helpers/Popper/Popper.tsx +6 -17
- package/src/helpers/__mocks__/util.ts +2 -0
- package/src/helpers/util.ts +22 -0
package/helpers/package.json
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"name":"@patternfly/react-core-helpers","main":"../dist/js/helpers/index.js","module":"../dist/esm/helpers/index.js","typings":"../dist/esm/helpers/index.d.ts","version":"5.2.0-prerelease.
|
|
1
|
+
{"name":"@patternfly/react-core-helpers","main":"../dist/js/helpers/index.js","module":"../dist/esm/helpers/index.js","typings":"../dist/esm/helpers/index.d.ts","version":"5.2.0-prerelease.16","private":true}
|
package/layouts/package.json
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"name":"@patternfly/react-core-layouts","main":"../dist/js/layouts/index.js","module":"../dist/esm/layouts/index.js","typings":"../dist/esm/layouts/index.d.ts","version":"5.2.0-prerelease.
|
|
1
|
+
{"name":"@patternfly/react-core-layouts","main":"../dist/js/layouts/index.js","module":"../dist/esm/layouts/index.js","typings":"../dist/esm/layouts/index.d.ts","version":"5.2.0-prerelease.16","private":true}
|
package/next/package.json
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"name":"@patternfly/react-core-next","main":"../dist/js/next/index.js","module":"../dist/esm/next/index.js","typings":"../dist/esm/next/index.d.ts","version":"5.2.0-prerelease.
|
|
1
|
+
{"name":"@patternfly/react-core-next","main":"../dist/js/next/index.js","module":"../dist/esm/next/index.js","typings":"../dist/esm/next/index.d.ts","version":"5.2.0-prerelease.16","private":true}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@patternfly/react-core",
|
|
3
|
-
"version": "5.2.0-prerelease.
|
|
3
|
+
"version": "5.2.0-prerelease.17",
|
|
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",
|
|
@@ -45,7 +45,7 @@
|
|
|
45
45
|
"subpaths": "node ../../scripts/exportSubpaths.js --config subpaths.config.json"
|
|
46
46
|
},
|
|
47
47
|
"dependencies": {
|
|
48
|
-
"@patternfly/react-icons": "^5.2.0-prerelease.
|
|
48
|
+
"@patternfly/react-icons": "^5.2.0-prerelease.5",
|
|
49
49
|
"@patternfly/react-styles": "^5.2.0-prerelease.3",
|
|
50
50
|
"@patternfly/react-tokens": "^5.2.0-prerelease.4",
|
|
51
51
|
"focus-trap": "7.5.2",
|
|
@@ -71,5 +71,5 @@
|
|
|
71
71
|
"react": "^17 || ^18",
|
|
72
72
|
"react-dom": "^17 || ^18"
|
|
73
73
|
},
|
|
74
|
-
"gitHead": "
|
|
74
|
+
"gitHead": "1eadbab2c8a6935859473e4ea30cb110d4d95463"
|
|
75
75
|
}
|
|
@@ -140,12 +140,13 @@ class Chip extends React.Component<ChipProps, ChipState> {
|
|
|
140
140
|
tooltipPosition,
|
|
141
141
|
component,
|
|
142
142
|
ouiaId,
|
|
143
|
+
textMaxWidth,
|
|
143
144
|
...props
|
|
144
145
|
} = this.props;
|
|
145
146
|
const Component = component as any;
|
|
146
147
|
return (
|
|
147
148
|
<Component
|
|
148
|
-
{...(
|
|
149
|
+
{...(textMaxWidth && {
|
|
149
150
|
style: this.setChipStyle()
|
|
150
151
|
})}
|
|
151
152
|
className={css(styles.chip, className)}
|
|
@@ -1,59 +1,276 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
|
-
import { render } from '@testing-library/react';
|
|
2
|
+
import { render, screen } from '@testing-library/react';
|
|
3
|
+
import userEvent from '@testing-library/user-event';
|
|
3
4
|
import { Chip } from '../Chip';
|
|
5
|
+
import styles from '@patternfly/react-styles/css/components/Chip/chip';
|
|
4
6
|
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
<
|
|
9
|
-
|
|
7
|
+
jest.mock('../../Tooltip', () => ({
|
|
8
|
+
Tooltip: ({ content, position }) => (
|
|
9
|
+
<div data-testid="tooltip-mock">
|
|
10
|
+
<p>{`content: ${content}`}</p>
|
|
11
|
+
<p>{`position: ${position}`}</p>
|
|
12
|
+
</div>
|
|
13
|
+
)
|
|
14
|
+
}));
|
|
15
|
+
|
|
16
|
+
['default chip', 'overflow chip'].forEach((chipType) => {
|
|
17
|
+
const isOverflowChip = chipType === 'overflow chip';
|
|
18
|
+
|
|
19
|
+
test(`Renders without children for ${chipType}`, () => {
|
|
20
|
+
render(
|
|
21
|
+
<div data-testid="container">
|
|
22
|
+
<Chip isOverflowChip={isOverflowChip} />
|
|
23
|
+
</div>
|
|
24
|
+
);
|
|
25
|
+
|
|
26
|
+
expect(screen.getByTestId('container').firstChild).toBeVisible();
|
|
27
|
+
});
|
|
28
|
+
|
|
29
|
+
test(`Renders with class ${styles.chip} on the ${chipType} container element`, () => {
|
|
30
|
+
render(
|
|
31
|
+
<Chip isOverflowChip={isOverflowChip} data-testid="container">
|
|
32
|
+
Chip text
|
|
33
|
+
</Chip>
|
|
34
|
+
);
|
|
35
|
+
|
|
36
|
+
// Only a non-overflow chip will have exactly the class "pf-v5-c-chip", we test for
|
|
37
|
+
// additional classes on overflow chips elsewhere in the suite
|
|
38
|
+
expect(screen.getByTestId('container')).toHaveClass(styles.chip, { exact: !isOverflowChip });
|
|
39
|
+
});
|
|
40
|
+
|
|
41
|
+
test(`Renders with class ${styles.chipContent} around the ${chipType} content`, () => {
|
|
42
|
+
render(
|
|
43
|
+
<Chip isOverflowChip={isOverflowChip} data-testid="container">
|
|
44
|
+
Chip text
|
|
10
45
|
</Chip>
|
|
11
46
|
);
|
|
12
|
-
|
|
47
|
+
|
|
48
|
+
expect(screen.getByTestId('container').firstChild).toHaveClass(styles.chipContent, { exact: true });
|
|
49
|
+
});
|
|
50
|
+
|
|
51
|
+
test(`Renders ${chipType} children with class ${styles.chipText}`, () => {
|
|
52
|
+
render(<Chip isOverflowChip={isOverflowChip}>Chip text</Chip>);
|
|
53
|
+
|
|
54
|
+
expect(screen.getByText('Chip text')).toHaveClass(styles.chipText, { exact: true });
|
|
13
55
|
});
|
|
14
56
|
|
|
15
|
-
test(
|
|
16
|
-
|
|
17
|
-
<Chip
|
|
18
|
-
Chip
|
|
57
|
+
test(`Renders with custom class on the ${chipType} container element`, () => {
|
|
58
|
+
render(
|
|
59
|
+
<Chip isOverflowChip={isOverflowChip} data-testid="container" className="custom-class">
|
|
60
|
+
Chip text
|
|
19
61
|
</Chip>
|
|
20
62
|
);
|
|
21
|
-
|
|
63
|
+
|
|
64
|
+
expect(screen.getByTestId('container')).toHaveClass('custom-class');
|
|
22
65
|
});
|
|
23
66
|
|
|
24
|
-
test(
|
|
25
|
-
|
|
26
|
-
<Chip
|
|
27
|
-
|
|
67
|
+
test(`Renders a badge when badge prop is passed to ${chipType}`, () => {
|
|
68
|
+
render(
|
|
69
|
+
<Chip isOverflowChip={isOverflowChip} badge={<div>Badge content</div>}>
|
|
70
|
+
Chip text
|
|
28
71
|
</Chip>
|
|
29
72
|
);
|
|
30
|
-
|
|
73
|
+
|
|
74
|
+
expect(screen.getByText('Badge content')).toBeVisible();
|
|
75
|
+
});
|
|
76
|
+
|
|
77
|
+
test(`Renders with div container on ${chipType} by default`, () => {
|
|
78
|
+
render(
|
|
79
|
+
<Chip isOverflowChip={isOverflowChip} data-testid="container">
|
|
80
|
+
Chip text
|
|
81
|
+
</Chip>
|
|
82
|
+
);
|
|
83
|
+
|
|
84
|
+
expect(screen.getByTestId('container').tagName).toBe('DIV');
|
|
31
85
|
});
|
|
32
86
|
|
|
33
|
-
test(
|
|
34
|
-
|
|
35
|
-
<Chip
|
|
36
|
-
|
|
87
|
+
test(`Renders with custom container on ${chipType} when component prop is passed`, () => {
|
|
88
|
+
render(
|
|
89
|
+
<Chip component="li" isOverflowChip={isOverflowChip}>
|
|
90
|
+
Chip text
|
|
37
91
|
</Chip>
|
|
38
92
|
);
|
|
39
|
-
|
|
93
|
+
|
|
94
|
+
expect(screen.getByRole('listitem')).toBeVisible();
|
|
40
95
|
});
|
|
41
96
|
|
|
42
|
-
test(
|
|
43
|
-
|
|
44
|
-
<Chip
|
|
45
|
-
|
|
97
|
+
test(`Renders maxWidth css var in style attribute when textMaxWidth is passed for ${chipType}`, () => {
|
|
98
|
+
render(
|
|
99
|
+
<Chip isOverflowChip={isOverflowChip} data-testid="container" textMaxWidth="10px">
|
|
100
|
+
Chip text
|
|
46
101
|
</Chip>
|
|
47
102
|
);
|
|
48
|
-
|
|
103
|
+
|
|
104
|
+
expect(screen.getByTestId('container')).toHaveAttribute('style', '--pf-v5-c-chip__text--MaxWidth: 10px;');
|
|
49
105
|
});
|
|
50
106
|
|
|
51
|
-
test(
|
|
52
|
-
|
|
53
|
-
<Chip
|
|
54
|
-
|
|
107
|
+
test(`Spreads additional props to container for ${chipType}`, () => {
|
|
108
|
+
render(
|
|
109
|
+
<Chip isOverflowChip={isOverflowChip} data-testid="container" role="button">
|
|
110
|
+
Chip text
|
|
55
111
|
</Chip>
|
|
56
112
|
);
|
|
57
|
-
|
|
113
|
+
|
|
114
|
+
expect(screen.getByTestId('container')).toHaveAttribute('role', 'button');
|
|
58
115
|
});
|
|
59
116
|
});
|
|
117
|
+
|
|
118
|
+
test(`Renders id prop on ${styles.chipText} container for default chip`, () => {
|
|
119
|
+
render(<Chip id="custom-id">Chip text</Chip>);
|
|
120
|
+
|
|
121
|
+
expect(screen.getByText('Chip text')).toHaveAttribute('id', 'custom-id');
|
|
122
|
+
});
|
|
123
|
+
|
|
124
|
+
test(`Does not render id prop on ${styles.chipText} container for overflow chip`, () => {
|
|
125
|
+
render(
|
|
126
|
+
<Chip isOverflowChip id="custom-id">
|
|
127
|
+
Chip text
|
|
128
|
+
</Chip>
|
|
129
|
+
);
|
|
130
|
+
|
|
131
|
+
expect(screen.getByText('Chip text')).not.toHaveAttribute('id');
|
|
132
|
+
});
|
|
133
|
+
|
|
134
|
+
test(`Renders actions container with class ${styles.chipActions} when isReadOnly is false`, () => {
|
|
135
|
+
render(<Chip>Chip text</Chip>);
|
|
136
|
+
|
|
137
|
+
expect(screen.getByRole('button').parentElement).toHaveClass(styles.chipActions);
|
|
138
|
+
});
|
|
139
|
+
|
|
140
|
+
test(`Renders aria-labelledby on action close button by default`, () => {
|
|
141
|
+
render(<Chip>Chip text</Chip>);
|
|
142
|
+
|
|
143
|
+
expect(screen.getByRole('button')).toHaveAccessibleName('close Chip text');
|
|
144
|
+
});
|
|
145
|
+
|
|
146
|
+
test(`Renders aria-labelledby on action close button with custom id passed`, () => {
|
|
147
|
+
render(<Chip id="custom-id">Chip text</Chip>);
|
|
148
|
+
|
|
149
|
+
expect(screen.getByRole('button')).toHaveAccessibleName('close Chip text');
|
|
150
|
+
});
|
|
151
|
+
|
|
152
|
+
test(`Renders concatenated aria-label on action close button by default`, () => {
|
|
153
|
+
render(<Chip>Chip text</Chip>);
|
|
154
|
+
|
|
155
|
+
expect(screen.getByRole('button')).toHaveAccessibleName('close Chip text');
|
|
156
|
+
});
|
|
157
|
+
|
|
158
|
+
test(`Renders custom aria-label on action close button when closeBtnAriaLabel is passed`, () => {
|
|
159
|
+
render(<Chip closeBtnAriaLabel="custom label">Chip text</Chip>);
|
|
160
|
+
|
|
161
|
+
expect(screen.getByRole('button')).toHaveAccessibleName('custom label Chip text');
|
|
162
|
+
});
|
|
163
|
+
|
|
164
|
+
test(`Does not render close button action when isOverflowChip is true`, () => {
|
|
165
|
+
render(<Chip isOverflowChip>Chip text</Chip>);
|
|
166
|
+
|
|
167
|
+
// Because overflow chip renders as a button, we need to add the accessible name to the query
|
|
168
|
+
expect(screen.queryByRole('button', { name: 'close Chip text' })).not.toBeInTheDocument();
|
|
169
|
+
});
|
|
170
|
+
|
|
171
|
+
test(`Does not render close button action when isReadOnly is true`, () => {
|
|
172
|
+
render(<Chip isReadOnly>Chip text</Chip>);
|
|
173
|
+
|
|
174
|
+
expect(screen.queryByRole('button')).not.toBeInTheDocument();
|
|
175
|
+
});
|
|
176
|
+
|
|
177
|
+
test(`Does not render with class ${styles.modifiers.overflow} when isOverflowChip is not passed`, () => {
|
|
178
|
+
render(<Chip data-testid="container">Chip text</Chip>);
|
|
179
|
+
|
|
180
|
+
expect(screen.getByTestId('container')).not.toHaveClass(styles.modifiers.overflow);
|
|
181
|
+
});
|
|
182
|
+
|
|
183
|
+
test(`Renders with class ${styles.modifiers.overflow} when isOverflowChip is true`, () => {
|
|
184
|
+
render(
|
|
185
|
+
<Chip isOverflowChip data-testid="container">
|
|
186
|
+
Chip text
|
|
187
|
+
</Chip>
|
|
188
|
+
);
|
|
189
|
+
|
|
190
|
+
expect(screen.getByTestId('container')).toHaveClass(styles.modifiers.overflow);
|
|
191
|
+
});
|
|
192
|
+
|
|
193
|
+
test(`Calls onClick when close button action is clicked for default chip`, async () => {
|
|
194
|
+
const user = userEvent.setup();
|
|
195
|
+
const onClickMock = jest.fn();
|
|
196
|
+
|
|
197
|
+
render(<Chip onClick={onClickMock}>Chip text</Chip>);
|
|
198
|
+
|
|
199
|
+
await user.click(screen.getByRole('button', { name: 'close Chip text' }));
|
|
200
|
+
|
|
201
|
+
expect(onClickMock).toHaveBeenCalledTimes(1);
|
|
202
|
+
});
|
|
203
|
+
|
|
204
|
+
test(`Does not call onClick when close button action is not clicked for default chip`, async () => {
|
|
205
|
+
const user = userEvent.setup();
|
|
206
|
+
const onClickMock = jest.fn();
|
|
207
|
+
|
|
208
|
+
render(
|
|
209
|
+
<>
|
|
210
|
+
<Chip onClick={onClickMock}>Chip text</Chip>
|
|
211
|
+
<button>Test clicker</button>
|
|
212
|
+
</>
|
|
213
|
+
);
|
|
214
|
+
|
|
215
|
+
await user.click(screen.getByRole('button', { name: 'Test clicker' }));
|
|
216
|
+
|
|
217
|
+
expect(onClickMock).not.toHaveBeenCalled();
|
|
218
|
+
});
|
|
219
|
+
|
|
220
|
+
test(`Calls onClick when chip is clicked for overflow chip`, async () => {
|
|
221
|
+
const user = userEvent.setup();
|
|
222
|
+
const onClickMock = jest.fn();
|
|
223
|
+
|
|
224
|
+
render(
|
|
225
|
+
<Chip isOverflowChip component="button" onClick={onClickMock}>
|
|
226
|
+
Chip text
|
|
227
|
+
</Chip>
|
|
228
|
+
);
|
|
229
|
+
|
|
230
|
+
await user.click(screen.getByRole('button', { name: 'Chip text' }));
|
|
231
|
+
|
|
232
|
+
expect(onClickMock).toHaveBeenCalledTimes(1);
|
|
233
|
+
});
|
|
234
|
+
|
|
235
|
+
test(`Does not call onClick when chip is not clicked for overflow chip`, async () => {
|
|
236
|
+
const user = userEvent.setup();
|
|
237
|
+
const onClickMock = jest.fn();
|
|
238
|
+
|
|
239
|
+
render(
|
|
240
|
+
<>
|
|
241
|
+
<Chip isOverflowChip component="button" onClick={onClickMock}>
|
|
242
|
+
Chip text
|
|
243
|
+
</Chip>
|
|
244
|
+
<button>Test clicker</button>
|
|
245
|
+
</>
|
|
246
|
+
);
|
|
247
|
+
|
|
248
|
+
await user.click(screen.getByRole('button', { name: 'Test clicker' }));
|
|
249
|
+
|
|
250
|
+
expect(onClickMock).not.toHaveBeenCalled();
|
|
251
|
+
});
|
|
252
|
+
|
|
253
|
+
test('Passes position to Tooltip', () => {
|
|
254
|
+
Object.defineProperty(HTMLElement.prototype, 'scrollWidth', { configurable: true, value: 500 });
|
|
255
|
+
render(<Chip tooltipPosition="bottom">Test chip text</Chip>);
|
|
256
|
+
|
|
257
|
+
expect(screen.getByText('position: bottom')).toBeVisible();
|
|
258
|
+
Object.defineProperty(HTMLElement.prototype, 'scrollWidth', { configurable: true, value: 0 });
|
|
259
|
+
});
|
|
260
|
+
|
|
261
|
+
test('Passes content to Tooltip', () => {
|
|
262
|
+
Object.defineProperty(HTMLElement.prototype, 'scrollWidth', { configurable: true, value: 500 });
|
|
263
|
+
render(<Chip>Test chip text</Chip>);
|
|
264
|
+
|
|
265
|
+
expect(screen.getByText(`content: Test chip text`)).toBeVisible();
|
|
266
|
+
Object.defineProperty(HTMLElement.prototype, 'scrollWidth', { configurable: true, value: 0 });
|
|
267
|
+
});
|
|
268
|
+
|
|
269
|
+
test('Matches snapshot', () => {
|
|
270
|
+
const { asFragment } = render(
|
|
271
|
+
<Chip id="snapshot-test" ouiaId="snapshot-test">
|
|
272
|
+
Chip text
|
|
273
|
+
</Chip>
|
|
274
|
+
);
|
|
275
|
+
expect(asFragment()).toMatchSnapshot();
|
|
276
|
+
});
|