@patternfly/react-core 4.202.16 → 4.202.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 (86) hide show
  1. package/CHANGELOG.md +24 -0
  2. package/dist/esm/components/CalendarMonth/CalendarMonth.d.ts.map +1 -1
  3. package/dist/esm/components/CalendarMonth/CalendarMonth.js +12 -4
  4. package/dist/esm/components/CalendarMonth/CalendarMonth.js.map +1 -1
  5. package/dist/js/components/CalendarMonth/CalendarMonth.d.ts.map +1 -1
  6. package/dist/js/components/CalendarMonth/CalendarMonth.js +12 -4
  7. package/dist/js/components/CalendarMonth/CalendarMonth.js.map +1 -1
  8. package/dist/umd/react-core.js +12 -4
  9. package/dist/umd/react-core.min.css +460 -460
  10. package/dist/umd/react-core.min.js +1 -1
  11. package/package.json +5 -5
  12. package/src/components/CalendarMonth/CalendarMonth.tsx +10 -4
  13. package/src/components/CalendarMonth/examples/CalendarMonth.md +9 -0
  14. package/src/components/CalendarMonth/examples/CalendarMonthDateRange.tsx +10 -0
  15. package/src/components/ContextSelector/examples/ContextSelector.md +3 -279
  16. package/src/components/ContextSelector/examples/ContextSelectorBasic.tsx +84 -0
  17. package/src/components/ContextSelector/examples/ContextSelectorPlainText.tsx +85 -0
  18. package/src/components/ContextSelector/examples/ContextSelectorWithFooter.tsx +91 -0
  19. package/src/components/DescriptionList/examples/DescriptionList.md +22 -930
  20. package/src/components/DescriptionList/examples/DescriptionListAutoFitBasic.tsx +40 -0
  21. package/src/components/DescriptionList/examples/DescriptionListAutoFitMinWidthModified.tsx +40 -0
  22. package/src/components/DescriptionList/examples/DescriptionListAutoFitMinWidthResponsive.tsx +40 -0
  23. package/src/components/DescriptionList/examples/DescriptionListBasic.tsx +40 -0
  24. package/src/components/DescriptionList/examples/DescriptionListColumnFill.tsx +42 -0
  25. package/src/components/DescriptionList/examples/DescriptionListCompact.tsx +40 -0
  26. package/src/components/DescriptionList/examples/DescriptionListCompactHorizontal.tsx +40 -0
  27. package/src/components/DescriptionList/examples/DescriptionListDefaultAutoColumn.tsx +40 -0
  28. package/src/components/DescriptionList/examples/DescriptionListDefaultInlineGrid.tsx +40 -0
  29. package/src/components/DescriptionList/examples/DescriptionListDefaultResponsiveColumns.tsx +40 -0
  30. package/src/components/DescriptionList/examples/DescriptionListDefaultThreeColLg.tsx +40 -0
  31. package/src/components/DescriptionList/examples/DescriptionListDefaultTwoCol.tsx +44 -0
  32. package/src/components/DescriptionList/examples/DescriptionListFluidHorizontal.tsx +40 -0
  33. package/src/components/DescriptionList/examples/DescriptionListHorizontal.tsx +40 -0
  34. package/src/components/DescriptionList/examples/DescriptionListHorizontalAutoColumn.tsx +40 -0
  35. package/src/components/DescriptionList/examples/DescriptionListHorizontalCustomTermWidth.tsx +50 -0
  36. package/src/components/DescriptionList/examples/DescriptionListHorizontalResponsiveColumns.tsx +40 -0
  37. package/src/components/DescriptionList/examples/DescriptionListHorizontalThreeColLg.tsx +40 -0
  38. package/src/components/DescriptionList/examples/DescriptionListHorizontalTwoCol.tsx +40 -0
  39. package/src/components/DescriptionList/examples/DescriptionListIconsOnTerms.tsx +45 -0
  40. package/src/components/DescriptionList/examples/DescriptionListResponsiveHoriVertGroup.tsx +48 -0
  41. package/src/components/DescriptionList/examples/DescriptionListWithTermHelpText.tsx +62 -0
  42. package/src/components/Divider/examples/Divider.md +15 -68
  43. package/src/components/Divider/examples/DividerInsetMedium.tsx +4 -0
  44. package/src/components/Divider/examples/DividerInsetVariousBreakpoints.tsx +13 -0
  45. package/src/components/Divider/examples/DividerUsingDiv.tsx +4 -0
  46. package/src/components/Divider/examples/DividerUsingHr.tsx +4 -0
  47. package/src/components/Divider/examples/DividerUsingLi.tsx +10 -0
  48. package/src/components/Divider/examples/DividerVerticalFlex.tsx +10 -0
  49. package/src/components/Divider/examples/DividerVerticalFlexInsetMedium.tsx +10 -0
  50. package/src/components/Divider/examples/DividerVerticalFlexInsetVariousBreakpoints.tsx +18 -0
  51. package/src/components/FormSelect/__tests__/FormSelect.test.tsx +0 -1
  52. package/src/components/List/__tests__/List.test.tsx +33 -33
  53. package/src/components/List/__tests__/__snapshots__/List.test.tsx.snap +33 -64
  54. package/src/components/Menu/__tests__/Menu.test.tsx +37 -33
  55. package/src/components/Menu/__tests__/__snapshots__/Menu.test.tsx.snap +3 -36
  56. package/src/components/Modal/__tests__/Modal.test.tsx +65 -67
  57. package/src/components/Modal/__tests__/ModalBoxCloseButton.test.tsx +13 -10
  58. package/src/components/Nav/__tests__/Nav.test.tsx +185 -214
  59. package/src/components/Nav/__tests__/__snapshots__/Nav.test.tsx.snap +877 -1729
  60. package/src/components/NotificationDrawer/__tests__/NotificationDrawer.test.tsx +13 -15
  61. package/src/components/NotificationDrawer/__tests__/NotificationDrawerBody.test.tsx +13 -15
  62. package/src/components/NotificationDrawer/__tests__/NotificationDrawerGroup.test.tsx +21 -27
  63. package/src/components/NotificationDrawer/__tests__/NotificationDrawerGroupList.test.tsx +13 -15
  64. package/src/components/NotificationDrawer/__tests__/NotificationDrawerHeader.test.tsx +25 -27
  65. package/src/components/NotificationDrawer/__tests__/NotificationDrawerList.test.tsx +17 -19
  66. package/src/components/NotificationDrawer/__tests__/NotificationDrawerListItem.test.tsx +20 -27
  67. package/src/components/NotificationDrawer/__tests__/NotificationDrawerListItemBody.test.tsx +17 -13
  68. package/src/components/NotificationDrawer/__tests__/NotificationDrawerListItemHeader.test.tsx +30 -25
  69. package/src/components/NotificationDrawer/__tests__/__snapshots__/NotificationDrawer.test.tsx.snap +3 -5
  70. package/src/components/NotificationDrawer/__tests__/__snapshots__/NotificationDrawerBody.test.tsx.snap +3 -5
  71. package/src/components/NotificationDrawer/__tests__/__snapshots__/NotificationDrawerGroup.test.tsx.snap +9 -11
  72. package/src/components/NotificationDrawer/__tests__/__snapshots__/NotificationDrawerGroupList.test.tsx.snap +3 -5
  73. package/src/components/NotificationDrawer/__tests__/__snapshots__/NotificationDrawerHeader.test.tsx.snap +16 -18
  74. package/src/components/NotificationDrawer/__tests__/__snapshots__/NotificationDrawerList.test.tsx.snap +7 -8
  75. package/src/components/NotificationDrawer/__tests__/__snapshots__/NotificationDrawerListItem.test.tsx.snap +3 -5
  76. package/src/components/NotificationDrawer/__tests__/__snapshots__/NotificationDrawerListItemBody.test.tsx.snap +6 -8
  77. package/src/components/NotificationDrawer/__tests__/__snapshots__/NotificationDrawerListItemHeader.test.tsx.snap +12 -14
  78. package/src/components/OverflowMenu/__tests__/OverflowMenu.test.tsx +15 -12
  79. package/src/components/OverflowMenu/__tests__/OverflowMenuControl.test.tsx +9 -8
  80. package/src/components/OverflowMenu/__tests__/OverflowMenuGroup.test.tsx +17 -18
  81. package/src/components/OverflowMenu/__tests__/OverflowMenuItem.test.tsx +10 -9
  82. package/src/components/OverflowMenu/__tests__/__snapshots__/OverflowMenu.test.tsx.snap +6 -16
  83. package/src/components/OverflowMenu/__tests__/__snapshots__/OverflowMenuControl.test.tsx.snap +3 -15
  84. package/src/components/OverflowMenu/__tests__/__snapshots__/OverflowMenuItem.test.tsx.snap +3 -17
  85. package/src/components/Modal/__tests__/__snapshots__/ModalBoxCloseButton.test.tsx.snap +0 -16
  86. package/src/components/OverflowMenu/__tests__/__snapshots__/OverflowMenuGroup.test.tsx.snap +0 -33
