@instructure/ui-modal 8.53.3-snapshot-10 → 8.53.3-snapshot-13

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 (34) hide show
  1. package/CHANGELOG.md +1 -1
  2. package/es/Modal/ModalBody/__new-tests__/ModalBody.test.js +101 -0
  3. package/es/Modal/ModalFooter/__new-tests__/ModalFooter.test.js +55 -0
  4. package/es/Modal/ModalHeader/__new-tests__/ModalHeader.test.js +91 -0
  5. package/es/Modal/__new-tests__/Modal.test.js +369 -0
  6. package/lib/Modal/ModalBody/__new-tests__/ModalBody.test.js +103 -0
  7. package/lib/Modal/ModalFooter/__new-tests__/ModalFooter.test.js +57 -0
  8. package/lib/Modal/ModalHeader/__new-tests__/ModalHeader.test.js +93 -0
  9. package/lib/Modal/__new-tests__/Modal.test.js +371 -0
  10. package/package.json +22 -21
  11. package/src/Modal/ModalBody/__new-tests__/ModalBody.test.tsx +117 -0
  12. package/src/Modal/ModalFooter/__new-tests__/ModalFooter.test.tsx +65 -0
  13. package/src/Modal/ModalHeader/__new-tests__/ModalHeader.test.tsx +107 -0
  14. package/src/Modal/__new-tests__/Modal.test.tsx +457 -0
  15. package/tsconfig.build.json +0 -2
  16. package/tsconfig.build.tsbuildinfo +1 -1
  17. package/types/Modal/ModalBody/__new-tests__/ModalBody.test.d.ts +2 -0
  18. package/types/Modal/ModalBody/__new-tests__/ModalBody.test.d.ts.map +1 -0
  19. package/types/Modal/ModalFooter/__new-tests__/ModalFooter.test.d.ts +2 -0
  20. package/types/Modal/ModalFooter/__new-tests__/ModalFooter.test.d.ts.map +1 -0
  21. package/types/Modal/ModalHeader/__new-tests__/ModalHeader.test.d.ts +2 -0
  22. package/types/Modal/ModalHeader/__new-tests__/ModalHeader.test.d.ts.map +1 -0
  23. package/types/Modal/__new-tests__/Modal.test.d.ts +2 -0
  24. package/types/Modal/__new-tests__/Modal.test.d.ts.map +1 -0
  25. package/es/Modal/ModalLocator.js +0 -46
  26. package/es/Modal/locator.js +0 -27
  27. package/lib/Modal/ModalLocator.js +0 -51
  28. package/lib/Modal/locator.js +0 -37
  29. package/src/Modal/ModalLocator.ts +0 -47
  30. package/src/Modal/locator.ts +0 -28
  31. package/types/Modal/ModalLocator.d.ts +0 -2656
  32. package/types/Modal/ModalLocator.d.ts.map +0 -1
  33. package/types/Modal/locator.d.ts +0 -4
  34. package/types/Modal/locator.d.ts.map +0 -1
package/CHANGELOG.md CHANGED
@@ -3,7 +3,7 @@
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
- ## [8.53.3-snapshot-10](https://github.com/instructure/instructure-ui/compare/v8.53.2...v8.53.3-snapshot-10) (2024-02-28)
6
+ ## [8.53.3-snapshot-13](https://github.com/instructure/instructure-ui/compare/v8.53.2...v8.53.3-snapshot-13) (2024-02-29)
7
7
 
8
8
  **Note:** Version bump only for package @instructure/ui-modal
9
9
 
