@patternfly/react-core 4.199.1 → 4.199.4

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 (45) hide show
  1. package/CHANGELOG.md +24 -0
  2. package/package.json +5 -5
  3. package/src/components/AboutModal/__tests__/AboutModal.test.tsx +41 -60
  4. package/src/components/Accordion/__tests__/Accordion.test.tsx +23 -17
  5. package/src/components/Alert/__tests__/Alert.test.tsx +195 -184
  6. package/src/components/Alert/__tests__/Generated/AlertActionCloseButton.test.tsx +19 -17
  7. package/src/components/Alert/__tests__/Generated/__snapshots__/AlertActionCloseButton.test.tsx.snap +26 -4
  8. package/src/components/Alert/__tests__/__snapshots__/Alert.test.tsx.snap +50 -700
  9. package/src/components/AlertGroup/__tests__/AlertGroup.test.tsx +68 -73
  10. package/src/components/AlertGroup/__tests__/__snapshots__/AlertGroup.test.tsx.snap +1 -893
  11. package/src/components/ApplicationLauncher/__tests__/Generated/ApplicationLauncherSeparator.test.tsx +13 -10
  12. package/src/components/ApplicationLauncher/__tests__/Generated/__snapshots__/ApplicationLauncherSeparator.test.tsx.snap +12 -1
  13. package/src/components/Button/__tests__/Button.test.tsx +116 -107
  14. package/src/components/Button/__tests__/__snapshots__/Button.test.tsx.snap +21 -21
  15. package/src/components/Card/__tests__/Card.test.tsx +119 -100
  16. package/src/components/Card/__tests__/CardBody.test.tsx +35 -28
  17. package/src/components/Card/__tests__/CardFooter.test.tsx +28 -24
  18. package/src/components/Card/__tests__/CardHeadMain.test.tsx +19 -14
  19. package/src/components/Card/__tests__/CardHeader.test.tsx +6 -22
  20. package/src/components/Card/__tests__/CardHeaderMain.test.tsx +19 -14
  21. package/src/components/Card/__tests__/CardTitle.test.tsx +25 -0
  22. package/src/components/Card/__tests__/__snapshots__/Card.test.tsx.snap +12 -28
  23. package/src/components/Card/__tests__/__snapshots__/CardBody.test.tsx.snap +2 -4
  24. package/src/components/Card/__tests__/__snapshots__/CardFooter.test.tsx.snap +1 -3
  25. package/src/components/Card/__tests__/__snapshots__/CardHeadMain.test.tsx.snap +1 -11
  26. package/src/components/Card/__tests__/__snapshots__/CardHeader.test.tsx.snap +1 -11
  27. package/src/components/Card/__tests__/__snapshots__/CardHeaderMain.test.tsx.snap +1 -11
  28. package/src/components/Card/__tests__/__snapshots__/CardTitle.test.tsx.snap +3 -0
  29. package/src/components/Checkbox/__tests__/Checkbox.test.tsx +66 -70
  30. package/src/components/Checkbox/__tests__/__snapshots__/Checkbox.test.tsx.snap +9 -204
  31. package/src/components/Chip/examples/Chip.md +1 -73
  32. package/src/components/Chip/examples/ChipDefault.tsx +68 -0
  33. package/src/components/ClipboardCopy/examples/ClipboardCopy.md +11 -123
  34. package/src/components/ClipboardCopy/examples/ClipboardCopyBasic.tsx +8 -0
  35. package/src/components/ClipboardCopy/examples/ClipboardCopyExpanded.tsx +9 -0
  36. package/src/components/ClipboardCopy/examples/ClipboardCopyExpandedWithArray.tsx +14 -0
  37. package/src/components/ClipboardCopy/examples/ClipboardCopyInlineCompact.tsx +7 -0
  38. package/src/components/ClipboardCopy/examples/ClipboardCopyInlineCompactCode.tsx +8 -0
  39. package/src/components/ClipboardCopy/examples/ClipboardCopyInlineCompactInSentence.tsx +36 -0
  40. package/src/components/ClipboardCopy/examples/ClipboardCopyInlineCompactWithAdditionalAction.tsx +20 -0
  41. package/src/components/ClipboardCopy/examples/ClipboardCopyJSONObject.tsx +18 -0
  42. package/src/components/ClipboardCopy/examples/ClipboardCopyReadOnly.tsx +8 -0
  43. package/src/components/ClipboardCopy/examples/ClipboardCopyReadOnlyExpanded.tsx +9 -0
  44. package/src/components/ClipboardCopy/examples/ClipboardCopyReadOnlyExpandedByDefault.tsx +9 -0
  45. package/src/layouts/Flex/examples/Flex.md +1 -1