@@ -1,120 +1,120 @@
1
1
  import React from 'react';
2
- import { render } from '@testing-library/react';
3
- import { mount } from 'enzyme';
4
- import { List, ListVariant, ListComponent, OrderType } from '../List';
5
- import { ListItem } from '../ListItem';
2
+
3
+ import { render, screen } from '@testing-library/react';
4
+ import '@testing-library/jest-dom';
5
+
6
6
  import BookOpen from '@patternfly/react-icons/dist/esm/icons/book-open-icon';
7
7
  import Key from '@patternfly/react-icons/dist/esm/icons/key-icon';
8
8
  import Desktop from '@patternfly/react-icons/dist/esm/icons/desktop-icon';
9
+ import { List, ListVariant, ListComponent, OrderType } from '../List';
10
+ import { ListItem } from '../ListItem';
9
11
 
10
12
  const ListItems = () => (
11
- <React.Fragment>
12
- <List>
13
- <ListItem>First</ListItem>
14
- <ListItem>Second</ListItem>
15
- <ListItem>Third</ListItem>
16
- </List>
17
- </React.Fragment>
13
+ <List>
14
+ <ListItem>First</ListItem>
15
+ <ListItem>Second</ListItem>
16
+ <ListItem>Third</ListItem>
17
+ </List>
18
18
  );
