@instructure/ui-alerts 10.16.1-snapshot-0 → 10.16.1
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/es/Alert/__new-tests__/Alert.test.js +56 -41
- package/es/Alert/index.js +45 -32
- package/lib/Alert/__new-tests__/Alert.test.js +65 -50
- package/lib/Alert/index.js +43 -32
- package/package.json +16 -16
- package/src/Alert/__new-tests__/Alert.test.tsx +0 -1
- package/src/Alert/index.tsx +7 -7
- package/tsconfig.build.tsbuildinfo +1 -1
- package/types/Alert/__new-tests__/Alert.test.d.ts.map +1 -1
- package/types/Alert/index.d.ts +9 -11
- package/types/Alert/index.d.ts.map +1 -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
|
-
## [10.16.1
|
|
6
|
+
## [10.16.1](https://github.com/instructure/instructure-ui/compare/v10.16.0...v10.16.1) (2025-04-22)
|
|
7
7
|
|
|
8
8
|
**Note:** Version bump only for package @instructure/ui-alerts
|
|
9
9
|
|
|
@@ -23,7 +23,6 @@ var _Alert, _Alert2, _div, _Alert4, _Alert5;
|
|
|
23
23
|
* SOFTWARE.
|
|
24
24
|
*/
|
|
25
25
|
|
|
26
|
-
import React from 'react';
|
|
27
26
|
import { render, screen, waitFor } from '@testing-library/react';
|
|
28
27
|
import { vi } from 'vitest';
|
|
29
28
|
import { runAxeCheck } from '@instructure/ui-axe-check';
|
|
@@ -33,6 +32,7 @@ import { Alert } from '../index';
|
|
|
33
32
|
// eslint-disable-next-line no-restricted-imports
|
|
34
33
|
import { generateA11yTests } from '@instructure/ui-scripts/lib/test/generateA11yTests';
|
|
35
34
|
import AlertExamples from '../__examples__/Alert.examples';
|
|
35
|
+
import { jsx as _jsx } from "@emotion/react/jsx-runtime";
|
|
36
36
|
describe('<Alert />', () => {
|
|
37
37
|
let srdiv;
|
|
38
38
|
let consoleWarningMock;
|
|
@@ -57,9 +57,10 @@ describe('<Alert />', () => {
|
|
|
57
57
|
consoleErrorMock.mockRestore();
|
|
58
58
|
});
|
|
59
59
|
it('should render', async () => {
|
|
60
|
-
render(_Alert || (_Alert =
|
|
61
|
-
variant: "success"
|
|
62
|
-
|
|
60
|
+
render(_Alert || (_Alert = _jsx(Alert, {
|
|
61
|
+
variant: "success",
|
|
62
|
+
children: "Success: Sample alert text."
|
|
63
|
+
})));
|
|
63
64
|
const text = screen.getByText('Success: Sample alert text.');
|
|
64
65
|
expect(text).toBeInTheDocument();
|
|
65
66
|
});
|
|
@@ -75,19 +76,23 @@ describe('<Alert />', () => {
|
|
|
75
76
|
}
|
|
76
77
|
});
|
|
77
78
|
it('should not render the Close button when `renderCloseButtonLabel` is not provided', async () => {
|
|
78
|
-
render(_Alert2 || (_Alert2 =
|
|
79
|
-
variant: "success"
|
|
80
|
-
|
|
79
|
+
render(_Alert2 || (_Alert2 = _jsx(Alert, {
|
|
80
|
+
variant: "success",
|
|
81
|
+
children: "Success: Sample alert text."
|
|
82
|
+
})));
|
|
81
83
|
const closeButton = screen.queryByRole('button');
|
|
82
84
|
expect(closeButton).not.toBeInTheDocument();
|
|
83
85
|
});
|
|
84
86
|
it('should call `onDismiss` when the close button is clicked with renderCloseButtonLabel', async () => {
|
|
85
87
|
const onDismiss = vi.fn();
|
|
86
|
-
render(
|
|
88
|
+
render(_jsx(Alert, {
|
|
87
89
|
variant: "success",
|
|
88
|
-
renderCloseButtonLabel: _div || (_div =
|
|
89
|
-
|
|
90
|
-
|
|
90
|
+
renderCloseButtonLabel: _div || (_div = _jsx("div", {
|
|
91
|
+
children: "Close"
|
|
92
|
+
})),
|
|
93
|
+
onDismiss: onDismiss,
|
|
94
|
+
children: "Success: Sample alert text."
|
|
95
|
+
}));
|
|
91
96
|
const closeButton = screen.getByRole('button');
|
|
92
97
|
userEvent.click(closeButton);
|
|
93
98
|
await waitFor(() => {
|
|
@@ -103,43 +108,47 @@ describe('<Alert />', () => {
|
|
|
103
108
|
Object.entries(iconComponentsVariants).forEach(([variant, iconComponent]) => {
|
|
104
109
|
var _Alert3;
|
|
105
110
|
it(`"${variant}" variant should have icon "${iconComponent}".`, async () => {
|
|
106
|
-
const _render2 = render(_Alert3 || (_Alert3 =
|
|
111
|
+
const _render2 = render(_Alert3 || (_Alert3 = _jsx(Alert, {
|
|
107
112
|
variant: variant,
|
|
108
|
-
transition: "none"
|
|
109
|
-
|
|
113
|
+
transition: "none",
|
|
114
|
+
children: "Success: Sample alert text."
|
|
115
|
+
}))),
|
|
110
116
|
container = _render2.container;
|
|
111
117
|
const icon = container.querySelector('svg[class$="-svgIcon"]');
|
|
112
118
|
expect(icon).toHaveAttribute('name', iconComponent);
|
|
113
119
|
});
|
|
114
120
|
});
|
|
115
121
|
it('should meet a11y standards', async () => {
|
|
116
|
-
const _render3 = render(_Alert4 || (_Alert4 =
|
|
122
|
+
const _render3 = render(_Alert4 || (_Alert4 = _jsx(Alert, {
|
|
117
123
|
variant: "success",
|
|
118
|
-
transition: "none"
|
|
119
|
-
|
|
124
|
+
transition: "none",
|
|
125
|
+
children: "Success: Sample alert text."
|
|
126
|
+
}))),
|
|
120
127
|
container = _render3.container;
|
|
121
128
|
const axeCheck = await runAxeCheck(container);
|
|
122
129
|
expect(axeCheck).toBe(true);
|
|
123
130
|
});
|
|
124
131
|
it('should add alert text to aria live region, when present', async () => {
|
|
125
132
|
const liveRegion = document.getElementById('_alertLiveRegion');
|
|
126
|
-
render(
|
|
133
|
+
render(_jsx(Alert, {
|
|
127
134
|
variant: "success",
|
|
128
135
|
transition: "none",
|
|
129
136
|
liveRegion: () => liveRegion,
|
|
130
|
-
liveRegionPoliteness: "polite"
|
|
131
|
-
|
|
137
|
+
liveRegionPoliteness: "polite",
|
|
138
|
+
children: "Success: Sample alert text."
|
|
139
|
+
}));
|
|
132
140
|
expect(liveRegion).toHaveTextContent('Success: Sample alert text.');
|
|
133
141
|
expect(liveRegion).toHaveAttribute('aria-live', 'polite');
|
|
134
142
|
});
|
|
135
143
|
describe('with `screenReaderOnly', () => {
|
|
136
144
|
it('should not render anything when using `liveRegion`', async () => {
|
|
137
145
|
const liveRegion = document.getElementById('_alertLiveRegion');
|
|
138
|
-
const _render4 = render(
|
|
146
|
+
const _render4 = render(_jsx(Alert, {
|
|
139
147
|
variant: "success",
|
|
140
148
|
liveRegion: () => liveRegion,
|
|
141
|
-
screenReaderOnly: true
|
|
142
|
-
|
|
149
|
+
screenReaderOnly: true,
|
|
150
|
+
children: "Success: Sample alert text. asdsfds"
|
|
151
|
+
})),
|
|
143
152
|
container = _render4.container;
|
|
144
153
|
expect(container.children.length).toBe(0);
|
|
145
154
|
expect(liveRegion.children.length).toBe(1);
|
|
@@ -147,63 +156,69 @@ describe('<Alert />', () => {
|
|
|
147
156
|
it('should warn if `liveRegion` is not defined', async () => {
|
|
148
157
|
const consoleWarningSpy = vi.spyOn(console, 'error').mockImplementation(() => {});
|
|
149
158
|
const warning = "Warning: [Alert] The 'screenReaderOnly' prop must be used in conjunction with 'liveRegion'.";
|
|
150
|
-
render(_Alert5 || (_Alert5 =
|
|
159
|
+
render(_Alert5 || (_Alert5 = _jsx(Alert, {
|
|
151
160
|
variant: "success",
|
|
152
|
-
screenReaderOnly: true
|
|
153
|
-
|
|
161
|
+
screenReaderOnly: true,
|
|
162
|
+
children: "Success: Sample alert text."
|
|
163
|
+
})));
|
|
154
164
|
await waitFor(() => {
|
|
155
165
|
expect(consoleWarningSpy.mock.calls[0][0]).toEqual(expect.stringContaining(warning));
|
|
156
166
|
});
|
|
157
167
|
});
|
|
158
168
|
it('should set aria-atomic to the aria live region when isLiveRegionAtomic is present', async () => {
|
|
159
169
|
const liveRegion = document.getElementById('_alertLiveRegion');
|
|
160
|
-
render(
|
|
170
|
+
render(_jsx(Alert, {
|
|
161
171
|
variant: "success",
|
|
162
172
|
transition: "none",
|
|
163
173
|
liveRegion: () => liveRegion,
|
|
164
174
|
liveRegionPoliteness: "polite",
|
|
165
|
-
isLiveRegionAtomic: true
|
|
166
|
-
|
|
175
|
+
isLiveRegionAtomic: true,
|
|
176
|
+
children: "Success: Sample alert text."
|
|
177
|
+
}));
|
|
167
178
|
expect(liveRegion).toHaveTextContent('Success: Sample alert text.');
|
|
168
179
|
expect(liveRegion).toHaveAttribute('aria-atomic', 'true');
|
|
169
180
|
});
|
|
170
181
|
it('should close when told to, with transition', async () => {
|
|
171
182
|
const liveRegion = document.getElementById('_alertLiveRegion');
|
|
172
|
-
const _render5 = render(
|
|
183
|
+
const _render5 = render(_jsx(Alert, {
|
|
173
184
|
variant: "success",
|
|
174
|
-
liveRegion: () => liveRegion
|
|
175
|
-
|
|
185
|
+
liveRegion: () => liveRegion,
|
|
186
|
+
children: "Success: Sample alert text."
|
|
187
|
+
})),
|
|
176
188
|
rerender = _render5.rerender;
|
|
177
189
|
expect(liveRegion.children.length).toBe(1);
|
|
178
190
|
|
|
179
191
|
//set open to false
|
|
180
|
-
rerender(
|
|
192
|
+
rerender(_jsx(Alert, {
|
|
181
193
|
variant: "success",
|
|
182
194
|
open: false,
|
|
183
|
-
liveRegion: () => liveRegion
|
|
184
|
-
|
|
195
|
+
liveRegion: () => liveRegion,
|
|
196
|
+
children: "Success: Sample alert text."
|
|
197
|
+
}));
|
|
185
198
|
await waitFor(() => {
|
|
186
199
|
expect(liveRegion.children.length).toBe(0);
|
|
187
200
|
});
|
|
188
201
|
});
|
|
189
202
|
it('should close when told to, without transition', async () => {
|
|
190
203
|
const liveRegion = document.getElementById('_alertLiveRegion');
|
|
191
|
-
const _render6 = render(
|
|
204
|
+
const _render6 = render(_jsx(Alert, {
|
|
192
205
|
variant: "success",
|
|
193
206
|
transition: "none",
|
|
194
|
-
liveRegion: () => liveRegion
|
|
195
|
-
|
|
207
|
+
liveRegion: () => liveRegion,
|
|
208
|
+
children: "Success: Sample alert text."
|
|
209
|
+
})),
|
|
196
210
|
rerender = _render6.rerender,
|
|
197
211
|
container = _render6.container;
|
|
198
212
|
expect(liveRegion.children.length).toBe(1);
|
|
199
213
|
|
|
200
214
|
//set open to false
|
|
201
|
-
rerender(
|
|
215
|
+
rerender(_jsx(Alert, {
|
|
202
216
|
open: false,
|
|
203
217
|
variant: "success",
|
|
204
218
|
transition: "none",
|
|
205
|
-
liveRegion: () => liveRegion
|
|
206
|
-
|
|
219
|
+
liveRegion: () => liveRegion,
|
|
220
|
+
children: "Success: Sample alert text."
|
|
221
|
+
}));
|
|
207
222
|
await waitFor(() => {
|
|
208
223
|
expect(container).not.toHaveTextContent('Success: Sample alert text.');
|
|
209
224
|
expect(liveRegion.children.length).toBe(0);
|
package/es/Alert/index.js
CHANGED
|
@@ -24,8 +24,8 @@ var _dec, _dec2, _class, _Alert;
|
|
|
24
24
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
25
25
|
* SOFTWARE.
|
|
26
26
|
*/
|
|
27
|
-
|
|
28
|
-
import
|
|
27
|
+
|
|
28
|
+
import { Fragment, Component } from 'react';
|
|
29
29
|
import ReactDOM from 'react-dom';
|
|
30
30
|
import keycode from 'keycode';
|
|
31
31
|
import { callRenderProp, withDeterministicId, passthroughProps } from '@instructure/ui-react-utils';
|
|
@@ -35,10 +35,11 @@ import { ScreenReaderContent } from '@instructure/ui-a11y-content';
|
|
|
35
35
|
import { IconCheckMarkSolid, IconInfoBorderlessSolid, IconWarningBorderlessSolid, IconNoSolid } from '@instructure/ui-icons';
|
|
36
36
|
import { Transition } from '@instructure/ui-motion';
|
|
37
37
|
import { logError as error } from '@instructure/console';
|
|
38
|
-
import { withStyle
|
|
38
|
+
import { withStyle } from '@instructure/emotion';
|
|
39
39
|
import generateStyle from './styles';
|
|
40
40
|
import generateComponentTheme from './theme';
|
|
41
41
|
import { propTypes, allowedProps } from './props';
|
|
42
|
+
import { jsx as _jsx, jsxs as _jsxs } from "@emotion/react/jsx-runtime";
|
|
42
43
|
/**
|
|
43
44
|
---
|
|
44
45
|
category: components
|
|
@@ -119,7 +120,9 @@ let Alert = (_dec = withDeterministicId(), _dec2 = withStyle(generateStyle, gene
|
|
|
119
120
|
}
|
|
120
121
|
}
|
|
121
122
|
createScreenreaderContentNode() {
|
|
122
|
-
return
|
|
123
|
+
return _jsx(ScreenReaderContent, {
|
|
124
|
+
children: this.props.children
|
|
125
|
+
});
|
|
123
126
|
}
|
|
124
127
|
createScreenreaderAlert() {
|
|
125
128
|
const liveRegion = this.getLiveRegion();
|
|
@@ -169,21 +172,22 @@ let Alert = (_dec = withDeterministicId(), _dec2 = withStyle(generateStyle, gene
|
|
|
169
172
|
renderIcon() {
|
|
170
173
|
var _this$props$styles;
|
|
171
174
|
const Icon = this.variantUI[this.props.variant];
|
|
172
|
-
return
|
|
173
|
-
css: (_this$props$styles = this.props.styles) === null || _this$props$styles === void 0 ? void 0 : _this$props$styles.icon
|
|
174
|
-
|
|
175
|
+
return _jsx("div", {
|
|
176
|
+
css: (_this$props$styles = this.props.styles) === null || _this$props$styles === void 0 ? void 0 : _this$props$styles.icon,
|
|
177
|
+
children: _jsx(Icon, {})
|
|
178
|
+
});
|
|
175
179
|
}
|
|
176
180
|
renderCloseButton() {
|
|
177
181
|
var _this$props$styles2;
|
|
178
182
|
const closeButtonLabel = this.props.renderCloseButtonLabel && callRenderProp(this.props.renderCloseButtonLabel);
|
|
179
|
-
return closeButtonLabel ?
|
|
183
|
+
return closeButtonLabel ? _jsx("div", {
|
|
180
184
|
css: (_this$props$styles2 = this.props.styles) === null || _this$props$styles2 === void 0 ? void 0 : _this$props$styles2.closeButton,
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
})
|
|
185
|
+
children: _jsx(CloseButton, {
|
|
186
|
+
onClick: this.close,
|
|
187
|
+
size: "small",
|
|
188
|
+
screenReaderLabel: closeButtonLabel
|
|
189
|
+
})
|
|
190
|
+
}, "closeButton") : null;
|
|
187
191
|
}
|
|
188
192
|
renderAlert() {
|
|
189
193
|
const _this$props3 = this.props,
|
|
@@ -191,23 +195,27 @@ let Alert = (_dec = withDeterministicId(), _dec2 = withStyle(generateStyle, gene
|
|
|
191
195
|
styles = _this$props3.styles,
|
|
192
196
|
children = _this$props3.children,
|
|
193
197
|
props = _objectWithoutProperties(_this$props3, _excluded);
|
|
194
|
-
return
|
|
195
|
-
...
|
|
196
|
-
|
|
198
|
+
return _jsxs(View, {
|
|
199
|
+
...passthroughProps({
|
|
200
|
+
...props
|
|
201
|
+
}),
|
|
197
202
|
as: "div",
|
|
198
203
|
margin: margin,
|
|
199
204
|
css: styles === null || styles === void 0 ? void 0 : styles.alert,
|
|
200
205
|
onKeyUp: this.handleKeyUp,
|
|
201
|
-
elementRef: this.handleRef
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
206
|
+
elementRef: this.handleRef,
|
|
207
|
+
children: [this.renderIcon(), _jsx("div", {
|
|
208
|
+
css: styles === null || styles === void 0 ? void 0 : styles.content,
|
|
209
|
+
children: children
|
|
210
|
+
}), this.renderCloseButton()]
|
|
211
|
+
});
|
|
205
212
|
}
|
|
206
213
|
createScreenReaderPortal(liveRegion) {
|
|
207
214
|
const open = this.state.open;
|
|
208
|
-
return open ? /*#__PURE__*/ReactDOM.createPortal(
|
|
209
|
-
id: this.srid
|
|
210
|
-
|
|
215
|
+
return open ? /*#__PURE__*/ReactDOM.createPortal(_jsx("div", {
|
|
216
|
+
id: this.srid,
|
|
217
|
+
children: this.createScreenreaderContentNode()
|
|
218
|
+
}), liveRegion) : null;
|
|
211
219
|
}
|
|
212
220
|
render() {
|
|
213
221
|
const liveRegion = this.getLiveRegion();
|
|
@@ -218,15 +226,20 @@ let Alert = (_dec = withDeterministicId(), _dec2 = withStyle(generateStyle, gene
|
|
|
218
226
|
return screenReaderContent;
|
|
219
227
|
}
|
|
220
228
|
if (this.props.transition === 'none') {
|
|
221
|
-
return this.state.open ?
|
|
229
|
+
return this.state.open ? _jsxs(Fragment, {
|
|
230
|
+
children: [screenReaderContent, this.renderAlert()]
|
|
231
|
+
}) : null;
|
|
222
232
|
}
|
|
223
|
-
return
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
233
|
+
return _jsxs(Fragment, {
|
|
234
|
+
children: [screenReaderContent, _jsx(Transition, {
|
|
235
|
+
type: this.props.transition,
|
|
236
|
+
transitionOnMount: true,
|
|
237
|
+
in: this.state.open,
|
|
238
|
+
unmountOnExit: true,
|
|
239
|
+
onExited: this.onExitTransition,
|
|
240
|
+
children: this.renderAlert()
|
|
241
|
+
})]
|
|
242
|
+
});
|
|
230
243
|
}
|
|
231
244
|
}, _Alert.displayName = "Alert", _Alert.componentId = 'Alert', _Alert.propTypes = propTypes, _Alert.allowedProps = allowedProps, _Alert.defaultProps = {
|
|
232
245
|
variant: 'info',
|
|
@@ -1,8 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
3
|
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
|
|
4
|
-
var _react =
|
|
5
|
-
var _react2 = require("@testing-library/react");
|
|
4
|
+
var _react = require("@testing-library/react");
|
|
6
5
|
var _vitest = require("vitest");
|
|
7
6
|
var _runAxeCheck = require("@instructure/ui-axe-check/lib/runAxeCheck.js");
|
|
8
7
|
require("@testing-library/jest-dom");
|
|
@@ -10,6 +9,7 @@ var _userEvent = _interopRequireDefault(require("@testing-library/user-event"));
|
|
|
10
9
|
var _index = require("../index");
|
|
11
10
|
var _generateA11yTests = require("@instructure/ui-scripts/lib/test/generateA11yTests");
|
|
12
11
|
var _Alert6 = _interopRequireDefault(require("../__examples__/Alert.examples"));
|
|
12
|
+
var _jsxRuntime = require("@emotion/react/jsx-runtime");
|
|
13
13
|
var _Alert, _Alert2, _div, _Alert4, _Alert5;
|
|
14
14
|
/*
|
|
15
15
|
* The MIT License (MIT)
|
|
@@ -59,17 +59,18 @@ describe('<Alert />', () => {
|
|
|
59
59
|
consoleErrorMock.mockRestore();
|
|
60
60
|
});
|
|
61
61
|
it('should render', async () => {
|
|
62
|
-
(0,
|
|
63
|
-
variant: "success"
|
|
64
|
-
|
|
65
|
-
|
|
62
|
+
(0, _react.render)(_Alert || (_Alert = (0, _jsxRuntime.jsx)(_index.Alert, {
|
|
63
|
+
variant: "success",
|
|
64
|
+
children: "Success: Sample alert text."
|
|
65
|
+
})));
|
|
66
|
+
const text = _react.screen.getByText('Success: Sample alert text.');
|
|
66
67
|
expect(text).toBeInTheDocument();
|
|
67
68
|
});
|
|
68
69
|
describe('with generated examples', () => {
|
|
69
70
|
const generatedComponents = (0, _generateA11yTests.generateA11yTests)(_index.Alert, _Alert6.default);
|
|
70
71
|
for (const component of generatedComponents) {
|
|
71
72
|
it(component.description, async () => {
|
|
72
|
-
const _render = (0,
|
|
73
|
+
const _render = (0, _react.render)(component.content),
|
|
73
74
|
container = _render.container;
|
|
74
75
|
const axeCheck = await (0, _runAxeCheck.runAxeCheck)(container);
|
|
75
76
|
expect(axeCheck).toBe(true);
|
|
@@ -77,22 +78,26 @@ describe('<Alert />', () => {
|
|
|
77
78
|
}
|
|
78
79
|
});
|
|
79
80
|
it('should not render the Close button when `renderCloseButtonLabel` is not provided', async () => {
|
|
80
|
-
(0,
|
|
81
|
-
variant: "success"
|
|
82
|
-
|
|
83
|
-
|
|
81
|
+
(0, _react.render)(_Alert2 || (_Alert2 = (0, _jsxRuntime.jsx)(_index.Alert, {
|
|
82
|
+
variant: "success",
|
|
83
|
+
children: "Success: Sample alert text."
|
|
84
|
+
})));
|
|
85
|
+
const closeButton = _react.screen.queryByRole('button');
|
|
84
86
|
expect(closeButton).not.toBeInTheDocument();
|
|
85
87
|
});
|
|
86
88
|
it('should call `onDismiss` when the close button is clicked with renderCloseButtonLabel', async () => {
|
|
87
89
|
const onDismiss = _vitest.vi.fn();
|
|
88
|
-
(0,
|
|
90
|
+
(0, _react.render)((0, _jsxRuntime.jsx)(_index.Alert, {
|
|
89
91
|
variant: "success",
|
|
90
|
-
renderCloseButtonLabel: _div || (_div =
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
92
|
+
renderCloseButtonLabel: _div || (_div = (0, _jsxRuntime.jsx)("div", {
|
|
93
|
+
children: "Close"
|
|
94
|
+
})),
|
|
95
|
+
onDismiss: onDismiss,
|
|
96
|
+
children: "Success: Sample alert text."
|
|
97
|
+
}));
|
|
98
|
+
const closeButton = _react.screen.getByRole('button');
|
|
94
99
|
_userEvent.default.click(closeButton);
|
|
95
|
-
await (0,
|
|
100
|
+
await (0, _react.waitFor)(() => {
|
|
96
101
|
expect(onDismiss).toHaveBeenCalled();
|
|
97
102
|
});
|
|
98
103
|
});
|
|
@@ -105,43 +110,47 @@ describe('<Alert />', () => {
|
|
|
105
110
|
Object.entries(iconComponentsVariants).forEach(([variant, iconComponent]) => {
|
|
106
111
|
var _Alert3;
|
|
107
112
|
it(`"${variant}" variant should have icon "${iconComponent}".`, async () => {
|
|
108
|
-
const _render2 = (0,
|
|
113
|
+
const _render2 = (0, _react.render)(_Alert3 || (_Alert3 = (0, _jsxRuntime.jsx)(_index.Alert, {
|
|
109
114
|
variant: variant,
|
|
110
|
-
transition: "none"
|
|
111
|
-
|
|
115
|
+
transition: "none",
|
|
116
|
+
children: "Success: Sample alert text."
|
|
117
|
+
}))),
|
|
112
118
|
container = _render2.container;
|
|
113
119
|
const icon = container.querySelector('svg[class$="-svgIcon"]');
|
|
114
120
|
expect(icon).toHaveAttribute('name', iconComponent);
|
|
115
121
|
});
|
|
116
122
|
});
|
|
117
123
|
it('should meet a11y standards', async () => {
|
|
118
|
-
const _render3 = (0,
|
|
124
|
+
const _render3 = (0, _react.render)(_Alert4 || (_Alert4 = (0, _jsxRuntime.jsx)(_index.Alert, {
|
|
119
125
|
variant: "success",
|
|
120
|
-
transition: "none"
|
|
121
|
-
|
|
126
|
+
transition: "none",
|
|
127
|
+
children: "Success: Sample alert text."
|
|
128
|
+
}))),
|
|
122
129
|
container = _render3.container;
|
|
123
130
|
const axeCheck = await (0, _runAxeCheck.runAxeCheck)(container);
|
|
124
131
|
expect(axeCheck).toBe(true);
|
|
125
132
|
});
|
|
126
133
|
it('should add alert text to aria live region, when present', async () => {
|
|
127
134
|
const liveRegion = document.getElementById('_alertLiveRegion');
|
|
128
|
-
(0,
|
|
135
|
+
(0, _react.render)((0, _jsxRuntime.jsx)(_index.Alert, {
|
|
129
136
|
variant: "success",
|
|
130
137
|
transition: "none",
|
|
131
138
|
liveRegion: () => liveRegion,
|
|
132
|
-
liveRegionPoliteness: "polite"
|
|
133
|
-
|
|
139
|
+
liveRegionPoliteness: "polite",
|
|
140
|
+
children: "Success: Sample alert text."
|
|
141
|
+
}));
|
|
134
142
|
expect(liveRegion).toHaveTextContent('Success: Sample alert text.');
|
|
135
143
|
expect(liveRegion).toHaveAttribute('aria-live', 'polite');
|
|
136
144
|
});
|
|
137
145
|
describe('with `screenReaderOnly', () => {
|
|
138
146
|
it('should not render anything when using `liveRegion`', async () => {
|
|
139
147
|
const liveRegion = document.getElementById('_alertLiveRegion');
|
|
140
|
-
const _render4 = (0,
|
|
148
|
+
const _render4 = (0, _react.render)((0, _jsxRuntime.jsx)(_index.Alert, {
|
|
141
149
|
variant: "success",
|
|
142
150
|
liveRegion: () => liveRegion,
|
|
143
|
-
screenReaderOnly: true
|
|
144
|
-
|
|
151
|
+
screenReaderOnly: true,
|
|
152
|
+
children: "Success: Sample alert text. asdsfds"
|
|
153
|
+
})),
|
|
145
154
|
container = _render4.container;
|
|
146
155
|
expect(container.children.length).toBe(0);
|
|
147
156
|
expect(liveRegion.children.length).toBe(1);
|
|
@@ -149,64 +158,70 @@ describe('<Alert />', () => {
|
|
|
149
158
|
it('should warn if `liveRegion` is not defined', async () => {
|
|
150
159
|
const consoleWarningSpy = _vitest.vi.spyOn(console, 'error').mockImplementation(() => {});
|
|
151
160
|
const warning = "Warning: [Alert] The 'screenReaderOnly' prop must be used in conjunction with 'liveRegion'.";
|
|
152
|
-
(0,
|
|
161
|
+
(0, _react.render)(_Alert5 || (_Alert5 = (0, _jsxRuntime.jsx)(_index.Alert, {
|
|
153
162
|
variant: "success",
|
|
154
|
-
screenReaderOnly: true
|
|
155
|
-
|
|
156
|
-
|
|
163
|
+
screenReaderOnly: true,
|
|
164
|
+
children: "Success: Sample alert text."
|
|
165
|
+
})));
|
|
166
|
+
await (0, _react.waitFor)(() => {
|
|
157
167
|
expect(consoleWarningSpy.mock.calls[0][0]).toEqual(expect.stringContaining(warning));
|
|
158
168
|
});
|
|
159
169
|
});
|
|
160
170
|
it('should set aria-atomic to the aria live region when isLiveRegionAtomic is present', async () => {
|
|
161
171
|
const liveRegion = document.getElementById('_alertLiveRegion');
|
|
162
|
-
(0,
|
|
172
|
+
(0, _react.render)((0, _jsxRuntime.jsx)(_index.Alert, {
|
|
163
173
|
variant: "success",
|
|
164
174
|
transition: "none",
|
|
165
175
|
liveRegion: () => liveRegion,
|
|
166
176
|
liveRegionPoliteness: "polite",
|
|
167
|
-
isLiveRegionAtomic: true
|
|
168
|
-
|
|
177
|
+
isLiveRegionAtomic: true,
|
|
178
|
+
children: "Success: Sample alert text."
|
|
179
|
+
}));
|
|
169
180
|
expect(liveRegion).toHaveTextContent('Success: Sample alert text.');
|
|
170
181
|
expect(liveRegion).toHaveAttribute('aria-atomic', 'true');
|
|
171
182
|
});
|
|
172
183
|
it('should close when told to, with transition', async () => {
|
|
173
184
|
const liveRegion = document.getElementById('_alertLiveRegion');
|
|
174
|
-
const _render5 = (0,
|
|
185
|
+
const _render5 = (0, _react.render)((0, _jsxRuntime.jsx)(_index.Alert, {
|
|
175
186
|
variant: "success",
|
|
176
|
-
liveRegion: () => liveRegion
|
|
177
|
-
|
|
187
|
+
liveRegion: () => liveRegion,
|
|
188
|
+
children: "Success: Sample alert text."
|
|
189
|
+
})),
|
|
178
190
|
rerender = _render5.rerender;
|
|
179
191
|
expect(liveRegion.children.length).toBe(1);
|
|
180
192
|
|
|
181
193
|
//set open to false
|
|
182
|
-
rerender(
|
|
194
|
+
rerender((0, _jsxRuntime.jsx)(_index.Alert, {
|
|
183
195
|
variant: "success",
|
|
184
196
|
open: false,
|
|
185
|
-
liveRegion: () => liveRegion
|
|
186
|
-
|
|
187
|
-
|
|
197
|
+
liveRegion: () => liveRegion,
|
|
198
|
+
children: "Success: Sample alert text."
|
|
199
|
+
}));
|
|
200
|
+
await (0, _react.waitFor)(() => {
|
|
188
201
|
expect(liveRegion.children.length).toBe(0);
|
|
189
202
|
});
|
|
190
203
|
});
|
|
191
204
|
it('should close when told to, without transition', async () => {
|
|
192
205
|
const liveRegion = document.getElementById('_alertLiveRegion');
|
|
193
|
-
const _render6 = (0,
|
|
206
|
+
const _render6 = (0, _react.render)((0, _jsxRuntime.jsx)(_index.Alert, {
|
|
194
207
|
variant: "success",
|
|
195
208
|
transition: "none",
|
|
196
|
-
liveRegion: () => liveRegion
|
|
197
|
-
|
|
209
|
+
liveRegion: () => liveRegion,
|
|
210
|
+
children: "Success: Sample alert text."
|
|
211
|
+
})),
|
|
198
212
|
rerender = _render6.rerender,
|
|
199
213
|
container = _render6.container;
|
|
200
214
|
expect(liveRegion.children.length).toBe(1);
|
|
201
215
|
|
|
202
216
|
//set open to false
|
|
203
|
-
rerender(
|
|
217
|
+
rerender((0, _jsxRuntime.jsx)(_index.Alert, {
|
|
204
218
|
open: false,
|
|
205
219
|
variant: "success",
|
|
206
220
|
transition: "none",
|
|
207
|
-
liveRegion: () => liveRegion
|
|
208
|
-
|
|
209
|
-
|
|
221
|
+
liveRegion: () => liveRegion,
|
|
222
|
+
children: "Success: Sample alert text."
|
|
223
|
+
}));
|
|
224
|
+
await (0, _react.waitFor)(() => {
|
|
210
225
|
expect(container).not.toHaveTextContent('Success: Sample alert text.');
|
|
211
226
|
expect(liveRegion.children.length).toBe(0);
|
|
212
227
|
});
|