@patternfly/react-core 4.202.34 → 4.202.37

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 (44) hide show
  1. package/CHANGELOG.md +24 -0
  2. package/dist/esm/components/Brand/Brand.d.ts +23 -3
  3. package/dist/esm/components/Brand/Brand.d.ts.map +1 -1
  4. package/dist/esm/components/Brand/Brand.js +12 -2
  5. package/dist/esm/components/Brand/Brand.js.map +1 -1
  6. package/dist/esm/components/Tabs/Tabs.d.ts +2 -0
  7. package/dist/esm/components/Tabs/Tabs.d.ts.map +1 -1
  8. package/dist/esm/components/Tabs/Tabs.js +3 -2
  9. package/dist/esm/components/Tabs/Tabs.js.map +1 -1
  10. package/dist/js/components/Brand/Brand.d.ts +23 -3
  11. package/dist/js/components/Brand/Brand.d.ts.map +1 -1
  12. package/dist/js/components/Brand/Brand.js +12 -2
  13. package/dist/js/components/Brand/Brand.js.map +1 -1
  14. package/dist/js/components/Tabs/Tabs.d.ts +2 -0
  15. package/dist/js/components/Tabs/Tabs.d.ts.map +1 -1
  16. package/dist/js/components/Tabs/Tabs.js +3 -2
  17. package/dist/js/components/Tabs/Tabs.js.map +1 -1
  18. package/dist/umd/react-core.css +115 -35
  19. package/dist/umd/react-core.js +145 -123
  20. package/dist/umd/react-core.min.css +80 -0
  21. package/dist/umd/react-core.min.js +4 -4
  22. package/package.json +6 -6
  23. package/src/components/Brand/Brand.tsx +61 -8
  24. package/src/components/Brand/__tests__/Brand.test.tsx +15 -4
  25. package/src/components/Brand/__tests__/__snapshots__/Brand.test.tsx.snap +1 -1
  26. package/src/components/Brand/examples/Brand.md +13 -0
  27. package/src/components/Brand/examples/BrandResponsive.tsx +18 -0
  28. package/src/components/Brand/examples/pf-c-brand--logo-base.jpg +0 -0
  29. package/src/components/Brand/examples/pf-c-brand--logo-on-lg.svg +32 -0
  30. package/src/components/Brand/examples/pf-c-brand--logo-on-md.svg +42 -0
  31. package/src/components/Brand/examples/pf-c-brand--logo-on-sm.svg +17 -0
  32. package/src/components/Brand/examples/pf-c-brand--logo-on-xl.svg +39 -0
  33. package/src/components/Brand/examples/pf-c-brand--logo.svg +10 -0
  34. package/src/components/Tabs/Tabs.tsx +5 -0
  35. package/src/components/Tabs/__tests__/Tabs.test.tsx +17 -0
  36. package/src/components/Tabs/__tests__/__snapshots__/Tabs.test.tsx.snap +153 -0
  37. package/src/components/TextInputGroup/__tests__/TextInputGroup.test.tsx +47 -146
  38. package/src/components/TextInputGroup/__tests__/TextInputGroupMain.test.tsx +302 -0
  39. package/src/components/TextInputGroup/__tests__/TextInputGroupUtilities.test.tsx +34 -0
  40. package/src/components/TextInputGroup/__tests__/__snapshots__/TextInputGroup.test.tsx.snap +2 -203
  41. package/src/components/TextInputGroup/__tests__/__snapshots__/TextInputGroupMain.test.tsx.snap +21 -0
  42. package/src/components/TextInputGroup/__tests__/__snapshots__/TextInputGroupUtilities.test.tsx.snap +13 -0
  43. package/src/demos/Tabs.md +5 -0
  44. package/src/demos/examples/Tabs/TabsAndTablesAutoWidthTabs.tsx +442 -0
@@ -1,192 +1,93 @@
1
1
  import React from 'react';
2
-
3
2
  import { render, screen } from '@testing-library/react';
4
- import userEvent from '@testing-library/user-event';
3
+ import '@testing-library/jest-dom';
5
4
 