@@ -0,0 +1,101 @@
1
+ var _ModalBody, _ModalBody2, _ModalBody3;
2
+ /*
3
+ * The MIT License (MIT)
4
+ *
5
+ * Copyright (c) 2015 - present Instructure, Inc.
6
+ *
7
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
8
+ * of this software and associated documentation files (the "Software"), to deal
9
+ * in the Software without restriction, including without limitation the rights
10
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11
+ * copies of the Software, and to permit persons to whom the Software is
12
+ * furnished to do so, subject to the following conditions:
13
+ *
14
+ * The above copyright notice and this permission notice shall be included in all
15
+ * copies or substantial portions of the Software.
16
+ *
17
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
23
+ * SOFTWARE.
24
+ */
25
+
26
+ import React from 'react';
27
+ import { render } from '@testing-library/react';
28
+ import '@testing-library/jest-dom';
29
+ import { color2hex } from '@instructure/ui-color-utils';
30
+ import { canvas } from '@instructure/ui-themes';
31
+ import { View } from '@instructure/ui-view';
32
+ import { ModalBody } from '../index';
33
+ import generateComponentTheme from '../theme';
34
+ const BODY_TEXT = 'Modal-body-text';
35
+ describe('<ModalBody />', () => {
36
+ it('should render', async () => {
37
+ const _render = render(_ModalBody || (_ModalBody = /*#__PURE__*/React.createElement(ModalBody, null, BODY_TEXT))),
38
+ findByText = _render.findByText;
39
+ const modalBody = await findByText(BODY_TEXT);
40
+ expect(modalBody).toBeInTheDocument();
41
+ });
42
+ it('should set inverse styles', async () => {
43
+ const themeVariables = generateComponentTheme(canvas);
44
+ const _render2 = render(_ModalBody2 || (_ModalBody2 = /*#__PURE__*/React.createElement(ModalBody, {
45
+ variant: "inverse"
46
+ }, BODY_TEXT))),
47
+ findByText = _render2.findByText;
48
+ const modalBody = await findByText(BODY_TEXT);
49
+ const modalBodyStyle = window.getComputedStyle(modalBody);
50
+ const bodyBackground = color2hex(modalBodyStyle.getPropertyValue('background-color'));
51
+ expect(modalBody).toBeInTheDocument();
52
+ expect(bodyBackground).toBe(themeVariables.inverseBackground);
53
+ });
54
+ it('should set the same width and height as the parent when overflow is set to fit', async () => {
55
+ const _render3 = render( /*#__PURE__*/React.createElement("div", {
56
+ style: {
57
+ width: '500px',
58
+ height: '600px'
59
+ }
60
+ }, _ModalBody3 || (_ModalBody3 = /*#__PURE__*/React.createElement(ModalBody, {
61
+ overflow: "fit"
62
+ }, BODY_TEXT)))),
63
+ findByText = _render3.findByText;
64
+ const modalBody = await findByText(BODY_TEXT);
65
+ const modalBodyStyle = window.getComputedStyle(modalBody);
66
+ expect(modalBodyStyle.width).toBe('100%');
67
+ expect(modalBodyStyle.height).toBe('100%');
68
+ });
69
+ describe('when passing down props to View', () => {
70
+ const allowedProps = {
71
+ padding: 'small',
72
+ elementRef: () => {},
73
+ as: 'section'
74
+ };
75
+ const allProps = View.allowedProps.filter(prop => prop !== 'children');
76
+ allProps.forEach(prop => {
77
+ if (prop in allowedProps) {
78
+ it(`should allow the '${prop}' prop`, () => {
79
+ const consoleErrorSpy = jest.spyOn(console, 'error').mockImplementation(() => {});
80
+ const props = {
81
+ [prop]: allowedProps[prop]
82
+ };
83
+ render( /*#__PURE__*/React.createElement(ModalBody, props));
84
+ expect(consoleErrorSpy).not.toHaveBeenCalled();
85
+ consoleErrorSpy.mockRestore();
86
+ });
87
+ } else {
88
+ it(`should NOT allow the '${prop}' prop`, () => {
89
+ const expectedErrorMessage = `prop '${prop}' is not allowed.`;
90
+ const consoleErrorSpy = jest.spyOn(console, 'error').mockImplementation(() => {});
91
+ const props = {
92
+ [prop]: 'NOT_ALLOWED_VALUE'
93
+ };
94
+ render( /*#__PURE__*/React.createElement(ModalBody, props));
95
+ expect(consoleErrorSpy).toHaveBeenCalledWith(expect.stringContaining(expectedErrorMessage), expect.any(String));
96
+ consoleErrorSpy.mockRestore();
97
+ });
98
+ }
99
+ });
100
+ });
101
+ });
@@ -0,0 +1,55 @@
1
+ var _ModalFooter, _ModalFooter2;
2
+ /*
3
+ * The MIT License (MIT)
4
+ *
5
+ * Copyright (c) 2015 - present Instructure, Inc.
6
+ *
7
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
8
+ * of this software and associated documentation files (the "Software"), to deal
9
+ * in the Software without restriction, including without limitation the rights
10
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11
+ * copies of the Software, and to permit persons to whom the Software is
12
+ * furnished to do so, subject to the following conditions:
13
+ *
14
+ * The above copyright notice and this permission notice shall be included in all
15
+ * copies or substantial portions of the Software.
16
+ *
17
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
23
+ * SOFTWARE.
24
+ */
25
+
26
+ import React from 'react';
27
+ import { render } from '@testing-library/react';
28
+ import '@testing-library/jest-dom';
29
+ import { canvas } from '@instructure/ui-themes';
30
+ import { color2hex } from '@instructure/ui-color-utils';
31
+ import { ModalFooter } from '../index';
32
+ import generateComponentTheme from '../theme';
33
+ const FOOTER_TEXT = 'Modal-footer-text';
34
+ describe('<ModalFooter />', () => {
35
+ it('should render', async () => {
36
+ const _render = render(_ModalFooter || (_ModalFooter = /*#__PURE__*/React.createElement(ModalFooter, null, FOOTER_TEXT))),
37
+ findByText = _render.findByText;
38
+ const modalFooter = await findByText(FOOTER_TEXT);
39
+ expect(modalFooter).toBeInTheDocument();
40
+ });
41
+ it('should set inverse styles', async () => {
42
+ const themeVariables = generateComponentTheme(canvas);
43
+ const _render2 = render(_ModalFooter2 || (_ModalFooter2 = /*#__PURE__*/React.createElement(ModalFooter, {
44
+ variant: "inverse"
45
+ }, FOOTER_TEXT))),
46
+ findByText = _render2.findByText;
47
+ const modalFooter = await findByText(FOOTER_TEXT);
48
+ const modalFooterStyle = window.getComputedStyle(modalFooter);
49
+ const footerBackground = color2hex(modalFooterStyle.getPropertyValue('background-color'));
50
+ const footerBorderColor = color2hex(modalFooterStyle.getPropertyValue('border-top-color'));
51
+ expect(modalFooter).toBeInTheDocument();
52
+ expect(footerBackground).toBe(themeVariables.inverseBackground);
53
+ expect(footerBorderColor).toBe(themeVariables.inverseBorderColor);
54
+ });
55
+ });
@@ -0,0 +1,91 @@
1
+ var _ModalHeader, _ModalHeader2, _ModalHeader3, _ModalHeader4, _ModalHeader5;
2
+ /*
3
+ * The MIT License (MIT)
4
+ *
5
+ * Copyright (c) 2015 - present Instructure, Inc.
6
+ *
7
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
8
+ * of this software and associated documentation files (the "Software"), to deal
9
+ * in the Software without restriction, including without limitation the rights
10
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11
+ * copies of the Software, and to permit persons to whom the Software is
12
+ * furnished to do so, subject to the following conditions:
13
+ *
14
+ * The above copyright notice and this permission notice shall be included in all
15
+ * copies or substantial portions of the Software.
16
+ *
17
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
23
+ * SOFTWARE.
24
+ */
25
+
26
+ import React from 'react';
27
+ import { render } from '@testing-library/react';
28
+ import '@testing-library/jest-dom';
29
+ import { canvas } from '@instructure/ui-themes';
30
+ import { color2hex } from '@instructure/ui-color-utils';
31
+ import { ModalHeader } from '../index';
32
+ import generateComponentTheme from '../theme';
33
+ const HEADER_TEXT = 'Modal-footer-text';
34
+ describe('<ModalHeader />', () => {
35
+ it('should render', async () => {
36
+ const _render = render(_ModalHeader || (_ModalHeader = /*#__PURE__*/React.createElement(ModalHeader, null, HEADER_TEXT))),
37
+ findByText = _render.findByText;
38
+ const modalHeader = await findByText(HEADER_TEXT);
39
+ expect(modalHeader).toBeInTheDocument();
40
+ });
41
+ it('should set inverse styles', async () => {
42
+ const themeVariables = generateComponentTheme(canvas);
43
+ const _render2 = render(_ModalHeader2 || (_ModalHeader2 = /*#__PURE__*/React.createElement(ModalHeader, {
44
+ variant: "inverse"
45
+ }, HEADER_TEXT))),
46
+ findByText = _render2.findByText;
47
+ const modalHeader = await findByText(HEADER_TEXT);
48
+ const modalHeaderStyle = window.getComputedStyle(modalHeader);
49
+ const headerBackground = color2hex(modalHeaderStyle.getPropertyValue('background-color'));
50
+ const headerBorderColor = color2hex(modalHeaderStyle.getPropertyValue('border-bottom-color'));
51
+ expect(modalHeader).toBeInTheDocument();
52
+ expect(headerBackground).toBe(themeVariables.inverseBackground);
53
+ expect(headerBorderColor).toBe(themeVariables.inverseBorderColor);
54
+ });
55
+ describe('spacing prop', () => {
56
+ it('should be correct by default', async () => {
57
+ const themeVariables = generateComponentTheme(canvas);
58
+ const _render3 = render(_ModalHeader3 || (_ModalHeader3 = /*#__PURE__*/React.createElement(ModalHeader, null, HEADER_TEXT))),
59
+ findByText = _render3.findByText;
60
+ const modalHeader = await findByText(HEADER_TEXT);
61
+ const modalHeaderStyle = window.getComputedStyle(modalHeader);
62
+ const headerPadding = modalHeaderStyle.padding;
63
+ expect(modalHeader).toBeInTheDocument();
64
+ expect(headerPadding).toBe(themeVariables.padding);
65
+ });
66
+ it('should correctly set default spacing', async () => {
67
+ const themeVariables = generateComponentTheme(canvas);
68
+ const _render4 = render(_ModalHeader4 || (_ModalHeader4 = /*#__PURE__*/React.createElement(ModalHeader, {
69
+ spacing: "default"
70
+ }, HEADER_TEXT))),
71
+ findByText = _render4.findByText;
72
+ const modalHeader = await findByText(HEADER_TEXT);
73
+ const modalHeaderStyle = window.getComputedStyle(modalHeader);
74
+ const headerPadding = modalHeaderStyle.padding;
75
+ expect(modalHeader).toBeInTheDocument();
76
+ expect(headerPadding).toBe(themeVariables.padding);
77
+ });
78
+ it('should correctly set compact spacing', async () => {
79
+ const themeVariables = generateComponentTheme(canvas);
80
+ const _render5 = render(_ModalHeader5 || (_ModalHeader5 = /*#__PURE__*/React.createElement(ModalHeader, {
81
+ spacing: "compact"
82
+ }, HEADER_TEXT))),
83
+ findByText = _render5.findByText;
84
+ const modalHeader = await findByText(HEADER_TEXT);
85
+ const modalHeaderStyle = window.getComputedStyle(modalHeader);
86
+ const headerPadding = modalHeaderStyle.padding;
87
+ expect(modalHeader).toBeInTheDocument();
88
+ expect(headerPadding).toBe(themeVariables.paddingCompact);
89
+ });
90
+ });
91
+ });
@@ -0,0 +1,369 @@
1
+ import _objectWithoutProperties from "@babel/runtime/helpers/esm/objectWithoutProperties";
2
+ const _excluded = ["label"];
3
+ var _Modal, _Modal2, _Modal$Body, _Modal3, _Modal4, _Modal5, _Modal$Body2, _Modal$Body3, _Modal$Body4, _Modal$Body5, _Modal$Body6, _Modal$Body7, _Modal6, _Modal7, _Modal8, _input, _Modal$Header, _Modal$Body8, _Modal$Footer;
4
+ /*
5
+ * The MIT License (MIT)
6
+ *
7
+ * Copyright (c) 2015 - present Instructure, Inc.
8
+ *
9
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
10
+ * of this software and associated documentation files (the "Software"), to deal
11
+ * in the Software without restriction, including without limitation the rights
12
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
13
+ * copies of the Software, and to permit persons to whom the Software is
14
+ * furnished to do so, subject to the following conditions:
15
+ *
16
+ * The above copyright notice and this permission notice shall be included in all
17
+ * copies or substantial portions of the Software.
18
+ *
19
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
22
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
24
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
25
+ * SOFTWARE.
26
+ */
27
+
28
+ import React from 'react';
29
+ import { render, waitFor } from '@testing-library/react';
30
+ import userEvent from '@testing-library/user-event';
31
+ import '@testing-library/jest-dom';
32
+ import { Modal } from '../index';
33
+ describe('<Modal />', () => {
34
+ afterEach(() => {
35
+ jest.clearAllMocks();
36
+ jest.restoreAllMocks();
37
+ });
38
+ it('should render nothing and have a node with no parent when closed', () => {
39
+ const _render = render(_Modal || (_Modal = /*#__PURE__*/React.createElement(Modal, {
40
+ label: "Modal Dialog",
41
+ shouldReturnFocus: false
42
+ }, /*#__PURE__*/React.createElement(Modal.Body, null, "Foo Bar Baz")))),
43
+ container = _render.container;
44
+ expect(container.firstChild).not.toBeInTheDocument();
45
+ });
46
+ it('should apply theme overrides when open', async () => {
47
+ const testFont = 'test-font';
48
+ const bodyText = 'Modal-body-text';
49
+ const _render2 = render( /*#__PURE__*/React.createElement(Modal, {
50
+ open: true,
51
+ size: "small",
52
+ label: "Modal Dialog",
53
+ shouldReturnFocus: false,
54
+ themeOverride: {
55
+ fontFamily: testFont
56
+ }
57
+ }, /*#__PURE__*/React.createElement(Modal.Body, null, bodyText))),
58
+ findByText = _render2.findByText,
59
+ findByRole = _render2.findByRole;
60
+ const modalBody = await findByText(bodyText);
61
+ const dialog = await findByRole('dialog');
62
+ const dialogStyle = window.getComputedStyle(dialog);
63
+ expect(modalBody).toBeInTheDocument();
64
+ expect(dialogStyle.fontFamily).toBe(testFont);
65
+ });
66
+ it('should render its own positioning context if constrained to parent', async () => {
67
+ const _render3 = render(_Modal2 || (_Modal2 = /*#__PURE__*/React.createElement(Modal, {
68
+ open: true,
69
+ label: "Modal Dialog",
70
+ shouldReturnFocus: false,
71
+ constrain: "parent"
72
+ }, /*#__PURE__*/React.createElement(Modal.Body, null, "Foo Bar Baz")))),
73
+ findByRole = _render3.findByRole;
74
+ const dialog = await findByRole('dialog');
75
+ const constrain = document.querySelector("[class*='constrainContext']");
76
+ expect(dialog).toBeInTheDocument();
77
+ expect(constrain).toBeInTheDocument();
78
+ });
79
+ it("should not inherit its parent's font color", async () => {
80
+ const _render4 = render( /*#__PURE__*/React.createElement("div", {
81
+ style: {
82
+ color: 'rgb(255, 255, 255)'
83
+ }
84
+ }, /*#__PURE__*/React.createElement(Modal, {
85
+ open: true,
86
+ label: "Modal Dialog",
87
+ shouldReturnFocus: false,
88
+ constrain: "parent",
89
+ themeOverride: {
90
+ textColor: 'rgb(0, 0, 0)'
91
+ }
92
+ }, _Modal$Body || (_Modal$Body = /*#__PURE__*/React.createElement(Modal.Body, null, "Foo Bar Baz"))))),
93
+ findByRole = _render4.findByRole;
94
+ const dialog = await findByRole('dialog');
95
+ const dialogStyle = window.getComputedStyle(dialog);
96
+ expect(dialog).toBeInTheDocument();
97
+ expect(dialogStyle.color).toBe('rgb(0, 0, 0)');
98
+ });
99
+ it('should pass `as` prop to the dialog', async () => {
100
+ const _render5 = render(_Modal3 || (_Modal3 = /*#__PURE__*/React.createElement(Modal, {
101
+ open: true,
102
+ label: "Modal Dialog",
103
+ shouldReturnFocus: false
104
+ }, /*#__PURE__*/React.createElement(Modal.Body, null, "Foo Bar Baz")))),
105
+ findByRole = _render5.findByRole,
106
+ rerender = _render5.rerender;
107
+ const dialog = await findByRole('dialog');
108
+ expect(dialog).toBeInTheDocument();
109
+ expect(dialog.tagName).toBe('SPAN');
110
+ rerender(_Modal4 || (_Modal4 = /*#__PURE__*/React.createElement(Modal, {
111
+ as: "form",
112
+ open: true,
113
+ label: "Modal Dialog",
114
+ shouldReturnFocus: false
115
+ }, /*#__PURE__*/React.createElement(Modal.Body, null, "Foo Bar Baz"))));
116
+ const dialogForm = await findByRole('dialog');
117
+ expect(dialogForm.tagName).toBe('FORM');
118
+ });
119
+ it('should handle null children', async () => {
120
+ const bodyText = 'Modal-body-text';
121
+ const _render6 = render( /*#__PURE__*/React.createElement(Modal, {
122
+ open: true,
123
+ label: "Modal Dialog",
124
+ shouldReturnFocus: false
125
+ }, null, /*#__PURE__*/React.createElement(Modal.Body, null, bodyText), null)),
126
+ findByText = _render6.findByText;
127
+ const modalBody = await findByText(bodyText);
128
+ expect(modalBody).toBeInTheDocument();
129
+ });
130
+ it('should apply the aria attributes', async () => {
131
+ const _render7 = render(_Modal5 || (_Modal5 = /*#__PURE__*/React.createElement(Modal, {
132
+ open: true,
133
+ label: "Modal Dialog",
134
+ shouldReturnFocus: false
135
+ }, /*#__PURE__*/React.createElement(Modal.Body, null, "Foo Bar Baz")))),
136
+ findByRole = _render7.findByRole;
137
+ const dialog = await findByRole('dialog');
138
+ expect(dialog).toBeInTheDocument();
139
+ expect(dialog).toHaveAttribute('aria-label', 'Modal Dialog');
140
+ });
141
+ it('should use transition', async () => {
142
+ const onEnter = jest.fn();
143
+ const onEntering = jest.fn();
144
+ const onEntered = jest.fn();
145
+ const _render8 = render( /*#__PURE__*/React.createElement(Modal, {
146
+ open: true,
147
+ onEnter: onEnter,
148
+ onEntering: onEntering,
149
+ onEntered: onEntered,
150
+ transition: "fade",
151
+ label: "Modal Dialog",
152
+ shouldReturnFocus: false
153
+ }, _Modal$Body2 || (_Modal$Body2 = /*#__PURE__*/React.createElement(Modal.Body, null, "Foo Bar Baz")))),
154
+ findByRole = _render8.findByRole;
155
+ const dialog = await findByRole('dialog');
156
+ expect(dialog).toBeInTheDocument();
157
+ await waitFor(() => {
158
+ expect(onEnter).toHaveBeenCalled();
159
+ expect(onEntering).toHaveBeenCalled();
160
+ expect(onEntered).toHaveBeenCalled();
161
+ });
162
+ });
163
+ it('should support onOpen prop', async () => {
164
+ const onOpen = jest.fn();
165
+ const _render9 = render( /*#__PURE__*/React.createElement(Modal, {
166
+ open: true,
167
+ onOpen: onOpen,
168
+ label: "Modal Dialog",
169
+ shouldReturnFocus: false
170
+ }, _Modal$Body3 || (_Modal$Body3 = /*#__PURE__*/React.createElement(Modal.Body, null, "Foo Bar Baz")))),
171
+ findByRole = _render9.findByRole;
172
+ const dialog = await findByRole('dialog');
173
+ expect(dialog).toBeInTheDocument();
174
+ await waitFor(() => {
175
+ expect(onOpen).toHaveBeenCalled();
176
+ });
177
+ });
178
+ it('should support onClose prop', async () => {
179
+ const onClose = jest.fn();
180
+ const _render10 = render( /*#__PURE__*/React.createElement(Modal, {
181
+ open: true,
182
+ onClose: onClose,
183
+ label: "Modal Dialog",
184
+ shouldReturnFocus: false
185
+ }, _Modal$Body4 || (_Modal$Body4 = /*#__PURE__*/React.createElement(Modal.Body, null, "Foo Bar Baz")))),
186
+ findByRole = _render10.findByRole,
187
+ rerender = _render10.rerender;
188
+ const dialog = await findByRole('dialog');
189
+ expect(dialog).toBeInTheDocument();
190
+ rerender( /*#__PURE__*/React.createElement(Modal, {
191
+ open: false,
192
+ onClose: onClose,
193
+ label: "Modal Dialog",
194
+ shouldReturnFocus: false
195
+ }, _Modal$Body5 || (_Modal$Body5 = /*#__PURE__*/React.createElement(Modal.Body, null, "Foo Bar Baz"))));
196
+ await waitFor(() => {
197
+ expect(onClose).toHaveBeenCalled();
198
+ });
199
+ });
200
+ it('should dismiss when overlay clicked by default', async () => {
201
+ const onDismiss = jest.fn();
202
+ const _render11 = render( /*#__PURE__*/React.createElement(Modal, {
203
+ open: true,
204
+ onDismiss: onDismiss,
205
+ label: "Modal Dialog",
206
+ shouldReturnFocus: false
207
+ }, _Modal$Body6 || (_Modal$Body6 = /*#__PURE__*/React.createElement(Modal.Body, null, "Modal Text")))),
208
+ findByText = _render11.findByText;
209
+ const modalBody = await findByText('Modal Text');
210
+ expect(modalBody).toBeInTheDocument();
211
+ await waitFor(() => {
212
+ userEvent.click(document.body);
213
+ expect(onDismiss).toHaveBeenCalled();
214
+ });
215
+ });
216
+ it('should NOT dismiss when overlay clicked with shouldCloseOnDocumentClick=false', async () => {
217
+ const onDismiss = jest.fn();
218
+ const onClickOuter = jest.fn();
219
+ const _render12 = render( /*#__PURE__*/React.createElement("div", null, /*#__PURE__*/React.createElement("button", {
220
+ "data-testid": "outer-element",
221
+ onClick: onClickOuter
222
+ }, "for dismiss"), /*#__PURE__*/React.createElement(Modal, {
223
+ open: true,
224
+ onDismiss: onDismiss,
225
+ label: "Modal Dialog",
226
+ shouldReturnFocus: false,
227
+ shouldCloseOnDocumentClick: false
228
+ }, _Modal$Body7 || (_Modal$Body7 = /*#__PURE__*/React.createElement(Modal.Body, null, "Foo Bar Baz ", /*#__PURE__*/React.createElement("button", null, "click me")))))),
229
+ findByRole = _render12.findByRole,
230
+ getByTestId = _render12.getByTestId;
231
+ const dialog = await findByRole('dialog');
232
+ expect(dialog).toBeInTheDocument();
233
+ userEvent.click(getByTestId('outer-element'));
234
+ await waitFor(() => {
235
+ expect(onClickOuter).toHaveBeenCalled();
236
+ expect(onDismiss).not.toHaveBeenCalled();
237
+ expect(dialog).toBeInTheDocument();
238
+ });
239
+ });
240
+ it('should render children', async () => {
241
+ const _render13 = render(_Modal6 || (_Modal6 = /*#__PURE__*/React.createElement(Modal, {
242
+ open: true,
243
+ label: "Modal Dialog",
244
+ shouldReturnFocus: false
245
+ }, /*#__PURE__*/React.createElement(Modal.Body, null, /*#__PURE__*/React.createElement("button", null, "Cancel"))))),
246
+ findByText = _render13.findByText;
247
+ const cancelButton = await findByText('Cancel');
248
+ expect(cancelButton).toBeInTheDocument();
249
+ });
250
+ describe('children validation', () => {
251
+ it('should pass validation when children are valid', async () => {
252
+ const consoleErrorSpy = jest.spyOn(console, 'error').mockImplementation(() => {});
253
+ const _render14 = render(_Modal7 || (_Modal7 = /*#__PURE__*/React.createElement(Modal, {
254
+ open: true,
255
+ label: "Modal Dialog",
256
+ shouldReturnFocus: false
257
+ }, /*#__PURE__*/React.createElement(Modal.Header, null, "Hello World"), /*#__PURE__*/React.createElement(Modal.Body, null, "Foo Bar Baz"), /*#__PURE__*/React.createElement(Modal.Footer, null, /*#__PURE__*/React.createElement("button", null, "Cancel"))))),
258
+ findByRole = _render14.findByRole;
259
+ const dialog = await findByRole('dialog');
260
+ expect(dialog).toBeInTheDocument();
261
+ expect(consoleErrorSpy).not.toHaveBeenCalled();
262
+ consoleErrorSpy.mockRestore();
263
+ });
264
+ it('should not pass validation when children are invalid', async () => {
265
+ const consoleErrorSpy = jest.spyOn(console, 'error').mockImplementation(() => {});
266
+ const _render15 = render(_Modal8 || (_Modal8 = /*#__PURE__*/React.createElement(Modal, {
267
+ open: true,
268
+ label: "Modal Dialog",
269
+ shouldReturnFocus: false
270
+ }, /*#__PURE__*/React.createElement(Modal.Body, null, "Foo Bar Baz"), /*#__PURE__*/React.createElement(Modal.Footer, null, /*#__PURE__*/React.createElement("button", null, "Cancel")), /*#__PURE__*/React.createElement(Modal.Header, null, "Hello World")))),
271
+ findByRole = _render15.findByRole;
272
+ const dialog = await findByRole('dialog');
273
+ const expectedErrorMessage = 'Expected children of Modal in one of the following formats:';
274
+ expect(dialog).toBeInTheDocument();
275
+ expect(consoleErrorSpy).toHaveBeenCalledWith(expect.any(String), expect.any(String), expect.stringContaining(expectedErrorMessage), expect.any(String));
276
+ consoleErrorSpy.mockRestore();
277
+ });
278
+ it('should pass inverse variant to children when set', async () => {
279
+ let headerRef = null;
280
+ let bodyRef = null;
281
+ let footerRef = null;
282
+ const _render16 = render( /*#__PURE__*/React.createElement(Modal, {
283
+ open: true,
284
+ label: "Dark Modal",
285
+ shouldReturnFocus: false,
286
+ variant: "inverse"
287
+ }, /*#__PURE__*/React.createElement(Modal.Header, {
288
+ ref: el => headerRef = el
289
+ }, "header"), /*#__PURE__*/React.createElement(Modal.Body, {
290
+ ref: el => bodyRef = el
291
+ }, "body"), /*#__PURE__*/React.createElement(Modal.Footer, {
292
+ ref: el => footerRef = el
293
+ }, "footer"))),
294
+ findByRole = _render16.findByRole;
295
+ const dialog = await findByRole('dialog');
296
+ expect(dialog).toBeInTheDocument();
297
+ expect(headerRef.props.variant).toBe('inverse');
298
+ expect(bodyRef.props.variant).toBe('inverse');
299
+ expect(footerRef.props.variant).toBe('inverse');
300
+ });
301
+ it('should pass overflow to Modal.Body', async () => {
302
+ let bodyRef = null;
303
+ const _render17 = render( /*#__PURE__*/React.createElement(Modal, {
304
+ open: true,
305
+ label: "Modal",
306
+ shouldReturnFocus: false,
307
+ overflow: "fit"
308
+ }, /*#__PURE__*/React.createElement(Modal.Body, {
309
+ ref: el => bodyRef = el
310
+ }, "body"))),
311
+ findByRole = _render17.findByRole;
312
+ const dialog = await findByRole('dialog');
313
+ expect(dialog).toBeInTheDocument();
314
+ expect(bodyRef.props.overflow).toBe('fit');
315
+ });
316
+ });
317
+ describe('managed focus', () => {
318
+ var _ModalExample;
319
+ class ModalExample extends React.Component {
320
+ render() {
321
+ const _this$props = this.props,
322
+ label = _this$props.label,
323
+ props = _objectWithoutProperties(_this$props, _excluded);
324
+ return /*#__PURE__*/React.createElement("div", null, _input || (_input = /*#__PURE__*/React.createElement("input", {
325
+ type: "text"
326
+ })), /*#__PURE__*/React.createElement(Modal, Object.assign({
327
+ label: label
328
+ }, props), _Modal$Header || (_Modal$Header = /*#__PURE__*/React.createElement(Modal.Header, null, /*#__PURE__*/React.createElement("button", null, "Close"))), _Modal$Body8 || (_Modal$Body8 = /*#__PURE__*/React.createElement(Modal.Body, null, /*#__PURE__*/React.createElement("input", {
329
+ type: "text",
330
+ id: "input-one",
331
+ "data-testid": "input-first"
332
+ }), /*#__PURE__*/React.createElement("input", {
333
+ type: "text",
334
+ id: "input-two",
335
+ "data-testid": "input-second"
336
+ }))), _Modal$Footer || (_Modal$Footer = /*#__PURE__*/React.createElement(Modal.Footer, null, /*#__PURE__*/React.createElement("button", null, "Cancel")))));
337
+ }
338
+ }
339
+ ModalExample.displayName = "ModalExample";
340
+ ModalExample.propTypes = {
341
+ // eslint-disable-next-line react/forbid-foreign-prop-types
342
+ ...Modal.propTypes
343
+ };
344
+ it('should focus closeButton by default', async () => {
345
+ const _render18 = render(_ModalExample || (_ModalExample = /*#__PURE__*/React.createElement(ModalExample, {
346
+ open: true,
347
+ label: "A Modal"
348
+ }))),
349
+ findByText = _render18.findByText;
350
+ const closeButton = await findByText('Close');
351
+ expect(closeButton).toBeInTheDocument();
352
+ await waitFor(() => {
353
+ expect(document.activeElement).toBe(closeButton);
354
+ });
355
+ });
356
+ it('should take a prop for finding default focus', async () => {
357
+ const _render19 = render( /*#__PURE__*/React.createElement(ModalExample, {
358
+ open: true,
359
+ label: "A Modal",
360
+ defaultFocusElement: () => document.getElementById('input-one')
361
+ })),
362
+ findByTestId = _render19.findByTestId;
363
+ const input = await findByTestId('input-first');
364
+ await waitFor(() => {
365
+ expect(input).toHaveFocus();
366
+ });
367
+ });
368
+ });
369
+ });