@patternfly/react-core 5.2.0-prerelease.18 → 5.2.0-prerelease.19

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.
Files changed (152) hide show
  1. package/CHANGELOG.md +4 -0
  2. package/components/package.json +1 -1
  3. package/deprecated/package.json +1 -1
  4. package/dist/dynamic/components/AboutModal/package.json +1 -1
  5. package/dist/dynamic/components/Accordion/package.json +1 -1
  6. package/dist/dynamic/components/ActionList/package.json +1 -1
  7. package/dist/dynamic/components/Alert/package.json +1 -1
  8. package/dist/dynamic/components/Avatar/package.json +1 -1
  9. package/dist/dynamic/components/BackToTop/package.json +1 -1
  10. package/dist/dynamic/components/Backdrop/package.json +1 -1
  11. package/dist/dynamic/components/BackgroundImage/package.json +1 -1
  12. package/dist/dynamic/components/Badge/package.json +1 -1
  13. package/dist/dynamic/components/Banner/package.json +1 -1
  14. package/dist/dynamic/components/Brand/package.json +1 -1
  15. package/dist/dynamic/components/Breadcrumb/package.json +1 -1
  16. package/dist/dynamic/components/Button/package.json +1 -1
  17. package/dist/dynamic/components/CalendarMonth/package.json +1 -1
  18. package/dist/dynamic/components/Card/package.json +1 -1
  19. package/dist/dynamic/components/Checkbox/package.json +1 -1
  20. package/dist/dynamic/components/Chip/package.json +1 -1
  21. package/dist/dynamic/components/ClipboardCopy/package.json +1 -1
  22. package/dist/dynamic/components/CodeBlock/package.json +1 -1
  23. package/dist/dynamic/components/DataList/package.json +1 -1
  24. package/dist/dynamic/components/DatePicker/package.json +1 -1
  25. package/dist/dynamic/components/DescriptionList/package.json +1 -1
  26. package/dist/dynamic/components/Divider/package.json +1 -1
  27. package/dist/dynamic/components/DragDrop/package.json +1 -1
  28. package/dist/dynamic/components/Drawer/package.json +1 -1
  29. package/dist/dynamic/components/Dropdown/package.json +1 -1
  30. package/dist/dynamic/components/DualListSelector/package.json +1 -1
  31. package/dist/dynamic/components/EmptyState/package.json +1 -1
  32. package/dist/dynamic/components/ExpandableSection/package.json +1 -1
  33. package/dist/dynamic/components/FileUpload/package.json +1 -1
  34. package/dist/dynamic/components/Form/package.json +1 -1
  35. package/dist/dynamic/components/FormSelect/package.json +1 -1
  36. package/dist/dynamic/components/HelperText/package.json +1 -1
  37. package/dist/dynamic/components/Hint/package.json +1 -1
  38. package/dist/dynamic/components/Icon/package.json +1 -1
  39. package/dist/dynamic/components/InputGroup/package.json +1 -1
  40. package/dist/dynamic/components/JumpLinks/package.json +1 -1
  41. package/dist/dynamic/components/Label/package.json +1 -1
  42. package/dist/dynamic/components/List/package.json +1 -1
  43. package/dist/dynamic/components/LoginPage/package.json +1 -1
  44. package/dist/dynamic/components/Masthead/package.json +1 -1
  45. package/dist/dynamic/components/Menu/package.json +1 -1
  46. package/dist/dynamic/components/MenuToggle/package.json +1 -1
  47. package/dist/dynamic/components/Modal/package.json +1 -1
  48. package/dist/dynamic/components/MultipleFileUpload/package.json +1 -1
  49. package/dist/dynamic/components/Nav/package.json +1 -1
  50. package/dist/dynamic/components/NotificationBadge/package.json +1 -1
  51. package/dist/dynamic/components/NotificationDrawer/package.json +1 -1
  52. package/dist/dynamic/components/NumberInput/package.json +1 -1
  53. package/dist/dynamic/components/OverflowMenu/package.json +1 -1
  54. package/dist/dynamic/components/Page/package.json +1 -1
  55. package/dist/dynamic/components/Pagination/package.json +1 -1
  56. package/dist/dynamic/components/Panel/package.json +1 -1
  57. package/dist/dynamic/components/Popover/package.json +1 -1
  58. package/dist/dynamic/components/Progress/package.json +1 -1
  59. package/dist/dynamic/components/ProgressStepper/package.json +1 -1
  60. package/dist/dynamic/components/Radio/package.json +1 -1
  61. package/dist/dynamic/components/SearchInput/package.json +1 -1
  62. package/dist/dynamic/components/Select/package.json +1 -1
  63. package/dist/dynamic/components/Sidebar/package.json +1 -1
  64. package/dist/dynamic/components/SimpleList/package.json +1 -1
  65. package/dist/dynamic/components/Skeleton/package.json +1 -1
  66. package/dist/dynamic/components/SkipToContent/package.json +1 -1
  67. package/dist/dynamic/components/Slider/package.json +1 -1
  68. package/dist/dynamic/components/Spinner/package.json +1 -1
  69. package/dist/dynamic/components/Switch/package.json +1 -1
  70. package/dist/dynamic/components/Tabs/package.json +1 -1
  71. package/dist/dynamic/components/Text/package.json +1 -1
  72. package/dist/dynamic/components/TextArea/package.json +1 -1
  73. package/dist/dynamic/components/TextInput/package.json +1 -1
  74. package/dist/dynamic/components/TextInputGroup/package.json +1 -1
  75. package/dist/dynamic/components/Tile/package.json +1 -1
  76. package/dist/dynamic/components/TimePicker/package.json +1 -1
  77. package/dist/dynamic/components/Timestamp/package.json +1 -1
  78. package/dist/dynamic/components/Title/package.json +1 -1
  79. package/dist/dynamic/components/ToggleGroup/package.json +1 -1
  80. package/dist/dynamic/components/Toolbar/package.json +1 -1
  81. package/dist/dynamic/components/Tooltip/package.json +1 -1
  82. package/dist/dynamic/components/TreeView/package.json +1 -1
  83. package/dist/dynamic/components/Truncate/package.json +1 -1
  84. package/dist/dynamic/components/Wizard/hooks/package.json +1 -1
  85. package/dist/dynamic/components/Wizard/package.json +1 -1
  86. package/dist/dynamic/deprecated/components/ApplicationLauncher/package.json +1 -1
  87. package/dist/dynamic/deprecated/components/ContextSelector/package.json +1 -1
  88. package/dist/dynamic/deprecated/components/Dropdown/package.json +1 -1
  89. package/dist/dynamic/deprecated/components/OptionsMenu/package.json +1 -1
  90. package/dist/dynamic/deprecated/components/PageHeader/package.json +1 -1
  91. package/dist/dynamic/deprecated/components/Select/package.json +1 -1
  92. package/dist/dynamic/deprecated/components/Wizard/package.json +1 -1
  93. package/dist/dynamic/deprecated/components/package.json +1 -1
  94. package/dist/dynamic/helpers/FocusTrap/FocusTrap/package.json +1 -1
  95. package/dist/dynamic/helpers/GenerateId/GenerateId/package.json +1 -1
  96. package/dist/dynamic/helpers/KeyboardHandler/package.json +1 -1
  97. package/dist/dynamic/helpers/OUIA/ouia/package.json +1 -1
  98. package/dist/dynamic/helpers/Popper/Popper/package.json +1 -1
  99. package/dist/dynamic/helpers/constants/package.json +1 -1
  100. package/dist/dynamic/helpers/datetimeUtils/package.json +1 -1
  101. package/dist/dynamic/helpers/favorites/package.json +1 -1
  102. package/dist/dynamic/helpers/fileUtils/package.json +1 -1
  103. package/dist/dynamic/helpers/htmlConstants/package.json +1 -1
  104. package/dist/dynamic/helpers/package.json +1 -1
  105. package/dist/dynamic/helpers/resizeObserver/package.json +1 -1
  106. package/dist/dynamic/helpers/typeUtils/package.json +1 -1
  107. package/dist/dynamic/helpers/useInterval/package.json +1 -1
  108. package/dist/dynamic/helpers/useIsomorphicLayout/package.json +1 -1
  109. package/dist/dynamic/helpers/useUnmountEffect/package.json +1 -1
  110. package/dist/dynamic/helpers/util/package.json +1 -1
  111. package/dist/dynamic/layouts/Bullseye/package.json +1 -1
  112. package/dist/dynamic/layouts/Flex/package.json +1 -1
  113. package/dist/dynamic/layouts/Gallery/package.json +1 -1
  114. package/dist/dynamic/layouts/Grid/package.json +1 -1
  115. package/dist/dynamic/layouts/Level/package.json +1 -1
  116. package/dist/dynamic/layouts/Split/package.json +1 -1
  117. package/dist/dynamic/layouts/Stack/package.json +1 -1
  118. package/dist/dynamic/next/components/package.json +1 -1
  119. package/dist/esm/components/ClipboardCopy/ClipboardCopy.d.ts +1 -1
  120. package/dist/esm/components/ClipboardCopy/ClipboardCopy.d.ts.map +1 -1
  121. package/dist/esm/components/ClipboardCopy/ClipboardCopyButton.d.ts.map +1 -1
  122. package/dist/esm/components/ClipboardCopy/ClipboardCopyButton.js +2 -2
  123. package/dist/esm/components/ClipboardCopy/ClipboardCopyButton.js.map +1 -1
  124. package/dist/esm/components/ClipboardCopy/ClipboardCopyToggle.js +1 -1
  125. package/dist/esm/components/ClipboardCopy/ClipboardCopyToggle.js.map +1 -1
  126. package/dist/js/components/ClipboardCopy/ClipboardCopy.d.ts +1 -1
  127. package/dist/js/components/ClipboardCopy/ClipboardCopy.d.ts.map +1 -1
  128. package/dist/js/components/ClipboardCopy/ClipboardCopyButton.d.ts.map +1 -1
  129. package/dist/js/components/ClipboardCopy/ClipboardCopyButton.js +2 -2
  130. package/dist/js/components/ClipboardCopy/ClipboardCopyButton.js.map +1 -1
  131. package/dist/js/components/ClipboardCopy/ClipboardCopyToggle.js +1 -1
  132. package/dist/js/components/ClipboardCopy/ClipboardCopyToggle.js.map +1 -1
  133. package/dist/umd/react-core.min.js +1 -1
  134. package/helpers/package.json +1 -1
  135. package/layouts/package.json +1 -1
  136. package/next/package.json +1 -1
  137. package/package.json +2 -2
  138. package/src/components/ClipboardCopy/ClipboardCopy.tsx +1 -1
  139. package/src/components/ClipboardCopy/ClipboardCopyButton.tsx +2 -0
  140. package/src/components/ClipboardCopy/ClipboardCopyToggle.tsx +1 -1
  141. package/src/components/ClipboardCopy/__tests__/ClipboardCopy.test.tsx +344 -0
  142. package/src/components/ClipboardCopy/__tests__/ClipboardCopyAction.test.tsx +37 -0
  143. package/src/components/ClipboardCopy/__tests__/ClipboardCopyButton.test.tsx +136 -19
  144. package/src/components/ClipboardCopy/__tests__/ClipboardCopyExpanded.test.tsx +71 -14
  145. package/src/components/ClipboardCopy/__tests__/ClipboardCopyToggle.test.tsx +78 -34
  146. package/src/components/ClipboardCopy/__tests__/__snapshots__/ClipboardCopy.test.tsx.snap +57 -0
  147. package/src/components/ClipboardCopy/__tests__/__snapshots__/ClipboardCopyAction.test.tsx.snap +11 -0
  148. package/src/components/ClipboardCopy/__tests__/__snapshots__/ClipboardCopyButton.test.tsx.snap +50 -24
  149. package/src/components/ClipboardCopy/__tests__/__snapshots__/ClipboardCopyExpanded.test.tsx.snap +3 -23
  150. package/src/components/ClipboardCopy/__tests__/__snapshots__/ClipboardCopyToggle.test.tsx.snap +5 -6
  151. package/src/components/ClipboardCopy/__tests__/Generated/ClipboardCopy.test.tsx +0 -40
  152. package/src/components/ClipboardCopy/__tests__/Generated/__snapshots__/ClipboardCopy.test.tsx.snap +0 -55