19
19
 
20
- describe('list', () => {
20
+ describe('List', () => {
21
21
  test('simple list', () => {
22
- const view = render(
22
+ const { asFragment } = render(
23
23
  <List>
24
24
  <ListItems />
25
25
  </List>
26
26
  );
27
- expect(view.container).toMatchSnapshot();
27
+ expect(asFragment()).toMatchSnapshot();
28
28
  });
29
29
 
30
30
  test('inline list', () => {
31
- const view = render(
31
+ const { asFragment } = render(
32
32
  <List variant={ListVariant.inline}>
33
33
  <ListItems />
34
34
  </List>
35
35
  );
36
- expect(view.container).toMatchSnapshot();
36
+ expect(asFragment()).toMatchSnapshot();
37
37
  });
38
38
 
39
39
  test('ordered list', () => {
40
- const view = mount(
40
+ const { asFragment } = render(
41
41
  <List component={ListComponent.ol}>
42
42
  <ListItem>Apple</ListItem>
43
43
  <ListItem>Banana</ListItem>
44
44
  <ListItem>Orange</ListItem>
45
45
  </List>
46
46
  );
47
- expect(view.find('ol').length).toBe(1);
47
+ expect(asFragment()).toMatchSnapshot();
48
48
  });
49
49
 
50
50
  test('ordered list starts with 2nd item', () => {
51
- const view = mount(
51
+ render(
52
52
  <List component={ListComponent.ol} start={2}>
53
53
  <ListItem>Banana</ListItem>
54
54
  <ListItem>Orange</ListItem>
55
55
  </List>
56
56
  );
57
- expect(view.find('ol').prop('start')).toBe(2);
57
+ expect(screen.getByRole('list')).toHaveAttribute('start', '2');
58
58
  });
59
59
 
60
60
  test('ordered list items will be numbered with uppercase letters', () => {
61
- const view = mount(
61
+ render(
62
62
  <List component={ListComponent.ol} type={OrderType.uppercaseLetter}>
63
63
  <ListItem>Banana</ListItem>
64
64
  <ListItem>Orange</ListItem>
65
65
  </List>
66
66
  );
67
- expect(view.find('ol').prop('type')).toBe('A');
67
+ expect(screen.getByRole('list')).toHaveAttribute('type', 'A');
68
68
  });
69
69
 
70
70
  test('inlined ordered list', () => {
71
- const view = mount(
71
+ render(
72
72
  <List variant={ListVariant.inline} component={ListComponent.ol}>
73
73
  <ListItem>Apple</ListItem>
74
74
  <ListItem>Banana</ListItem>
75
75
  <ListItem>Orange</ListItem>
76
76
  </List>
77
77
  );
78
- expect(view.find('ol.pf-m-inline').length).toBe(1);
78
+ expect(screen.getByRole('list')).toHaveClass('pf-m-inline');
79
79
  });
80
80
 
81
81
  test('bordered list', () => {
82
- const view = render(
82
+ render(
83
83
  <List isBordered>
84
84
  <ListItems />
85
85
  </List>
86
86
  );
87
- expect(view.container).toMatchSnapshot();
87
+ expect(screen.getAllByRole('list')[0]).toHaveClass('pf-m-bordered');
88
88
  });
89
89
 
90
90
  test('plain list', () => {
91
- const view = render(
91
+ render(
92
92
  <List isPlain>
93
93
  <ListItems />
94
94
  </List>
95
95
  );
96
- expect(view.container).toMatchSnapshot();
96
+ expect(screen.getAllByRole('list')[0]).toHaveClass('pf-m-plain');
97
97
  });
98
98
 
99
99
  test('icon list', () => {
100
- const view = render(
100
+ const { asFragment } = render(
101
101
  <List isPlain>
102
102
  <ListItem icon={<BookOpen />}>Apple</ListItem>
103
103
  <ListItem icon={<Key />}>Banana</ListItem>
104
104
  <ListItem icon={<Desktop />}>Orange</ListItem>
105
105
  </List>
106
106
  );
107
- expect(view.container).toMatchSnapshot();
107
+ expect(asFragment()).toMatchSnapshot();
108
108
  });
109
109
 
110
110
  test('icon large list', () => {
111
- const view = render(
112
- <List iconSize='large'>
111
+ const { asFragment } = render(
112
+ <List iconSize="large">
113
113
  <ListItem icon={<BookOpen />}>Apple</ListItem>
114
114
  <ListItem icon={<Key />}>Banana</ListItem>
115
115
  <ListItem icon={<Desktop />}>Orange</ListItem>
116
116
  </List>
117
117
  );
118
- expect(view.container).toMatchSnapshot();
118
+ expect(asFragment()).toMatchSnapshot();
119
119
  });
120
120
  });
@@ -1,35 +1,7 @@
1
1
  // Jest Snapshot v1, https://goo.gl/fbAQLP
2
2
 
3
- exports[`list bordered list 1`] = `
4
- <div>
5
- <ul
6
- class="pf-c-list pf-m-bordered"
7
- >
8
- <ul
9
- class="pf-c-list"
10
- >
11
- <li
12
- class=""
13
- >
14
- First
15
- </li>
16
- <li
17
- class=""
18
- >
19
- Second
20
- </li>
21
- <li
22
- class=""
23
- >
24
- Third
25
- </li>
26
- </ul>
27
- </ul>
28
- </div>
29
- `;
30
-
31
- exports[`list icon large list 1`] = `
32
- <div>
3
+ exports[`List icon large list 1`] = `
4
+ <DocumentFragment>
33
5
  <ul
34
6
  class="pf-c-list pf-m-icon-lg"
35
7
  >
@@ -100,11 +72,11 @@ exports[`list icon large list 1`] = `
100
72
  Orange
101
73
  </li>
102
74
  </ul>
103
- </div>
75
+ </DocumentFragment>
104
76
  `;
105
77
 
106
- exports[`list icon list 1`] = `
107
- <div>
78
+ exports[`List icon list 1`] = `
79
+ <DocumentFragment>
108
80
  <ul
109
81
  class="pf-c-list pf-m-plain"
110
82
  >
@@ -175,11 +147,11 @@ exports[`list icon list 1`] = `
175
147
  Orange
176
148
  </li>
177
149
  </ul>
178
- </div>
150
+ </DocumentFragment>
179
151
  `;
180
152
 
181
- exports[`list inline list 1`] = `
182
- <div>
153
+ exports[`List inline list 1`] = `
154
+ <DocumentFragment>
183
155
  <ul
184
156
  class="pf-c-list pf-m-inline"
185
157
  >
@@ -203,39 +175,36 @@ exports[`list inline list 1`] = `
203
175
  </li>
204
176
  </ul>
205
177
  </ul>
206
- </div>
178
+ </DocumentFragment>
207
179
  `;
208
180
 
209
- exports[`list plain list 1`] = `
210
- <div>
211
- <ul
212
- class="pf-c-list pf-m-plain"
181
+ exports[`List ordered list 1`] = `
182
+ <DocumentFragment>
183
+ <ol
184
+ class="pf-c-list"
185
+ type="1"
213
186
  >
214
- <ul
215
- class="pf-c-list"
187
+ <li
188
+ class=""
216
189
  >
217
- <li
218
- class=""
219
- >
220
- First
221
- </li>
222
- <li
223
- class=""
224
- >
225
- Second
226
- </li>
227
- <li
228
- class=""
229
- >
230
- Third
231
- </li>
232
- </ul>
233
- </ul>
234
- </div>
190
+ Apple
191
+ </li>
192
+ <li
193
+ class=""
194
+ >
195
+ Banana
196
+ </li>
197
+ <li
198
+ class=""
199
+ >
200
+ Orange
201
+ </li>
202
+ </ol>
203
+ </DocumentFragment>
235
204
  `;
236
205
 
237
- exports[`list simple list 1`] = `
238
- <div>
206
+ exports[`List simple list 1`] = `
207
+ <DocumentFragment>
239
208
  <ul
240
209
  class="pf-c-list"
241
210
  >
@@ -259,5 +228,5 @@ exports[`list simple list 1`] = `
259
228
  </li>
260
229
  </ul>
261
230
  </ul>
262
- </div>
231
+ </DocumentFragment>
263
232
  `;
@@ -1,46 +1,50 @@
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 "@testing-library/jest-dom";
5
+
4
6
  import { Menu } from '../Menu';
5
7
 
6
- test('should render Menu successfully', () => {
7
- const view = render(
8
- <Menu activeItemId={0} onSelect={jest.fn()}>
9
- content
10
- </Menu>
8
+ describe('Menu', () => {
9
+ test('should render Menu successfully', () => {
10
+ const { asFragment } = render(
11
+ <Menu activeItemId={0} onSelect={jest.fn()}>
12
+ content
13
+ </Menu>
11
14
  );
12
- expect(view.container).toMatchSnapshot();
13
- });
15
+ expect(asFragment()).toMatchSnapshot();
16
+ });
14
17
 
15
- describe('with isPlain', () => {
18
+ describe('with isPlain', () => {
16
19
  test('should render Menu with plain styles applied', () => {
17
- const view = mount(
18
- <Menu activeItemId={0} onSelect={jest.fn()} isPlain>
19
- content
20
- </Menu>
21
- );
22
- expect(view.find('div.pf-m-plain')).toMatchSnapshot();
20
+ render(
21
+ <Menu activeItemId={0} onSelect={jest.fn()} isPlain>
22
+ content
23
+ </Menu>
24
+ );
25
+ expect(screen.getByText('content')).toHaveClass('pf-m-plain');
23
26
  });
24
- });
27
+ });
25
28
 
26
- describe('with isScrollable', () => {
29
+ describe('with isScrollable', () => {
27
30
  test('should render Menu with scrollable styles applied', () => {
28
- const view = mount(
29
- <Menu activeItemId={0} onSelect={jest.fn()} isScrollable>
30
- content
31
- </Menu>
32
- );
33
- expect(view.find('div.pf-m-scrollable')).toMatchSnapshot();
31
+ render(
32
+ <Menu activeItemId={0} onSelect={jest.fn()} isScrollable>
33
+ content
34
+ </Menu>
35
+ );
36
+ expect(screen.getByText('content')).toHaveClass('pf-m-scrollable');
34
37
  });
35
- });
38
+ });
36
39
 
37
- describe('with isNavFlyout', () => {
40
+ describe('with isNavFlyout', () => {
38
41
  test('should render Menu with nav flyout styles applied', () => {
39
- const view = mount(
40
- <Menu activeItemId={0} onSelect={jest.fn()} isNavFlyout>
41
- content
42
- </Menu>
43
- );
44
- expect(view.find('div.pf-m-nav')).toMatchSnapshot();
42
+ render(
43
+ <Menu activeItemId={0} onSelect={jest.fn()} isNavFlyout>
44
+ content
45
+ </Menu>
46
+ );
47
+ expect(screen.getByText('content')).toHaveClass('pf-m-nav');
45
48
  });
46
- });
49
+ });
50
+ });
@@ -1,7 +1,7 @@
1
1
  // Jest Snapshot v1, https://goo.gl/fbAQLP
2
2
 
3
- exports[`should render Menu successfully 1`] = `
4
- <div>
3
+ exports[`Menu should render Menu successfully 1`] = `
4
+ <DocumentFragment>
5
5
  <div
6
6
  class="pf-c-menu"
7
7
  data-ouia-component-id="OUIA-Generated-Menu-1"
@@ -10,38 +10,5 @@ exports[`should render Menu successfully 1`] = `
10
10
  >
11
11
  content
12
12
  </div>
13
- </div>
14
- `;
15
-
16
- exports[`with isNavFlyout should render Menu with nav flyout styles applied 1`] = `
17
- <div
18
- className="pf-c-menu pf-m-nav"
19
- data-ouia-component-id="OUIA-Generated-Menu-4"
20
- data-ouia-component-type="PF4/Menu"
21
- data-ouia-safe={true}
22
- >
23
- content
24
- </div>
25
- `;
26
-
27
- exports[`with isPlain should render Menu with plain styles applied 1`] = `
28
- <div
29
- className="pf-c-menu pf-m-plain"
30
- data-ouia-component-id="OUIA-Generated-Menu-2"
31
- data-ouia-component-type="PF4/Menu"
32
- data-ouia-safe={true}
33
- >
34
- content
35
- </div>
36
- `;
37
-
38
- exports[`with isScrollable should render Menu with scrollable styles applied 1`] = `
39
- <div
40
- className="pf-c-menu pf-m-scrollable"
41
- data-ouia-component-id="OUIA-Generated-Menu-3"
42
- data-ouia-component-type="PF4/Menu"
43
- data-ouia-safe={true}
44
- >
45
- content
46
- </div>
13
+ </DocumentFragment>
47
14
  `;
@@ -1,6 +1,9 @@
1
1
  import * as React from 'react';
2
- import { shallow, mount } from 'enzyme';
3
- import { KEY_CODES } from '../../../helpers/constants';
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 { css } from '../../../../../react-styles/dist/js';
5
8
  import styles from '@patternfly/react-styles/css/components/Backdrop/backdrop';
6
9
 
@@ -16,76 +19,71 @@ const props = {
16
19
  children: 'modal content'
17
20
  };
18
21
 
19
- test('Modal creates a container element once for div', () => {
20
- const view = shallow(<Modal {...props} />);
21
- view.update();
22
- expect(document.createElement).toBeCalledWith('div');
23
- expect(document.createElement).toHaveBeenCalledTimes(1);
24
- });
22
+ describe('Modal', () => {
23
+ test('Modal creates a container element once for div', () => {
24
+ render(<Modal {...props} />);
25
+ expect(document.createElement).toBeCalledWith('div');
26
+ });
25
27
 
26
- test('modal closes with escape', () => {
27
- shallow(<Modal {...props} isOpen appendTo={document.body} />);
28
- const mock: any = (document.body.addEventListener as any).mock;
29
- const [event, handler] = mock.calls[0];
30
- expect(event).toBe('keydown');
31
- handler({ keyCode: KEY_CODES.ESCAPE_KEY });
32
- expect(props.onClose).toBeCalled();
33
- });
28
+ test('modal closes with escape', () => {
29
+ render(<Modal {...props} isOpen appendTo={document.body} />);
34
30
 
35
- test('modal does not call onClose for esc key if it is not open', () => {
36
- shallow(<Modal {...props} />);
37
- const mock: any = (document.body.addEventListener as any).mock;
38
- const [event, handler] = mock.calls[0];
39
- expect(event).toBe('keydown');
40
- handler({ keyCode: KEY_CODES.ESCAPE_KEY });
41
- expect(props.onClose).not.toBeCalled();
42
- });
31
+ userEvent.type(screen.getByText(props.title), '{esc}');
32
+ expect(props.onClose).toBeCalled();
33
+ });
43
34
 
44
- test('Each modal is given a new id', () => {
45
- const first = shallow(<Modal {...props} />);
46
- const second = shallow(<Modal {...props} />);
47
- expect((first.instance() as any).descriptorId).not.toBe((second.instance() as any).descriptorId);
48
- });
35
+ test('modal does not call onClose for esc key if it is not open', () => {
36
+ render(<Modal {...props} />);
37
+ expect(screen.queryByRole('dialog')).toBeNull();
38
+ expect(props.onClose).not.toBeCalled();
39
+ });
49
40
 
50
- test('modal removes body backdropOpen class when removed', () => {
51
- const view = shallow(<Modal {...props} isOpen />);
52
- view.update();
53
- expect(document.body.className).toContain(css(styles.backdropOpen));
54
- view.setProps({ isOpen: false });
55
- view.update();
56
- expect(document.body.className).not.toContain(css(styles.backdropOpen));
57
- });
41
+ test('modal has body backdropOpen class when open', () => {
42
+ render(<Modal {...props} isOpen />);
43
+ expect(document.body).toHaveClass(css(styles.backdropOpen));
44
+ });
58
45
 
59
- test('modal shows/hides the close button based on showClose (default true)', () => {
60
- const view = mount(<Modal {...props} isOpen />);
61
- view.update();
62
- expect(view.exists('.pf-c-modal-box .pf-c-button')).toBeTruthy();
63
- view.setProps({ showClose: false });
64
- view.update();
65
- expect(view.exists('.pf-c-modal-box .pf-c-button')).toBeFalsy();
66
- });
46
+ test('modal has no body backdropOpen class when not open', () => {
47
+ render(<Modal {...props} />);
48
+ expect(document.body).not.toHaveClass(css(styles.backdropOpen));
49
+ });
67
50
 
68
- test('modal generates console error when no accessible name is provided', () => {
69
- const props = {
70
- onClose: jest.fn(),
71
- isOpen: true,
72
- children: 'modal content'
73
- };
74
- const consoleErrorMock = jest.fn();
75
- global.console = { error: consoleErrorMock } as any;
76
- shallow(<Modal {...props} />);
77
- expect(consoleErrorMock).toBeCalled();
78
- });
51
+ test('modal shows the close button when showClose is true (true by default)', () => {
52
+ render(<Modal {...props} isOpen />);
53
+ expect(screen.getByRole('button', { name: 'Close' })).toBeInTheDocument();
54
+ });
55
+
56
+ test('modal does not show the close button when showClose is false', () => {
57
+ render(<Modal {...props} isOpen showClose={false} tabIndex={0} />);
58
+ expect(screen.queryByRole('button', { name: 'Close' })).toBeNull();
59
+ });
60
+
61
+ test('modal generates console error when no accessible name is provided', () => {
62
+ const props = {
63
+ onClose: jest.fn(),
64
+ isOpen: true,
65
+ children: 'modal content'
66
+ };
67
+ const consoleErrorMock = jest.fn();
68
+ global.console = { error: consoleErrorMock } as any;
69
+
70
+ render(<Modal {...props} />);
71
+
72
+ expect(consoleErrorMock).toBeCalled();
73
+ });
74
+
75
+ test('modal generates console warning when conflicting accessible name strategies are provided', () => {
76
+ const props = {
77
+ hasNoBodyWrapper: true,
78
+ onClose: jest.fn(),
79
+ isOpen: true,
80
+ children: 'modal content'
81
+ };
82
+ const consoleErrorMock = jest.fn();
83
+ global.console = { error: consoleErrorMock } as any;
84
+
85
+ render(<Modal {...props} />);
79
86
 
80
- test('modal generates console warning when conflicting accessible name strategies are provided', () => {
81
- const props = {
82
- hasNoBodyWrapper: true,
83
- onClose: jest.fn(),
84
- isOpen: true,
85
- children: 'modal content'
86
- };
87
- const consoleErrorMock = jest.fn();
88
- global.console = { error: consoleErrorMock } as any;
89
- shallow(<Modal {...props} />);
90
- expect(consoleErrorMock).toBeCalled();
87
+ expect(consoleErrorMock).toBeCalled();
88
+ });
91
89
  });
@@ -1,14 +1,17 @@
1
1
  import * as React from 'react';
2
- import { shallow } from 'enzyme';
2
+
3
+ import { render, screen } from '@testing-library/react';
4
+ import userEvent from '@testing-library/user-event';
5
+
3
6
  import { ModalBoxCloseButton } from '../ModalBoxCloseButton';
4
7
 
5
- test('ModalBoxCloseButton Test', () => {
6
- const mockfn = jest.fn();
7
- const view = shallow(<ModalBoxCloseButton className="test-box-close-button-class" onClose={mockfn} />);
8
- expect(view).toMatchSnapshot();
9
- view
10
- .find('.test-box-close-button-class')
11
- .at(0)
12
- .simulate('click');
13
- expect(mockfn.mock.calls).toHaveLength(1);
8
+ describe('ModalBoxCloseButton', () => {
9
+ test('onClose called when clicked', () => {
10
+ const onClose = jest.fn();
11
+
12
+ render(<ModalBoxCloseButton className="test-box-close-button-class" onClose={onClose} />);
13
+
14
+ userEvent.click(screen.getByRole('button'));
15
+ expect(onClose).toHaveBeenCalledTimes(1);
16
+ });
14
17
  });