package/CHANGELOG.md CHANGED
@@ -3,6 +3,30 @@
3
3
  All notable changes to this project will be documented in this file.
4
4
  See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
5
5
 
6
+ ## 4.199.4 (2022-03-19)
7
+
8
+ **Note:** Version bump only for package @patternfly/react-core
9
+
10
+
11
+
12
+
13
+
14
+ ## 4.199.3 (2022-03-17)
15
+
16
+ **Note:** Version bump only for package @patternfly/react-core
17
+
18
+
19
+
20
+
21
+
22
+ ## 4.199.2 (2022-03-17)
23
+
24
+ **Note:** Version bump only for package @patternfly/react-core
25
+
26
+
27
+
28
+
29
+
6
30
  ## 4.199.1 (2022-03-16)
7
31
 
8
32
  **Note:** Version bump only for package @patternfly/react-core
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@patternfly/react-core",
3
- "version": "4.199.1",
3
+ "version": "4.199.4",
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",
@@ -34,9 +34,9 @@
34
34
  "generate": "node scripts/copyStyles.js"
35
35
  },
36
36
  "dependencies": {
37
- "@patternfly/react-icons": "^4.50.1",
38
- "@patternfly/react-styles": "^4.49.1",
39
- "@patternfly/react-tokens": "^4.51.1",
37
+ "@patternfly/react-icons": "^4.50.4",
38
+ "@patternfly/react-styles": "^4.49.4",
39
+ "@patternfly/react-tokens": "^4.51.4",
40
40
  "focus-trap": "6.2.2",
41
41
  "react-dropzone": "9.0.0",
42
42
  "tippy.js": "5.1.2",
@@ -60,5 +60,5 @@
60
60
  "react": "^16.8.0 || ^17.0.0",
61
61
  "react-dom": "^16.8.0 || ^17.0.0"
62
62
  },
63
- "gitHead": "1cd7ab585c501674c2a1d741f460f73be08ad861"
63
+ "gitHead": "e6697ee34e57a0c8c5051937c5e5ed2dcddce3e2"
64
64
  }
@@ -1,72 +1,53 @@
1
1
  import * as React from 'react';
2
- import * as ReactDOM from 'react-dom';
3
- import { shallow } from 'enzyme';
4
- import { AboutModal } from '../AboutModal';
5
- import { KEY_CODES } from '../../../helpers/constants';
6
2
 
7
- const mockListener = jest.spyOn(ReactDOM, 'createPortal');
8
- jest.spyOn(document, 'createElement');
9
- jest.spyOn(document.body, 'addEventListener');
3
+ import { render, screen } from '@testing-library/react';
4
+ import userEvent from '@testing-library/user-event';
10
5
 
11
- mockListener.mockImplementation(node => node as React.ReactPortal);
6
+ import { AboutModal, AboutModalProps } from '../AboutModal';
12
7
 