6
5
  import { TextInputGroup, TextInputGroupContext } from '../TextInputGroup';
7
- import { TextInputGroupMain } from '../TextInputGroupMain';
8
- import { TextInputGroupUtilities } from '../TextInputGroupUtilities';
9
- import SearchIcon from '@patternfly/react-icons/dist/esm/icons/search-icon';
10
6
 
11
7
  describe('TextInputGroup', () => {
12
- test('renders content', () => {
13
- const { asFragment } = render(
14
- <TextInputGroup>
15
- <TextInputGroupMain>Foo</TextInputGroupMain>
16
- <TextInputGroupUtilities />
17
- </TextInputGroup>
18
- );
19
- expect(asFragment()).toMatchSnapshot();
20
- });
21
-
22
- test('gets custom class and id', () => {
23
- const { asFragment } = render(
24
- <TextInputGroup className="custom-class" id="test-id">
25
- <TextInputGroupMain>Foo</TextInputGroupMain>
26
- <TextInputGroupUtilities />
27
- </TextInputGroup>
28
- );
29
- expect(asFragment()).toMatchSnapshot();
30
- });
8
+ it('renders without children', () => {
9
+ render(<TextInputGroup data-testid="TextInputGroup" />);
31
10
 
32
- test('renders with the proper stying when disabled', () => {
33
- const { asFragment } = render(
34
- <TextInputGroup isDisabled>
35
- <TextInputGroupMain>Foo</TextInputGroupMain>
36
- <TextInputGroupUtilities />
37
- </TextInputGroup>
38
- );
39
- expect(asFragment()).toMatchSnapshot();
11
+ expect(screen.getByTestId('TextInputGroup')).toBeVisible();
40
12
  });
41
13
 
42
- test('passes isDisabled=false to children via a context when isDisabled prop is not passed', () => {
43
- const TestComponent: React.FunctionComponent = () => {
44
- const context = React.useContext(TextInputGroupContext);
14
+ it('renders children', () => {
15
+ render(<TextInputGroup>Test</TextInputGroup>);
45
16
 
46
- return <div>{context.isDisabled ? 'is disabled' : 'not disabled'}</div>;
47
- };
48
-
49
- render(
50
- <TextInputGroup>
51
- <TestComponent />
52
- </TextInputGroup>
53
- );
54
-
55
- expect(screen.queryByText('is disabled')).toBeNull();
17
+ expect(screen.getByText('Test')).toBeVisible();
56
18
  });
57
19
 
58
- test('passes isDisabled=true to children via a context when isDisabled prop is passed', () => {
59
- const TestComponent: React.FunctionComponent = () => {
60
- const context = React.useContext(TextInputGroupContext);
20
+ it('renders with class pf-c-text-input-group', () => {
21
+ render(<TextInputGroup>Test</TextInputGroup>);
61
22
 
62
- return <div>{context.isDisabled ? 'is disabled' : 'not disabled'}</div>;
63
- };
64
-
65
- render(
66
- <TextInputGroup isDisabled>
67
- <TestComponent />
68
- </TextInputGroup>
69
- );
23
+ const inputGroup = screen.getByText('Test');
70
24
 
71
- expect(screen.queryByText('not disabled')).toBeNull();
25
+ expect(inputGroup).toHaveClass('pf-c-text-input-group');
72
26
  });
73
- });
74
27
 
75
- describe('TextInputGroupMain', () => {
76
- test('renders content', () => {
77
- const { asFragment } = render(<TextInputGroupMain>Foo</TextInputGroupMain>);
78
- expect(asFragment()).toMatchSnapshot();
79
- });
28
+ it('renders with custom class names provided via prop', () => {
29
+ render(<TextInputGroup className="custom-class">Test</TextInputGroup>);
80
30
 
81
- test('renders given input icon props', () => {
82
- const { asFragment } = render(<TextInputGroupMain icon={<SearchIcon />}>Foo</TextInputGroupMain>);
83
- expect(asFragment()).toMatchSnapshot();
84
- });
31
+ const inputGroup = screen.getByText('Test');
85
32
 
86
- test('renders the input with custom aria label when given', () => {
87
- const { asFragment } = render(<TextInputGroupMain aria-label="Foo">Foo</TextInputGroupMain>);
88
- expect(asFragment()).toMatchSnapshot();
33
+ expect(inputGroup).toHaveClass('custom-class');
89
34
  });
90
35
 
91
- test('does not call onChange callback when the input does not change', () => {
92
- const onChangeMock = jest.fn();
36
+ it('does not render with the pf-m-disabled class when not disabled', () => {
37
+ render(<TextInputGroup>Test</TextInputGroup>);
93
38
 
94
- render(<TextInputGroupMain onChange={onChangeMock}>Foo</TextInputGroupMain>);
95
- expect(onChangeMock).not.toHaveBeenCalled();
96
- });
97
-
98
- test('calls the onChange callback when the input changes', () => {
99
- const onChangeMock = jest.fn();
39
+ const inputGroup = screen.getByText('Test');
100
40
 
101
- render(<TextInputGroupMain onChange={onChangeMock}>Foo</TextInputGroupMain>);
102
-
103
- userEvent.type(screen.getByText('Foo').querySelector('input'), 'Foo');
104
- expect(onChangeMock).toHaveBeenCalled();
41
+ expect(inputGroup).not.toHaveClass('pf-m-disabled');
105
42
  });
106
43
 
107
- test('does not call onFocus callback when the input does not get focus', () => {
108
- const onFocusMock = jest.fn();
44
+ it('renders with the pf-m-disabled class when disabled', () => {
45
+ render(<TextInputGroup isDisabled>Test</TextInputGroup>);
109
46
 
110
- render(<TextInputGroupMain onFocus={onFocusMock}>Foo</TextInputGroupMain>);
111
- expect(onFocusMock).not.toHaveBeenCalled();
112
- });
47
+ const inputGroup = screen.getByText('Test');
113
48
 
114
- test('calls the onFocus callback when the input is focused', () => {
115
- const onFocusMock = jest.fn();
116
-
117
- render(<TextInputGroupMain onFocus={onFocusMock}>Foo</TextInputGroupMain>);
118
- userEvent.click(screen.getByText('Foo').querySelector('input'));
119
- expect(onFocusMock).toHaveBeenCalledTimes(1);
49
+ expect(inputGroup).toHaveClass('pf-m-disabled');
120
50
  });
121
51
 
122
- test('does not call onBlur callback when the input does not lose focus', () => {
123
- const onBlurMock = jest.fn();
124
-
125
- render(<TextInputGroupMain onBlur={onBlurMock}>Foo</TextInputGroupMain>);
126
-
127
- userEvent.type(screen.getByText('Foo').querySelector('input'), 'Foo');
128
- expect(onBlurMock).not.toHaveBeenCalled();
129
- });
52
+ it('passes isDisabled=false to children via a context when isDisabled prop is not passed', () => {
53
+ const TestComponent: React.FunctionComponent = () => {
54
+ const context = React.useContext(TextInputGroupContext);
130
55
 
131
- test('calls the onFocus callback when the input loses focus', () => {
132
- const onBlurMock = jest.fn();
56
+ return <button disabled={context.isDisabled} />;
57
+ };
133
58
 
134
59
  render(
135
- <>
136
- <div>Other element</div>
137
- <TextInputGroupMain onBlur={onBlurMock}>Foo</TextInputGroupMain>
138
- </>
60
+ <TextInputGroup>
61
+ <TestComponent />
62
+ </TextInputGroup>
139
63
  );
140
64
 
141
- userEvent.type(screen.getByText('Foo').querySelector('input'), 'Foo');
142
- userEvent.click(screen.getByText('Other element'));
65
+ const testComponent = screen.getByRole('button');
143
66
 
144
- expect(onBlurMock).toHaveBeenCalled();
67
+ expect(testComponent).not.toBeDisabled();
145
68
  });
146
69
 
147
- test('input type defaults to text', () => {
148
- render(<TextInputGroupMain>Foo</TextInputGroupMain>);
149
- expect(
150
- screen
151
- .getByText('Foo')
152
- .querySelector('input')
153
- .getAttribute('type')
154
- ).toEqual('text');
155
- });
70
+ it('passes isDisabled=true to children via a context when isDisabled prop is passed', () => {
71
+ const TestComponent: React.FunctionComponent = () => {
72
+ const context = React.useContext(TextInputGroupContext);
156
73
 
157
- test('input type is updated when a different type is passed', () => {
158
- render(<TextInputGroupMain type="search">Foo</TextInputGroupMain>);
159
- expect(
160
- screen
161
- .getByText('Foo')
162
- .querySelector('input')
163
- .getAttribute('type')
164
- ).toEqual('search');
165
- });
74
+ return <button disabled={context.isDisabled} />;
75
+ };
166
76
 
167
- test('input is not disabled when TextInputGroupContext isDisabled is false', () => {
168
- const { asFragment } = render(
169
- <TextInputGroupContext.Provider value={{ isDisabled: false }}>
170
- <TextInputGroupMain />
171
- </TextInputGroupContext.Provider>
77
+ render(
78
+ <TextInputGroup isDisabled>
79
+ <TestComponent />
80
+ </TextInputGroup>
172
81
  );
173
82
 
174
- expect(asFragment()).toMatchSnapshot();
175
- });
83
+ const testComponent = screen.getByRole('button');
176
84
 
177
- test('input is disabled when TextInputGroupContext isDisabled is true', () => {
178
- const { asFragment } = render(
179
- <TextInputGroupContext.Provider value={{ isDisabled: true }}>
180
- <TextInputGroupMain />
181
- </TextInputGroupContext.Provider>
182
- );
183
- expect(asFragment()).toMatchSnapshot();
85
+ expect(testComponent).toBeDisabled();
184
86
  });
185
- });
186
87
 
187
- describe('TextInputGroupUtilities', () => {
188
- test('renders the content', () => {
189
- const { asFragment } = render(<TextInputGroupUtilities>{<button>Foo</button>}</TextInputGroupUtilities>);
88
+ it('matches the snapshot', () => {
89
+ const { asFragment } = render(<TextInputGroup>Test</TextInputGroup>);
90
+
190
91
  expect(asFragment()).toMatchSnapshot();
191
92
  });
192
93
  });
@@ -0,0 +1,302 @@
1
+ import React from 'react';
2
+ import { render, screen } from '@testing-library/react';
3
+ import userEvent from '@testing-library/user-event';
4
+ import '@testing-library/jest-dom';
5
+
6
+ import { TextInputGroupMain } from '../TextInputGroupMain';
7
+ import { TextInputGroupContext } from '../TextInputGroup';
8
+ import SearchIcon from '@patternfly/react-icons/dist/esm/icons/search-icon';
9
+
10
+ describe('TextInputGroupMain', () => {
11
+ it('renders without children', () => {
12
+ render(<TextInputGroupMain data-testid='TextInputGroupMain'/>);
13
+
14
+ expect(screen.getByTestId('TextInputGroupMain')).toBeVisible();
15
+ });
16
+
17
+ it('renders children', () => {
18
+ render(<TextInputGroupMain>Test</TextInputGroupMain>);
19
+
20
+ expect(screen.getByText('Test')).toBeVisible();
21
+ });
22
+
23
+ it('renders with class pf-c-text-input-group__main', () => {
24
+ render(<TextInputGroupMain>Test</TextInputGroupMain>);
25
+
26
+ const inputGroupMain = screen.getByText('Test');
27
+
28
+ expect(inputGroupMain).toHaveClass('pf-c-text-input-group__main');
29
+ });
30
+
31
+ it('does not render with class pf-m-icon when an icon prop is not passed', () => {
32
+ render(<TextInputGroupMain>Test</TextInputGroupMain>);
33
+
34
+ const inputGroupMain = screen.getByText('Test');
35
+
36
+ expect(inputGroupMain).not.toHaveClass('pf-m-icon');
37
+ });
38
+
39
+ it('renders with class pf-m-icon when an icon prop is passed', () => {
40
+ render(<TextInputGroupMain icon="icon">Test</TextInputGroupMain>);
41
+
42
+ const inputGroupMain = screen.getByText('Test');
43
+
44
+ expect(inputGroupMain).toHaveClass('pf-m-icon');
45
+ });
46
+
47
+ it('renders with custom class names provided via prop', () => {
48
+ render(<TextInputGroupMain className="custom-class">Test</TextInputGroupMain>);
49
+
50
+ const inputGroupMain = screen.getByText('Test');
51
+
52
+ expect(inputGroupMain).toHaveClass('custom-class');
53
+ });
54
+
55
+ it('renders with class pf-c-text-input-group__text on the inputs parent', () => {
56
+ render(<TextInputGroupMain>Test</TextInputGroupMain>);
57
+
58
+ const inputGroupText = screen.getByRole('textbox').parentNode;
59
+
60
+ expect(inputGroupText).toHaveClass('pf-c-text-input-group__text');
61
+ });
62
+
63
+ it('renders the input with class pf-c-text-input-group__text-input', () => {
64
+ render(<TextInputGroupMain>Test</TextInputGroupMain>);
65
+
66
+ const input = screen.getByRole('textbox');
67
+
68
+ expect(input).toHaveClass('pf-c-text-input-group__text-input');
69
+ });
70
+
71
+ it('does not render the icon when it is not passed', () => {
72
+ render(<TextInputGroupMain />);
73
+
74
+ const icon = screen.queryByRole('img', { hidden: true });
75
+
76
+ expect(icon).not.toBeInTheDocument();
77
+ });
78
+
79
+ it('renders the icon when passed', () => {
80
+ render(<TextInputGroupMain icon={<SearchIcon />} />);
81
+
82
+ const icon = screen.getByRole('img', { hidden: true });
83
+
84
+ expect(icon).toBeInTheDocument();
85
+ });
86
+
87
+ it('renders the icon as aria hidden', () => {
88
+ render(<TextInputGroupMain icon={<SearchIcon />} />);
89
+
90
+ const icon = screen.getByRole('img', { hidden: true });
91
+
92
+ expect(icon).toHaveAttribute('aria-hidden', 'true');
93
+ });
94
+
95
+ it('passes the aria-label prop to the input', () => {
96
+ render(<TextInputGroupMain aria-label="Test label">Test</TextInputGroupMain>);
97
+
98
+ const input = screen.getByRole('textbox');
99
+
100
+ expect(input).toHaveAccessibleName('Test label');
101
+ });
102
+
103
+ it('passes the value prop to the input', () => {
104
+ render(<TextInputGroupMain value="value text">Test</TextInputGroupMain>);
105
+
106
+ const inputValue = screen.getByDisplayValue('value text');
107
+
108
+ expect(inputValue).toBeVisible();
109
+ });
110
+
111
+ it('passes the placeholder prop to the input', () => {
112
+ render(<TextInputGroupMain placeholder="placeholder text">Test</TextInputGroupMain>);
113
+
114
+ const inputPlaceholder = screen.getByPlaceholderText('placeholder text');
115
+
116
+ expect(inputPlaceholder).toBeVisible();
117
+ });
118
+
119
+ it('defaults to an input type of text', () => {
120
+ render(<TextInputGroupMain>Test</TextInputGroupMain>);
121
+
122
+ const input = screen.getByRole('textbox');
123
+
124
+ expect(input).toHaveAttribute('type', 'text');
125
+ });
126
+
127
+ it('updates the input type when a different type is passed', () => {
128
+ render(<TextInputGroupMain type="search">Test</TextInputGroupMain>);
129
+
130
+ const textInput = screen.queryByRole('textbox');
131
+ const searchInput = screen.getByRole('searchbox');
132
+
133
+ expect(textInput).not.toBeInTheDocument();
134
+ expect(searchInput).toBeVisible();
135
+ });
136
+
137
+ it('does not disable the input when TextInputGroupContext isDisabled is false', () => {
138
+ render(
139
+ <TextInputGroupContext.Provider value={{ isDisabled: false }}>
140
+ <TextInputGroupMain />
141
+ </TextInputGroupContext.Provider>
142
+ );
143
+
144
+ const input = screen.getByRole('textbox');
145
+
146
+ expect(input).not.toBeDisabled();
147
+ });
148
+
149
+ it('disables the input when TextInputGroupContext isDisabled is true', () => {
150
+ render(
151
+ <TextInputGroupContext.Provider value={{ isDisabled: true }}>
152
+ <TextInputGroupMain />
153
+ </TextInputGroupContext.Provider>
154
+ );
155
+
156
+ const input = screen.getByRole('textbox');
157
+
158
+ expect(input).toBeDisabled();
159
+ });
160
+
161
+ it("doesn't render the hint input when a hint prop isn't passed", () => {
162
+ // we set the type of the main input to search here so that we can accurately target the hint input
163
+ render(<TextInputGroupMain type="search">Test</TextInputGroupMain>);
164
+
165
+ const hintInput = screen.queryByRole('textbox', { hidden: true });
166
+
167
+ expect(hintInput).not.toBeInTheDocument();
168
+ });
169
+
170
+ it('renders the hint input when a hint prop is passed', () => {
171
+ // we set the type of the main input to search here so that we can accurately target the hint input
172
+ render(
173
+ <TextInputGroupMain hint="Test" type="search">
174
+ Test
175
+ </TextInputGroupMain>
176
+ );
177
+
178
+ const hintInput = screen.getByRole('textbox', { hidden: true });
179
+
180
+ expect(hintInput).toBeInTheDocument();
181
+ });
182
+
183
+ it('renders the hint input with classes pf-c-text-input-group__text-input and pf-m-hint', () => {
184
+ // we set the type of the main input to search here so that we can accurately target the hint input
185
+ render(
186
+ <TextInputGroupMain hint="Test" type="search">
187
+ Test
188
+ </TextInputGroupMain>
189
+ );
190
+
191
+ const hintInput = screen.getByRole('textbox', { hidden: true });
192
+
193
+ expect(hintInput).toHaveClass('pf-m-hint');
194
+ expect(hintInput).toHaveClass('pf-c-text-input-group__text-input');
195
+ });
196
+
197
+ it('renders the hint input as disabled', () => {
198
+ // we set the type of the main input to search here so that we can accurately target the hint input
199
+ render(
200
+ <TextInputGroupMain hint="Test" type="search">
201
+ Test
202
+ </TextInputGroupMain>
203
+ );
204
+
205
+ const hintInput = screen.getByRole('textbox', { hidden: true });
206
+
207
+ expect(hintInput).toBeDisabled();
208
+ });
209
+
210
+ it('renders the hint input as aria-hidden', () => {
211
+ // we set the type of the main input to search here so that we can accurately target the hint input
212
+ render(
213
+ <TextInputGroupMain hint="Test" type="search">
214
+ Test
215
+ </TextInputGroupMain>
216
+ );
217
+
218
+ const hintInput = screen.getByRole('textbox', { hidden: true });
219
+
220
+ expect(hintInput).toHaveAttribute('aria-hidden', 'true');
221
+ });
222
+
223
+ it('passes the hint prop to the hint input as its value', () => {
224
+ // we set the type of the main input to search here so that we can accurately target the hint input
225
+ render(
226
+ <TextInputGroupMain hint="value text" type="search">
227
+ Test
228
+ </TextInputGroupMain>
229
+ );
230
+
231
+ const hintInput = screen.getByDisplayValue('value text');
232
+
233
+ expect(hintInput).toBeVisible();
234
+ });
235
+
236
+ it('does not call onChange callback when the input does not change', () => {
237
+ const onChangeMock = jest.fn();
238
+
239
+ render(<TextInputGroupMain onChange={onChangeMock}>Test</TextInputGroupMain>);
240
+
241
+ expect(onChangeMock).not.toHaveBeenCalled();
242
+ });
243
+
244
+ it('calls the onChange callback when the input changes', () => {
245
+ const onChangeMock = jest.fn();
246
+
247
+ render(<TextInputGroupMain onChange={onChangeMock}>Test</TextInputGroupMain>);
248
+
249
+ const input = screen.getByRole('textbox');
250
+ userEvent.type(input, 'Test');
251
+
252
+ expect(onChangeMock).toHaveBeenCalledTimes(4);
253
+ });
254
+
255
+ it('does not call onFocus callback when the input does not get focus', () => {
256
+ const onFocusMock = jest.fn();
257
+
258
+ render(<TextInputGroupMain onFocus={onFocusMock}>Test</TextInputGroupMain>);
259
+
260
+ expect(onFocusMock).not.toHaveBeenCalled();
261
+ });
262
+
263
+ it('calls the onFocus callback when the input is focused', () => {
264
+ const onFocusMock = jest.fn();
265
+
266
+ render(<TextInputGroupMain onFocus={onFocusMock}>Test</TextInputGroupMain>);
267
+
268
+ const input = screen.getByRole('textbox');
269
+ userEvent.click(input);
270
+
271
+ expect(onFocusMock).toHaveBeenCalledTimes(1);
272
+ });
273
+
274
+ it('does not call onBlur callback when the input does not lose focus', () => {
275
+ const onBlurMock = jest.fn();
276
+
277
+ render(<TextInputGroupMain onBlur={onBlurMock}>Test</TextInputGroupMain>);
278
+
279
+ const input = screen.getByRole('textbox');
280
+ userEvent.click(input);
281
+
282
+ expect(onBlurMock).not.toHaveBeenCalled();
283
+ });
284
+
285
+ it('calls the onBlur callback when the input loses focus', () => {
286
+ const onBlurMock = jest.fn();
287
+
288
+ render(<TextInputGroupMain onBlur={onBlurMock}>Test</TextInputGroupMain>);
289
+
290
+ const input = screen.getByRole('textbox');
291
+ userEvent.click(input);
292
+ userEvent.click(document.body);
293
+
294
+ expect(onBlurMock).toHaveBeenCalledTimes(1);
295
+ });
296
+
297
+ it('matches the snapshot', () => {
298
+ const { asFragment } = render(<TextInputGroupMain>Test</TextInputGroupMain>);
299
+
300
+ expect(asFragment()).toMatchSnapshot();
301
+ });
302
+ });
@@ -0,0 +1,34 @@
1
+ import React from 'react';
2
+ import { render, screen } from '@testing-library/react';
3
+ import userEvent from '@testing-library/user-event';
4
+ import '@testing-library/jest-dom';
5
+
6
+ import { TextInputGroupUtilities } from '../TextInputGroupUtilities';
7
+
8
+ describe('TextInputGroupUtilities', () => {
9
+ it('renders without children', () => {
10
+ render(<TextInputGroupUtilities data-testid="TextInputGroupUtilities" />);
11
+
12
+ expect(screen.getByTestId('TextInputGroupUtilities')).toBeVisible();
13
+ });
14
+
15
+ it('renders the children', () => {
16
+ render(<TextInputGroupUtilities>{<button>Test</button>}</TextInputGroupUtilities>);
17
+
18
+ expect(screen.getByRole('button', { name: 'Test' })).toBeVisible();
19
+ });
20
+
21
+ it('renders with class pf-c-text-input-group__utilities', () => {
22
+ render(<TextInputGroupUtilities>Test</TextInputGroupUtilities>);
23
+
24
+ const utilities = screen.getByText('Test');
25
+
26
+ expect(utilities).toHaveClass('pf-c-text-input-group__utilities');
27
+ });
28
+
29
+ it('matches the snapshot', () => {
30
+ const { asFragment } = render(<TextInputGroupUtilities>{<button>Test</button>}</TextInputGroupUtilities>);
31
+
32
+ expect(asFragment()).toMatchSnapshot();
33
+ });
34
+ });