@patternfly/react-core 4.202.30 → 4.202.31

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 (56) hide show
  1. package/CHANGELOG.md +8 -0
  2. package/package.json +5 -5
  3. package/src/components/Dropdown/__tests__/DropdownToggleCheckbox.test.tsx +1 -1
  4. package/src/components/Page/__tests__/Page.test.tsx +225 -205
  5. package/src/components/Page/__tests__/__snapshots__/Page.test.tsx.snap +1088 -2059
  6. package/src/components/Pagination/__tests__/Pagination.test.tsx +235 -283
  7. package/src/components/Pagination/__tests__/__snapshots__/Pagination.test.tsx.snap +143 -577
  8. package/src/components/Radio/__tests__/Radio.test.tsx +38 -44
  9. package/src/components/Radio/__tests__/__snapshots__/Radio.test.tsx.snap +30 -30
  10. package/src/components/SearchInput/__tests__/SearchInput.test.tsx +87 -68
  11. package/src/components/SearchInput/__tests__/__snapshots__/SearchInput.test.tsx.snap +230 -137
  12. package/src/components/Select/__tests__/Select.test.tsx +238 -195
  13. package/src/components/Select/__tests__/SelectToggle.test.tsx +68 -130
  14. package/src/components/Select/__tests__/__snapshots__/Select.test.tsx.snap +978 -2149
  15. package/src/components/Select/__tests__/__snapshots__/SelectToggle.test.tsx.snap +3 -3
  16. package/src/components/SimpleList/__tests__/SimpleList.test.tsx +29 -32
  17. package/src/components/SimpleList/__tests__/__snapshots__/SimpleList.test.tsx.snap +4 -366
  18. package/src/components/Switch/__tests__/Switch.test.tsx +85 -75
  19. package/src/components/Switch/__tests__/__snapshots__/Switch.test.tsx.snap +30 -40
  20. package/src/components/TextArea/__tests__/TextArea.test.tsx +98 -103
  21. package/src/components/TextArea/__tests__/__snapshots__/TextArea.test.tsx.snap +24 -103
  22. package/src/components/TextInput/__tests__/TextInput.test.tsx +71 -70
  23. package/src/components/TextInput/__tests__/__snapshots__/TextInput.test.tsx.snap +15 -103
  24. package/src/components/TextInputGroup/__tests__/TextInputGroup.test.tsx +65 -39
  25. package/src/components/TextInputGroup/__tests__/__snapshots__/TextInputGroup.test.tsx.snap +53 -14
  26. package/src/components/TimePicker/__tests__/TimePicker.test.tsx +113 -110
  27. package/src/components/Title/__tests__/Title.test.tsx +21 -20
  28. package/src/components/Title/__tests__/__snapshots__/Title.test.tsx.snap +24 -30
  29. package/src/components/ToggleGroup/__tests__/ToggleGroup.test.tsx +43 -39
  30. package/src/components/ToggleGroup/__tests__/__snapshots__/ToggleGroup.test.tsx.snap +20 -19
  31. package/src/components/Wizard/__tests__/Wizard.test.tsx +195 -189
  32. package/src/components/Wizard/__tests__/__snapshots__/Wizard.test.tsx.snap +131 -10
  33. package/src/helpers/__tests__/util.test.ts +113 -0
  34. package/src/layouts/Bullseye/__tests__/Bullseye.test.tsx +25 -25
  35. package/src/layouts/Bullseye/__tests__/__snapshots__/Bullseye.test.tsx.snap +3 -5
  36. package/src/layouts/Flex/__tests__/Flex.test.tsx +159 -96
  37. package/src/layouts/Flex/__tests__/__snapshots__/Flex.test.tsx.snap +9 -17
  38. package/src/components/Page/__tests__/Generated/Page.test.tsx +0 -28
  39. package/src/components/Page/__tests__/Generated/__snapshots__/Page.test.tsx.snap +0 -19
  40. package/src/components/Pagination/__tests__/Generated/Pagination.test.tsx +0 -58
  41. package/src/components/Pagination/__tests__/Generated/__snapshots__/Pagination.test.tsx.snap +0 -205
  42. package/src/components/Radio/__tests__/Generated/Radio.test.tsx +0 -29
  43. package/src/components/Radio/__tests__/Generated/__snapshots__/Radio.test.tsx.snap +0 -36
  44. package/src/components/Select/__tests__/Generated/Select.test.tsx +0 -49
  45. package/src/components/Select/__tests__/Generated/SelectToggle.test.tsx +0 -34
  46. package/src/components/Select/__tests__/Generated/__snapshots__/Select.test.tsx.snap +0 -48
  47. package/src/components/Select/__tests__/Generated/__snapshots__/SelectToggle.test.tsx.snap +0 -36
  48. package/src/components/SimpleList/__tests__/Generated/SimpleList.test.tsx +0 -22
  49. package/src/components/SimpleList/__tests__/Generated/__snapshots__/SimpleList.test.tsx.snap +0 -13
  50. package/src/components/Switch/__tests__/Generated/Switch.test.tsx +0 -24
  51. package/src/components/Switch/__tests__/Generated/__snapshots__/Switch.test.tsx.snap +0 -36
  52. package/src/components/TextArea/__tests__/Generated/TextArea.test.tsx +0 -23
  53. package/src/components/TextArea/__tests__/Generated/__snapshots__/TextArea.test.tsx.snap +0 -13
  54. package/src/components/Title/__tests__/Generated/Title.test.tsx +0 -13
  55. package/src/components/Title/__tests__/Generated/__snapshots__/Title.test.tsx.snap +0 -12
  56. package/src/helpers/__tests__/util.test.js +0 -235