@@ -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.17","private":true}
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.18","private":true}
@@ -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.17","private":true}
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.18","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.17","private":true}
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.18","private":true}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@patternfly/react-core",
3
- "version": "5.2.0-prerelease.18",
3
+ "version": "5.2.0-prerelease.19",
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",
@@ -71,5 +71,5 @@
71
71
  "react": "^17 || ^18",
72
72
  "react-dom": "^17 || ^18"
73
73
  },
74
- "gitHead": "044826a3f3ee454f616c35c0cfd5652d6baa9614"
74
+ "gitHead": "177b67612018e68f66e0d83d7285eebd48cb3f27"
75
75
  }
@@ -75,7 +75,7 @@ export interface ClipboardCopyProps extends Omit<React.HTMLProps<HTMLDivElement>
75
75
  onChange?: (event: React.FormEvent, text?: string | number) => void;
76
76
  /** The text which is copied. */
77
77
  children: React.ReactNode;
78
- /** Additional actions for inline clipboard copy. Should be wrapped with ClipboardCopyAction. */
78
+ /** Additional actions for inline-compact clipboard copy. Should be wrapped with ClipboardCopyAction. */
79
79
  additionalActions?: React.ReactNode;
80
80
  /** Value to overwrite the randomly generated data-ouia-component-id.*/
