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