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