81
81
  ouiaId?: number | string;
@@ -57,6 +57,7 @@ export const ClipboardCopyButton: React.FunctionComponent<ClipboardCopyButtonPro
57
57
  children,
58
58
  variant = 'control',
59
59
  onTooltipHidden = () => {},
60
+ className,
60
61
  ...props
61
62
  }: ClipboardCopyButtonProps) => {
62
63
  const triggerRef = React.createRef<HTMLButtonElement>();
@@ -79,6 +80,7 @@ export const ClipboardCopyButton: React.FunctionComponent<ClipboardCopyButtonPro
79
80
  variant={variant}
80
81
  onClick={onClick}
81
82
  aria-label={ariaLabel}
83
+ className={className}
82
84
  id={id}
83
85
  aria-labelledby={`${id} ${textId}`}
84
86
  {...props}
@@ -28,7 +28,7 @@ export const ClipboardCopyToggle: React.FunctionComponent<ClipboardCopyTogglePro
28
28
  onClick={onClick}
29
29
  id={id}
30
30
  aria-labelledby={`${id} ${textId}`}
31
- aria-controls={`${id} ${contentId}`}
31
+ aria-controls={contentId}
32
32
  aria-expanded={isExpanded}
33
33
  {...props}
34
34
  >
@@ -0,0 +1,344 @@
1
+ import React from 'react';
2
+ import { screen, render } from '@testing-library/react';
3
+ import { ClipboardCopy } from '../ClipboardCopy';
4
+ import styles from '@patternfly/react-styles/css/components/ClipboardCopy/clipboard-copy';
5
+ import userEvent from '@testing-library/user-event';
6
+
7
+ jest.mock('../ClipboardCopyButton', () => ({
8
+ ClipboardCopyButton: ({ 'aria-label': ariaLabel, children, entryDelay, exitDelay, maxWidth, position, onClick }) => (
9
+ <div data-testid="clipboardCopyButton-mock">
10
+ <p>{`exitDelay: ${exitDelay}`}</p>
11
+ <p>{`entryDelay: ${entryDelay}`}</p>
12
+ <p>{`maxWidth: ${maxWidth}`}</p>
13
+ <p>{`position: ${position}`}</p>
14
+ <p>{`button-ariaLabel: ${ariaLabel}`}</p>
15
+ <div>{`children: ${children}`}</div>
16
+ <button onClick={onClick}>Test CCB clicker</button>
17
+ </div>
18
+ )
19
+ }));
20
+
21
+ jest.mock('../ClipboardCopyToggle', () => ({
22
+ ClipboardCopyToggle: ({ 'aria-label': ariaLabel }) => (
23
+ <div data-testid="clipboardCopyToggle-mock">
24
+ <p>{`toggle-ariaLabel: ${ariaLabel}`}</p>
25
+ </div>
26
+ )
27
+ }));
28
+
29
+ const children = 'Copyable text';
30
+ const testId = 'clipboard-copy';
31
+
32
+ test(`Renders with class ${styles.clipboardCopy} by default`, () => {
33
+ render(<ClipboardCopy data-testid={testId}>{children}</ClipboardCopy>);
34
+
35
+ expect(screen.getByTestId(testId)).toHaveClass(styles.clipboardCopy, { exact: true });
36
+ });
37
+
38
+ test(`Renders with custom class when className is passed`, () => {
39
+ render(
40
+ <ClipboardCopy className="test-class" data-testid={testId}>
41
+ {children}
42
+ </ClipboardCopy>
43
+ );
44
+
45
+ expect(screen.getByTestId(testId)).toHaveClass('test-class');
46
+ });
47
+
48
+ test(`Does not render with class ${styles.modifiers.inline} by default`, () => {
49
+ render(<ClipboardCopy data-testid={testId}>{children}</ClipboardCopy>);
50
+
51
+ expect(screen.getByTestId(testId)).not.toHaveClass(styles.modifiers.inline);
52
+ });
53
+
54
+ test(`Does not render with class ${styles.modifiers.inline} if variant is not inline-compact`, () => {
55
+ render(
56
+ <ClipboardCopy variant="expansion" data-testid={testId}>
57
+ {children}
58
+ </ClipboardCopy>
59
+ );
60
+
61
+ expect(screen.getByTestId(testId)).not.toHaveClass(styles.modifiers.inline);
62
+ });
63
+
64
+ test(`Renders with class ${styles.modifiers.inline} when variant is inline-compact`, () => {
65
+ render(
66
+ <ClipboardCopy variant="inline-compact" data-testid={testId}>
67
+ {children}
68
+ </ClipboardCopy>
69
+ );
70
+
71
+ expect(screen.getByTestId(testId)).toHaveClass(styles.modifiers.inline);
72
+ });
73
+
74
+ test(`Does not render with class ${styles.modifiers.expanded} by default`, () => {
75
+ render(<ClipboardCopy data-testid={testId}>{children}</ClipboardCopy>);
76
+
77
+ expect(screen.getByTestId(testId)).not.toHaveClass(styles.modifiers.expanded);
78
+ });
79
+
80
+ test(`Renders with class ${styles.modifiers.expanded} when isExpanded is passed`, () => {
81
+ render(
82
+ <ClipboardCopy isExpanded data-testid={testId}>
83
+ {children}
84
+ </ClipboardCopy>
85
+ );
86
+
87
+ expect(screen.getByTestId(testId)).toHaveClass(styles.modifiers.expanded);
88
+ });
89
+
90
+ test(`Does not render with class ${styles.modifiers.block} by default`, () => {
91
+ render(<ClipboardCopy data-testid={testId}>{children}</ClipboardCopy>);
92
+
93
+ expect(screen.getByTestId(testId)).not.toHaveClass(styles.modifiers.block);
94
+ });
95
+
96
+ test(`Renders with class ${styles.modifiers.block} when isBlock is passed`, () => {
97
+ render(
98
+ <ClipboardCopy isBlock data-testid={testId}>
99
+ {children}
100
+ </ClipboardCopy>
101
+ );
102
+
103
+ expect(screen.getByTestId(testId)).toHaveClass(styles.modifiers.block);
104
+ });
105
+
106
+ test('Spreads additional props to container div', () => {
107
+ render(
108
+ <ClipboardCopy data-testid={testId} role="group">
109
+ {children}
110
+ </ClipboardCopy>
111
+ );
112
+
113
+ expect(screen.getByTestId(testId)).toHaveAttribute('role', 'group');
114
+ });
115
+
116
+ test(`Renders children without class ${styles.modifiers.code} when variant is inline-compact and isCode is not passed`, () => {
117
+ render(
118
+ <ClipboardCopy variant="inline-compact" data-testid={testId}>
119
+ {children}
120
+ </ClipboardCopy>
121
+ );
122
+
123
+ expect(screen.getByText(children)).not.toHaveClass(styles.modifiers.code);
124
+ });
125
+
126
+ test(`Renders children with class ${styles.modifiers.code} when variant is inline-compact and isCode is passed`, () => {
127
+ render(
128
+ <ClipboardCopy isCode variant="inline-compact" data-testid={testId}>
129
+ {children}
130
+ </ClipboardCopy>
131
+ );
132
+
133
+ expect(screen.getByText(children)).toHaveClass(styles.modifiers.code);
134
+ });
135
+
136
+ test('Does not render content passed to additionalActions by default', () => {
137
+ render(<ClipboardCopy additionalActions="Additional action">{children}</ClipboardCopy>);
138
+
139
+ expect(screen.queryByText('Additional action')).toBeNull();
140
+ });
141
+
142
+ test('Does not render content passed to additionalActions when variant is not inline-compact', () => {
143
+ render(
144
+ <ClipboardCopy variant="expansion" additionalActions="Additional action">
145
+ {children}
146
+ </ClipboardCopy>
147
+ );
148
+
149
+ expect(screen.queryByText('Additional action')).toBeNull();
150
+ });
151
+
152
+ test('Renders content passed to additionalActions when variant is inline-compact', () => {
153
+ render(
154
+ <ClipboardCopy variant="inline-compact" additionalActions="Additional action">
155
+ {children}
156
+ </ClipboardCopy>
157
+ );
158
+
159
+ expect(screen.getByText('Additional action')).toBeVisible();
160
+ });
161
+
162
+ test('Passes hoverTip to ClipboardCopyButton by default', () => {
163
+ render(<ClipboardCopy hoverTip="hover tip">{children}</ClipboardCopy>);
164
+
165
+ expect(screen.getByText('button-ariaLabel: hover tip')).toBeVisible();
166
+ expect(screen.getByText('children: hover tip')).toBeVisible();
167
+ });
168
+
169
+ test('Passes hoverTip to ClipboardCopyButton when variant is inline-compact', () => {
170
+ render(
171
+ <ClipboardCopy variant="inline-compact" hoverTip="hover tip">
172
+ {children}
173
+ </ClipboardCopy>
174
+ );
175
+
176
+ expect(screen.getByText('button-ariaLabel: hover tip')).toBeVisible();
177
+ expect(screen.getByText('children: hover tip')).toBeVisible();
178
+ });
179
+
180
+ test('Passes clickTip when ClipboardCopyButton clicked', async () => {
181
+ const user = userEvent.setup();
182
+ render(<ClipboardCopy clickTip="click tip">{children}</ClipboardCopy>);
183
+
184
+ await user.click(screen.getByRole('button', { name: 'Test CCB clicker' }));
185
+
186
+ expect(screen.getByText('children: click tip')).toBeVisible();
187
+ });
188
+
189
+ test('Passes entryDelay to ClipboardCopyButton by default', () => {
190
+ render(<ClipboardCopy entryDelay={100}>{children}</ClipboardCopy>);
191
+
192
+ expect(screen.getByText('entryDelay: 100')).toBeVisible();
193
+ });
194
+
195
+ test('Passes entryDelay to ClipboardCopyButton when variant is inline-compact', () => {
196
+ render(
197
+ <ClipboardCopy variant="inline-compact" entryDelay={100}>
198
+ {children}
199
+ </ClipboardCopy>
200
+ );
201
+
202
+ expect(screen.getByText('entryDelay: 100')).toBeVisible();
203
+ });
204
+
205
+ test('Passes exitDelay to ClipboardCopyButton by default', () => {
206
+ render(<ClipboardCopy exitDelay={100}>{children}</ClipboardCopy>);
207
+
208
+ expect(screen.getByText('exitDelay: 100')).toBeVisible();
209
+ });
210
+
211
+ test('Passes exitDelay to ClipboardCopyButton when variant is inline-compact', () => {
212
+ render(
213
+ <ClipboardCopy variant="inline-compact" exitDelay={100}>
214
+ {children}
215
+ </ClipboardCopy>
216
+ );
217
+
218
+ expect(screen.getByText('exitDelay: 100')).toBeVisible();
219
+ });
220
+
221
+ test('Passes maxWidth to ClipboardCopyButton by default', () => {
222
+ render(<ClipboardCopy maxWidth="100">{children}</ClipboardCopy>);
223
+
224
+ expect(screen.getByText('maxWidth: 100')).toBeVisible();
225
+ });
226
+
227
+ test('Passes maxWidth to ClipboardCopyButton when variant is inline-compact', () => {
228
+ render(
229
+ <ClipboardCopy variant="inline-compact" maxWidth="100">
230
+ {children}
231
+ </ClipboardCopy>
232
+ );
233
+
234
+ expect(screen.getByText('maxWidth: 100')).toBeVisible();
235
+ });
236
+
237
+ test('Passes position to ClipboardCopyButton by default', () => {
238
+ render(<ClipboardCopy position="bottom">{children}</ClipboardCopy>);
239
+
240
+ expect(screen.getByText('position: bottom')).toBeVisible();
241
+ });
242
+
243
+ test('Passes position to ClipboardCopyButton when variant is inline-compact', () => {
244
+ render(
245
+ <ClipboardCopy variant="inline-compact" position="bottom">
246
+ {children}
247
+ </ClipboardCopy>
248
+ );
249
+
250
+ expect(screen.getByText('position: bottom')).toBeVisible();
251
+ });
252
+
253
+ test('Passes toggleAriaLabel to ClipboardCopyToggle when variant is expansion', () => {
254
+ render(
255
+ <ClipboardCopy variant="expansion" toggleAriaLabel="toggle label">
256
+ {children}
257
+ </ClipboardCopy>
258
+ );
259
+
260
+ expect(screen.getByText('toggle-ariaLabel: toggle label')).toBeVisible();
261
+ });
262
+
263
+ test('Does not set textinput to readonly when isReadOnly is not passed', () => {
264
+ render(<ClipboardCopy>{children}</ClipboardCopy>);
265
+
266
+ expect(screen.getByRole('textbox')).not.toHaveAttribute('readonly');
267
+ });
268
+
269
+ test('Passes isReadOnly to TextInput', () => {
270
+ render(<ClipboardCopy isReadOnly>{children}</ClipboardCopy>);
271
+
272
+ expect(screen.getByRole('textbox')).toHaveAttribute('readonly');
273
+ });
274
+
275
+ test('Passes textAriaLabel to TextInput', () => {
276
+ render(<ClipboardCopy textAriaLabel="text label">{children}</ClipboardCopy>);
277
+
278
+ expect(screen.getByRole('textbox')).toHaveAccessibleName('text label');
279
+ });
280
+
281
+ test('Calls onChange when ClipboardCopy textinput is typed in', async () => {
282
+ const onChangeMock = jest.fn();
283
+ const user = userEvent.setup();
284
+ const typedText = 'stuff';
285
+
286
+ render(<ClipboardCopy onChange={onChangeMock}>{children}</ClipboardCopy>);
287
+
288
+ await user.type(screen.getByRole('textbox'), typedText);
289
+
290
+ expect(onChangeMock).toHaveBeenCalledTimes(typedText.length);
291
+ });
292
+
293
+ test('Does not call onChange when ClipboardCopy textinput is not typed in', async () => {
294
+ const onChangeMock = jest.fn();
295
+ const user = userEvent.setup();
296
+ const typedText = 'stuff';
297
+
298
+ render(
299
+ <>
300
+ <ClipboardCopy onChange={onChangeMock}>{children}</ClipboardCopy>
301
+ <input aria-label="native input" />
302
+ </>
303
+ );
304
+
305
+ await user.type(screen.getByRole('textbox', { name: 'native input' }), typedText);
306
+
307
+ expect(onChangeMock).not.toHaveBeenCalled();
308
+ });
309
+
310
+ test('Calls onCopy when ClipboardCopyButton is clicked', async () => {
311
+ const onCopyMock = jest.fn();
312
+ const user = userEvent.setup();
313
+
314
+ render(<ClipboardCopy onCopy={onCopyMock}>{children}</ClipboardCopy>);
315
+
316
+ await user.click(screen.getByRole('button', { name: 'Test CCB clicker' }));
317
+
318
+ expect(onCopyMock).toHaveBeenCalledTimes(1);
319
+ });
320
+
321
+ test('Does not call onCopy when ClipboardCopyButton is not clicked', async () => {
322
+ const onCopyMock = jest.fn();
323
+ const user = userEvent.setup();
324
+
325
+ render(
326
+ <>
327
+ <ClipboardCopy onCopy={onCopyMock}>{children}</ClipboardCopy>
328
+ <button>Test native clicker</button>
329
+ </>
330
+ );
331
+
332
+ await user.click(screen.getByRole('button', { name: 'Test native clicker' }));
333
+
334
+ expect(onCopyMock).not.toHaveBeenCalled();
335
+ });
336
+
337
+ test('Matches snapshot', () => {
338
+ const { asFragment } = render(
339
+ <ClipboardCopy id="snapshot" ouiaId="snapshot">
340
+ {children}
341
+ </ClipboardCopy>
342
+ );
343
+ expect(asFragment()).toMatchSnapshot();
344
+ });
@@ -0,0 +1,37 @@
1
+ import React from 'react';
2
+ import { screen, render } from '@testing-library/react';
3
+ import { ClipboardCopyAction } from '../ClipboardCopyAction';
4
+ import styles from '@patternfly/react-styles/css/components/ClipboardCopy/clipboard-copy';
5
+
6
+ test('Renders without children', () => {
7
+ render(
8
+ <div data-testid="container">
9
+ <ClipboardCopyAction />
10
+ </div>
11
+ );
12
+
13
+ expect(screen.getByTestId('container').firstChild).toBeVisible();
14
+ });
15
+
16
+ test(`Renders with class ${styles.clipboardCopyActionsItem} by default`, () => {
17
+ render(<ClipboardCopyAction>Action text</ClipboardCopyAction>);
18
+
19
+ expect(screen.getByText('Action text')).toHaveClass(styles.clipboardCopyActionsItem, { exact: true });
20
+ });
21
+
22
+ test(`Renders with custom class when className is passed`, () => {
23
+ render(<ClipboardCopyAction className="custom-class">Action text</ClipboardCopyAction>);
24
+
25
+ expect(screen.getByText('Action text')).toHaveClass('custom-class');
26
+ });
27
+
28
+ test(`Spreads additional props`, () => {
29
+ render(<ClipboardCopyAction id="test-id">Action text</ClipboardCopyAction>);
30
+
31
+ expect(screen.getByText('Action text')).toHaveAttribute('id', 'test-id');
32
+ });
33
+
34
+ test('Matches snapshot', () => {
35
+ const { asFragment } = render(<ClipboardCopyAction>Action text</ClipboardCopyAction>);
36
+ expect(asFragment()).toMatchSnapshot();
37
+ });
@@ -2,36 +2,153 @@ import React from 'react';
2
2
 
3
3
  import { render, screen } from '@testing-library/react';
4
4
  import userEvent from '@testing-library/user-event';
5
-
6
5
  import { ClipboardCopyButton } from '../ClipboardCopyButton';
6
+ import buttonStyles from '@patternfly/react-styles/css/components/Button/button';
7
+
8
+ jest.mock('../../Tooltip', () => ({
9
+ Tooltip: ({ content, children, exitDelay, entryDelay, maxWidth, position, onTooltipHidden }) => (
10
+ <div data-testid="tooltip-mock">
11
+ <div data-testid="tooltip-mock-content">{content}</div>
12
+ <p>{`exitDelay: ${exitDelay}`}</p>
13
+ <p>{`entryDelay: ${entryDelay}`}</p>
14
+ <p>{`maxWidth: ${maxWidth}`}</p>
15
+ <p>{`position: ${position}`}</p>
16
+ <a onClick={onTooltipHidden}>onTooltipHidden clicker</a>
17
+ {children}
18
+ </div>
19
+ )
20
+ }));
7
21
 
8
- const props = {
9
- id: 'my-id',
10
- textId: 'my-text-id',
11
- className: 'fancy-copy-button',
22
+ const requiredProps = {
12
23
  onClick: jest.fn(),
13
- exitDelay: 1000,
14
- entryDelay: 2000,
15
- maxWidth: '500px',
16
- position: 'right' as 'right',
17
- 'aria-label': 'click this button to copy text'
24
+ children: 'Button content',
25
+ id: 'button-id',
26
+ textId: 'text-id'
18
27
  };
19
28
 
20
- test('copy button render', () => {
21
- const { asFragment } = render(<ClipboardCopyButton {...props}>Copy Me</ClipboardCopyButton>);
29
+ // Must be kept as first test to avoid Button's ouiaId updating in snapshots
30
+ test('Matches snapshot', () => {
31
+ const { asFragment } = render(<ClipboardCopyButton {...requiredProps} />);
22
32
  expect(asFragment()).toMatchSnapshot();
23
33
  });
24
34
 
25
- test('copy button onClick', async () => {
26
- const onclick = jest.fn();
27
- const user = userEvent.setup();
35
+ test('Renders with passed id prop', () => {
36
+ render(<ClipboardCopyButton {...requiredProps} />);
37
+
38
+ expect(screen.getByRole('button')).toHaveAttribute('id', 'button-id');
39
+ });
40
+
41
+ test('Renders with aria-labelledby with passed id and textId prop values', () => {
42
+ render(
43
+ <>
44
+ <div id="text-id">Copyable text</div>
45
+ <ClipboardCopyButton {...requiredProps} />
46
+ </>
47
+ );
48
+
49
+ expect(screen.getByRole('button')).toHaveAccessibleName('Copyable input Copyable text');
50
+ });
51
+
52
+ test('Renders with concatenated aria-label by default', () => {
53
+ render(
54
+ <>
55
+ <div id="text-id">Copyable text</div>
56
+ <ClipboardCopyButton {...requiredProps} />
57
+ </>
58
+ );
59
+
60
+ expect(screen.getByRole('button')).toHaveAccessibleName('Copyable input Copyable text');
61
+ });
28
62
 
63
+ test('Renders with concatenated aria-label when custom aria-label is passed', () => {
29
64
  render(
30
- <ClipboardCopyButton {...props} onClick={onclick}>
31
- Copy to Clipboard
32
- </ClipboardCopyButton>
65
+ <>
66
+ <div id="text-id">Copyable text</div>
67
+ <ClipboardCopyButton aria-label="Custom label" {...requiredProps} />
68
+ </>
33
69
  );
34
70
 
71
+ expect(screen.getByRole('button')).toHaveAccessibleName('Custom label Copyable text');
72
+ });
73
+
74
+ test('Passes className to Button', () => {
75
+ render(<ClipboardCopyButton className="test-class" {...requiredProps} />);
76
+
77
+ expect(screen.getByRole('button')).toHaveClass('test-class');
78
+ });
79
+
80
+ test('Passes variant to Button by default', () => {
81
+ render(<ClipboardCopyButton {...requiredProps} />);
82
+
83
+ expect(screen.getByRole('button')).toHaveClass(buttonStyles.modifiers.control);
84
+ });
85
+
86
+ test('Passes variant to Button when variant is passed', () => {
87
+ render(<ClipboardCopyButton variant="plain" {...requiredProps} />);
88
+
89
+ expect(screen.getByRole('button')).toHaveClass(buttonStyles.modifiers.plain);
90
+ });
91
+
92
+ test('Calls onClick when ClipboardCopyButton is clicked', async () => {
93
+ const user = userEvent.setup();
94
+
95
+ render(<ClipboardCopyButton {...requiredProps} />);
96
+
35
97
  await user.click(screen.getByRole('button'));
36
- expect(onclick).toHaveBeenCalled();
98
+ expect(requiredProps.onClick).toHaveBeenCalledTimes(1);
99
+ });
100
+
101
+ test('Does not call onClick when ClipboardCopyButton is not clicked', async () => {
102
+ const user = userEvent.setup();
103
+
104
+ render(
105
+ <>
106
+ <ClipboardCopyButton {...requiredProps} />
107
+ <button>Test clicker</button>
108
+ </>
109
+ );
110
+
111
+ await user.click(screen.getByRole('button', { name: 'Test clicker' }));
112
+ expect(requiredProps.onClick).not.toHaveBeenCalled();
113
+ });
114
+
115
+ test('Passes children to Tooltip content', () => {
116
+ render(<ClipboardCopyButton {...requiredProps} />);
117
+
118
+ expect(screen.getByText('Button content')).toBeVisible();
119
+ });
120
+
121
+ test('Passes exitDelay to Tooltip', () => {
122
+ render(<ClipboardCopyButton exitDelay={200} {...requiredProps} />);
123
+
124
+ expect(screen.getByText('exitDelay: 200')).toBeVisible();
125
+ });
126
+
127
+ test('Passes entryDelay to Tooltip', () => {
128
+ render(<ClipboardCopyButton entryDelay={200} {...requiredProps} />);
129
+
130
+ expect(screen.getByText('entryDelay: 200')).toBeVisible();
131
+ });
132
+
133
+ test('Passes maxWidth to Tooltip', () => {
134
+ render(<ClipboardCopyButton maxWidth="200px" {...requiredProps} />);
135
+
136
+ expect(screen.getByText('maxWidth: 200px')).toBeVisible();
137
+ });
138
+
139
+ test('Passes position to Tooltip', () => {
140
+ render(<ClipboardCopyButton position="bottom" {...requiredProps} />);
141
+
142
+ expect(screen.getByText('position: bottom')).toBeVisible();
143
+ });
144
+
145
+ test('Passes onTooltipHidden to Tooltip', async () => {
146
+ const user = userEvent.setup();
147
+ const onTooltipHiddenMock = jest.fn();
148
+
149
+ render(<ClipboardCopyButton onTooltipHidden={onTooltipHiddenMock} {...requiredProps} />);
150
+
151
+ await user.click(screen.getByText('onTooltipHidden clicker'));
152
+
153
+ expect(onTooltipHiddenMock).toHaveBeenCalled();
37
154
  });