13
- const props = {
8
+ const props: AboutModalProps = {
14
9
  onClose: jest.fn(),
15
10
  children: 'modal content',
16
11
  productName: 'Product Name',
17
12
  trademark: 'Trademark and copyright information here',
18
13
  brandImageSrc: 'brandImg...',
19
- brandImageAlt: 'Brand Image',
20
- logoImageSrc: 'logoImg...',
21
- logoImageAlt: 'AboutModal Logo'
14
+ brandImageAlt: 'Brand Image'
22
15
  };
23
16
 
24
- test('AboutModal creates a container element once for div', () => {
25
- const view = shallow(<AboutModal {...props}> Test About Modal </AboutModal>);
26
- view.update();
27
- expect(document.createElement).toBeCalledWith('div');
28
- expect(document.createElement).toHaveBeenCalledTimes(1);
29
- });
30
-
31
- test('About Modal closes with escape', () => {
32
- shallow(
33
- <AboutModal {...props} isOpen>
34
- Test About Modal
35
- </AboutModal>
36
- );
37
- const [event, handler] = (document.body.addEventListener as any).mock.calls[0];
38
- expect(event).toBe('keydown');
39
- handler({ keyCode: KEY_CODES.ESCAPE_KEY });
40
- expect(props.onClose).toBeCalled();
41
- });
42
-
43
- test('modal does not call onClose for esc key if it is not open', () => {
44
- shallow(<AboutModal {...props} />);
45
- const [event, handler] = (document.body.addEventListener as any).mock.calls[0];
46
- expect(event).toBe('keydown');
47
- handler({ keyCode: KEY_CODES.ESCAPE_KEY });
48
- expect(props.onClose).not.toBeCalled();
49
- });
50
-
51
- test('Each modal is given new aria-describedby and aria-labelledby', () => {
52
- const first = new AboutModal(props);
53
- const second = new AboutModal(props);
54
- expect(first.ariaLabelledBy).not.toBe(second.ariaLabelledBy);
55
- expect(first.ariaDescribedBy).not.toBe(second.ariaDescribedBy);
56
- });
57
-
58
- test('Console error is generated when the logoImageSrc is provided without logoImageAlt', () => {
59
- const noImgAltrops = {
60
- onClose: jest.fn(),
61
- children: 'modal content',
62
- productName: 'Product Name',
63
- trademark: 'Trademark and copyright information here',
64
- brandImageSrc: 'brandImg...',
65
- logoImageSrc: 'logoImg...'
66
- };
67
- const myMock = jest.fn() as any;
68
- global.console = { error: myMock } as any;
69
- const JSAboutModal = AboutModal as any;
70
- shallow(<JSAboutModal {...noImgAltrops}> Test About Modal </JSAboutModal>);
71
- expect(myMock).toBeCalled();
17
+ describe('AboutModal', () => {
18
+ test('closes with escape', () => {
19
+ render(<AboutModal {...props} isOpen />);
20
+
21
+ userEvent.type(screen.getByRole('dialog'), '{esc}');
22
+ expect(props.onClose).toBeCalled();
23
+ });
24
+
25
+ test('does not render the modal when isOpen is not specified', () => {
26
+ render(<AboutModal {...props} />);
27
+ expect(screen.queryByRole('dialog')).toBeNull();
28
+ });
29
+
30
+ test('Each modal is given new aria-describedby and aria-labelledby', () => {
31
+ const first = new AboutModal(props);
32
+ const second = new AboutModal(props);
33
+
34
+ expect(first.ariaLabelledBy).not.toBe(second.ariaLabelledBy);
35
+ expect(first.ariaDescribedBy).not.toBe(second.ariaDescribedBy);
36
+ });
37
+
38
+ test('Console error is generated when the logoImageSrc is provided without logoImageAlt', () => {
39
+ const noImgAltrops = {
40
+ onClose: jest.fn(),
41
+ children: 'modal content',
42
+ productName: 'Product Name',
43
+ trademark: 'Trademark and copyright information here',
44
+ brandImageSrc: 'brandImg...',
45
+ logoImageSrc: 'logoImg...'
46
+ } as any;
47
+ const myMock = jest.fn() as any;
48
+ global.console = { error: myMock } as any;
49
+
50
+ render(<AboutModal {...noImgAltrops}>Test About Modal</AboutModal>);
51
+ expect(myMock).toBeCalled();
52
+ });
72
53
  });
@@ -1,6 +1,8 @@
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 { Accordion } from '../Accordion';
5
7
  import { AccordionToggle } from '../AccordionToggle';
6
8
  import { AccordionContent } from '../AccordionContent';
@@ -26,31 +28,34 @@ describe('Accordion', () => {
26
28
  });
27
29
 
28
30
  test('It should pass optional aria props', () => {
29
- const view = mount(
31
+ render(
30
32
  <Accordion asDefinitionList>
31
33
  <AccordionToggle aria-label="Toggle details for" aria-labelledby="ex-toggle2 ex-item2" id="ex-toggle2" />
32
34
  </Accordion>
33
35
  );
34
- const button = view.find('button[id="ex-toggle2"]').getElement();
35
- expect(button.props['aria-label']).toBe('Toggle details for');
36
- expect(button.props['aria-labelledby']).toBe('ex-toggle2 ex-item2');
37
- expect(button.props['aria-expanded']).toBe(false);
36
+ const button = screen.getByRole('button');
37
+
38
+ expect(button.getAttribute('aria-label')).toEqual('Toggle details for');
39
+ expect(button.getAttribute('aria-labelledby')).toEqual('ex-toggle2 ex-item2');
40
+ expect(button.getAttribute('aria-expanded')).toEqual('false');
38
41
  });
39
42
 
40
43
  test('Toggle expanded', () => {
41
- const view = mount(
44
+ render(
42
45
  <Accordion asDefinitionList>
43
46
  <AccordionToggle aria-label="Toggle details for" id="ex-toggle2" isExpanded />
44
47
  </Accordion>
45
48
  );
46
- const button = view.find('button[id="ex-toggle2"]').getElement();
47
- expect(button.props['aria-expanded']).toBe(true);
48
- expect(button.props.className).toContain('pf-m-expanded');
49
+ const button = screen.getByRole('button');
50
+
51
+ expect(button.getAttribute('aria-expanded')).toEqual('true');
52
+ expect(button.className).toContain('pf-m-expanded');
49
53
  });
50
54
 
51
- test('Custom containers', () => {
55
+ test('renders content with custom Toggle and Content containers', () => {
52
56
  const container = 'a';
53
- const view = mount(
57
+
58
+ const view = render(
54
59
  <Accordion headingLevel="h2">
55
60
  <AccordionItem>
56
61
  <AccordionToggle id="item-1" component={container}>
@@ -60,8 +65,9 @@ describe('Accordion', () => {
60
65
  </AccordionItem>
61
66
  </Accordion>
62
67
  );
63
- expect(view.find(AccordionToggle).getDOMNode().tagName).toBe(container.toLocaleUpperCase());
64
- expect(view.find(AccordionContent).getDOMNode().tagName).toBe(container.toLocaleUpperCase());
68
+
69
+ expect(screen.getByText('Item One')).toBeInTheDocument();
70
+ expect(screen.getByText('Item One Content')).toBeInTheDocument();
65
71
  });
66
72
 
67
73
  test('Accordion bordered', () => {
@@ -78,7 +84,7 @@ describe('Accordion', () => {
78
84
 
79
85
  test('Accordion display large', () => {
80
86
  const view = render(
81
- <Accordion displaySize='large'>
87
+ <Accordion displaySize="large">
82
88
  <AccordionItem>
83
89
  <AccordionToggle id="item-1">Item One</AccordionToggle>
84
90
  <AccordionContent>Item One Content</AccordionContent>
@@ -96,7 +102,7 @@ describe('Accordion', () => {
96
102
  <AccordionContent isCustomContent>
97
103
  <AccordionExpandedContentBody>Item one content body 1</AccordionExpandedContentBody>
98
104
  <AccordionExpandedContentBody>Item one Content body 2</AccordionExpandedContentBody>
99
- </AccordionContent>
105
+ </AccordionContent>
100
106
  </AccordionItem>
101
107
  </Accordion>
102
108
  );
@@ -1,197 +1,208 @@
1
1
  import * as React from 'react';
2
- import { render } from '@testing-library/react';
3
- import { mount } from 'enzyme';
2
+ import { render, screen } from '@testing-library/react';
3
+ import userEvent from '@testing-library/user-event';
4
4
 
5
5
  import { Alert, AlertVariant } from '../Alert';
6
6
  import { AlertActionLink } from '../AlertActionLink';
7
7
  import { AlertActionCloseButton } from '../AlertActionCloseButton';
8
8
  import { UsersIcon } from '@patternfly/react-icons';
9
9
 
10
- test('default Alert variant is default', () => {
11
- const view = mount(<Alert title="this is a test">Alert testing</Alert>);
12
- expect(
13
- view
14
- .find('Alert')
15
- .childAt(0)
16
- .prop('className')
17
- ).toContain('pf-c-alert');
18
- });
19
-
20
- Object.values(AlertVariant).forEach(variant => {
21
- describe(`Alert - ${variant}`, () => {
22
- test('Description', () => {
23
- const view = render(
24
- <Alert variant={variant} title="">
25
- Some alert
26
- </Alert>
27
- );
28
- expect(view.container).toMatchSnapshot();
29
- });
30
-
31
- test('Title', () => {
32
- const view = render(
33
- <Alert variant={variant} title="Some title">
34
- Some alert
35
- </Alert>
36
- );
37
- expect(view.container).toMatchSnapshot();
38
- });
39
-
40
- test('Heading level', () => {
41
- const view = render(
42
- <Alert variant={variant} title="Some title" titleHeadingLevel="h1">
43
- Some alert
44
- </Alert>
45
- );
46
- expect(view.container).toMatchSnapshot();
47
- });
48
-
49
- test('Action Link', () => {
50
- const view = render(
51
- <Alert variant={variant} actionLinks={[<AlertActionLink key={'action-1'}>test</AlertActionLink>]} title="">
52
- Some alert
53
- </Alert>
54
- );
55
- expect(view.container).toMatchSnapshot();
56
- });
57
-
58
- test('Action Close Button', () => {
59
- const onClose = jest.fn();
60
- const view = mount(
61
- <Alert
62
- variant={variant}
63
- actionClose={<AlertActionCloseButton aria-label="Close" onClose={onClose} />}
64
- title={`Sample ${variant} alert`}
65
- >
66
- Some alert
67
- </Alert>
68
- );
69
- expect(view).toMatchSnapshot();
70
- view.find('button[aria-label="Close"]').simulate('click');
71
- expect(onClose).toHaveBeenCalled();
72
- });
73
-
74
- test('Action and Title', () => {
75
- const view = render(
76
- <Alert variant={variant} actionLinks={[<AlertActionLink key={'action-1'}>test</AlertActionLink>]} title="Some title">
77
- Some alert
78
- </Alert>
79
- );
80
- expect(view.container).toMatchSnapshot();
81
- });
82
-
83
- test('Custom aria label', () => {
84
- const view = render(
85
- <Alert
86
- variant={variant}
87
- aria-label={`Custom aria label for ${variant}`}
88
- actionLinks={[<AlertActionLink key={'action-1'}>test</AlertActionLink>]}
89
- title="Some title"
90
- >
91
- Some alert
92
- </Alert>
93
- );
94
- expect(view.container).toMatchSnapshot();
95
- });
96
-
97
- test('inline variation', () => {
98
- const view = render(
99
- <Alert variant={variant} isInline title="Some title">
100
- Some alert
101
- </Alert>
102
- );
103
- expect(view.container).toMatchSnapshot();
104
- });
105
-
106
- test('expandable variation', () => {
107
- const view = render(
108
- <Alert variant={variant} title="Some title" isExpandable>
109
- <p>Success alert description. This should tell the user more information about the alert.</p>
110
- </Alert>
111
- )
112
- expect(view.container).toMatchSnapshot();
113
- })
114
-
115
- test('expandable variation description hidden', () => {
116
- const wrapper = mount(
117
- <Alert variant={variant} title="Some title" isExpandable>
118
- <p>Success alert description. This should tell the user more information about the alert.</p>
119
- </Alert>
120
- )
121
- const descriptionExists = wrapper.find('.pf-c-alert__description').exists();
122
- expect(descriptionExists).toBeFalsy();
123
- })
124
-
125
- test('Toast alerts match snapsnot', () => {
126
- const view = render(
127
- <Alert isLiveRegion={true} variant={variant} aria-label={`${variant} toast alert`} title="Some title">
128
- Some toast alert
129
- </Alert>
130
- );
131
- expect(view.container).toMatchSnapshot();
132
- });
133
-
134
- test('Toast alerts contain default live region', () => {
135
- const wrapper = mount(
136
- <Alert isLiveRegion={true} variant={variant} aria-label={`${variant} toast alert`} title="Some title">
137
- Some toast alert
138
- </Alert>
139
- );
140
- const liveRegion = wrapper.find({ 'aria-live': 'polite' }).length;
141
- expect(liveRegion).toBe(1);
142
- });
143
-
144
- test('Toast alert live regions are not atomic', () => {
145
- const wrapper = mount(
146
- <Alert isLiveRegion={true} variant={variant} aria-label={`${variant} toast alert`} title="Some title">
147
- Some toast alert
148
- </Alert>
149
- );
150
- expect(wrapper.find('.pf-c-alert').prop('aria-atomic')).toBe('false');
151
- });
152
-
153
- test('Non-toast alerts can have custom live region settings', () => {
154
- const wrapper = mount(
155
- <Alert
156
- aria-live="assertive"
157
- aria-relevant="all"
158
- aria-atomic="true"
159
- variant={variant}
160
- aria-label={`${variant} toast alert`}
161
- title="Some title"
162
- >
163
- Some noisy alert
164
- </Alert>
165
- );
166
- const alert = wrapper.find(Alert);
167
-
168
- expect(alert.prop('aria-live')).toBe('assertive');
169
- expect(alert.prop('aria-relevant')).toBe('all');
170
- expect(alert.prop('aria-atomic')).toBe('true');
171
- });
10
+ describe('Alert', () => {
11
+ test('default Alert variant is default', () => {
12
+ render(<Alert title="this is a test">Alert testing</Alert>);
13
+ expect(screen.getByText('this is a test').className).toContain('pf-c-alert');
14
+ });
172
15
 
173
- test('Custom icon', () => {
174
- const view = render(
175
- <Alert
176
- customIcon={<UsersIcon />}
177
- variant={variant}
178
- aria-label={`${variant} custom icon alert`}
179
- title="custom icon alert title"
180
- >
181
- Some noisy alert
182
- </Alert>
183
- );
184
- expect(view.container).toMatchSnapshot();
16
+ Object.values(AlertVariant).forEach(variant => {
17
+ describe(`Alert - ${variant}`, () => {
18
+ test('Description', () => {
19
+ const view = render(
20
+ <Alert variant={variant} title="">
21
+ Some alert
22
+ </Alert>
23
+ );
24
+ expect(view.container).toMatchSnapshot();
25
+ });
26
+
27
+ test('Title', () => {
28
+ const view = render(
29
+ <Alert variant={variant} title="Some title">
30
+ Some alert
31
+ </Alert>
32
+ );
33
+ expect(view.container).toMatchSnapshot();
34
+ });
35
+
36
+ test('Heading level', () => {
37
+ const view = render(
38
+ <Alert variant={variant} title="Some title" titleHeadingLevel="h1">
39
+ Some alert
40
+ </Alert>
41
+ );
42
+ expect(view.container).toMatchSnapshot();
43
+ });
44
+
45
+ test('Action Link', () => {
46
+ const view = render(
47
+ <Alert variant={variant} actionLinks={[<AlertActionLink key={'action-1'}>test</AlertActionLink>]} title="">
48
+ Some alert
49
+ </Alert>
50
+ );
51
+ expect(view.container).toMatchSnapshot();
52
+ });
53
+
54
+ test('Action Close Button', () => {
55
+ const onClose = jest.fn();
56
+
57
+ render(
58
+ <Alert
59
+ variant={variant}
60
+ actionClose={<AlertActionCloseButton aria-label="Close" onClose={onClose} />}
61
+ title={`Sample ${variant} alert`}
62
+ >
63
+ Some alert
64
+ </Alert>
65
+ );
66
+
67
+ userEvent.click(screen.getByLabelText('Close'));
68
+ expect(onClose).toHaveBeenCalled();
69
+ });
70
+
71
+ test('Action and Title', () => {
72
+ const view = render(
73
+ <Alert
74
+ variant={variant}
75
+ actionLinks={[<AlertActionLink key={'action-1'}>test</AlertActionLink>]}
76
+ title="Some title"
77
+ >
78
+ Some alert
79
+ </Alert>
80
+ );
81
+ expect(view.container).toMatchSnapshot();
82
+ });
83
+
84
+ test('Custom aria label', () => {
85
+ const view = render(
86
+ <Alert
87
+ variant={variant}
88
+ aria-label={`Custom aria label for ${variant}`}
89
+ actionLinks={[<AlertActionLink key={'action-1'}>test</AlertActionLink>]}
90
+ title="Some title"
91
+ >
92
+ Some alert
93
+ </Alert>
94
+ );
95
+ expect(view.container).toMatchSnapshot();
96
+ });
97
+
98
+ test('inline variation', () => {
99
+ const view = render(
100
+ <Alert variant={variant} isInline title="Some title">
101
+ Some alert
102
+ </Alert>
103
+ );
104
+ expect(view.container).toMatchSnapshot();
105
+ });
106
+
107
+ test('expandable variation', () => {
108
+ const view = render(
109
+ <Alert variant={variant} title="Some title" isExpandable>
110
+ <p>Success alert description. This should tell the user more information about the alert.</p>
111
+ </Alert>
112
+ );
113
+ expect(view.container).toMatchSnapshot();
114
+ });
115
+
116
+ test('expandable variation description hidden', () => {
117
+ const description = 'Success alert description.';
118
+
119
+ render(
120
+ <Alert variant={variant} title="Some title" isExpandable>
121
+ <p>{description}</p>
122
+ </Alert>
123
+ );
124
+
125
+ expect(screen.queryByText(description)).toBeNull();
126
+ });
127
+
128
+ test('Toast alerts match snapsnot', () => {
129
+ const view = render(
130
+ <Alert isLiveRegion={true} variant={variant} aria-label={`${variant} toast alert`} title="Some title">
131
+ Some toast alert
132
+ </Alert>
133
+ );
134
+ expect(view.container).toMatchSnapshot();
135
+ });
136
+
137
+ test('Toast alerts contain default live region', () => {
138
+ const ariaLabel = `${variant} toast alert`;
139
+
140
+ render(
141
+ <Alert isLiveRegion={true} variant={variant} aria-label={ariaLabel} title="Some title">
142
+ Some toast alert
143
+ </Alert>
144
+ );
145
+
146
+ expect(screen.getByLabelText(ariaLabel).getAttribute('aria-live')).toEqual('polite');
147
+ });
148
+
149
+ test('Toast alert live regions are not atomic', () => {
150
+ const ariaLabel = `${variant} toast alert`;
151
+
152
+ render(
153
+ <Alert isLiveRegion={true} variant={variant} aria-label={ariaLabel} title="Some title">
154
+ Some toast alert
155
+ </Alert>
156
+ );
157
+
158
+ expect(screen.getByLabelText(ariaLabel).getAttribute('aria-atomic')).toEqual('false');
159
+ });
160
+
161
+ test('Non-toast alerts can have custom live region settings', () => {
162
+ const ariaLabel = `${variant} toast alert`;
163
+
164
+ render(
165
+ <Alert
166
+ aria-live="assertive"
167
+ aria-relevant="all"
168
+ aria-atomic="true"
169
+ variant={variant}
170
+ aria-label={ariaLabel}
171
+ title="Some title"
172
+ >
173
+ Some noisy alert
174
+ </Alert>
175
+ );
176
+ const alert = screen.getByLabelText(ariaLabel);
177
+
178
+ expect(alert.getAttribute('aria-live')).toEqual('assertive');
179
+ expect(alert.getAttribute('aria-relevant')).toEqual('all');
180
+ expect(alert.getAttribute('aria-atomic')).toEqual('true');
181
+ });
182
+
183
+ test('Custom icon', () => {
184
+ const view = render(
185
+ <Alert
186
+ customIcon={<UsersIcon />}
187
+ variant={variant}
188
+ aria-label={`${variant} custom icon alert`}
189
+ title="custom icon alert title"
190
+ >
191
+ Some noisy alert
192
+ </Alert>
193
+ );
194
+ expect(view.container).toMatchSnapshot();
195
+ });
185
196
  });
186
197
  });
187
- });
188
198
 
199
+ test('Alert truncate title', () => {
200
+ render(
201
+ <Alert truncateTitle={1} title="this is a test">
202
+ Alert testing
203
+ </Alert>
204
+ );
189
205
 
190
- test('Alert truncate title', () => {
191
- const view = mount(<Alert truncateTitle={1} title="this is a test">Alert testing</Alert>);
192
- expect(
193
- view
194
- .find('h4')
195
- .prop('className')
196
- ).toContain('pf-m-truncate');
206
+ expect(screen.getByText('this is a test').className).toContain('pf-m-truncate');
207
+ });
197
208
  });