@@ -1,96 +1,90 @@
1
- import * as React from 'react';
2
- import { render } from '@testing-library/react';
3
- import { shallow } from 'enzyme';
1
+ import React from 'react';
2
+
3
+ import { render, screen } from '@testing-library/react';
4
+ import userEvent from '@testing-library/user-event';
5
+ import '@testing-library/jest-dom';
6
+
4
7
  import { Radio } from '../Radio';
5
8
 
6
9
  const props = {
7
10
  onChange: jest.fn()
8
11
  };
9
12
 
10
- describe('Radio check component', () => {
13
+ describe('Radio', () => {
11
14
  test('controlled', () => {
12
- const view = render(<Radio isChecked id="check" aria-label="check" name="check" />);
13
- expect(view.container).toMatchSnapshot();
15
+ const { asFragment } = render(<Radio isChecked id="check" aria-label="check" name="check" />);
16
+ expect(asFragment()).toMatchSnapshot();
14
17
  });
15
18
 
16
19
  test('uncontrolled', () => {
17
- const view = render(<Radio id="check" aria-label="check" name="check" />);
18
- expect(view.container).toMatchSnapshot();
20
+ const { asFragment } = render(<Radio id="check" aria-label="check" name="check" />);
21
+ expect(asFragment()).toMatchSnapshot();
19
22
  });
20
23
 
21
24
  test('isDisabled', () => {
22
- const view = render(<Radio id="check" isDisabled aria-label="check" name="check" />);
23
- expect(view.container).toMatchSnapshot();
25
+ const { asFragment } = render(<Radio id="check" isDisabled aria-label="check" name="check" />);
26
+ expect(asFragment()).toMatchSnapshot();
24
27
  });
25
28
 
26
29
  test('isLabelBeforeButton', () => {
27
- const view = render(<Radio id="check" isLabelBeforeButton label="Radio label" aria-label="check" name="check" />);
28
- expect(view.container).toMatchSnapshot();
30
+ const { asFragment } = render(<Radio id="check" isLabelBeforeButton label="Radio label" aria-label="check" name="check" />);
31
+ expect(asFragment()).toMatchSnapshot();
29
32
  });
30
33
 
31
34
  test('isLabelWrapped', () => {
32
- const view = render(<Radio id="check" isLabelWrapped label="Radio label" aria-label="check" name="check" />);
33
- expect(view.container).toMatchSnapshot();
35
+ const { asFragment } = render(<Radio id="check" isLabelWrapped label="Radio label" aria-label="check" name="check" />);
36
+ expect(asFragment()).toMatchSnapshot();
34
37
  });
35
38
 
36
39
  test('label is string', () => {
37
- const view = render(<Radio label="Label" id="check" isChecked aria-label="check" name="check" />);
38
- expect(view.container).toMatchSnapshot();
40
+ const { asFragment } = render(<Radio label="Label" id="check" isChecked aria-label="check" name="check" />);
41
+ expect(asFragment()).toMatchSnapshot();
39
42
  });
40
43
 
41
44
  test('label is function', () => {
42
45
  const functionLabel = () => <h1>Header</h1>;
43
- const view = render(<Radio label={functionLabel()} id="check" isChecked aria-label="check" name="check" />);
44
- expect(view.container).toMatchSnapshot();
46
+ const { asFragment } = render(<Radio label={functionLabel()} id="check" isChecked aria-label="check" name="check" />);
47
+ expect(asFragment()).toMatchSnapshot();
45
48
  });
46
49
 
47
50
  test('label is node', () => {
48
- const view = render(<Radio label={<h1>Header</h1>} id="check" isChecked aria-label="check" name="check" />);
49
- expect(view.container).toMatchSnapshot();
51
+ const { asFragment } = render(<Radio label={<h1>Header</h1>} id="check" isChecked aria-label="check" name="check" />);
52
+ expect(asFragment()).toMatchSnapshot();
50
53
  });
51
54
 
52
55
  test('passing class', () => {
53
- const view = render(
54
- <Radio label="label" className="class-123" id="check" isChecked aria-label="check" name="check" />
55
- );
56
- expect(view.container).toMatchSnapshot();
56
+ const { asFragment } = render(<Radio label="label" className="class-123" id="check" isChecked aria-label="check" name="check" />);
57
+ expect(asFragment()).toMatchSnapshot();
57
58
  });
58
59
 
59
60
  test('passing HTML attribute', () => {
60
- const view = render(
61
- <Radio label="label" aria-labelledby="labelId" id="check" isChecked aria-label="check" name="check" />
62
- );
63
- expect(view.container).toMatchSnapshot();
61
+ const { asFragment } = render(<Radio label="label" aria-labelledby="labelId" id="check" isChecked aria-label="check" name="check" />);
62
+ expect(asFragment()).toMatchSnapshot();
64
63
  });
65
64
 
66
65
  test('Radio passes value and event to onChange handler', () => {
67
- const newValue = true;
68
- const event = {
69
- currentTarget: { checked: newValue }
70
- };
71
- const view = shallow(<Radio id="check" {...props} aria-label="check" name="check" />);
72
- view.find('input').simulate('change', event);
73
- expect(props.onChange).toBeCalledWith(newValue, event);
66
+ render(<Radio id="check" {...props} aria-label="check" name="check" />);
67
+
68
+ userEvent.click(screen.getByRole('radio'));
69
+ expect(props.onChange).toHaveBeenCalledWith(true, expect.any(Object));
74
70
  });
75
71
 
76
72
  test('Radio description', () => {
77
- const view = shallow(<Radio id="check" name="check" aria-label="check" description="Text description..." />);
78
- const descriptionEl = view.find('span[className="pf-c-radio__description"]');
79
- expect(descriptionEl.length).toBe(1);
80
- expect(descriptionEl.text()).toBe('Text description...');
73
+ render(<Radio id="check" name="check" aria-label="check" description="Text description..." />);
74
+ expect(screen.getByText('Text description...')).toBeInTheDocument();
81
75
  });
82
76
 
83
77
  test('Radio body', () => {
84
- const view = shallow(<Radio id="check" name="check" aria-label="check" body="Text body..." />);
85
- const bodyEl = view.find('span[className="pf-c-radio__body"]');
86
- expect(bodyEl.length).toBe(1);
87
- expect(bodyEl.text()).toBe('Text body...');
78
+ render(<Radio id="check" name="check" aria-label="check" body="Text body..." />);
79
+ expect(screen.getByText('Text body...')).toBeInTheDocument();
88
80
  });
89
81
 
90
82
  test('should throw console error when no id is given', () => {
91
83
  const myMock = jest.fn();
92
84
  global.console = { ...global.console, error: myMock };
93
- shallow(<Radio name="check" aria-label="check" description="Text description..." />);
85
+
86
+ render(<Radio id={undefined} name="check" aria-label="check" description="Text description..." />);
87
+
94
88
  expect(myMock).toBeCalled();
95
89
  });
96
90
  });
@@ -1,7 +1,7 @@
1
1
  // Jest Snapshot v1, https://goo.gl/fbAQLP
2
2
 
3
- exports[`Radio check component controlled 1`] = `
4
- <div>
3
+ exports[`Radio controlled 1`] = `
4
+ <DocumentFragment>
5
5
  <div
6
6
  class="pf-c-radio pf-m-standalone"
7
7
  >
@@ -18,11 +18,11 @@ exports[`Radio check component controlled 1`] = `
18
18
  type="radio"
19
19
  />
20
20
  </div>
21
- </div>
21
+ </DocumentFragment>
22
22
  `;
23
23
 
24
- exports[`Radio check component isDisabled 1`] = `
25
- <div>
24
+ exports[`Radio isDisabled 1`] = `
25
+ <DocumentFragment>
26
26
  <div
27
27
  class="pf-c-radio pf-m-standalone"
28
28
  >
@@ -39,11 +39,11 @@ exports[`Radio check component isDisabled 1`] = `
39
39
  type="radio"
40
40
  />
41
41
  </div>
42
- </div>
42
+ </DocumentFragment>
43
43
  `;
44
44
 
45
- exports[`Radio check component isLabelBeforeButton 1`] = `
46
- <div>
45
+ exports[`Radio isLabelBeforeButton 1`] = `
46
+ <DocumentFragment>
47
47
  <div
48
48
  class="pf-c-radio"
49
49
  >
@@ -64,11 +64,11 @@ exports[`Radio check component isLabelBeforeButton 1`] = `
64
64
  type="radio"
65
65
  />
66
66
  </div>
67
- </div>
67
+ </DocumentFragment>
68
68
  `;
69
69
 
70
- exports[`Radio check component isLabelWrapped 1`] = `
71
- <div>
70
+ exports[`Radio isLabelWrapped 1`] = `
71
+ <DocumentFragment>
72
72
  <label
73
73
  class="pf-c-radio"
74
74
  for="check"
@@ -89,11 +89,11 @@ exports[`Radio check component isLabelWrapped 1`] = `
89
89
  Radio label
90
90
  </span>
91
91
  </label>
92
- </div>
92
+ </DocumentFragment>
93
93
  `;
94
94
 
95
- exports[`Radio check component label is function 1`] = `
96
- <div>
95
+ exports[`Radio label is function 1`] = `
96
+ <DocumentFragment>
97
97
  <div
98
98
  class="pf-c-radio"
99
99
  >
@@ -117,11 +117,11 @@ exports[`Radio check component label is function 1`] = `
117
117
  </h1>
118
118
  </label>
119
119
  </div>
120
- </div>
120
+ </DocumentFragment>
121
121
  `;
122
122
 
123
- exports[`Radio check component label is node 1`] = `
124
- <div>
123
+ exports[`Radio label is node 1`] = `
124
+ <DocumentFragment>
125
125
  <div
126
126
  class="pf-c-radio"
127
127
  >
@@ -145,11 +145,11 @@ exports[`Radio check component label is node 1`] = `
145
145
  </h1>
146
146
  </label>
147
147
  </div>
148
- </div>
148
+ </DocumentFragment>
149
149
  `;
150
150
 
151
- exports[`Radio check component label is string 1`] = `
152
- <div>
151
+ exports[`Radio label is string 1`] = `
152
+ <DocumentFragment>
153
153
  <div
154
154
  class="pf-c-radio"
155
155
  >
@@ -171,11 +171,11 @@ exports[`Radio check component label is string 1`] = `
171
171
  Label
172
172
  </label>
173
173
  </div>
174
- </div>
174
+ </DocumentFragment>
175
175
  `;
176
176
 
177
- exports[`Radio check component passing HTML attribute 1`] = `
178
- <div>
177
+ exports[`Radio passing HTML attribute 1`] = `
178
+ <DocumentFragment>
179
179
  <div
180
180
  class="pf-c-radio"
181
181
  >
@@ -198,11 +198,11 @@ exports[`Radio check component passing HTML attribute 1`] = `
198
198
  label
199
199
  </label>
200
200
  </div>
201
- </div>
201
+ </DocumentFragment>
202
202
  `;
203
203
 
204
- exports[`Radio check component passing class 1`] = `
205
- <div>
204
+ exports[`Radio passing class 1`] = `
205
+ <DocumentFragment>
206
206
  <div
207
207
  class="pf-c-radio class-123"
208
208
  >
@@ -224,11 +224,11 @@ exports[`Radio check component passing class 1`] = `
224
224
  label
225
225
  </label>
226
226
  </div>
227
- </div>
227
+ </DocumentFragment>
228
228
  `;
229
229
 
230
- exports[`Radio check component uncontrolled 1`] = `
231
- <div>
230
+ exports[`Radio uncontrolled 1`] = `
231
+ <DocumentFragment>
232
232
  <div
233
233
  class="pf-c-radio pf-m-standalone"
234
234
  >
@@ -244,5 +244,5 @@ exports[`Radio check component uncontrolled 1`] = `
244
244
  type="radio"
245
245
  />
246
246
  </div>
247
- </div>
247
+ </DocumentFragment>
248
248
  `;
@@ -1,6 +1,9 @@
1
1
  import React from 'react';
2
- import { render } from '@testing-library/react';
3
- import { mount } from 'enzyme';
2
+
3
+ import { render, screen } from '@testing-library/react';
4
+ import userEvent from '@testing-library/user-event';
5
+ import '@testing-library/jest-dom';
6
+
4
7
  import { SearchInput } from '../SearchInput';
5
8
  import { FormGroup } from '../../Form';
6
9
  import { Button } from '../../Button';
@@ -15,76 +18,92 @@ const props = {
15
18
  onSearch: jest.fn()
16
19
  };
17
20
 
18
- test('simple search input', () => {
19
- const view = render(<SearchInput {...props} aria-label="simple text input" />);
20
- expect(view.container).toMatchSnapshot();
21
- });
21
+ describe('SearchInput', () => {
22
+ test('simple search input', () => {
23
+ const { asFragment } = render(<SearchInput {...props} aria-label="simple text input" />);
24
+ expect(asFragment()).toMatchSnapshot();
25
+ });
22
26
 
23
- test('search input with hint', () => {
24
- const view = render(<SearchInput {...props} hint="test hint" aria-label="simple text input" />);
25
- expect(view.container).toMatchSnapshot();
26
- });
27
+ test('search input with hint', () => {
28
+ const { asFragment } = render(<SearchInput {...props} hint="test hint" aria-label="simple text input" />);
29
+ expect(asFragment()).toMatchSnapshot();
30
+ });
27
31
 
28
- test('result count', () => {
29
- const view = mount(<SearchInput {...props} resultsCount={3} aria-label="simple text input" />);
30
- expect(view.find('.pf-c-badge')).toMatchSnapshot();
31
- });
32
+ test('result count', () => {
33
+ render(<SearchInput {...props} resultsCount={3} aria-label="simple text input" data-testid="test-id" />);
34
+ expect(screen.getByTestId('test-id').querySelector('.pf-c-badge')).toBeInTheDocument();
35
+ });
32
36
 
33
- test('navigable search results', () => {
34
- const view = mount(
35
- <SearchInput
36
- {...props}
37
- resultsCount='3 / 7'
38
- aria-label="simple text input"
39
- />);
40
- expect(view.find('.pf-c-search-input__nav')).toMatchSnapshot();
41
- expect(view.find('.pf-c-badge')).toMatchSnapshot();
42
-
43
- view.find('.pf-c-button').at(0).simulate('click', {});
44
- expect(props.onPreviousClick).toBeCalled();
45
- view.find('.pf-c-button').at(1).simulate('click', {});
46
- expect(props.onNextClick).toBeCalled();
47
- view.find('.pf-c-button').at(2).simulate('click', {});
48
- expect(props.onClear).toBeCalled();
49
- });
37
+ test('navigable search results', () => {
38
+ render(<SearchInput {...props} resultsCount="3 / 7" aria-label="simple text input" data-testid="test-id" />);
50
39
 
51
- test('hide clear button', () => {
52
- const { onClear, ...testProps } = props;
53
- const view = mount(
54
- <SearchInput {...testProps} resultsCount='3' aria-label="simple text input without on clear" />
55
- );
56
- expect(view.find('.pf-c-search-input__clear').length).toBe(0);
57
- });
40
+ const input = screen.getByTestId('test-id');
41
+ expect(input.querySelector('.pf-c-search-input__nav')).toBeInTheDocument();
42
+ expect(input.querySelector('.pf-c-badge')).toBeInTheDocument();
58
43
 
59
- test('advanced search', () => {
60
- const view = mount(
61
- <SearchInput
62
- attributes={[{attr:"username", display:"Username"}, {attr: "firstname", display: "First name"}]}
63
- advancedSearchDelimiter=":"
64
- value='username:player firstname:john'
65
- onChange={props.onChange}
66
- onSearch={props.onSearch}
67
- onClear={props.onClear}
68
- />
69
- );
70
- view.find('.pf-c-button').at(2).simulate('click', {});
71
- expect(props.onSearch).toBeCalled();
72
- expect(view.find('input')).toMatchSnapshot();
73
- });
44
+ userEvent.click(screen.getByRole('button', { name: 'Previous' }));
45
+ expect(props.onPreviousClick).toBeCalled();
46
+
47
+ userEvent.click(screen.getByRole('button', { name: 'Next' }));
48
+ expect(props.onNextClick).toBeCalled();
49
+
50
+ userEvent.click(screen.getByRole('button', { name: 'Reset' }));
51
+ expect(props.onClear).toBeCalled();
52
+ });
53
+
54
+ test('hide clear button', () => {
55
+ const { onClear, ...testProps } = props;
56
+
57
+ render(<SearchInput {...testProps} resultsCount="3" aria-label="simple text input without on clear" />);
58
+ expect(screen.queryByRole('button', { name: 'Reset' })).not.toBeInTheDocument();
59
+ });
60
+
61
+ test('advanced search', () => {
62
+ const { asFragment } = render(
63
+ <SearchInput
64
+ attributes={[
65
+ { attr: 'username', display: 'Username' },
66
+ { attr: 'firstname', display: 'First name' }
67
+ ]}
68
+ advancedSearchDelimiter=":"
69
+ value="username:player firstname:john"
70
+ onChange={props.onChange}
71
+ onSearch={props.onSearch}
72
+ onClear={props.onClear}
73
+ />
74
+ );
75
+
76
+ userEvent.click(screen.getByRole('button', { name: 'Search' }));
77
+
78
+ expect(props.onSearch).toBeCalled();
79
+ expect(asFragment()).toMatchSnapshot();
80
+ });
81
+
82
+ test('advanced search with custom attributes', () => {
83
+ const { asFragment } = render(
84
+ <SearchInput
85
+ attributes={[
86
+ { attr: 'username', display: 'Username' },
87
+ { attr: 'firstname', display: 'First name' }
88
+ ]}
89
+ advancedSearchDelimiter=":"
90
+ formAdditionalItems={
91
+ <FormGroup fieldId="test-form-group">
92
+ <Button variant="link" isInline icon={<ExternalLinkSquareAltIcon />} iconPosition="right">
93
+ Link
94
+ </Button>
95
+ </FormGroup>
96
+ }
97
+ value="username:player firstname:john"
98
+ onChange={props.onChange}
99
+ onSearch={props.onSearch}
100
+ onClear={props.onClear}
101
+ />
102
+ );
103
+
104
+ userEvent.click(screen.getByRole('button', { name: 'Search' }));
74
105
 
75
- test('advanced search with custom attributes', () => {
76
- const view = mount(
77
- <SearchInput
78
- attributes={[{attr:"username", display:"Username"}, {attr: "firstname", display: "First name"}]}
79
- advancedSearchDelimiter=":"
80
- formAdditionalItems={<FormGroup fieldId='test-form-group'><Button variant="link" isInline icon={<ExternalLinkSquareAltIcon />} iconPosition="right">Link</Button></FormGroup>}
81
- value='username:player firstname:john'
82
- onChange={props.onChange}
83
- onSearch={props.onSearch}
84
- onClear={props.onClear}
85
- />
86
- );
87
- view.find('.pf-c-button').at(2).simulate('click', {});
88
- expect(props.onSearch).toBeCalled();
89
- expect(view.find('input')).toMatchSnapshot();
106
+ expect(props.onSearch).toBeCalled();
107
+ expect(asFragment()).toMatchSnapshot();
108
+ });
90
109
  });