@instructure/ui-alerts 10.2.1 → 10.2.2-snapshot-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 +8 -0
- package/es/Alert/__new-tests__/Alert.test.js +213 -0
- package/lib/Alert/__new-tests__/Alert.test.js +215 -0
- package/package.json +20 -14
- package/src/Alert/__new-tests__/Alert.test.tsx +275 -0
- package/tsconfig.build.json +2 -0
- package/tsconfig.build.tsbuildinfo +1 -1
- package/types/Alert/__new-tests__/Alert.test.d.ts +2 -0
- package/types/Alert/__new-tests__/Alert.test.d.ts.map +1 -0
package/CHANGELOG.md
CHANGED
|
@@ -3,6 +3,14 @@
|
|
|
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.2.2-snapshot-1](https://github.com/instructure/instructure-ui/compare/v10.2.1...v10.2.2-snapshot-1) (2024-09-03)
|
|
7
|
+
|
|
8
|
+
**Note:** Version bump only for package @instructure/ui-alerts
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
|
|
6
14
|
## [10.2.1](https://github.com/instructure/instructure-ui/compare/v10.2.0...v10.2.1) (2024-08-30)
|
|
7
15
|
|
|
8
16
|
**Note:** Version bump only for package @instructure/ui-alerts
|
|
@@ -0,0 +1,213 @@
|
|
|
1
|
+
var _Alert, _Alert2, _div, _Alert4, _Alert5;
|
|
2
|
+
/*
|
|
3
|
+
* The MIT License (MIT)
|
|
4
|
+
*
|
|
5
|
+
* Copyright (c) 2015 - present Instructure, Inc.
|
|
6
|
+
*
|
|
7
|
+
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
8
|
+
* of this software and associated documentation files (the "Software"), to deal
|
|
9
|
+
* in the Software without restriction, including without limitation the rights
|
|
10
|
+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
11
|
+
* copies of the Software, and to permit persons to whom the Software is
|
|
12
|
+
* furnished to do so, subject to the following conditions:
|
|
13
|
+
*
|
|
14
|
+
* The above copyright notice and this permission notice shall be included in all
|
|
15
|
+
* copies or substantial portions of the Software.
|
|
16
|
+
*
|
|
17
|
+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
18
|
+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
19
|
+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
20
|
+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
21
|
+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
22
|
+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
23
|
+
* SOFTWARE.
|
|
24
|
+
*/
|
|
25
|
+
|
|
26
|
+
import React from 'react';
|
|
27
|
+
import { render, screen, waitFor } from '@testing-library/react';
|
|
28
|
+
import { vi } from 'vitest';
|
|
29
|
+
import { runAxeCheck } from '@instructure/ui-axe-check';
|
|
30
|
+
import '@testing-library/jest-dom';
|
|
31
|
+
import userEvent from '@testing-library/user-event';
|
|
32
|
+
import { Alert } from '../index';
|
|
33
|
+
// eslint-disable-next-line no-restricted-imports
|
|
34
|
+
import { generateA11yTests } from '@instructure/ui-scripts/lib/test/generateA11yTests';
|
|
35
|
+
import AlertExamples from '../__examples__/Alert.examples';
|
|
36
|
+
describe('<Alert />', () => {
|
|
37
|
+
let srdiv;
|
|
38
|
+
let consoleWarningMock;
|
|
39
|
+
let consoleErrorMock;
|
|
40
|
+
beforeEach(async () => {
|
|
41
|
+
// Mocking console to prevent test output pollution and expect
|
|
42
|
+
consoleWarningMock = vi.spyOn(console, 'warn').mockImplementation(() => {});
|
|
43
|
+
consoleErrorMock = vi.spyOn(console, 'error').mockImplementation(() => {});
|
|
44
|
+
srdiv = document.createElement('div');
|
|
45
|
+
srdiv.id = '_alertLiveRegion';
|
|
46
|
+
srdiv.setAttribute('role', 'alert');
|
|
47
|
+
srdiv.setAttribute('aria-live', 'assertive');
|
|
48
|
+
srdiv.setAttribute('aria-relevant', 'additions text');
|
|
49
|
+
srdiv.setAttribute('aria-atomic', 'false');
|
|
50
|
+
document.body.appendChild(srdiv);
|
|
51
|
+
});
|
|
52
|
+
afterEach(async () => {
|
|
53
|
+
var _srdiv, _srdiv$parentNode;
|
|
54
|
+
(_srdiv = srdiv) === null || _srdiv === void 0 ? void 0 : (_srdiv$parentNode = _srdiv.parentNode) === null || _srdiv$parentNode === void 0 ? void 0 : _srdiv$parentNode.removeChild(srdiv);
|
|
55
|
+
srdiv = null;
|
|
56
|
+
consoleWarningMock.mockRestore();
|
|
57
|
+
consoleErrorMock.mockRestore();
|
|
58
|
+
});
|
|
59
|
+
it('should render', async () => {
|
|
60
|
+
render(_Alert || (_Alert = /*#__PURE__*/React.createElement(Alert, {
|
|
61
|
+
variant: "success"
|
|
62
|
+
}, "Success: Sample alert text.")));
|
|
63
|
+
const text = screen.getByText('Success: Sample alert text.');
|
|
64
|
+
expect(text).toBeInTheDocument();
|
|
65
|
+
});
|
|
66
|
+
describe('with generated examples', () => {
|
|
67
|
+
const generatedComponents = generateA11yTests(Alert, AlertExamples);
|
|
68
|
+
for (const component of generatedComponents) {
|
|
69
|
+
it(component.description, async () => {
|
|
70
|
+
const _render = render(component.content),
|
|
71
|
+
container = _render.container;
|
|
72
|
+
const axeCheck = await runAxeCheck(container);
|
|
73
|
+
expect(axeCheck).toBe(true);
|
|
74
|
+
});
|
|
75
|
+
}
|
|
76
|
+
});
|
|
77
|
+
it('should not render the Close button when `renderCloseButtonLabel` is not provided', async () => {
|
|
78
|
+
render(_Alert2 || (_Alert2 = /*#__PURE__*/React.createElement(Alert, {
|
|
79
|
+
variant: "success"
|
|
80
|
+
}, "Success: Sample alert text.")));
|
|
81
|
+
const closeButton = screen.queryByRole('button');
|
|
82
|
+
expect(closeButton).not.toBeInTheDocument();
|
|
83
|
+
});
|
|
84
|
+
it('should call `onDismiss` when the close button is clicked with renderCloseButtonLabel', async () => {
|
|
85
|
+
const onDismiss = vi.fn();
|
|
86
|
+
render( /*#__PURE__*/React.createElement(Alert, {
|
|
87
|
+
variant: "success",
|
|
88
|
+
renderCloseButtonLabel: _div || (_div = /*#__PURE__*/React.createElement("div", null, "Close")),
|
|
89
|
+
onDismiss: onDismiss
|
|
90
|
+
}, "Success: Sample alert text."));
|
|
91
|
+
const closeButton = screen.getByRole('button');
|
|
92
|
+
userEvent.click(closeButton);
|
|
93
|
+
await waitFor(() => {
|
|
94
|
+
expect(onDismiss).toHaveBeenCalled();
|
|
95
|
+
});
|
|
96
|
+
});
|
|
97
|
+
const iconComponentsVariants = {
|
|
98
|
+
error: 'IconNo',
|
|
99
|
+
info: 'IconInfoBorderless',
|
|
100
|
+
success: 'IconCheckMark',
|
|
101
|
+
warning: 'IconWarningBorderless'
|
|
102
|
+
};
|
|
103
|
+
Object.entries(iconComponentsVariants).forEach(([variant, iconComponent]) => {
|
|
104
|
+
var _Alert3;
|
|
105
|
+
it(`"${variant}" variant should have icon "${iconComponent}".`, async () => {
|
|
106
|
+
const _render2 = render(_Alert3 || (_Alert3 = /*#__PURE__*/React.createElement(Alert, {
|
|
107
|
+
variant: variant,
|
|
108
|
+
transition: "none"
|
|
109
|
+
}, "Success: Sample alert text."))),
|
|
110
|
+
container = _render2.container;
|
|
111
|
+
const icon = container.querySelector('svg[class$="-svgIcon"]');
|
|
112
|
+
expect(icon).toHaveAttribute('name', iconComponent);
|
|
113
|
+
});
|
|
114
|
+
});
|
|
115
|
+
it('should meet a11y standards', async () => {
|
|
116
|
+
const _render3 = render(_Alert4 || (_Alert4 = /*#__PURE__*/React.createElement(Alert, {
|
|
117
|
+
variant: "success",
|
|
118
|
+
transition: "none"
|
|
119
|
+
}, "Success: Sample alert text."))),
|
|
120
|
+
container = _render3.container;
|
|
121
|
+
const axeCheck = await runAxeCheck(container);
|
|
122
|
+
expect(axeCheck).toBe(true);
|
|
123
|
+
});
|
|
124
|
+
it('should add alert text to aria live region, when present', async () => {
|
|
125
|
+
const liveRegion = document.getElementById('_alertLiveRegion');
|
|
126
|
+
render( /*#__PURE__*/React.createElement(Alert, {
|
|
127
|
+
variant: "success",
|
|
128
|
+
transition: "none",
|
|
129
|
+
liveRegion: () => liveRegion,
|
|
130
|
+
liveRegionPoliteness: "polite"
|
|
131
|
+
}, "Success: Sample alert text."));
|
|
132
|
+
expect(liveRegion).toHaveTextContent('Success: Sample alert text.');
|
|
133
|
+
expect(liveRegion).toHaveAttribute('aria-live', 'polite');
|
|
134
|
+
});
|
|
135
|
+
describe('with `screenReaderOnly', () => {
|
|
136
|
+
it('should not render anything when using `liveRegion`', async () => {
|
|
137
|
+
const liveRegion = document.getElementById('_alertLiveRegion');
|
|
138
|
+
const _render4 = render( /*#__PURE__*/React.createElement(Alert, {
|
|
139
|
+
variant: "success",
|
|
140
|
+
liveRegion: () => liveRegion,
|
|
141
|
+
screenReaderOnly: true
|
|
142
|
+
}, "Success: Sample alert text. asdsfds")),
|
|
143
|
+
container = _render4.container;
|
|
144
|
+
expect(container.children.length).toBe(0);
|
|
145
|
+
expect(liveRegion.children.length).toBe(1);
|
|
146
|
+
});
|
|
147
|
+
it('should warn if `liveRegion` is not defined', async () => {
|
|
148
|
+
const consoleWarningSpy = vi.spyOn(console, 'error').mockImplementation(() => {});
|
|
149
|
+
const warning = "Warning: [Alert] The 'screenReaderOnly' prop must be used in conjunction with 'liveRegion'.";
|
|
150
|
+
render(_Alert5 || (_Alert5 = /*#__PURE__*/React.createElement(Alert, {
|
|
151
|
+
variant: "success",
|
|
152
|
+
screenReaderOnly: true
|
|
153
|
+
}, "Success: Sample alert text.")));
|
|
154
|
+
await waitFor(() => {
|
|
155
|
+
expect(consoleWarningSpy.mock.calls[0][0]).toEqual(expect.stringContaining(warning));
|
|
156
|
+
});
|
|
157
|
+
});
|
|
158
|
+
it('should set aria-atomic to the aria live region when isLiveRegionAtomic is present', async () => {
|
|
159
|
+
const liveRegion = document.getElementById('_alertLiveRegion');
|
|
160
|
+
render( /*#__PURE__*/React.createElement(Alert, {
|
|
161
|
+
variant: "success",
|
|
162
|
+
transition: "none",
|
|
163
|
+
liveRegion: () => liveRegion,
|
|
164
|
+
liveRegionPoliteness: "polite",
|
|
165
|
+
isLiveRegionAtomic: true
|
|
166
|
+
}, "Success: Sample alert text."));
|
|
167
|
+
expect(liveRegion).toHaveTextContent('Success: Sample alert text.');
|
|
168
|
+
expect(liveRegion).toHaveAttribute('aria-atomic', 'true');
|
|
169
|
+
});
|
|
170
|
+
it('should close when told to, with transition', async () => {
|
|
171
|
+
const liveRegion = document.getElementById('_alertLiveRegion');
|
|
172
|
+
const _render5 = render( /*#__PURE__*/React.createElement(Alert, {
|
|
173
|
+
variant: "success",
|
|
174
|
+
liveRegion: () => liveRegion
|
|
175
|
+
}, "Success: Sample alert text.")),
|
|
176
|
+
rerender = _render5.rerender;
|
|
177
|
+
expect(liveRegion.children.length).toBe(1);
|
|
178
|
+
|
|
179
|
+
//set open to false
|
|
180
|
+
rerender( /*#__PURE__*/React.createElement(Alert, {
|
|
181
|
+
variant: "success",
|
|
182
|
+
open: false,
|
|
183
|
+
liveRegion: () => liveRegion
|
|
184
|
+
}, "Success: Sample alert text."));
|
|
185
|
+
await waitFor(() => {
|
|
186
|
+
expect(liveRegion.children.length).toBe(0);
|
|
187
|
+
});
|
|
188
|
+
});
|
|
189
|
+
it('should close when told to, without transition', async () => {
|
|
190
|
+
const liveRegion = document.getElementById('_alertLiveRegion');
|
|
191
|
+
const _render6 = render( /*#__PURE__*/React.createElement(Alert, {
|
|
192
|
+
variant: "success",
|
|
193
|
+
transition: "none",
|
|
194
|
+
liveRegion: () => liveRegion
|
|
195
|
+
}, "Success: Sample alert text.")),
|
|
196
|
+
rerender = _render6.rerender,
|
|
197
|
+
container = _render6.container;
|
|
198
|
+
expect(liveRegion.children.length).toBe(1);
|
|
199
|
+
|
|
200
|
+
//set open to false
|
|
201
|
+
rerender( /*#__PURE__*/React.createElement(Alert, {
|
|
202
|
+
open: false,
|
|
203
|
+
variant: "success",
|
|
204
|
+
transition: "none",
|
|
205
|
+
liveRegion: () => liveRegion
|
|
206
|
+
}, "Success: Sample alert text."));
|
|
207
|
+
await waitFor(() => {
|
|
208
|
+
expect(container).not.toHaveTextContent('Success: Sample alert text.');
|
|
209
|
+
expect(liveRegion.children.length).toBe(0);
|
|
210
|
+
});
|
|
211
|
+
});
|
|
212
|
+
});
|
|
213
|
+
});
|
|
@@ -0,0 +1,215 @@
|
|
|
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
|
+
var _vitest = require("vitest");
|
|
7
|
+
var _runAxeCheck = require("@instructure/ui-axe-check/lib/runAxeCheck.js");
|
|
8
|
+
require("@testing-library/jest-dom");
|
|
9
|
+
var _userEvent = _interopRequireDefault(require("@testing-library/user-event"));
|
|
10
|
+
var _index = require("../index");
|
|
11
|
+
var _generateA11yTests = require("@instructure/ui-scripts/lib/test/generateA11yTests");
|
|
12
|
+
var _Alert6 = _interopRequireDefault(require("../__examples__/Alert.examples"));
|
|
13
|
+
var _Alert, _Alert2, _div, _Alert4, _Alert5;
|
|
14
|
+
/*
|
|
15
|
+
* The MIT License (MIT)
|
|
16
|
+
*
|
|
17
|
+
* Copyright (c) 2015 - present Instructure, Inc.
|
|
18
|
+
*
|
|
19
|
+
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
20
|
+
* of this software and associated documentation files (the "Software"), to deal
|
|
21
|
+
* in the Software without restriction, including without limitation the rights
|
|
22
|
+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
23
|
+
* copies of the Software, and to permit persons to whom the Software is
|
|
24
|
+
* furnished to do so, subject to the following conditions:
|
|
25
|
+
*
|
|
26
|
+
* The above copyright notice and this permission notice shall be included in all
|
|
27
|
+
* copies or substantial portions of the Software.
|
|
28
|
+
*
|
|
29
|
+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
30
|
+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
31
|
+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
32
|
+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
33
|
+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
34
|
+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
35
|
+
* SOFTWARE.
|
|
36
|
+
*/
|
|
37
|
+
// eslint-disable-next-line no-restricted-imports
|
|
38
|
+
describe('<Alert />', () => {
|
|
39
|
+
let srdiv;
|
|
40
|
+
let consoleWarningMock;
|
|
41
|
+
let consoleErrorMock;
|
|
42
|
+
beforeEach(async () => {
|
|
43
|
+
// Mocking console to prevent test output pollution and expect
|
|
44
|
+
consoleWarningMock = _vitest.vi.spyOn(console, 'warn').mockImplementation(() => {});
|
|
45
|
+
consoleErrorMock = _vitest.vi.spyOn(console, 'error').mockImplementation(() => {});
|
|
46
|
+
srdiv = document.createElement('div');
|
|
47
|
+
srdiv.id = '_alertLiveRegion';
|
|
48
|
+
srdiv.setAttribute('role', 'alert');
|
|
49
|
+
srdiv.setAttribute('aria-live', 'assertive');
|
|
50
|
+
srdiv.setAttribute('aria-relevant', 'additions text');
|
|
51
|
+
srdiv.setAttribute('aria-atomic', 'false');
|
|
52
|
+
document.body.appendChild(srdiv);
|
|
53
|
+
});
|
|
54
|
+
afterEach(async () => {
|
|
55
|
+
var _srdiv, _srdiv$parentNode;
|
|
56
|
+
(_srdiv = srdiv) === null || _srdiv === void 0 ? void 0 : (_srdiv$parentNode = _srdiv.parentNode) === null || _srdiv$parentNode === void 0 ? void 0 : _srdiv$parentNode.removeChild(srdiv);
|
|
57
|
+
srdiv = null;
|
|
58
|
+
consoleWarningMock.mockRestore();
|
|
59
|
+
consoleErrorMock.mockRestore();
|
|
60
|
+
});
|
|
61
|
+
it('should render', async () => {
|
|
62
|
+
(0, _react2.render)(_Alert || (_Alert = /*#__PURE__*/_react.default.createElement(_index.Alert, {
|
|
63
|
+
variant: "success"
|
|
64
|
+
}, "Success: Sample alert text.")));
|
|
65
|
+
const text = _react2.screen.getByText('Success: Sample alert text.');
|
|
66
|
+
expect(text).toBeInTheDocument();
|
|
67
|
+
});
|
|
68
|
+
describe('with generated examples', () => {
|
|
69
|
+
const generatedComponents = (0, _generateA11yTests.generateA11yTests)(_index.Alert, _Alert6.default);
|
|
70
|
+
for (const component of generatedComponents) {
|
|
71
|
+
it(component.description, async () => {
|
|
72
|
+
const _render = (0, _react2.render)(component.content),
|
|
73
|
+
container = _render.container;
|
|
74
|
+
const axeCheck = await (0, _runAxeCheck.runAxeCheck)(container);
|
|
75
|
+
expect(axeCheck).toBe(true);
|
|
76
|
+
});
|
|
77
|
+
}
|
|
78
|
+
});
|
|
79
|
+
it('should not render the Close button when `renderCloseButtonLabel` is not provided', async () => {
|
|
80
|
+
(0, _react2.render)(_Alert2 || (_Alert2 = /*#__PURE__*/_react.default.createElement(_index.Alert, {
|
|
81
|
+
variant: "success"
|
|
82
|
+
}, "Success: Sample alert text.")));
|
|
83
|
+
const closeButton = _react2.screen.queryByRole('button');
|
|
84
|
+
expect(closeButton).not.toBeInTheDocument();
|
|
85
|
+
});
|
|
86
|
+
it('should call `onDismiss` when the close button is clicked with renderCloseButtonLabel', async () => {
|
|
87
|
+
const onDismiss = _vitest.vi.fn();
|
|
88
|
+
(0, _react2.render)( /*#__PURE__*/_react.default.createElement(_index.Alert, {
|
|
89
|
+
variant: "success",
|
|
90
|
+
renderCloseButtonLabel: _div || (_div = /*#__PURE__*/_react.default.createElement("div", null, "Close")),
|
|
91
|
+
onDismiss: onDismiss
|
|
92
|
+
}, "Success: Sample alert text."));
|
|
93
|
+
const closeButton = _react2.screen.getByRole('button');
|
|
94
|
+
_userEvent.default.click(closeButton);
|
|
95
|
+
await (0, _react2.waitFor)(() => {
|
|
96
|
+
expect(onDismiss).toHaveBeenCalled();
|
|
97
|
+
});
|
|
98
|
+
});
|
|
99
|
+
const iconComponentsVariants = {
|
|
100
|
+
error: 'IconNo',
|
|
101
|
+
info: 'IconInfoBorderless',
|
|
102
|
+
success: 'IconCheckMark',
|
|
103
|
+
warning: 'IconWarningBorderless'
|
|
104
|
+
};
|
|
105
|
+
Object.entries(iconComponentsVariants).forEach(([variant, iconComponent]) => {
|
|
106
|
+
var _Alert3;
|
|
107
|
+
it(`"${variant}" variant should have icon "${iconComponent}".`, async () => {
|
|
108
|
+
const _render2 = (0, _react2.render)(_Alert3 || (_Alert3 = /*#__PURE__*/_react.default.createElement(_index.Alert, {
|
|
109
|
+
variant: variant,
|
|
110
|
+
transition: "none"
|
|
111
|
+
}, "Success: Sample alert text."))),
|
|
112
|
+
container = _render2.container;
|
|
113
|
+
const icon = container.querySelector('svg[class$="-svgIcon"]');
|
|
114
|
+
expect(icon).toHaveAttribute('name', iconComponent);
|
|
115
|
+
});
|
|
116
|
+
});
|
|
117
|
+
it('should meet a11y standards', async () => {
|
|
118
|
+
const _render3 = (0, _react2.render)(_Alert4 || (_Alert4 = /*#__PURE__*/_react.default.createElement(_index.Alert, {
|
|
119
|
+
variant: "success",
|
|
120
|
+
transition: "none"
|
|
121
|
+
}, "Success: Sample alert text."))),
|
|
122
|
+
container = _render3.container;
|
|
123
|
+
const axeCheck = await (0, _runAxeCheck.runAxeCheck)(container);
|
|
124
|
+
expect(axeCheck).toBe(true);
|
|
125
|
+
});
|
|
126
|
+
it('should add alert text to aria live region, when present', async () => {
|
|
127
|
+
const liveRegion = document.getElementById('_alertLiveRegion');
|
|
128
|
+
(0, _react2.render)( /*#__PURE__*/_react.default.createElement(_index.Alert, {
|
|
129
|
+
variant: "success",
|
|
130
|
+
transition: "none",
|
|
131
|
+
liveRegion: () => liveRegion,
|
|
132
|
+
liveRegionPoliteness: "polite"
|
|
133
|
+
}, "Success: Sample alert text."));
|
|
134
|
+
expect(liveRegion).toHaveTextContent('Success: Sample alert text.');
|
|
135
|
+
expect(liveRegion).toHaveAttribute('aria-live', 'polite');
|
|
136
|
+
});
|
|
137
|
+
describe('with `screenReaderOnly', () => {
|
|
138
|
+
it('should not render anything when using `liveRegion`', async () => {
|
|
139
|
+
const liveRegion = document.getElementById('_alertLiveRegion');
|
|
140
|
+
const _render4 = (0, _react2.render)( /*#__PURE__*/_react.default.createElement(_index.Alert, {
|
|
141
|
+
variant: "success",
|
|
142
|
+
liveRegion: () => liveRegion,
|
|
143
|
+
screenReaderOnly: true
|
|
144
|
+
}, "Success: Sample alert text. asdsfds")),
|
|
145
|
+
container = _render4.container;
|
|
146
|
+
expect(container.children.length).toBe(0);
|
|
147
|
+
expect(liveRegion.children.length).toBe(1);
|
|
148
|
+
});
|
|
149
|
+
it('should warn if `liveRegion` is not defined', async () => {
|
|
150
|
+
const consoleWarningSpy = _vitest.vi.spyOn(console, 'error').mockImplementation(() => {});
|
|
151
|
+
const warning = "Warning: [Alert] The 'screenReaderOnly' prop must be used in conjunction with 'liveRegion'.";
|
|
152
|
+
(0, _react2.render)(_Alert5 || (_Alert5 = /*#__PURE__*/_react.default.createElement(_index.Alert, {
|
|
153
|
+
variant: "success",
|
|
154
|
+
screenReaderOnly: true
|
|
155
|
+
}, "Success: Sample alert text.")));
|
|
156
|
+
await (0, _react2.waitFor)(() => {
|
|
157
|
+
expect(consoleWarningSpy.mock.calls[0][0]).toEqual(expect.stringContaining(warning));
|
|
158
|
+
});
|
|
159
|
+
});
|
|
160
|
+
it('should set aria-atomic to the aria live region when isLiveRegionAtomic is present', async () => {
|
|
161
|
+
const liveRegion = document.getElementById('_alertLiveRegion');
|
|
162
|
+
(0, _react2.render)( /*#__PURE__*/_react.default.createElement(_index.Alert, {
|
|
163
|
+
variant: "success",
|
|
164
|
+
transition: "none",
|
|
165
|
+
liveRegion: () => liveRegion,
|
|
166
|
+
liveRegionPoliteness: "polite",
|
|
167
|
+
isLiveRegionAtomic: true
|
|
168
|
+
}, "Success: Sample alert text."));
|
|
169
|
+
expect(liveRegion).toHaveTextContent('Success: Sample alert text.');
|
|
170
|
+
expect(liveRegion).toHaveAttribute('aria-atomic', 'true');
|
|
171
|
+
});
|
|
172
|
+
it('should close when told to, with transition', async () => {
|
|
173
|
+
const liveRegion = document.getElementById('_alertLiveRegion');
|
|
174
|
+
const _render5 = (0, _react2.render)( /*#__PURE__*/_react.default.createElement(_index.Alert, {
|
|
175
|
+
variant: "success",
|
|
176
|
+
liveRegion: () => liveRegion
|
|
177
|
+
}, "Success: Sample alert text.")),
|
|
178
|
+
rerender = _render5.rerender;
|
|
179
|
+
expect(liveRegion.children.length).toBe(1);
|
|
180
|
+
|
|
181
|
+
//set open to false
|
|
182
|
+
rerender( /*#__PURE__*/_react.default.createElement(_index.Alert, {
|
|
183
|
+
variant: "success",
|
|
184
|
+
open: false,
|
|
185
|
+
liveRegion: () => liveRegion
|
|
186
|
+
}, "Success: Sample alert text."));
|
|
187
|
+
await (0, _react2.waitFor)(() => {
|
|
188
|
+
expect(liveRegion.children.length).toBe(0);
|
|
189
|
+
});
|
|
190
|
+
});
|
|
191
|
+
it('should close when told to, without transition', async () => {
|
|
192
|
+
const liveRegion = document.getElementById('_alertLiveRegion');
|
|
193
|
+
const _render6 = (0, _react2.render)( /*#__PURE__*/_react.default.createElement(_index.Alert, {
|
|
194
|
+
variant: "success",
|
|
195
|
+
transition: "none",
|
|
196
|
+
liveRegion: () => liveRegion
|
|
197
|
+
}, "Success: Sample alert text.")),
|
|
198
|
+
rerender = _render6.rerender,
|
|
199
|
+
container = _render6.container;
|
|
200
|
+
expect(liveRegion.children.length).toBe(1);
|
|
201
|
+
|
|
202
|
+
//set open to false
|
|
203
|
+
rerender( /*#__PURE__*/_react.default.createElement(_index.Alert, {
|
|
204
|
+
open: false,
|
|
205
|
+
variant: "success",
|
|
206
|
+
transition: "none",
|
|
207
|
+
liveRegion: () => liveRegion
|
|
208
|
+
}, "Success: Sample alert text."));
|
|
209
|
+
await (0, _react2.waitFor)(() => {
|
|
210
|
+
expect(container).not.toHaveTextContent('Success: Sample alert text.');
|
|
211
|
+
expect(liveRegion.children.length).toBe(0);
|
|
212
|
+
});
|
|
213
|
+
});
|
|
214
|
+
});
|
|
215
|
+
});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@instructure/ui-alerts",
|
|
3
|
-
"version": "10.2.1",
|
|
3
|
+
"version": "10.2.2-snapshot-1",
|
|
4
4
|
"description": "An alert component",
|
|
5
5
|
"author": "Instructure, Inc. Engineering and Product Design",
|
|
6
6
|
"module": "./es/index.js",
|
|
@@ -23,22 +23,28 @@
|
|
|
23
23
|
},
|
|
24
24
|
"license": "MIT",
|
|
25
25
|
"devDependencies": {
|
|
26
|
-
"@instructure/ui-
|
|
27
|
-
"@instructure/ui-
|
|
28
|
-
"@instructure/ui-
|
|
26
|
+
"@instructure/ui-axe-check": "10.2.2-snapshot-1",
|
|
27
|
+
"@instructure/ui-babel-preset": "10.2.2-snapshot-1",
|
|
28
|
+
"@instructure/ui-color-utils": "10.2.2-snapshot-1",
|
|
29
|
+
"@instructure/ui-scripts": "10.2.2-snapshot-1",
|
|
30
|
+
"@instructure/ui-test-utils": "10.2.2-snapshot-1",
|
|
31
|
+
"@testing-library/jest-dom": "^6.4.6",
|
|
32
|
+
"@testing-library/react": "^15.0.7",
|
|
33
|
+
"@testing-library/user-event": "^14.5.2",
|
|
34
|
+
"vitest": "^2.0.2"
|
|
29
35
|
},
|
|
30
36
|
"dependencies": {
|
|
31
37
|
"@babel/runtime": "^7.24.5",
|
|
32
|
-
"@instructure/console": "10.2.1",
|
|
33
|
-
"@instructure/emotion": "10.2.1",
|
|
34
|
-
"@instructure/shared-types": "10.2.1",
|
|
35
|
-
"@instructure/ui-a11y-content": "10.2.1",
|
|
36
|
-
"@instructure/ui-buttons": "10.2.1",
|
|
37
|
-
"@instructure/ui-icons": "10.2.1",
|
|
38
|
-
"@instructure/ui-motion": "10.2.1",
|
|
39
|
-
"@instructure/ui-react-utils": "10.2.1",
|
|
40
|
-
"@instructure/ui-themes": "10.2.1",
|
|
41
|
-
"@instructure/ui-view": "10.2.1",
|
|
38
|
+
"@instructure/console": "10.2.2-snapshot-1",
|
|
39
|
+
"@instructure/emotion": "10.2.2-snapshot-1",
|
|
40
|
+
"@instructure/shared-types": "10.2.2-snapshot-1",
|
|
41
|
+
"@instructure/ui-a11y-content": "10.2.2-snapshot-1",
|
|
42
|
+
"@instructure/ui-buttons": "10.2.2-snapshot-1",
|
|
43
|
+
"@instructure/ui-icons": "10.2.2-snapshot-1",
|
|
44
|
+
"@instructure/ui-motion": "10.2.2-snapshot-1",
|
|
45
|
+
"@instructure/ui-react-utils": "10.2.2-snapshot-1",
|
|
46
|
+
"@instructure/ui-themes": "10.2.2-snapshot-1",
|
|
47
|
+
"@instructure/ui-view": "10.2.2-snapshot-1",
|
|
42
48
|
"keycode": "^2",
|
|
43
49
|
"prop-types": "^15.8.1"
|
|
44
50
|
},
|